summaryrefslogtreecommitdiff
path: root/src/minijava/visitor
diff options
context:
space:
mode:
Diffstat (limited to 'src/minijava/visitor')
-rw-r--r--src/minijava/visitor/BuildSymbolTableVisitor.java732
-rw-r--r--src/minijava/visitor/DepthFirstVisitor.java623
-rw-r--r--src/minijava/visitor/GJDepthFirst.java727
-rw-r--r--src/minijava/visitor/GJNoArguDepthFirst.java727
-rw-r--r--src/minijava/visitor/GJNoArguVisitor.java416
-rw-r--r--src/minijava/visitor/GJVisitor.java415
-rw-r--r--src/minijava/visitor/GJVoidDepthFirst.java633
-rw-r--r--src/minijava/visitor/GJVoidVisitor.java416
-rw-r--r--src/minijava/visitor/Visitor.java416
9 files changed, 5105 insertions, 0 deletions
diff --git a/src/minijava/visitor/BuildSymbolTableVisitor.java b/src/minijava/visitor/BuildSymbolTableVisitor.java
new file mode 100644
index 0000000..d8d40f1
--- /dev/null
+++ b/src/minijava/visitor/BuildSymbolTableVisitor.java
@@ -0,0 +1,732 @@
+/**
+ * 用于建立符号表的类
+ */
+package minijava.visitor;
+
+import java.util.Enumeration;
+
+import minijava.symboltable.*;
+import minijava.syntaxtree.*;
+import minijava.typecheck.PrintError;
+
+public class BuildSymbolTableVisitor extends GJDepthFirst<MType, MType> {
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public MType visit(NodeList n, MType argu) {
+ MType _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public MType visit(NodeListOptional n, MType argu) {
+ if ( n.present() ) {
+ MType _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+ else
+ return null;
+ }
+
+ public MType visit(NodeOptional n, MType argu) {
+ if ( n.present() )
+ return n.node.accept(this,argu);
+ else
+ return null;
+ }
+
+ public MType visit(NodeSequence n, MType argu) {
+ MType _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public MType visit(NodeToken n, MType argu) { return null; }
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public MType visit(Goal n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public MType visit(MainClass n, MType argu) {
+ MType _ret=null;
+ MClass m_class;
+ String class_name;
+ String error_msg;
+
+ n.f0.accept(this, argu);
+
+ // 处理类定义的标识符Identifier()
+ // 获得名字
+ class_name = ((MIdentifier) n.f1.accept(this, argu)).getName();
+
+ // 在符号表中插入该类,如果出错,打印出错信息
+ m_class = new MClass(class_name, (MClasses) argu, n.f1.f0.beginLine,
+ n.f1.f0.beginColumn);
+ error_msg = ((MClasses) argu).InsertClass(m_class);
+ if (error_msg != null)
+ PrintError.print(m_class.getLine(), m_class.getColumn(), error_msg);
+
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ // main的参数,待处理
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ n.f13.accept(this, argu);
+ // printStatement
+ n.f14.accept(this, argu);
+ n.f15.accept(this, argu);
+ n.f16.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public MType visit(TypeDeclaration n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public MType visit(ClassDeclaration n, MType argu) {
+ MType _ret = null;
+ MClass m_class;
+ String class_name;
+ String error_msg;
+
+ n.f0.accept(this, argu);
+
+ // 处理类定义的标识符Identifier()
+ // 获得名字
+ class_name = ((MIdentifier) n.f1.accept(this, argu)).getName();
+
+ // 在符号表中插入该类,如果出错,打印出错信息
+ m_class = new MClass(class_name, (MClasses) argu, n.f1.f0.beginLine,
+ n.f1.f0.beginColumn);
+ error_msg = ((MClasses) argu).InsertClass(m_class);
+ if (error_msg != null)
+ PrintError.print(m_class.getLine(), m_class.getColumn(), error_msg);
+
+ n.f2.accept(this, argu);
+ n.f3.accept(this, m_class);
+ n.f4.accept(this, m_class);
+ n.f5.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public MType visit(ClassExtendsDeclaration n, MType argu) {
+ MType _ret=null;
+ MClass m_class;
+ String class_name;
+ String error_msg;
+
+ n.f0.accept(this, argu);
+
+ // 处理子类定义,并加入符号表
+ class_name = ((MIdentifier) n.f1.accept(this, argu)).getName();
+ m_class = new MClass(class_name, (MClasses) argu, n.f1.f0.beginLine,
+ n.f1.f0.beginColumn);
+ error_msg = ((MClasses) argu).InsertClass(m_class);
+ if (error_msg != null)
+ PrintError.print(m_class.getLine(), m_class.getColumn(), error_msg);
+
+ n.f2.accept(this, argu);
+
+ // 将父类名称加入类属性
+ m_class.extend_class_name = ((MIdentifier) n.f3.accept(this, argu)).getName();
+
+ n.f4.accept(this, argu);
+ n.f5.accept(this, m_class);
+ n.f6.accept(this, m_class);
+ n.f7.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public MType visit(VarDeclaration n, MType argu) {
+ MType _ret=null;
+ MClass m_class = (MClass)argu;
+ String var_name = n.f1.accept(this, argu).getName();
+ String type_name = n.f0.accept(this, argu).getName();
+ // debug
+ System.out.println("Variable: \'" + var_name + "\' from class " + m_class.getName());
+ System.out.println("It has type: " + type_name);
+
+ // 建立并插入变量
+ MVariable var = new MVariable(var_name, type_name, n.f1.f0.beginLine, n.f1.f0.beginColumn);
+ String _err = m_class.insertVar(var);
+ if (_err!=null) {
+ // 重复定义,则输出错误信息
+ PrintError.print(var.getLine(), var.getColumn(), _err);
+ }
+
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public MType visit(MethodDeclaration n, MType argu) {
+ MType _ret = null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public MType visit(FormalParameterList n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public MType visit(FormalParameter n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public MType visit(FormalParameterRest n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public MType visit(Type n, MType argu) {
+ return n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public MType visit(ArrayType n, MType argu) {
+ MType _ret = new MIdentifier(MIdentifier.arrType, n.f0.beginLine, n.f0.beginColumn);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public MType visit(BooleanType n, MType argu) {
+ MType _ret = new MIdentifier(MIdentifier.boolType, n.f0.beginLine, n.f0.beginColumn);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public MType visit(IntegerType n, MType argu) {
+ MType _ret = new MIdentifier(MIdentifier.intType, n.f0.beginLine, n.f0.beginColumn);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public MType visit(Statement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public MType visit(Block n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public MType visit(AssignmentStatement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public MType visit(ArrayAssignmentStatement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public MType visit(IfStatement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public MType visit(WhileStatement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public MType visit(PrintStatement n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public MType visit(Expression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public MType visit(AndExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public MType visit(CompareExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public MType visit(PlusExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public MType visit(MinusExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public MType visit(TimesExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public MType visit(ArrayLookup n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public MType visit(ArrayLength n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public MType visit(MessageSend n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public MType visit(ExpressionList n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public MType visit(ExpressionRest n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public MType visit(PrimaryExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public MType visit(IntegerLiteral n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public MType visit(TrueLiteral n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public MType visit(FalseLiteral n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public MType visit(Identifier n, MType argu) {
+ String identifier_name = n.f0.toString();
+ MType _ret = null;
+ _ret = new MIdentifier(identifier_name, n.f0.beginLine, n.f0.beginColumn);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public MType visit(ThisExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public MType visit(ArrayAllocationExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public MType visit(AllocationExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public MType visit(NotExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public MType visit(BracketExpression n, MType argu) {
+ MType _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+} \ No newline at end of file
diff --git a/src/minijava/visitor/DepthFirstVisitor.java b/src/minijava/visitor/DepthFirstVisitor.java
new file mode 100644
index 0000000..57d16c2
--- /dev/null
+++ b/src/minijava/visitor/DepthFirstVisitor.java
@@ -0,0 +1,623 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import java.util.Enumeration;
+
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.Node;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * Provides default methods which visit each node in the tree in depth-first
+ * order. Your visitors may extend this class.
+ */
+public class DepthFirstVisitor implements Visitor {
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public void visit(NodeList n) {
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); )
+ e.nextElement().accept(this);
+ }
+
+ public void visit(NodeListOptional n) {
+ if ( n.present() )
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); )
+ e.nextElement().accept(this);
+ }
+
+ public void visit(NodeOptional n) {
+ if ( n.present() )
+ n.node.accept(this);
+ }
+
+ public void visit(NodeSequence n) {
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); )
+ e.nextElement().accept(this);
+ }
+
+ public void visit(NodeToken n) { }
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public void visit(Goal n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public void visit(MainClass n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ n.f8.accept(this);
+ n.f9.accept(this);
+ n.f10.accept(this);
+ n.f11.accept(this);
+ n.f12.accept(this);
+ n.f13.accept(this);
+ n.f14.accept(this);
+ n.f15.accept(this);
+ n.f16.accept(this);
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public void visit(TypeDeclaration n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public void visit(ClassDeclaration n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public void visit(ClassExtendsDeclaration n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public void visit(VarDeclaration n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public void visit(MethodDeclaration n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ n.f8.accept(this);
+ n.f9.accept(this);
+ n.f10.accept(this);
+ n.f11.accept(this);
+ n.f12.accept(this);
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public void visit(FormalParameterList n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public void visit(FormalParameter n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public void visit(FormalParameterRest n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public void visit(Type n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public void visit(ArrayType n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public void visit(BooleanType n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public void visit(IntegerType n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public void visit(Statement n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public void visit(Block n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public void visit(AssignmentStatement n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public void visit(ArrayAssignmentStatement n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public void visit(IfStatement n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public void visit(WhileStatement n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public void visit(PrintStatement n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public void visit(Expression n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(AndExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(CompareExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(PlusExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(MinusExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(TimesExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public void visit(ArrayLookup n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public void visit(ArrayLength n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public void visit(MessageSend n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public void visit(ExpressionList n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public void visit(ExpressionRest n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public void visit(PrimaryExpression n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public void visit(TrueLiteral n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public void visit(FalseLiteral n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Identifier n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public void visit(ThisExpression n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public void visit(ArrayAllocationExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public void visit(AllocationExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public void visit(NotExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public void visit(BracketExpression n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ }
+
+}
diff --git a/src/minijava/visitor/GJDepthFirst.java b/src/minijava/visitor/GJDepthFirst.java
new file mode 100644
index 0000000..3b3889e
--- /dev/null
+++ b/src/minijava/visitor/GJDepthFirst.java
@@ -0,0 +1,727 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import java.util.Enumeration;
+
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.Node;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * Provides default methods which visit each node in the tree in depth-first
+ * order. Your visitors may extend this class.
+ */
+public class GJDepthFirst<R,A> implements GJVisitor<R,A> {
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public R visit(NodeList n, A argu) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public R visit(NodeListOptional n, A argu) {
+ if ( n.present() ) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+ else
+ return null;
+ }
+
+ public R visit(NodeOptional n, A argu) {
+ if ( n.present() )
+ return n.node.accept(this,argu);
+ else
+ return null;
+ }
+
+ public R visit(NodeSequence n, A argu) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public R visit(NodeToken n, A argu) { return null; }
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public R visit(Goal n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public R visit(MainClass n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ n.f13.accept(this, argu);
+ n.f14.accept(this, argu);
+ n.f15.accept(this, argu);
+ n.f16.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public R visit(TypeDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public R visit(ClassDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public R visit(ClassExtendsDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public R visit(VarDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public R visit(MethodDeclaration n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public R visit(FormalParameterList n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public R visit(FormalParameter n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public R visit(FormalParameterRest n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public R visit(Type n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public R visit(ArrayType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public R visit(BooleanType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public R visit(IntegerType n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public R visit(Statement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public R visit(Block n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public R visit(AssignmentStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public R visit(ArrayAssignmentStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public R visit(IfStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public R visit(WhileStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public R visit(PrintStatement n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public R visit(Expression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(AndExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(CompareExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(PlusExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(MinusExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(TimesExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public R visit(ArrayLookup n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public R visit(ArrayLength n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public R visit(MessageSend n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public R visit(ExpressionList n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public R visit(ExpressionRest n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public R visit(PrimaryExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public R visit(TrueLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public R visit(FalseLiteral n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Identifier n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public R visit(ThisExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public R visit(ArrayAllocationExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public R visit(AllocationExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public R visit(NotExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public R visit(BracketExpression n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ }
+
+}
diff --git a/src/minijava/visitor/GJNoArguDepthFirst.java b/src/minijava/visitor/GJNoArguDepthFirst.java
new file mode 100644
index 0000000..b44ecbc
--- /dev/null
+++ b/src/minijava/visitor/GJNoArguDepthFirst.java
@@ -0,0 +1,727 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import java.util.Enumeration;
+
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.Node;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * Provides default methods which visit each node in the tree in depth-first
+ * order. Your visitors may extend this class.
+ */
+public class GJNoArguDepthFirst<R> implements GJNoArguVisitor<R> {
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public R visit(NodeList n) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public R visit(NodeListOptional n) {
+ if ( n.present() ) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this);
+ _count++;
+ }
+ return _ret;
+ }
+ else
+ return null;
+ }
+
+ public R visit(NodeOptional n) {
+ if ( n.present() )
+ return n.node.accept(this);
+ else
+ return null;
+ }
+
+ public R visit(NodeSequence n) {
+ R _ret=null;
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this);
+ _count++;
+ }
+ return _ret;
+ }
+
+ public R visit(NodeToken n) { return null; }
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public R visit(Goal n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public R visit(MainClass n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ n.f8.accept(this);
+ n.f9.accept(this);
+ n.f10.accept(this);
+ n.f11.accept(this);
+ n.f12.accept(this);
+ n.f13.accept(this);
+ n.f14.accept(this);
+ n.f15.accept(this);
+ n.f16.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public R visit(TypeDeclaration n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public R visit(ClassDeclaration n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public R visit(ClassExtendsDeclaration n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public R visit(VarDeclaration n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public R visit(MethodDeclaration n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ n.f7.accept(this);
+ n.f8.accept(this);
+ n.f9.accept(this);
+ n.f10.accept(this);
+ n.f11.accept(this);
+ n.f12.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public R visit(FormalParameterList n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public R visit(FormalParameter n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public R visit(FormalParameterRest n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public R visit(Type n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public R visit(ArrayType n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public R visit(BooleanType n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public R visit(IntegerType n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public R visit(Statement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public R visit(Block n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public R visit(AssignmentStatement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public R visit(ArrayAssignmentStatement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public R visit(IfStatement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ n.f6.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public R visit(WhileStatement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public R visit(PrintStatement n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public R visit(Expression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(AndExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(CompareExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(PlusExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(MinusExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(TimesExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public R visit(ArrayLookup n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public R visit(ArrayLength n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public R visit(MessageSend n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ n.f5.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public R visit(ExpressionList n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public R visit(ExpressionRest n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public R visit(PrimaryExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public R visit(TrueLiteral n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public R visit(FalseLiteral n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Identifier n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public R visit(ThisExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public R visit(ArrayAllocationExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public R visit(AllocationExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public R visit(NotExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public R visit(BracketExpression n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ }
+
+}
diff --git a/src/minijava/visitor/GJNoArguVisitor.java b/src/minijava/visitor/GJNoArguVisitor.java
new file mode 100644
index 0000000..3ef4ecc
--- /dev/null
+++ b/src/minijava/visitor/GJNoArguVisitor.java
@@ -0,0 +1,416 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * All GJ visitors with no argument must implement this interface.
+ */
+
+public interface GJNoArguVisitor<R> {
+
+ //
+ // GJ Auto class visitors with no argument
+ //
+
+ public R visit(NodeList n);
+ public R visit(NodeListOptional n);
+ public R visit(NodeOptional n);
+ public R visit(NodeSequence n);
+ public R visit(NodeToken n);
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public R visit(Goal n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public R visit(MainClass n);
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public R visit(TypeDeclaration n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public R visit(ClassDeclaration n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public R visit(ClassExtendsDeclaration n);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public R visit(VarDeclaration n);
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public R visit(MethodDeclaration n);
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public R visit(FormalParameterList n);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public R visit(FormalParameter n);
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public R visit(FormalParameterRest n);
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public R visit(Type n);
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public R visit(ArrayType n);
+
+ /**
+ * f0 -> "boolean"
+ */
+ public R visit(BooleanType n);
+
+ /**
+ * f0 -> "int"
+ */
+ public R visit(IntegerType n);
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public R visit(Statement n);
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public R visit(Block n);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public R visit(AssignmentStatement n);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public R visit(ArrayAssignmentStatement n);
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public R visit(IfStatement n);
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public R visit(WhileStatement n);
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public R visit(PrintStatement n);
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public R visit(Expression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(AndExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(CompareExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(PlusExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(MinusExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(TimesExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public R visit(ArrayLookup n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public R visit(ArrayLength n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public R visit(MessageSend n);
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public R visit(ExpressionList n);
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public R visit(ExpressionRest n);
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public R visit(PrimaryExpression n);
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n);
+
+ /**
+ * f0 -> "true"
+ */
+ public R visit(TrueLiteral n);
+
+ /**
+ * f0 -> "false"
+ */
+ public R visit(FalseLiteral n);
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Identifier n);
+
+ /**
+ * f0 -> "this"
+ */
+ public R visit(ThisExpression n);
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public R visit(ArrayAllocationExpression n);
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public R visit(AllocationExpression n);
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public R visit(NotExpression n);
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public R visit(BracketExpression n);
+
+}
+
diff --git a/src/minijava/visitor/GJVisitor.java b/src/minijava/visitor/GJVisitor.java
new file mode 100644
index 0000000..46c2ea9
--- /dev/null
+++ b/src/minijava/visitor/GJVisitor.java
@@ -0,0 +1,415 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * All GJ visitors must implement this interface.
+ */
+
+public interface GJVisitor<R,A> {
+
+ //
+ // GJ Auto class visitors
+ //
+
+ public R visit(NodeList n, A argu);
+ public R visit(NodeListOptional n, A argu);
+ public R visit(NodeOptional n, A argu);
+ public R visit(NodeSequence n, A argu);
+ public R visit(NodeToken n, A argu);
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public R visit(Goal n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public R visit(MainClass n, A argu);
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public R visit(TypeDeclaration n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public R visit(ClassDeclaration n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public R visit(ClassExtendsDeclaration n, A argu);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public R visit(VarDeclaration n, A argu);
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public R visit(MethodDeclaration n, A argu);
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public R visit(FormalParameterList n, A argu);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public R visit(FormalParameter n, A argu);
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public R visit(FormalParameterRest n, A argu);
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public R visit(Type n, A argu);
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public R visit(ArrayType n, A argu);
+
+ /**
+ * f0 -> "boolean"
+ */
+ public R visit(BooleanType n, A argu);
+
+ /**
+ * f0 -> "int"
+ */
+ public R visit(IntegerType n, A argu);
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public R visit(Statement n, A argu);
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public R visit(Block n, A argu);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public R visit(AssignmentStatement n, A argu);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public R visit(ArrayAssignmentStatement n, A argu);
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public R visit(IfStatement n, A argu);
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public R visit(WhileStatement n, A argu);
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public R visit(PrintStatement n, A argu);
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public R visit(Expression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(AndExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(CompareExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(PlusExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(MinusExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public R visit(TimesExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public R visit(ArrayLookup n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public R visit(ArrayLength n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public R visit(MessageSend n, A argu);
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public R visit(ExpressionList n, A argu);
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public R visit(ExpressionRest n, A argu);
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public R visit(PrimaryExpression n, A argu);
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n, A argu);
+
+ /**
+ * f0 -> "true"
+ */
+ public R visit(TrueLiteral n, A argu);
+
+ /**
+ * f0 -> "false"
+ */
+ public R visit(FalseLiteral n, A argu);
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Identifier n, A argu);
+
+ /**
+ * f0 -> "this"
+ */
+ public R visit(ThisExpression n, A argu);
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public R visit(ArrayAllocationExpression n, A argu);
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public R visit(AllocationExpression n, A argu);
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public R visit(NotExpression n, A argu);
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public R visit(BracketExpression n, A argu);
+
+}
diff --git a/src/minijava/visitor/GJVoidDepthFirst.java b/src/minijava/visitor/GJVoidDepthFirst.java
new file mode 100644
index 0000000..29d6f1f
--- /dev/null
+++ b/src/minijava/visitor/GJVoidDepthFirst.java
@@ -0,0 +1,633 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import java.util.Enumeration;
+
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.Node;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * Provides default methods which visit each node in the tree in depth-first
+ * order. Your visitors may extend this class.
+ */
+public class GJVoidDepthFirst<A> implements GJVoidVisitor<A> {
+ //
+ // Auto class visitors--probably don't need to be overridden.
+ //
+ public void visit(NodeList n, A argu) {
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ }
+
+ public void visit(NodeListOptional n, A argu) {
+ if ( n.present() ) {
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ }
+ }
+
+ public void visit(NodeOptional n, A argu) {
+ if ( n.present() )
+ n.node.accept(this,argu);
+ }
+
+ public void visit(NodeSequence n, A argu) {
+ int _count=0;
+ for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) {
+ e.nextElement().accept(this,argu);
+ _count++;
+ }
+ }
+
+ public void visit(NodeToken n, A argu) {}
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public void visit(Goal n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public void visit(MainClass n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ n.f13.accept(this, argu);
+ n.f14.accept(this, argu);
+ n.f15.accept(this, argu);
+ n.f16.accept(this, argu);
+ }
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public void visit(TypeDeclaration n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public void visit(ClassDeclaration n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public void visit(ClassExtendsDeclaration n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public void visit(VarDeclaration n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public void visit(MethodDeclaration n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ n.f7.accept(this, argu);
+ n.f8.accept(this, argu);
+ n.f9.accept(this, argu);
+ n.f10.accept(this, argu);
+ n.f11.accept(this, argu);
+ n.f12.accept(this, argu);
+ }
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public void visit(FormalParameterList n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public void visit(FormalParameter n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public void visit(FormalParameterRest n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public void visit(Type n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public void visit(ArrayType n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "boolean"
+ */
+ public void visit(BooleanType n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "int"
+ */
+ public void visit(IntegerType n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public void visit(Statement n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public void visit(Block n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public void visit(AssignmentStatement n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public void visit(ArrayAssignmentStatement n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public void visit(IfStatement n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ n.f6.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public void visit(WhileStatement n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public void visit(PrintStatement n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ }
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public void visit(Expression n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(AndExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(CompareExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(PlusExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(MinusExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(TimesExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public void visit(ArrayLookup n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public void visit(ArrayLength n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public void visit(MessageSend n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ n.f5.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public void visit(ExpressionList n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public void visit(ExpressionRest n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public void visit(PrimaryExpression n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "true"
+ */
+ public void visit(TrueLiteral n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "false"
+ */
+ public void visit(FalseLiteral n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Identifier n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "this"
+ */
+ public void visit(ThisExpression n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public void visit(ArrayAllocationExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public void visit(AllocationExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public void visit(NotExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public void visit(BracketExpression n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ }
+
+}
diff --git a/src/minijava/visitor/GJVoidVisitor.java b/src/minijava/visitor/GJVoidVisitor.java
new file mode 100644
index 0000000..43cf200
--- /dev/null
+++ b/src/minijava/visitor/GJVoidVisitor.java
@@ -0,0 +1,416 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * All GJ void visitors must implement this interface.
+ */
+
+public interface GJVoidVisitor<A> {
+
+ //
+ // GJ void Auto class visitors
+ //
+
+ public void visit(NodeList n, A argu);
+ public void visit(NodeListOptional n, A argu);
+ public void visit(NodeOptional n, A argu);
+ public void visit(NodeSequence n, A argu);
+ public void visit(NodeToken n, A argu);
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public void visit(Goal n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public void visit(MainClass n, A argu);
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public void visit(TypeDeclaration n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public void visit(ClassDeclaration n, A argu);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public void visit(ClassExtendsDeclaration n, A argu);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public void visit(VarDeclaration n, A argu);
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public void visit(MethodDeclaration n, A argu);
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public void visit(FormalParameterList n, A argu);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public void visit(FormalParameter n, A argu);
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public void visit(FormalParameterRest n, A argu);
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public void visit(Type n, A argu);
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public void visit(ArrayType n, A argu);
+
+ /**
+ * f0 -> "boolean"
+ */
+ public void visit(BooleanType n, A argu);
+
+ /**
+ * f0 -> "int"
+ */
+ public void visit(IntegerType n, A argu);
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public void visit(Statement n, A argu);
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public void visit(Block n, A argu);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public void visit(AssignmentStatement n, A argu);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public void visit(ArrayAssignmentStatement n, A argu);
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public void visit(IfStatement n, A argu);
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public void visit(WhileStatement n, A argu);
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public void visit(PrintStatement n, A argu);
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public void visit(Expression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(AndExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(CompareExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(PlusExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(MinusExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(TimesExpression n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public void visit(ArrayLookup n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public void visit(ArrayLength n, A argu);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public void visit(MessageSend n, A argu);
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public void visit(ExpressionList n, A argu);
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public void visit(ExpressionRest n, A argu);
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public void visit(PrimaryExpression n, A argu);
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n, A argu);
+
+ /**
+ * f0 -> "true"
+ */
+ public void visit(TrueLiteral n, A argu);
+
+ /**
+ * f0 -> "false"
+ */
+ public void visit(FalseLiteral n, A argu);
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Identifier n, A argu);
+
+ /**
+ * f0 -> "this"
+ */
+ public void visit(ThisExpression n, A argu);
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public void visit(ArrayAllocationExpression n, A argu);
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public void visit(AllocationExpression n, A argu);
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public void visit(NotExpression n, A argu);
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public void visit(BracketExpression n, A argu);
+
+}
+
diff --git a/src/minijava/visitor/Visitor.java b/src/minijava/visitor/Visitor.java
new file mode 100644
index 0000000..c2a3afa
--- /dev/null
+++ b/src/minijava/visitor/Visitor.java
@@ -0,0 +1,416 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package minijava.visitor;
+import minijava.syntaxtree.AllocationExpression;
+import minijava.syntaxtree.AndExpression;
+import minijava.syntaxtree.ArrayAllocationExpression;
+import minijava.syntaxtree.ArrayAssignmentStatement;
+import minijava.syntaxtree.ArrayLength;
+import minijava.syntaxtree.ArrayLookup;
+import minijava.syntaxtree.ArrayType;
+import minijava.syntaxtree.AssignmentStatement;
+import minijava.syntaxtree.Block;
+import minijava.syntaxtree.BooleanType;
+import minijava.syntaxtree.BracketExpression;
+import minijava.syntaxtree.ClassDeclaration;
+import minijava.syntaxtree.ClassExtendsDeclaration;
+import minijava.syntaxtree.CompareExpression;
+import minijava.syntaxtree.Expression;
+import minijava.syntaxtree.ExpressionList;
+import minijava.syntaxtree.ExpressionRest;
+import minijava.syntaxtree.FalseLiteral;
+import minijava.syntaxtree.FormalParameter;
+import minijava.syntaxtree.FormalParameterList;
+import minijava.syntaxtree.FormalParameterRest;
+import minijava.syntaxtree.Goal;
+import minijava.syntaxtree.Identifier;
+import minijava.syntaxtree.IfStatement;
+import minijava.syntaxtree.IntegerLiteral;
+import minijava.syntaxtree.IntegerType;
+import minijava.syntaxtree.MainClass;
+import minijava.syntaxtree.MessageSend;
+import minijava.syntaxtree.MethodDeclaration;
+import minijava.syntaxtree.MinusExpression;
+import minijava.syntaxtree.NodeList;
+import minijava.syntaxtree.NodeListOptional;
+import minijava.syntaxtree.NodeOptional;
+import minijava.syntaxtree.NodeSequence;
+import minijava.syntaxtree.NodeToken;
+import minijava.syntaxtree.NotExpression;
+import minijava.syntaxtree.PlusExpression;
+import minijava.syntaxtree.PrimaryExpression;
+import minijava.syntaxtree.PrintStatement;
+import minijava.syntaxtree.Statement;
+import minijava.syntaxtree.ThisExpression;
+import minijava.syntaxtree.TimesExpression;
+import minijava.syntaxtree.TrueLiteral;
+import minijava.syntaxtree.Type;
+import minijava.syntaxtree.TypeDeclaration;
+import minijava.syntaxtree.VarDeclaration;
+import minijava.syntaxtree.WhileStatement;
+
+/**
+ * All void visitors must implement this interface.
+ */
+
+public interface Visitor {
+
+ //
+ // void Auto class visitors
+ //
+
+ public void visit(NodeList n);
+ public void visit(NodeListOptional n);
+ public void visit(NodeOptional n);
+ public void visit(NodeSequence n);
+ public void visit(NodeToken n);
+
+ //
+ // User-generated visitor methods below
+ //
+
+ /**
+ * f0 -> MainClass()
+ * f1 -> ( TypeDeclaration() )*
+ * f2 -> <EOF>
+ */
+ public void visit(Goal n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> "public"
+ * f4 -> "static"
+ * f5 -> "void"
+ * f6 -> "main"
+ * f7 -> "("
+ * f8 -> "String"
+ * f9 -> "["
+ * f10 -> "]"
+ * f11 -> Identifier()
+ * f12 -> ")"
+ * f13 -> "{"
+ * f14 -> PrintStatement()
+ * f15 -> "}"
+ * f16 -> "}"
+ */
+ public void visit(MainClass n);
+
+ /**
+ * f0 -> ClassDeclaration()
+ * | ClassExtendsDeclaration()
+ */
+ public void visit(TypeDeclaration n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "{"
+ * f3 -> ( VarDeclaration() )*
+ * f4 -> ( MethodDeclaration() )*
+ * f5 -> "}"
+ */
+ public void visit(ClassDeclaration n);
+
+ /**
+ * f0 -> "class"
+ * f1 -> Identifier()
+ * f2 -> "extends"
+ * f3 -> Identifier()
+ * f4 -> "{"
+ * f5 -> ( VarDeclaration() )*
+ * f6 -> ( MethodDeclaration() )*
+ * f7 -> "}"
+ */
+ public void visit(ClassExtendsDeclaration n);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ * f2 -> ";"
+ */
+ public void visit(VarDeclaration n);
+
+ /**
+ * f0 -> "public"
+ * f1 -> Type()
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( FormalParameterList() )?
+ * f5 -> ")"
+ * f6 -> "{"
+ * f7 -> ( VarDeclaration() )*
+ * f8 -> ( Statement() )*
+ * f9 -> "return"
+ * f10 -> Expression()
+ * f11 -> ";"
+ * f12 -> "}"
+ */
+ public void visit(MethodDeclaration n);
+
+ /**
+ * f0 -> FormalParameter()
+ * f1 -> ( FormalParameterRest() )*
+ */
+ public void visit(FormalParameterList n);
+
+ /**
+ * f0 -> Type()
+ * f1 -> Identifier()
+ */
+ public void visit(FormalParameter n);
+
+ /**
+ * f0 -> ","
+ * f1 -> FormalParameter()
+ */
+ public void visit(FormalParameterRest n);
+
+ /**
+ * f0 -> ArrayType()
+ * | BooleanType()
+ * | IntegerType()
+ * | Identifier()
+ */
+ public void visit(Type n);
+
+ /**
+ * f0 -> "int"
+ * f1 -> "["
+ * f2 -> "]"
+ */
+ public void visit(ArrayType n);
+
+ /**
+ * f0 -> "boolean"
+ */
+ public void visit(BooleanType n);
+
+ /**
+ * f0 -> "int"
+ */
+ public void visit(IntegerType n);
+
+ /**
+ * f0 -> Block()
+ * | AssignmentStatement()
+ * | ArrayAssignmentStatement()
+ * | IfStatement()
+ * | WhileStatement()
+ * | PrintStatement()
+ */
+ public void visit(Statement n);
+
+ /**
+ * f0 -> "{"
+ * f1 -> ( Statement() )*
+ * f2 -> "}"
+ */
+ public void visit(Block n);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "="
+ * f2 -> Expression()
+ * f3 -> ";"
+ */
+ public void visit(AssignmentStatement n);
+
+ /**
+ * f0 -> Identifier()
+ * f1 -> "["
+ * f2 -> Expression()
+ * f3 -> "]"
+ * f4 -> "="
+ * f5 -> Expression()
+ * f6 -> ";"
+ */
+ public void visit(ArrayAssignmentStatement n);
+
+ /**
+ * f0 -> "if"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ * f5 -> "else"
+ * f6 -> Statement()
+ */
+ public void visit(IfStatement n);
+
+ /**
+ * f0 -> "while"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> Statement()
+ */
+ public void visit(WhileStatement n);
+
+ /**
+ * f0 -> "System.out.println"
+ * f1 -> "("
+ * f2 -> Expression()
+ * f3 -> ")"
+ * f4 -> ";"
+ */
+ public void visit(PrintStatement n);
+
+ /**
+ * f0 -> AndExpression()
+ * | CompareExpression()
+ * | PlusExpression()
+ * | MinusExpression()
+ * | TimesExpression()
+ * | ArrayLookup()
+ * | ArrayLength()
+ * | MessageSend()
+ * | PrimaryExpression()
+ */
+ public void visit(Expression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "&&"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(AndExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "<"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(CompareExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "+"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(PlusExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "-"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(MinusExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "*"
+ * f2 -> PrimaryExpression()
+ */
+ public void visit(TimesExpression n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "["
+ * f2 -> PrimaryExpression()
+ * f3 -> "]"
+ */
+ public void visit(ArrayLookup n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> "length"
+ */
+ public void visit(ArrayLength n);
+
+ /**
+ * f0 -> PrimaryExpression()
+ * f1 -> "."
+ * f2 -> Identifier()
+ * f3 -> "("
+ * f4 -> ( ExpressionList() )?
+ * f5 -> ")"
+ */
+ public void visit(MessageSend n);
+
+ /**
+ * f0 -> Expression()
+ * f1 -> ( ExpressionRest() )*
+ */
+ public void visit(ExpressionList n);
+
+ /**
+ * f0 -> ","
+ * f1 -> Expression()
+ */
+ public void visit(ExpressionRest n);
+
+ /**
+ * f0 -> IntegerLiteral()
+ * | TrueLiteral()
+ * | FalseLiteral()
+ * | Identifier()
+ * | ThisExpression()
+ * | ArrayAllocationExpression()
+ * | AllocationExpression()
+ * | NotExpression()
+ * | BracketExpression()
+ */
+ public void visit(PrimaryExpression n);
+
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n);
+
+ /**
+ * f0 -> "true"
+ */
+ public void visit(TrueLiteral n);
+
+ /**
+ * f0 -> "false"
+ */
+ public void visit(FalseLiteral n);
+
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Identifier n);
+
+ /**
+ * f0 -> "this"
+ */
+ public void visit(ThisExpression n);
+
+ /**
+ * f0 -> "new"
+ * f1 -> "int"
+ * f2 -> "["
+ * f3 -> Expression()
+ * f4 -> "]"
+ */
+ public void visit(ArrayAllocationExpression n);
+
+ /**
+ * f0 -> "new"
+ * f1 -> Identifier()
+ * f2 -> "("
+ * f3 -> ")"
+ */
+ public void visit(AllocationExpression n);
+
+ /**
+ * f0 -> "!"
+ * f1 -> Expression()
+ */
+ public void visit(NotExpression n);
+
+ /**
+ * f0 -> "("
+ * f1 -> Expression()
+ * f2 -> ")"
+ */
+ public void visit(BracketExpression n);
+
+}
+