Roger L. Kraft

CS 50200 - Programming Assignment 3

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

This assignment is based on Language_6. You will add one new type of expression to Language_6 to create Language_6a.

In the zip file there is a file Language_6a.txt that describes the syntax of Language_6a, which adds a for-loop expression to Language_6. Your assignment is to add code to the interpreter for Language_6 so that the new interpreter can handle the new expression.

The for-loop in Language_6a should have the same semantics as a for-loop in C++ or Java. In particular, be sure to notice the difference between (using C++/Java notation)

      for (int i = 0; i < 2; i++)

and

      for (i = 0; i < 2; i++)

For the purpose of this assignment, the interpreter code is structured a bit differently than the interpreters we used in class. In this assignment, the file Language_6.java defines a class whose instances are interpreters for Language_6. Notice that the functions in Language_6.java are member functions, not static functions. To modify the Language_6 interpreter to create a Language_6a interpreter, you subclass Language_6.java and either override methods from Language_6.java or add new methods. The file Language_6a.java in the zip file is already set up to subclass Language_6.java. To implement the Language_6a interpreter, you need to define one new function in Language_6a.java

Also in the zip file there is the file AST2infix_6a.java. As distributed, this file converts Language_6 into infix form. Modify this file so that it handles the new for-loop expression. The infix notation for a for-loop should be exactly like its C++/Java counterpart.

When you have finished implementing Language_6a.java and AST2infix_6a.java, include your version of PrettyPrinter2.java from Assignment 2 in the hw3 folder. Then the file Language_6a_Examples.java should compile and run. The output from running this program should look exactly like the file Language_6a_Examples_output.txt. Also, make sure that you didn't break anything from Language_6. The program Language_6_Examples.java from the zip file should also compile and run correctly and the program's output should look exactly like the file Language_6_Examples_output.txt.

To possibly help you with debugging, there is also in the zip file Language_6a_Examples_output_debug.txt which includes all of the environment debugging output. It's a lot of text, but you might find it useful to trace how the environments are supposed to work in Language_6a. You get the interpreter to produce all this output by setting

       DEBUG = 1;

in the file Language_6.java.

Turn in a zip file called CS502Hw3Surname.zip (where Surname is your last name) containing your versions of Language_6a.java, AST2infix_6a.java, and PrettyPrinter2.java (just those three files).

This assignment is due Thursday, February 20.