diff options
author | Iru Cai <mytbk920423@gmail.com> | 2014-10-08 21:15:43 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2014-10-08 21:15:43 +0800 |
commit | 748308e11e6791284b302f61e5bc0d99a0957b6a (patch) | |
tree | 31b88d40d043f39d54ab90393656300656aaa209 /src/spiglet/visitor | |
download | minijava-748308e11e6791284b302f61e5bc0d99a0957b6a.tar.xz |
First commit
Diffstat (limited to 'src/spiglet/visitor')
-rw-r--r-- | src/spiglet/visitor/DepthFirstVisitor.java | 305 | ||||
-rw-r--r-- | src/spiglet/visitor/GJDepthFirst.java | 369 | ||||
-rw-r--r-- | src/spiglet/visitor/GJNoArguDepthFirst.java | 369 | ||||
-rw-r--r-- | src/spiglet/visitor/GJNoArguVisitor.java | 212 | ||||
-rw-r--r-- | src/spiglet/visitor/GJVisitor.java | 211 | ||||
-rw-r--r-- | src/spiglet/visitor/GJVoidDepthFirst.java | 315 | ||||
-rw-r--r-- | src/spiglet/visitor/GJVoidVisitor.java | 212 | ||||
-rw-r--r-- | src/spiglet/visitor/Visitor.java | 212 |
8 files changed, 2205 insertions, 0 deletions
diff --git a/src/spiglet/visitor/DepthFirstVisitor.java b/src/spiglet/visitor/DepthFirstVisitor.java new file mode 100644 index 0000000..e9920b8 --- /dev/null +++ b/src/spiglet/visitor/DepthFirstVisitor.java @@ -0,0 +1,305 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import java.util.Enumeration; + +import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.Node; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public void visit(Goal n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ } +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public void visit(StmtList n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public void visit(Procedure n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ } +
+ /**
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public void visit(Stmt n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> "NOOP"
+ */
+ public void visit(NoOpStmt n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> "ERROR"
+ */
+ public void visit(ErrorStmt n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ } +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ } +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public void visit(HStoreStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ } +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public void visit(HLoadStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ } +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public void visit(MoveStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ } +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public void visit(PrintStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ } +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public void visit(Exp n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ } +
+ /**
+ * f0 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ n.f4.accept(this);
+ } +
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public void visit(HAllocate n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ } +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public void visit(BinOp n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ } +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(SimpleExp n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public void visit(Temp n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ } +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n) {
+ n.f0.accept(this);
+ } +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Label n) {
+ n.f0.accept(this);
+ } +
+}
diff --git a/src/spiglet/visitor/GJDepthFirst.java b/src/spiglet/visitor/GJDepthFirst.java new file mode 100644 index 0000000..c105eea --- /dev/null +++ b/src/spiglet/visitor/GJDepthFirst.java @@ -0,0 +1,369 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import java.util.Enumeration; + +import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.Node; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <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);
+ n.f3.accept(this, argu);
+ n.f4.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public R visit(StmtList n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public R visit(Procedure 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 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public R visit(Stmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "NOOP"
+ */
+ public R visit(NoOpStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "ERROR"
+ */
+ public R visit(ErrorStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public R visit(HStoreStmt 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 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public R visit(HLoadStmt 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 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public R visit(MoveStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public R visit(PrintStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public R visit(Exp n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp 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 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call 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 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public R visit(HAllocate n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public R visit(BinOp n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(SimpleExp n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public R visit(Temp n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.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 -> <IDENTIFIER>
+ */
+ public R visit(Label n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ } +
+}
diff --git a/src/spiglet/visitor/GJNoArguDepthFirst.java b/src/spiglet/visitor/GJNoArguDepthFirst.java new file mode 100644 index 0000000..ebbd988 --- /dev/null +++ b/src/spiglet/visitor/GJNoArguDepthFirst.java @@ -0,0 +1,369 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import java.util.Enumeration; + +import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.Node; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public R visit(Goal 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 -> ( ( Label() )? Stmt() )*
+ */
+ public R visit(StmtList n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public R visit(Procedure 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 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public R visit(Stmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "NOOP"
+ */
+ public R visit(NoOpStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "ERROR"
+ */
+ public R visit(ErrorStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public R visit(HStoreStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public R visit(HLoadStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ n.f3.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public R visit(MoveStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public R visit(PrintStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public R visit(Exp n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp 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 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call 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 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public R visit(HAllocate n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public R visit(BinOp n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ n.f2.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(SimpleExp n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public R visit(Temp n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Label n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ } +
+}
diff --git a/src/spiglet/visitor/GJNoArguVisitor.java b/src/spiglet/visitor/GJNoArguVisitor.java new file mode 100644 index 0000000..57dcc78 --- /dev/null +++ b/src/spiglet/visitor/GJNoArguVisitor.java @@ -0,0 +1,212 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public R visit(Goal n); +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public R visit(StmtList n); +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public R visit(Procedure n); +
+ /**
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public R visit(Stmt n); +
+ /**
+ * f0 -> "NOOP"
+ */
+ public R visit(NoOpStmt n); +
+ /**
+ * f0 -> "ERROR"
+ */
+ public R visit(ErrorStmt n); +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n); +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n); +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public R visit(HStoreStmt n); +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public R visit(HLoadStmt n); +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public R visit(MoveStmt n); +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public R visit(PrintStmt n); +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public R visit(Exp n); +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp n); +
+ /**
+ * f0 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call n); +
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public R visit(HAllocate n); +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public R visit(BinOp n); +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator n); +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(SimpleExp n); +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public R visit(Temp n); +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n); +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Label n); +
+} +
diff --git a/src/spiglet/visitor/GJVisitor.java b/src/spiglet/visitor/GJVisitor.java new file mode 100644 index 0000000..f78417b --- /dev/null +++ b/src/spiglet/visitor/GJVisitor.java @@ -0,0 +1,211 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public R visit(Goal n, A argu); +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public R visit(StmtList n, A argu); +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public R visit(Procedure n, A argu); +
+ /**
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public R visit(Stmt n, A argu); +
+ /**
+ * f0 -> "NOOP"
+ */
+ public R visit(NoOpStmt n, A argu); +
+ /**
+ * f0 -> "ERROR"
+ */
+ public R visit(ErrorStmt n, A argu); +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n, A argu); +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n, A argu); +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public R visit(HStoreStmt n, A argu); +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public R visit(HLoadStmt n, A argu); +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public R visit(MoveStmt n, A argu); +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public R visit(PrintStmt n, A argu); +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public R visit(Exp n, A argu); +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp n, A argu); +
+ /**
+ * f0 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call n, A argu); +
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public R visit(HAllocate n, A argu); +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public R visit(BinOp n, A argu); +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator n, A argu); +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(SimpleExp n, A argu); +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public R visit(Temp n, A argu); +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public R visit(IntegerLiteral n, A argu); +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public R visit(Label n, A argu); +
+}
diff --git a/src/spiglet/visitor/GJVoidDepthFirst.java b/src/spiglet/visitor/GJVoidDepthFirst.java new file mode 100644 index 0000000..f035e98 --- /dev/null +++ b/src/spiglet/visitor/GJVoidDepthFirst.java @@ -0,0 +1,315 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import java.util.Enumeration; + +import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.Node; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public void visit(Goal 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 -> ( ( Label() )? Stmt() )*
+ */
+ public void visit(StmtList n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public void visit(Procedure 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 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public void visit(Stmt n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> "NOOP"
+ */
+ public void visit(NoOpStmt n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> "ERROR"
+ */
+ public void visit(ErrorStmt n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ } +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ } +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public void visit(HStoreStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ } +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public void visit(HLoadStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ n.f3.accept(this, argu);
+ } +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public void visit(MoveStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ } +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public void visit(PrintStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ } +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public void visit(Exp n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp 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 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call 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 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public void visit(HAllocate n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ } +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public void visit(BinOp n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ n.f2.accept(this, argu);
+ } +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(SimpleExp n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public void visit(Temp n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ } +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Label n, A argu) {
+ n.f0.accept(this, argu);
+ } +
+}
diff --git a/src/spiglet/visitor/GJVoidVisitor.java b/src/spiglet/visitor/GJVoidVisitor.java new file mode 100644 index 0000000..ac47082 --- /dev/null +++ b/src/spiglet/visitor/GJVoidVisitor.java @@ -0,0 +1,212 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public void visit(Goal n, A argu); +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public void visit(StmtList n, A argu); +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public void visit(Procedure n, A argu); +
+ /**
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public void visit(Stmt n, A argu); +
+ /**
+ * f0 -> "NOOP"
+ */
+ public void visit(NoOpStmt n, A argu); +
+ /**
+ * f0 -> "ERROR"
+ */
+ public void visit(ErrorStmt n, A argu); +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n, A argu); +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n, A argu); +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public void visit(HStoreStmt n, A argu); +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public void visit(HLoadStmt n, A argu); +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public void visit(MoveStmt n, A argu); +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public void visit(PrintStmt n, A argu); +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public void visit(Exp n, A argu); +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp n, A argu); +
+ /**
+ * f0 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call n, A argu); +
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public void visit(HAllocate n, A argu); +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public void visit(BinOp n, A argu); +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator n, A argu); +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(SimpleExp n, A argu); +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public void visit(Temp n, A argu); +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n, A argu); +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Label n, A argu); +
+} +
diff --git a/src/spiglet/visitor/Visitor.java b/src/spiglet/visitor/Visitor.java new file mode 100644 index 0000000..b3a1af6 --- /dev/null +++ b/src/spiglet/visitor/Visitor.java @@ -0,0 +1,212 @@ +// +// Generated by JTB 1.3.2 +//
+
+package spiglet.visitor;
+import spiglet.syntaxtree.BinOp; +import spiglet.syntaxtree.CJumpStmt; +import spiglet.syntaxtree.Call; +import spiglet.syntaxtree.ErrorStmt; +import spiglet.syntaxtree.Exp; +import spiglet.syntaxtree.Goal; +import spiglet.syntaxtree.HAllocate; +import spiglet.syntaxtree.HLoadStmt; +import spiglet.syntaxtree.HStoreStmt; +import spiglet.syntaxtree.IntegerLiteral; +import spiglet.syntaxtree.JumpStmt; +import spiglet.syntaxtree.Label; +import spiglet.syntaxtree.MoveStmt; +import spiglet.syntaxtree.NoOpStmt; +import spiglet.syntaxtree.NodeList; +import spiglet.syntaxtree.NodeListOptional; +import spiglet.syntaxtree.NodeOptional; +import spiglet.syntaxtree.NodeSequence; +import spiglet.syntaxtree.NodeToken; +import spiglet.syntaxtree.Operator; +import spiglet.syntaxtree.PrintStmt; +import spiglet.syntaxtree.Procedure; +import spiglet.syntaxtree.SimpleExp; +import spiglet.syntaxtree.Stmt; +import spiglet.syntaxtree.StmtExp; +import spiglet.syntaxtree.StmtList; +import spiglet.syntaxtree.Temp; +
+/**
+ * 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 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+ public void visit(Goal n); +
+ /**
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+ public void visit(StmtList n); +
+ /**
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+ public void visit(Procedure n); +
+ /**
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+ public void visit(Stmt n); +
+ /**
+ * f0 -> "NOOP"
+ */
+ public void visit(NoOpStmt n); +
+ /**
+ * f0 -> "ERROR"
+ */
+ public void visit(ErrorStmt n); +
+ /**
+ * f0 -> "CJUMP"
+ * f1 -> Temp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n); +
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n); +
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Temp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Temp()
+ */
+ public void visit(HStoreStmt n); +
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Temp()
+ * f3 -> IntegerLiteral()
+ */
+ public void visit(HLoadStmt n); +
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public void visit(MoveStmt n); +
+ /**
+ * f0 -> "PRINT"
+ * f1 -> SimpleExp()
+ */
+ public void visit(PrintStmt n); +
+ /**
+ * f0 -> Call()
+ * | HAllocate()
+ * | BinOp()
+ * | SimpleExp()
+ */
+ public void visit(Exp n); +
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> SimpleExp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp n); +
+ /**
+ * f0 -> "CALL"
+ * f1 -> SimpleExp()
+ * f2 -> "("
+ * f3 -> ( Temp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call n); +
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> SimpleExp()
+ */
+ public void visit(HAllocate n); +
+ /**
+ * f0 -> Operator()
+ * f1 -> Temp()
+ * f2 -> SimpleExp()
+ */
+ public void visit(BinOp n); +
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator n); +
+ /**
+ * f0 -> Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(SimpleExp n); +
+ /**
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+ public void visit(Temp n); +
+ /**
+ * f0 -> <INTEGER_LITERAL>
+ */
+ public void visit(IntegerLiteral n); +
+ /**
+ * f0 -> <IDENTIFIER>
+ */
+ public void visit(Label n); +
+} +
|