University of New Brunswick, Faculty of Computer Science
CS4905 Introduction to Compiler Construction
PrettyPrintVisitor example for MiniJava grammar
The code for this example is saved as UNIX tar (tape archive) files. Download them to a UNIX machine, then untar the files in a subdirectory you create using the following command: tar xvf name.tar where "name" is replaced with the name of the tar file you wish to untar. For example, to untar the "syntaxtree.tar" file, you would type tar xvf syntaxtree.tar
To create a .tar file for the complete contents of a subdirectory, go to the subdirectory that you wish to create a .tar file for, and issue the following command: tar cvf name.tar . where "name" is replaced with the name of the tar file you wish to create. Don't forget the "." at the end of the command; it stands for the pathname of the current working directory.
syntaxtree.tar tape archive (.tar) file containing the abstract syntax tree classes for the MiniJava grammar. Constructors for these classes are defined on p.99 (Figure 4.9) of Appel. Each class definition has an accept method with a callback to the visit method of the visitor.
visitor.tar contains the Visitor.java interface definition and the PrettyPrintVisitor.java implementation of the Visitor interface. A visit method is defined for each abstract syntax class defined for the MiniJava grammar.
Partial solution to the MiniJava parser required for Lab 4. Missing are the definitions for nonterminals IntegerType, AssignmentStatement, WhileStatement, TimesExpression, FalseLiteral, Identifier
QuickSort.mj sample MiniJava program to test the PrettyPrintVisitor for Lab 4.