MC97 Lab 1: Warm-Up Interpreter (Spring 1999)
Due: February 17, 1999
For this lab, you are to do the two problems listed on page 12 of the
textbook.
First, copy the three files that Appel provides into the directory
you are going to work in and look at them. They are
You can access these three files off of this web page or copy them
from the directory ~max/www-docs/courses/S1999/MC97/labs/lab1/.
Next, compile and run the program as it stands. This will print out
a 0, because the maxargs procedure is a stub that pretends the answer
is always 0 and the interp is a stub that does nothing. Once you have
written maxargs, you will get a real answer in place of 0, and once
you have written interp, that count will be followed by the sample
program's output. In order to compile the program, you need to give
the following three commands:
javac slp.java
javac prog.java
javac interp.java
Because of the way in which Appel packaged the program into files, you
need to give the three javac commands separately and in the order
shown. Once the program is compiled, you can run it as follows:
java interp
Now you should write maxargs and interp, testing your work as you
go. Here are some pointers:
- If a program contains multiple prints, Appel does not clearly
specify the order in which the output should appear, particularly if
there is nesting. For example, what should the output be from print(3,
(print(5), 8))? Decide what you think is reasonable, document it, and
implement it.
- It is probably easiest to cave in to Appel's non-object-oriented
style, using instanceof. However, you could also avoid instanceof in
either of two ways:
- by adding maxargs and interp methods to the various classes in
slp.java, or
- by using the Visitor pattern, as I'll describe in class, which
requires slp.java to be modified, but in a generalized way
(independent of specific tree traversals such as maxargs and interp),
with the traversal-specific code remaining in interp.java.
- In any case, you may well want to add classes and methods other
than those Appel mentions
Your lab report should include the tests you used as well as your
code.
Instructor: Max Hailperin