MC97 Lab 3: Parsing and AST generation (Spring 1999)

Due: March 10, 1999

For this lab, you are to do the parsing and AST generation assignments from pages 83-84 and 106 of the textbook. You need not turn in a separate solution for the chapter 3 part; it should be included in your solution to the chapter 4 portion. However, it may be to your advantage to deal with the chapter 3 issues (parsing) first, and only then move on to chapter 4 (AST generation).

First, copy the chap3 directory and the chap4 directory of files that Appel provides into the directory you are going to work in and look at them. You can access the chap3 directory off of this web page or copy it from ~max/www-docs/courses/S1999/MC97/tiger/chap3 and similarly for chap4. The simplest way to do this would be using the command

cp -pr ~max/www-docs/courses/S1999/MC97/tiger/chap[34] .
which will give you your very own chap3 and chap4 directory trees, just like mine. Note that I have fixed a couple bugs in Appel's code; if you for some reason want to use the code from his web site instead of mine, you'll need to make those same fixes.

Next, copy your chap2/Parse/Tiger.lex into chap3/Parse. Then compile the program as it stands. To do this, change directory to the chap3 directory, set your CLASSPATH environment variable so that java can find JLex and java_cup, and then run the make command:

cd chap3
setenv CLASSPATH ~max/JavaLib:.
make
To test this initial minimal version of the lexical analyzer, make a file (called foo.tig, for instance) containing nothing but a single identifier (possibly with spaces, newlines, and comments). Then give the command
java Parse.Main foo.tig
This should terminate silently, which is the sign of a successful parse. If you now repeat the experiment, but with foo.tig containing any other sequence of tokens, you should get a syntax error reported. This is because the initial grammar specifies that a program is nothing but a single identifier.

Your lab report should include documentation of design and testing as well as your code.

Tips regarding tiger/chap3

Tips regarding tiger/chap4


Instructor: Max Hailperin