This assignment makes use of the files contained in this zip file. This assignment is due Tuesday, March 18.
This assignment is based on Language_7. You will add one new Value type to Language_7 (arrays), and several new expressions, to create Language_7a.
In the zip file there is a file Language_7a.txt
that describes the syntax and semantics of Language_7a. Your assignment is to add code to the interpreter for Language_7 so that the new interpreter can handle array values and array expressions. Language_7a also includes the for-loop expression from Assignment 3 and the increment/decrement expressions from Assignment 2.
The interpreter code is structured as it was in Assignment 3. The file Language_7.java
defines a class whose instances are interpreters for Language_7. To create a Language_7a interpreter, you subclass Language_7.java
and either override methods from Language_7.java
or add new methods. The file Language_7a.java
in the zip file is already set up to subclass Language_7.java
. To implement the Language_7a interpreter, you need to define several new methods in Language_7a.java
. You also need to modify the file Value.java
to add to it the new array type. (You will also copy some code from your solutions to Assignment 2 and Assignment 3 into the file Language_7a.java
.)
Also in the zip file there is the file AST2infix_7.java
which defines a class whose instances convert Language_7 ASTs into infix form. To create a Language_7a infix converter, you subclass AST2infix_7.java
. Create a subclass AST2infix_7a.java
of AST2infix_7.java
so that the subclass handles the new array syntax, the for-loop expression, and the increment/decrement expressions. The file AST2infix_7a.java
in the zip file is already set up to subclass AST2infix_7.java
. Notice that AST2infix_7a.java
currently contains "stub" methods that just convert the associated expression into its prefix form. These stub methods are there so that you can compile the code and work on the methods one at a time. You should eventualy rewrite each of the stub methods. (Creating temporary stub methods, so that you can incrementally solve a problem, is an important strategy for writing large programs.)
When you have finished implementing Language_7a.java
and AST2infix_7a.java
, include your version of PrettyPrinter2.java
from Assignments 2 and 3 in the hw4
folder. Then the file Language_7a_Examples.java
should compile and run. The output from running this program should look almost exactly like the file Language_7a_Examples_output.txt
(your output cannot look exactly like Language_7a_Examples_output.txt
because some of the output is randomly generated). Also, make sure that you didn't break anything from Language_7. The program Language_7_Examples.java
from the zip file should also compile and run correctly and the program's output should look exactly like the file Language_7_Examples_output.txt
.
To possibly help you with debugging, there is also in the zip file Language_7a_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_7a. You get the interpreter to produce all this output by setting
DEBUG = 1;
in the file Language_7.java
.
Turn in a zip file called CS502Hw4Surname.zip
(where Surname
is your last name) containing your versions of Language_7a.java
, Value.java
, AST2infix_7a.java
, and PrettyPrinter2.java
(just those four files).
This assignment is due Tuesday, March 18.