Programming Assignment 2
CS 51530
Programming Languages, Interpreters and Compilers
Spring, 2021

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

This assignment is based on Language_3. This is not a difficult assignment. It is meant to help you familiarize yourself with the interpreter code for Language_3.

In the zip file there is a file Language_3a.txt that describes a new language. Language_3a adds five new operators to Language_3. Your assignment is to add code to the interpreter for Language_3 so that the new interpreter can handle the new operators.

In the zip file there is the file Evaluate_3a.java. As distributed, this file is the interpreter for Language_3. Modify this file so that it handles the five new operators described in Language_3a.txt.

In the zip file there is a prettyprinter for trees, PrettyPrinter.java. But this prettyprinter is very verbose. Write a prettyprinter, called PrettyPrinter2.java, that does the following.

  1. It always puts the left node inline with the root.
  2. It handles the special case when depth==1 by putting everything inline with the root.
  3. It handles the special case when depth==2 by putting everything inline with the root.
  4. All non-inlined child nodes are vertically aligned with the left node.
  5. All consecutive closing parentheses are at the end of a line.

In the zip file there are output files Language_3_Examples_output.txt and Language_3a_Examples_output.txt. Look at that them to get a idea of what the prettyprinter should produce.

When you have finished implementing Evaluate_3a.java and PrettyPrinter2.java, then the file Language_3a_Examples.java should compile and run. The output from running this program should look exactly like the file Language_3a_Examples_output.txt. Also, make sure that you didn't break anything from Language_3. The program Language_3_Examples.java from the zip file should also compile and run correctly and the program's output should look exactly like the file Language_3_Examples_output.txt (every Language_3 expression is also a valid Language_3a expression).

You can interactively test your interpreter by using the two shell scripts build_all_classes.cmd and build_jar_file.cmd to build a REPL from your interpreter. Those two scripts build a jar file, Language_3a.jar, and then the script Language_3a.cmd will run the jar file.

Turn in a zip file called CS51530Hw2Surname.zip (where Surname is your last name) containing your versions of Evaluate_3a.java and PrettyPrinter2.java (just those two files). Be sure to put your name and email address in every file your turn in.

This assignment is due Monday, February 15.