summaryrefslogtreecommitdiff
path: root/src/minijava/visitor/DepthFirstVisitor.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/minijava/visitor/DepthFirstVisitor.java')
-rw-r--r--src/minijava/visitor/DepthFirstVisitor.java623
1 files changed, 623 insertions, 0 deletions
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);
+ }
+
+}