CS 50200 - Programming Assignment 6

This assignment makes use of the files contained in this zip file. This assignment is due Monday, November 15.

In this assignment, you will write an interpreter that adds two data types to language cs502-language-hw4. In the zip file there is a text file Language-Hw6.txt that defines the syntax and semantics of the language you are to interpret. Read this description carefully.

You are to add a double data type to the language and an array data type. You will also overload some of the interpreter's builtin operators to handle these data types. For example, the '+' operator should handle the sum of two integers, the sum of two doubles, the sum of a integer and a double, the sum of two arrays, the sum of an integer and an array, and the sum of a double and an array (notice that these last three kinds of sums do not exist in languages like C/C++/Java).

When you write your interpreter, first add the double data type and then get the arithmetic and relational operators overloaded for that type. Then implement the array type (with its index and sizeOf functions). Test your array type using while-loops. Finally, overload the '+', '*' and '^' operators for the array type.

The language defined in the file Language-Hw6.txt is a subset of the tree-language from the first homework assignment. A version of BuildTree.java from Assignment 1 is included in the zip file. Use it as the parser for this assignment's language.

In the zip file there is a file Evaluate.java that is supposed to be an interpreter for the Language-Hw6. You need to complete this interpreter. Start with your interpreter from homework assignment 4.

Also in the zip file there is a file AST2infix.java which is supposed to format strings from the Language-Hw6 in a "C like" notation that includes infix notation for arithmetic and boolean expressions. You need to complete this "translator". Your AST2infix.java program should use operator precedence to create an infix notation that uses the minimum number of needed parentheses. Start with your translator from homework assignment 4.

You will need to modify the file Value.java from zip file to implement the two new data types.

The files Tokenizer.java, Tree.java, BuildTree.java, PrettyPrinter.java, Environment.java, FunctionEnvironment.java, ParseException.java, and EvalException.java which are in the zip file, do not need to be modified. You should use them exactly as they are.

When you have finished implementing Evaluate.java, Value.java, and AST2infix.java, then the file Tests.java should compile and run. The output from running this program should look exactly like the file output.txt. Notice that Tests.java uses try-catch clauses to handle exceptions thrown by Evaluate.java. Your version of Evaluate.java should throw EvalException when it detects a runtime error.

In zip file there is also a file called output-long.txt that contains a lot of logging information about the interpreter's environments while executing Tests.java. This file is there to help you debug your interpreter. Sometimes you can look at this file and figure out what the interpreter should be doing.

Turn in a zip file containing your versions of Evaluate.java, Value.java, AST2infix.java, BuildTree.java, and PrettyPrint.java along with the other files from the zip file.

This assignment is due Monday, November 15.


Return to the main homework page.
Return to the CS 50200 home page.


compliments and criticisms