Writing Compilers and Interpreters (3rd edition):
A Software Engineering Approach
by Ronald Mak
Published by John Wiley & Sons, Inc.
Comments, criticisms, or suggestions? Please send them to firstname.lastname@example.org.
Each chapter's Java code is packed in a jar file. Click on a link below to download the jar file containing the corresponding chapter's code:
To extract the code for Chapter 12, for example, enter the command
jar -xvf Chapter12.jar
to create the directory Chapter12 containing the Java source tree.
To compile the Java code for Chapter 12, for example, enter the commands:
cd Chapter12 mkdir classes javac -classpath classes -d classes -sourcepath src src/*.java
Of course, a much better way to work with the Java source tree is to load it into a development environment such as the Eclipse IDE for Java developers.
After compiling the Java code for Chapter 12, for example, the following command (entered while in directory Chapter12) will interpret the Pascal program hilbert.pas (enter 5 when it prompts for the rank):
java -classpath classes Pascal execute hilbert.pas
To view the cross-reference table and the intermediate code (parse trees), include the -x and -i options, respectively. You can combine the options as -ix:
java -classpath classes Pascal execute -ix hilbert.pas
The book describes each of the options i, x, l, a, f, c, and r.