Final Report Polynomial Manipulation Language PML COMS 4115 Programming Languages and Translators Melinda Agyekum Shezan Baig Hari Kurup Subadhra Sridharan December 18 2003 Contents 1 An Introduction to PML 1 1 Background 5 1 2 Language Features 7 1 3 Language Implementations 8 1 4 PML Scope and Limitation 9 2 Tutorial 2 1 A Simple PML Program 10 2 2 Compiling and Running PML 10 2 3 A More Complex Problem 12 3 Language Reference Manual 3 1 Lexical Conventions 12 3 1 1 Comments 12 3 1 2 Identifiers Names 13 3 1 3 Keywords 13 3 1 4 Type Specifiers 13 3 1 4 1 int 13 3 1 4 2 float 13 3 1 4 3 term 13 3 1 4 4 poly 14 3 1 4 5 polyeq 14 3 1 4 6 termarray 14 3 1 4 7 chararry 14 3 1 4 8 string literals 14 3 2 Conversions 14 3 3 Expressions 15 3 3 1 Identifiers 15 3 3 2 expression 15 3 3 3 Operators 15 3 3 3 1 Multiplicative 15 3 3 3 1 1 expr expr 15 3 3 3 1 2 expr expr 16 3 3 3 2 Additive 16 3 3 3 2 1 expr expr 16 3 3 3 2 2 expr expr 17 3 3 3 3 Relational 19 3 3 3 3 1 Equality 19 3 3 3 4 Power 19 3 4 Declarations 19 3 5 Statements 20 3 5 1 Compound Statement 20 3 5 2 Conditional Statement 21 3 5 3 Loop Statement 21 3 5 4 Break Statement 21 3 5 5 Return Statement 21 3 5 6 Print Statement 21 3 6 External Definition 22 3 7 Scope Rules 22 3 7 1 Global Scope 22 3 7 2 Local Scope 23 3 7 3 Relationship Between Global and Local Scope 26 3 8 NameSpace Rules 27 3 9 Entry Point 27 3 10 Semantics For Variable Initiation 27 3 10 1 Local Variables 28 3 10 2 Global Variables 28 4 Project Plan 4 1 Project Process 31 4 1 1 Planning and Specification 31 4 1 2 Development and Testing 31 4 2 Team Responsibilities 31 4 3 Programming style Coding Conventions 31 4 3 1 ANTLR Conventions 31 4 3 2 JAVA Conventions 32 4 4 Project Timeline 32 4 5 Software Development Environment 33 4 6 Project Log 33 5 Architecture Design 5 1 Compiler Overview 33 5 2 Lexer 34 5 3 Parser 35 5 4 Walker and Executor 35 5 4 1 class PMLRuntimeEnvironment 36 5 4 2 class PMLCompilationUnit 36 5 4 3 abstract class PMLVariable 36 5 4 4 abstract class PMLFunction 37 5 4 5 class PMLSymbolTable 37 5 4 6 interface PMLFunctionInstance 37 5 4 7 interface PMLStatement 37 5 4 8 interface PMLExpression 37 5 5 Back End 38 6 Testing Plan 6 1 Unit Testing 38 6 2 Integrated Testing 38 6 3 Regression Testing 39 7 Lessons Learned 7 1 Quotes 39 7 2 Future Plans 40 Appendix A Standard Library Functions 42 Appendix B Source Code 44 Chapter 1 Introduction Polynomial equations are mathematical representations of real world problems and are used in a variety of professional fields These mathematical expressions are written as the sum of the products of numbers and variables A few practical applications which rely heavily on polynomial expressions are missile trajectory weather forecasting spacecraft re entry building construction and financial market calculations One example of a real world problem where polynomial functions are applied is testing the effectiveness of a new drug The quantity of medication given to a person under testing can be varied and the improvement or degradation can be noted There may be other variables which can be applied to the same problem like the patient s age weight and other existing medical conditions if any Regardless of the situation the use of polynomials can provide an individual better insight into a problem Although polynomials are extremely important components of algebra solving these problems manually can be a time consuming and tedious process It is because of this there is a need for a system which will perform computations in a methodical way irrespective of the problem at hand The polynomial manipulation language PML tool is a programming language built for flexible manipulation of polynomial expressions With its extensive set of built in operations and functions PML can be used to specify an algorithm involving polynomials In addition this language is easy to understand allowing this to be a user friendly language for programmers to enjoy PML is designed for manipulating symbolic mathematical computations In contrast to numerical computation PML emphasizes computing with symbols representing mathematical concepts The input to algorithms will be expressions or polynomial equations while the output of the translations will be returned in algebraic form From such an expression one can deduce how the change in parameters will affect the result of computation Although PML will be able to handle numbers and symbols with equal capacity the primary role of this application is to facilitate symbolic computational programs 1 1 Background Given below is a brief description about types of polynomials and equations supported by PML Polynomials A polynomial is a mathematical expression involving a sum of powers multiplied by coefficients Broadly classified there are two types of polynomials depending on the number of unique variables within the equations These types are called univariate and multivariate polynomials Univariate Polynomial A polynomial expressed in one variable is known as a univariate polynomial An example of a univariate polynomial can be found below in Eq 1 cixi ci 1x i 1 c0 Eq 1 In the aforementioned expression ci ci 1 terms each represent coefficients while the superscripts represent the degree of each term This polynomial has only one variable which is represented by x Multivariate Polynomial A polynomial expressed in more than one variable is known as a multivariate polynomial An example of a multivariate polynomial can be found below in Equation 2 cixiyi ci 1x i 1 y i 1 ci Eq 2 This equation is expressed using two variables x and y Linear Equations Polynomials equations of the form ax b c Eq 3 are called linear equations having only one variable whose degree is one All other equations not in the form mentioned by Eq 3 are non liner equations Quadratic Equations All polynomials equations of the form ax2 bx c 0 Eq 4 are called quadratic equations Quadratic equations are second order degree equations and the roots of the equation can be determined using the quadratic formula Roots and Factoring A root of a polynomial P z is a number zi such that P zi 0 A polynomial of n degrees has n roots A factor is any number that divides a given number evenly without a remainder If r is a root of a polynomial equation f x 0 then x r is a factor of the polynomial f x PML supports all of the above mentioned types of polynomials and equations and more 1 2 LANGUAGE FEATURES PML contains several features enabling it to be
View Full Document
Unlocking...