CS 50200 - Programming Assignment 2

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

This assignment is based on the languages cs502-language-2 and cs502-language-3 from the first week of class.

Languages cs502-language-2 and cs502-language-3 defined, and interpreted, arithmetic and boolean binary expressions. In this assignment, you will write an interpreter for a language of arithmetic and boolean expressions where the operators need not all be binary. In the zip file there is a text file cs502-language-hw2.txt that defines the syntax and semantics of the language you are to interpret.

The language defined in the file cs502-language-hw2.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-hw2. In other words, use your version of BuildTree.java to build the 'abstract syntax trees" that will be needed by your interpreter.

In the zip file there is a file Evaluate.java that is supposed to be an interpreter for the language cs502-language-hw2. 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.

In Assignment 1 you wrote a pretty-printer for the tree language. But this pretty-printer is too verbose, it takes too many lines to print a tree. So for this assignment you should write a better pretty-printer. Look in the zip file at the file output.txt, which is sample output from the program Tests.java, to see how the new pretty-printer should format a tree. Notice that a pretty-printer is essentially a pre-order traversal of the abstract syntax tree created by your program BuildTree.java.

Also in the zip file there is a file AST2infix.java which is supposed to format the strings from cs502-language-hw2 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 converting an expression tree into infix notation is essentially a in-order traversal of the tree.

The files Tokenizer.java, Tree.java, and Value.java, which are in zip file, do not need to be modified. You should use them exactly as they are.

When you have finished implementing Evaluate.java, PrettyPrint.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.

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

This assignment is due Monday, September 13.


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


compliments and criticisms