MC97 Lab 2: Lexical Analysis (Spring 1999)

Due: February 24, 1999

For this lab, you are to do the lexical analysis assignment from pages 34-35 of the textbook.

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

cp -pr ~max/www-docs/courses/S1999/MC97/tiger/chap2 .
which will give you your very own chap2 directory tree, 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, compile the program as it stands. To do this, change directory to the chap2 directory, set your CLASSPATH environment variable so that java can find JLex and java_cup, and then run the make command:

cd chap2
setenv CLASSPATH ~max/JavaLib:.
make
To test this initial minimal version of the lexical analyzer, make a file (called commas.tig, for instance) containing nothing but commas, spaces, and newlines. Then give the command
java Parse.Main commas.tig
This should report the position in your file of each comma and of the end of file.

Here are some tips for extending this lexical analyzer to the full Tiger language:

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


Instructor: Max Hailperin