This assignment makes use of the files contained in this zip file.
This assignment is due Monday, September 20.
This assignment is based on the language cs502-language-6 from the second week of class.
Language cs502-language-6 defined, and interpreted, arithmetic and boolean binary expressions with local variables and nested scopes. In this assignment, you will write an interpreter for a language of arithmetic and boolean expressions with local variables and nested scopes where the operators are not all binary. In the zip file there is a text file cs502-language-hw3.txt that defines the syntax and semantics of the language you are to interpret. Read this description carefully, since there are several important differences between this language and language cs502-language-6.
The language defined in the file cs502-language-hw3.txt is a subset of the tree-language from the first homework assignment. You should use your program BuildTree.java from Assignment 1 as the parser for this assignment's language cs502-language-hw3 . In other words, use your version of BuildTree.java to build the "abstract syntax trees" that will be needed by your interpreter of language cs502-language-hw3.
In the zip file there is a file Evaluate.java that is supposed to be an interpreter for the language cs502-language-hw3 . You need to complete this interpreter. Your interpreter should essentially do a post-order traversal of the abstract syntax tree produced by your program BuildTree.java .
Also in the zip file there is a file AST2infix.java which is supposed to format strings from the language cs502-language-hw3 in infix notation. 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. Notice that you will need to treat Var and Set terms as "operators" for the purposes of this program.
Use the pretty-printer that you wrote in Assignment 2 to give well formatted displays of the expressions from language cs502-language-hw3 .
The files Tokenizer.java , Tree.java , Value.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 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. From the contents of the file output.txt you can see what kinds of runtime errors your Evaluate.java should be able to detect.
Turn in a zip file containing your versions of Evaluate.java , AST2infix.java , BuildTree.java , and PrettyPrint.java along with the other files from the zip file.
This assignment is due Monday, September 20.
|