This assignment makes use of the files contained in this zip file. This assignment is due Monday, March 8.
This assignment is based on Language_6 and programming assignment 2. You will add two new expressions to Language_6 and also the five operators from Langauage_3a to create Language_6a.
In the zip file there is a file Language_6a.txt
that describes the syntax and semantics of Language_6a. Language_6a adds for-loop and repeat-loop expressions to Language_6 and it also adds the five operators from Language_3a.
In the zip file there is the file Evaluate_6a.java
. As distributed, this file is the interpreter for Language_6. Your assignment is to copy your code for the five operators from Language_3a into Evaluate_6a.java
and then add code that handles the two new loop expressions.
The for-loop in Language_6a should have the same semantics as a for-loop in Java or C++. In particular, be sure to notice the difference between (using Java/C++ notation)
int i = 0; for (i = 1; i < 3; ++i)
and
for (int i = 1; i < 3; ++i)
In the second for-loop, the variable i
is declared local to the for-loop. In order to implement a local variable for a for-loop, your for-loop implementation will need to add an Environment
object to the current environment chain, much like the begin
expression. Your for-loop implementation should evaluate all four of the for-loop's expressions using the new environment chain (see the file Language_6a.txt
for more details).
The repeat-loop expression is, unlike the while-loop and for-loop, a "real" expression in that it can compute a useful value (a while-loop, or a for-loop, always evaluates to false
and is only useful for its side effects). A repeat-loop has two expressions. The second expression must evaluate to a boolean value. The first expression will provide the value of the repeat-loop expression. The repeat-loop first evaluates, and remembers the value of, its first expression. Then it evaluates its second expression. If the boolean value is false, then the repeat-loop is done and its value is the saved value from the first expression. If the boolean value is true, the repeat-loop should continue looping until the boolean value is false. The value of the repeat-loop expression will be the last evaluation of its first expression.
When you have finished implementing Evaluate_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 Language_6a_Examples_output_debug_0.txt
or Language_6a_Examples_output_debug_1.txt
, depending on how you set the debug level. To help you with debugging, Language_6a_Examples_output_debug_1.txt
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 the static variable
DEBUG = 1;
in the file Evaluate_6a.java
.
Also, make sure that you didn't break anything from Language_6. The program Language_6_Examples.java
from the zip file should compile and run correctly and the program's output should look exactly like Language_6_Examples_output_debug_0.txt
or Language_6_Examples_output_debug_1.txt
.
Turn in a zip file called CS51530Hw3Surname.zip
(where Surname
is your last name) containing your versions of Evaluate_6a.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, March 8.