Lab 7 - P.S. It's Just a Stack
Due: Monday, November 1, 2004 at 9:00 AM
Short Answers
Complete the following problems from the book and turn them in as a
text file lab7.txt at the start of lab.
Lab Program
Do the laboratory in Section 9.5 in the Bailey book.
Before lab, copy the starter files from
here
on our text's web page. Familiarize yourself with these three
classes and make sure you understand how they work.
Come to lab with a handwritten sketch of the main class of your
PostScript interpreter (where you will process the tokens being
delivered to your interpreter by the provided iterator class).
A few things to consider as you implement this lab:
- Please name the file with your interpreter Interpreter.java.
- Make use of the functionality of the classes you are given to
start. Be careful not to spend time developing code that is already
there!
- Make your main method very short. All it should do is
create an Interpreter object and tell it to start parsing the
postscript program presented at the command line. Create a method
interpret that takes a single parameter of type java.util.Iterator (which will be an instance of the provided Reader class) and processes the PostScript tokens returned by that
Iterator.
- Develop your interpret method incrementally. Get your
simple push, pop, and pstack operations working, then move on to the
arithmetic operators, and finally the definition and usage of
symbols.
- Your program should throw exceptions when it encounters invalid
input, but these should contain meaningful error messages. You can
use Assert.condition() and Assert.fail() for this.
- Answer thought questions 1, 2, and 5.
- For an extra point, you can implement procedures as described in
thought question 3. If you design everything else properly, this
should be almost a trivial extension.
- For another extra point, you can implement the if operator
as described in thought question 4.
When you're finished, create and submit a tar file lab7.tar that
includes the following:
- Your well-documented source code for Interpreter.java.
- A README file that contains your answers to
thought questions 1, 2, and 5.
You should not include the three files from the textbook's web
page in your submitted tar file.