Computer Science 5641
Compiler Design
Project Part 4 (70 points)
Due December 15, 2009 (No Late Programs)
To complete the project you will now need to implement an interpreter for one of your parsers. You are welcome to use either your C++ or your Java parser in this section (and no, you do not have to do both). Again our language is the one found in math_language.html. You should implement the language by parsing a file of commands, then executing a statement at a time, before executing the statement you should type check that statement to make sure all of the operators can be correctly applied.
Implementation Rules
- A number with a decimal point is assumed to be a float. A number without a decimal point is assumed to be an integer. Arithmetic perations on ints produce ints, arithmetic operations on floats produce floats. Logical operations produce booleans. Arithmetic operations on an int and float produces a float. Logical operations on an int and float produces a boolean.
- An identifier is a variable which can hold a boolean, int, float or matrix.
- A matrix has one or more dimensions and all of the elements in a matrix should be of the same (base, non matrix) type.
- Unary - (and +) apply to ints, floats and matrices of ints or floats, when (-) applies to a matrix each of the elements in the matrix is negated.
- NOT applies to booleans and negates the boolean.
- The transpose operator (') applies to matrices and transposes that matrix.
- The binary +, -, and / operators apply to ints, floats and matrices of ints or floats that have the same dimensions. On a matrix the +, -, and / do an element wise addition (or subtraction or division) of the matrices (this is the same as .+ and .- ./).
- The binary * operator applies to ints and floats. The .* operator does an element-wise multiplaction of the matrices and the * does a matrix multiplication (checking that the dimensions allow this).
- The comparison operators <, >, <=, >= apply to ints and floats and do the corresponding comparison producing a boolean value.
- The == and != operator apply to any base type plus matrices of the same size checking equal or not equal (they return a boolean). For matrices the elements of the matrices are compared to determine if all are equal or any are not equal.
- The [ E E .. E ; E E ... E ; ... ] operation produces a matrix with the number of rows and columns specified. Note that the number of expressions in each row group (separated by ;) must be the same. If no ; is provided the matrix is one dimensional.
- A matrix lookup is done using the matrix name, a ( expression for each dimension separated by commas and a ). Each expression must produce an integer.
- The ones and zeros functions produce arrays as discussed in the language notes.
- The Identifier = Expression operator assigns the value Expression to the variable Identifier (replacing any existing variable).
- A matrix reference can be used in the place of an identifier in an assignment to set that matrix location.
- The print(Expression) statement works on boolean, integer and float values.
- In an if and a while the Expression must return a boolean value.
- A for loop applies only to integer expressions.
- Your error messages should be reasonable, telling the user where in a file the error occurred. Note that you only need provide one error message for the first error noticed.
- Runtime errors should be caught and supplied to the user.
Testing
Test your code on a variety of input files showing each of the errors you can capture as well as how each command executes. Also, attempt to implement a larger programming (calculating the inverse of a matrix if possible) to show off your code's capabilities. Note that you will be graded on how completely you test your code..
Writeup
Document your code and your testing. You should writeup a summary of the system. In addition, each student should write up an assessment of their teammates performance.
Extra Credit (up to 20 points)
Make a second version of your code that reads and executes individual statements from a command line. If you do this make sure to test this code as well. In this version you may want to add an extra command to show all of the variables that have been defined.