summaryrefslogtreecommitdiff
path: root/src/piglet
diff options
context:
space:
mode:
Diffstat (limited to 'src/piglet')
-rw-r--r--src/piglet/JavaCharStream.java587
-rw-r--r--src/piglet/ParseException.java192
-rw-r--r--src/piglet/PigletParser.java676
-rw-r--r--src/piglet/PigletParserConstants.java106
-rw-r--r--src/piglet/PigletParserTokenManager.java925
-rw-r--r--src/piglet/Token.java80
-rw-r--r--src/piglet/TokenMgrError.java132
-rw-r--r--src/piglet/piglet2spiglet/Main.java38
-rw-r--r--src/piglet/syntaxtree/BinOp.java37
-rw-r--r--src/piglet/syntaxtree/CJumpStmt.java43
-rw-r--r--src/piglet/syntaxtree/Call.java51
-rw-r--r--src/piglet/syntaxtree/ErrorStmt.java35
-rw-r--r--src/piglet/syntaxtree/Exp.java37
-rw-r--r--src/piglet/syntaxtree/Goal.java51
-rw-r--r--src/piglet/syntaxtree/HAllocate.java39
-rw-r--r--src/piglet/syntaxtree/HLoadStmt.java47
-rw-r--r--src/piglet/syntaxtree/HStoreStmt.java47
-rw-r--r--src/piglet/syntaxtree/IntegerLiteral.java31
-rw-r--r--src/piglet/syntaxtree/JumpStmt.java39
-rw-r--r--src/piglet/syntaxtree/Label.java31
-rw-r--r--src/piglet/syntaxtree/MoveStmt.java43
-rw-r--r--src/piglet/syntaxtree/NoOpStmt.java35
-rw-r--r--src/piglet/syntaxtree/Node.java16
-rw-r--r--src/piglet/syntaxtree/NodeChoice.java36
-rw-r--r--src/piglet/syntaxtree/NodeList.java45
-rw-r--r--src/piglet/syntaxtree/NodeListInterface.java22
-rw-r--r--src/piglet/syntaxtree/NodeListOptional.java46
-rw-r--r--src/piglet/syntaxtree/NodeOptional.java41
-rw-r--r--src/piglet/syntaxtree/NodeSequence.java46
-rw-r--r--src/piglet/syntaxtree/NodeToken.java88
-rw-r--r--src/piglet/syntaxtree/Operator.java34
-rw-r--r--src/piglet/syntaxtree/PrintStmt.java39
-rw-r--r--src/piglet/syntaxtree/Procedure.java51
-rw-r--r--src/piglet/syntaxtree/Stmt.java38
-rw-r--r--src/piglet/syntaxtree/StmtExp.java51
-rw-r--r--src/piglet/syntaxtree/StmtList.java31
-rw-r--r--src/piglet/syntaxtree/Temp.java39
-rw-r--r--src/piglet/visitor/DepthFirstVisitor.java298
-rw-r--r--src/piglet/visitor/GJDepthFirst.java360
-rw-r--r--src/piglet/visitor/GJNoArguDepthFirst.java360
-rw-r--r--src/piglet/visitor/GJNoArguVisitor.java207
-rw-r--r--src/piglet/visitor/GJVisitor.java206
-rw-r--r--src/piglet/visitor/GJVoidDepthFirst.java308
-rw-r--r--src/piglet/visitor/GJVoidVisitor.java207
-rw-r--r--src/piglet/visitor/Visitor.java207
45 files changed, 6078 insertions, 0 deletions
diff --git a/src/piglet/JavaCharStream.java b/src/piglet/JavaCharStream.java
new file mode 100644
index 0000000..1b04b25
--- /dev/null
+++ b/src/piglet/JavaCharStream.java
@@ -0,0 +1,587 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.0 */
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (with java-like unicode escape processing).
+ */
+
+public class JavaCharStream
+{
+ public static final boolean staticFlag = true;
+ static final int hexval(char c) throws java.io.IOException {
+ switch(c)
+ {
+ case '0' :
+ return 0;
+ case '1' :
+ return 1;
+ case '2' :
+ return 2;
+ case '3' :
+ return 3;
+ case '4' :
+ return 4;
+ case '5' :
+ return 5;
+ case '6' :
+ return 6;
+ case '7' :
+ return 7;
+ case '8' :
+ return 8;
+ case '9' :
+ return 9;
+
+ case 'a' :
+ case 'A' :
+ return 10;
+ case 'b' :
+ case 'B' :
+ return 11;
+ case 'c' :
+ case 'C' :
+ return 12;
+ case 'd' :
+ case 'D' :
+ return 13;
+ case 'e' :
+ case 'E' :
+ return 14;
+ case 'f' :
+ case 'F' :
+ return 15;
+ }
+
+ throw new java.io.IOException(); // Should never come here
+ }
+
+ static public int bufpos = -1;
+ static int bufsize;
+ static int available;
+ static int tokenBegin;
+ static protected int bufline[];
+ static protected int bufcolumn[];
+
+ static protected int column = 0;
+ static protected int line = 1;
+
+ static protected boolean prevCharIsCR = false;
+ static protected boolean prevCharIsLF = false;
+
+ static protected java.io.Reader inputStream;
+
+ static protected char[] nextCharBuf;
+ static protected char[] buffer;
+ static protected int maxNextCharInd = 0;
+ static protected int nextCharInd = -1;
+ static protected int inBuf = 0;
+ static protected int tabSize = 8;
+
+ static protected void setTabSize(int i) { tabSize = i; }
+ static protected int getTabSize(int i) { return tabSize; }
+
+ static protected void ExpandBuff(boolean wrapAround)
+ {
+ char[] newbuffer = new char[bufsize + 2048];
+ int newbufline[] = new int[bufsize + 2048];
+ int newbufcolumn[] = new int[bufsize + 2048];
+
+ try
+ {
+ if (wrapAround)
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer,
+ bufsize - tokenBegin, bufpos);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+ bufcolumn = newbufcolumn;
+
+ bufpos += (bufsize - tokenBegin);
+ }
+ else
+ {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer = newbuffer;
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ bufline = newbufline;
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ bufcolumn = newbufcolumn;
+
+ bufpos -= tokenBegin;
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new Error(t.getMessage());
+ }
+
+ available = (bufsize += 2048);
+ tokenBegin = 0;
+ }
+
+ static protected void FillBuff() throws java.io.IOException
+ {
+ int i;
+ if (maxNextCharInd == 4096)
+ maxNextCharInd = nextCharInd = 0;
+
+ try {
+ if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
+ 4096 - maxNextCharInd)) == -1)
+ {
+ inputStream.close();
+ throw new java.io.IOException();
+ }
+ else
+ maxNextCharInd += i;
+ return;
+ }
+ catch(java.io.IOException e) {
+ if (bufpos != 0)
+ {
+ --bufpos;
+ backup(0);
+ }
+ else
+ {
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+ throw e;
+ }
+ }
+
+ static protected char ReadByte() throws java.io.IOException
+ {
+ if (++nextCharInd >= maxNextCharInd)
+ FillBuff();
+
+ return nextCharBuf[nextCharInd];
+ }
+
+ static public char BeginToken() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+
+ if (++bufpos == bufsize)
+ bufpos = 0;
+
+ tokenBegin = bufpos;
+ return buffer[bufpos];
+ }
+
+ tokenBegin = 0;
+ bufpos = -1;
+
+ return readChar();
+ }
+
+ static protected void AdjustBuffSize()
+ {
+ if (available == bufsize)
+ {
+ if (tokenBegin > 2048)
+ {
+ bufpos = 0;
+ available = tokenBegin;
+ }
+ else
+ ExpandBuff(false);
+ }
+ else if (available > tokenBegin)
+ available = bufsize;
+ else if ((tokenBegin - available) < 2048)
+ ExpandBuff(true);
+ else
+ available = tokenBegin;
+ }
+
+ static protected void UpdateLineColumn(char c)
+ {
+ column++;
+
+ if (prevCharIsLF)
+ {
+ prevCharIsLF = false;
+ line += (column = 1);
+ }
+ else if (prevCharIsCR)
+ {
+ prevCharIsCR = false;
+ if (c == '\n')
+ {
+ prevCharIsLF = true;
+ }
+ else
+ line += (column = 1);
+ }
+
+ switch (c)
+ {
+ case '\r' :
+ prevCharIsCR = true;
+ break;
+ case '\n' :
+ prevCharIsLF = true;
+ break;
+ case '\t' :
+ column--;
+ column += (tabSize - (column % tabSize));
+ break;
+ default :
+ break;
+ }
+
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+
+ static public char readChar() throws java.io.IOException
+ {
+ if (inBuf > 0)
+ {
+ --inBuf;
+
+ if (++bufpos == bufsize)
+ bufpos = 0;
+
+ return buffer[bufpos];
+ }
+
+ char c;
+
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ if ((buffer[bufpos] = c = ReadByte()) == '\\')
+ {
+ UpdateLineColumn(c);
+
+ int backSlashCnt = 1;
+
+ for (;;) // Read all the backslashes
+ {
+ if (++bufpos == available)
+ AdjustBuffSize();
+
+ try
+ {
+ if ((buffer[bufpos] = c = ReadByte()) != '\\')
+ {
+ UpdateLineColumn(c);
+ // found a non-backslash char.
+ if ((c == 'u') && ((backSlashCnt & 1) == 1))
+ {
+ if (--bufpos < 0)
+ bufpos = bufsize - 1;
+
+ break;
+ }
+
+ backup(backSlashCnt);
+ return '\\';
+ }
+ }
+ catch(java.io.IOException e)
+ {
+ if (backSlashCnt > 1)
+ backup(backSlashCnt);
+
+ return '\\';
+ }
+
+ UpdateLineColumn(c);
+ backSlashCnt++;
+ }
+
+ // Here, we have seen an odd number of backslash's followed by a 'u'
+ try
+ {
+ while ((c = ReadByte()) == 'u')
+ ++column;
+
+ buffer[bufpos] = c = (char)(hexval(c) << 12 |
+ hexval(ReadByte()) << 8 |
+ hexval(ReadByte()) << 4 |
+ hexval(ReadByte()));
+
+ column += 4;
+ }
+ catch(java.io.IOException e)
+ {
+ throw new Error("Invalid escape character at line " + line +
+ " column " + column + ".");
+ }
+
+ if (backSlashCnt == 1)
+ return c;
+ else
+ {
+ backup(backSlashCnt - 1);
+ return '\\';
+ }
+ }
+ else
+ {
+ UpdateLineColumn(c);
+ return (c);
+ }
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+
+ static public int getColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+
+ static public int getLine() {
+ return bufline[bufpos];
+ }
+
+ static public int getEndColumn() {
+ return bufcolumn[bufpos];
+ }
+
+ static public int getEndLine() {
+ return bufline[bufpos];
+ }
+
+ static public int getBeginColumn() {
+ return bufcolumn[tokenBegin];
+ }
+
+ static public int getBeginLine() {
+ return bufline[tokenBegin];
+ }
+
+ static public void backup(int amount) {
+
+ inBuf += amount;
+ if ((bufpos -= amount) < 0)
+ bufpos += bufsize;
+ }
+
+ public JavaCharStream(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ if (inputStream != null)
+ throw new Error("\n ERROR: Second call to the constructor of a static JavaCharStream. You must\n" +
+ " either use ReInit() or set the JavaCC option STATIC to false\n" +
+ " during the generation of this class.");
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+
+ public JavaCharStream(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.Reader dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn, int buffersize)
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ if (buffer == null || buffersize != buffer.length)
+ {
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+ prevCharIsLF = prevCharIsCR = false;
+ tokenBegin = inBuf = maxNextCharInd = 0;
+ nextCharInd = bufpos = -1;
+ }
+
+ public void ReInit(java.io.Reader dstream,
+ int startline, int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+ public void ReInit(java.io.Reader dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+ public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
+ {
+ this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn) throws java.io.UnsupportedEncodingException
+ {
+ this(dstream, encoding, startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
+ {
+ this(dstream, encoding, 1, 1, 4096);
+ }
+
+ public JavaCharStream(java.io.InputStream dstream)
+ {
+ this(dstream, 1, 1, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
+ }
+
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn, int buffersize)
+ {
+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
+ }
+ public void ReInit(java.io.InputStream dstream, String encoding, int startline,
+ int startcolumn) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(dstream, encoding, startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, int startline,
+ int startcolumn)
+ {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
+ {
+ ReInit(dstream, encoding, 1, 1, 4096);
+ }
+
+ public void ReInit(java.io.InputStream dstream)
+ {
+ ReInit(dstream, 1, 1, 4096);
+ }
+
+ static public String GetImage()
+ {
+ if (bufpos >= tokenBegin)
+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+ else
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+ new String(buffer, 0, bufpos + 1);
+ }
+
+ static public char[] GetSuffix(int len)
+ {
+ char[] ret = new char[len];
+
+ if ((bufpos + 1) >= len)
+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+ else
+ {
+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
+ len - bufpos - 1);
+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+ }
+
+ return ret;
+ }
+
+ static public void Done()
+ {
+ nextCharBuf = null;
+ buffer = null;
+ bufline = null;
+ bufcolumn = null;
+ }
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.
+ */
+ static public void adjustBeginLineColumn(int newLine, int newCol)
+ {
+ int start = tokenBegin;
+ int len;
+
+ if (bufpos >= tokenBegin)
+ {
+ len = bufpos - tokenBegin + inBuf + 1;
+ }
+ else
+ {
+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
+ }
+
+ int i = 0, j = 0, k = 0;
+ int nextColDiff = 0, columnDiff = 0;
+
+ while (i < len &&
+ bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
+ {
+ bufline[j] = newLine;
+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+ bufcolumn[j] = newCol + columnDiff;
+ columnDiff = nextColDiff;
+ i++;
+ }
+
+ if (i < len)
+ {
+ bufline[j] = newLine++;
+ bufcolumn[j] = newCol + columnDiff;
+
+ while (i++ < len)
+ {
+ if (bufline[j = start % bufsize] != bufline[++start % bufsize])
+ bufline[j] = newLine++;
+ else
+ bufline[j] = newLine;
+ }
+ }
+
+ line = bufline[j];
+ column = bufcolumn[j];
+ }
+
+}
diff --git a/src/piglet/ParseException.java b/src/piglet/ParseException.java
new file mode 100644
index 0000000..8923138
--- /dev/null
+++ b/src/piglet/ParseException.java
@@ -0,0 +1,192 @@
+package piglet;
+
+/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
+/**
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
+ */
+public class ParseException extends Exception {
+
+ /**
+ * This constructor is used by the method "generateParseException"
+ * in the generated parser. Calling this constructor generates
+ * a new object of this type with the fields "currentToken",
+ * "expectedTokenSequences", and "tokenImage" set. The boolean
+ * flag "specialConstructor" is also set to true to indicate that
+ * this constructor was used to create this object.
+ * This constructor calls its super class with the empty string
+ * to force the "toString" method of parent class "Throwable" to
+ * print the error message in the form:
+ * ParseException: <result of getMessage>
+ */
+ public ParseException(Token currentTokenVal,
+ int[][] expectedTokenSequencesVal,
+ String[] tokenImageVal
+ )
+ {
+ super("");
+ specialConstructor = true;
+ currentToken = currentTokenVal;
+ expectedTokenSequences = expectedTokenSequencesVal;
+ tokenImage = tokenImageVal;
+ }
+
+ /**
+ * The following constructors are for use by you for whatever
+ * purpose you can think of. Constructing the exception in this
+ * manner makes the exception behave in the normal way - i.e., as
+ * documented in the class "Throwable". The fields "errorToken",
+ * "expectedTokenSequences", and "tokenImage" do not contain
+ * relevant information. The JavaCC generated code does not use
+ * these constructors.
+ */
+
+ public ParseException() {
+ super();
+ specialConstructor = false;
+ }
+
+ public ParseException(String message) {
+ super(message);
+ specialConstructor = false;
+ }
+
+ /**
+ * This variable determines which constructor was used to create
+ * this object and thereby affects the semantics of the
+ * "getMessage" method (see below).
+ */
+ protected boolean specialConstructor;
+
+ /**
+ * This is the last token that has been consumed successfully. If
+ * this object has been created due to a parse error, the token
+ * followng this token will (therefore) be the first error token.
+ */
+ public Token currentToken;
+
+ /**
+ * Each entry in this array is an array of integers. Each array
+ * of integers represents a sequence of tokens (by their ordinal
+ * values) that is expected at this point of the parse.
+ */
+ public int[][] expectedTokenSequences;
+
+ /**
+ * This is a reference to the "tokenImage" array of the generated
+ * parser within which the parse error occurred. This array is
+ * defined in the generated ...Constants interface.
+ */
+ public String[] tokenImage;
+
+ /**
+ * This method has the standard behavior when this object has been
+ * created using the standard constructors. Otherwise, it uses
+ * "currentToken" and "expectedTokenSequences" to generate a parse
+ * error message and returns it. If this object has been created
+ * due to a parse error, and you do not catch it (it gets thrown
+ * from the parser), then this method is called during the printing
+ * of the final stack trace, and hence the correct error message
+ * gets displayed.
+ */
+ public String getMessage() {
+ if (!specialConstructor) {
+ return super.getMessage();
+ }
+ StringBuffer expected = new StringBuffer();
+ int maxSize = 0;
+ for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (maxSize < expectedTokenSequences[i].length) {
+ maxSize = expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+ expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" ");
+ }
+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+ expected.append("...");
+ }
+ expected.append(eol).append(" ");
+ }
+ String retval = "Encountered \"";
+ Token tok = currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) retval += " ";
+ if (tok.kind == 0) {
+ retval += tokenImage[0];
+ break;
+ }
+ retval += add_escapes(tok.image);
+ tok = tok.next;
+ }
+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += "." + eol;
+ if (expectedTokenSequences.length == 1) {
+ retval += "Was expecting:" + eol + " ";
+ } else {
+ retval += "Was expecting one of:" + eol + " ";
+ }
+ retval += expected.toString();
+ return retval;
+ }
+
+ /**
+ * The end of line string for this machine.
+ */
+ protected String eol = System.getProperty("line.separator", "\n");
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal.
+ */
+ protected String add_escapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+}
diff --git a/src/piglet/PigletParser.java b/src/piglet/PigletParser.java
new file mode 100644
index 0000000..fe6b4ec
--- /dev/null
+++ b/src/piglet/PigletParser.java
@@ -0,0 +1,676 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. PigletParser.java */
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.NodeChoice;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.syntaxtree.Temp;
+
+
+public class PigletParser implements PigletParserConstants {
+
+ static final public Goal Goal() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ StmtList n2;
+ NodeToken n3;
+ Token n4;
+ NodeListOptional n5 = new NodeListOptional();
+ Procedure n6;
+ NodeToken n7;
+ Token n8;
+ n1 = jj_consume_token(MAIN);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = StmtList();
+ n4 = jj_consume_token(END);
+ n3 = JTBToolkit.makeNodeToken(n4);
+ label_1:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IDENTIFIER:
+ ;
+ break;
+ default:
+ jj_la1[0] = jj_gen;
+ break label_1;
+ }
+ n6 = Procedure();
+ n5.addNode(n6);
+ }
+ n5.nodes.trimToSize();
+ n8 = jj_consume_token(0);
+ n8.beginColumn++; n8.endColumn++;
+ n7 = JTBToolkit.makeNodeToken(n8);
+ {if (true) return new Goal(n0,n2,n3,n5,n7);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public StmtList StmtList() throws ParseException {
+ NodeListOptional n0 = new NodeListOptional();
+ NodeSequence n1;
+ NodeOptional n2;
+ Label n3;
+ Stmt n4;
+ label_2:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case NOOP:
+ case MOVE:
+ case ERROR:
+ case PRINT:
+ case JUMP:
+ case CJUMP:
+ case HSTORE:
+ case HLOAD:
+ case IDENTIFIER:
+ ;
+ break;
+ default:
+ jj_la1[1] = jj_gen;
+ break label_2;
+ }
+ n2 = new NodeOptional();
+ n1 = new NodeSequence(2);
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case IDENTIFIER:
+ n3 = Label();
+ n2.addNode(n3);
+ break;
+ default:
+ jj_la1[2] = jj_gen;
+ ;
+ }
+ n1.addNode(n2);
+ n4 = Stmt();
+ n1.addNode(n4);
+ n0.addNode(n1);
+ }
+ n0.nodes.trimToSize();
+ {if (true) return new StmtList(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Procedure Procedure() throws ParseException {
+ Label n0;
+ NodeToken n1;
+ Token n2;
+ IntegerLiteral n3;
+ NodeToken n4;
+ Token n5;
+ StmtExp n6;
+ n0 = Label();
+ n2 = jj_consume_token(LSQPAREN);
+ n1 = JTBToolkit.makeNodeToken(n2);
+ n3 = IntegerLiteral();
+ n5 = jj_consume_token(RSQPAREN);
+ n4 = JTBToolkit.makeNodeToken(n5);
+ n6 = StmtExp();
+ {if (true) return new Procedure(n0,n1,n3,n4,n6);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Stmt Stmt() throws ParseException {
+ NodeChoice n0;
+ NoOpStmt n1;
+ ErrorStmt n2;
+ CJumpStmt n3;
+ JumpStmt n4;
+ HStoreStmt n5;
+ HLoadStmt n6;
+ MoveStmt n7;
+ PrintStmt n8;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case NOOP:
+ n1 = NoOpStmt();
+ n0 = new NodeChoice(n1, 0);
+ break;
+ case ERROR:
+ n2 = ErrorStmt();
+ n0 = new NodeChoice(n2, 1);
+ break;
+ case CJUMP:
+ n3 = CJumpStmt();
+ n0 = new NodeChoice(n3, 2);
+ break;
+ case JUMP:
+ n4 = JumpStmt();
+ n0 = new NodeChoice(n4, 3);
+ break;
+ case HSTORE:
+ n5 = HStoreStmt();
+ n0 = new NodeChoice(n5, 4);
+ break;
+ case HLOAD:
+ n6 = HLoadStmt();
+ n0 = new NodeChoice(n6, 5);
+ break;
+ case MOVE:
+ n7 = MoveStmt();
+ n0 = new NodeChoice(n7, 6);
+ break;
+ case PRINT:
+ n8 = PrintStmt();
+ n0 = new NodeChoice(n8, 7);
+ break;
+ default:
+ jj_la1[3] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ {if (true) return new Stmt(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public NoOpStmt NoOpStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ n1 = jj_consume_token(NOOP);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ {if (true) return new NoOpStmt(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public ErrorStmt ErrorStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ n1 = jj_consume_token(ERROR);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ {if (true) return new ErrorStmt(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public CJumpStmt CJumpStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Exp n2;
+ Label n3;
+ n1 = jj_consume_token(CJUMP);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Exp();
+ n3 = Label();
+ {if (true) return new CJumpStmt(n0,n2,n3);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public JumpStmt JumpStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Label n2;
+ n1 = jj_consume_token(JUMP);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Label();
+ {if (true) return new JumpStmt(n0,n2);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public HStoreStmt HStoreStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Exp n2;
+ IntegerLiteral n3;
+ Exp n4;
+ n1 = jj_consume_token(HSTORE);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Exp();
+ n3 = IntegerLiteral();
+ n4 = Exp();
+ {if (true) return new HStoreStmt(n0,n2,n3,n4);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public HLoadStmt HLoadStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Temp n2;
+ Exp n3;
+ IntegerLiteral n4;
+ n1 = jj_consume_token(HLOAD);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Temp();
+ n3 = Exp();
+ n4 = IntegerLiteral();
+ {if (true) return new HLoadStmt(n0,n2,n3,n4);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public MoveStmt MoveStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Temp n2;
+ Exp n3;
+ n1 = jj_consume_token(MOVE);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Temp();
+ n3 = Exp();
+ {if (true) return new MoveStmt(n0,n2,n3);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public PrintStmt PrintStmt() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Exp n2;
+ n1 = jj_consume_token(PRINT);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Exp();
+ {if (true) return new PrintStmt(n0,n2);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Exp Exp() throws ParseException {
+ NodeChoice n0;
+ StmtExp n1;
+ Call n2;
+ HAllocate n3;
+ BinOp n4;
+ Temp n5;
+ IntegerLiteral n6;
+ Label n7;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case BEGIN:
+ n1 = StmtExp();
+ n0 = new NodeChoice(n1, 0);
+ break;
+ case CALL:
+ n2 = Call();
+ n0 = new NodeChoice(n2, 1);
+ break;
+ case HALLOCATE:
+ n3 = HAllocate();
+ n0 = new NodeChoice(n3, 2);
+ break;
+ case LT:
+ case PLUS:
+ case MINUS:
+ case TIMES:
+ n4 = BinOp();
+ n0 = new NodeChoice(n4, 3);
+ break;
+ case TEMP:
+ n5 = Temp();
+ n0 = new NodeChoice(n5, 4);
+ break;
+ case INTEGER_LITERAL:
+ n6 = IntegerLiteral();
+ n0 = new NodeChoice(n6, 5);
+ break;
+ case IDENTIFIER:
+ n7 = Label();
+ n0 = new NodeChoice(n7, 6);
+ break;
+ default:
+ jj_la1[4] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ {if (true) return new Exp(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public StmtExp StmtExp() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ StmtList n2;
+ NodeToken n3;
+ Token n4;
+ Exp n5;
+ NodeToken n6;
+ Token n7;
+ n1 = jj_consume_token(BEGIN);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = StmtList();
+ n4 = jj_consume_token(RETURN);
+ n3 = JTBToolkit.makeNodeToken(n4);
+ n5 = Exp();
+ n7 = jj_consume_token(END);
+ n6 = JTBToolkit.makeNodeToken(n7);
+ {if (true) return new StmtExp(n0,n2,n3,n5,n6);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Call Call() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Exp n2;
+ NodeToken n3;
+ Token n4;
+ NodeListOptional n5 = new NodeListOptional();
+ Exp n6;
+ NodeToken n7;
+ Token n8;
+ n1 = jj_consume_token(CALL);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Exp();
+ n4 = jj_consume_token(LPAREN);
+ n3 = JTBToolkit.makeNodeToken(n4);
+ label_3:
+ while (true) {
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LT:
+ case PLUS:
+ case MINUS:
+ case TIMES:
+ case HALLOCATE:
+ case CALL:
+ case BEGIN:
+ case TEMP:
+ case INTEGER_LITERAL:
+ case IDENTIFIER:
+ ;
+ break;
+ default:
+ jj_la1[5] = jj_gen;
+ break label_3;
+ }
+ n6 = Exp();
+ n5.addNode(n6);
+ }
+ n5.nodes.trimToSize();
+ n8 = jj_consume_token(RPAREN);
+ n7 = JTBToolkit.makeNodeToken(n8);
+ {if (true) return new Call(n0,n2,n3,n5,n7);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public HAllocate HAllocate() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ Exp n2;
+ n1 = jj_consume_token(HALLOCATE);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = Exp();
+ {if (true) return new HAllocate(n0,n2);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public BinOp BinOp() throws ParseException {
+ Operator n0;
+ Exp n1;
+ Exp n2;
+ n0 = Operator();
+ n1 = Exp();
+ n2 = Exp();
+ {if (true) return new BinOp(n0,n1,n2);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Operator Operator() throws ParseException {
+ NodeChoice n0;
+ NodeToken n1;
+ Token n2;
+ NodeToken n3;
+ Token n4;
+ NodeToken n5;
+ Token n6;
+ NodeToken n7;
+ Token n8;
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case LT:
+ n2 = jj_consume_token(LT);
+ n1 = JTBToolkit.makeNodeToken(n2);
+ n0 = new NodeChoice(n1, 0);
+ break;
+ case PLUS:
+ n4 = jj_consume_token(PLUS);
+ n3 = JTBToolkit.makeNodeToken(n4);
+ n0 = new NodeChoice(n3, 1);
+ break;
+ case MINUS:
+ n6 = jj_consume_token(MINUS);
+ n5 = JTBToolkit.makeNodeToken(n6);
+ n0 = new NodeChoice(n5, 2);
+ break;
+ case TIMES:
+ n8 = jj_consume_token(TIMES);
+ n7 = JTBToolkit.makeNodeToken(n8);
+ n0 = new NodeChoice(n7, 3);
+ break;
+ default:
+ jj_la1[6] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ {if (true) return new Operator(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Temp Temp() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ IntegerLiteral n2;
+ n1 = jj_consume_token(TEMP);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ n2 = IntegerLiteral();
+ {if (true) return new Temp(n0,n2);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public IntegerLiteral IntegerLiteral() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ n1 = jj_consume_token(INTEGER_LITERAL);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ {if (true) return new IntegerLiteral(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static final public Label Label() throws ParseException {
+ NodeToken n0;
+ Token n1;
+ n1 = jj_consume_token(IDENTIFIER);
+ n0 = JTBToolkit.makeNodeToken(n1);
+ {if (true) return new Label(n0);}
+ throw new Error("Missing return statement in function");
+ }
+
+ static private boolean jj_initialized_once = false;
+ static public PigletParserTokenManager token_source;
+ static JavaCharStream jj_input_stream;
+ static public Token token, jj_nt;
+ static private int jj_ntk;
+ static private int jj_gen;
+ static final private int[] jj_la1 = new int[7];
+ static private int[] jj_la1_0;
+ static private int[] jj_la1_1;
+ static {
+ jj_la1_0();
+ jj_la1_1();
+ }
+ private static void jj_la1_0() {
+ jj_la1_0 = new int[] {0x0,0x0,0x0,0x0,0x48c10000,0x48c10000,0x8c10000,};
+ }
+ private static void jj_la1_1() {
+ jj_la1_1 = new int[] {0x8000,0x879b,0x8000,0x79b,0xd024,0xd024,0x0,};
+ }
+
+ public PigletParser(java.io.InputStream stream) {
+ this(stream, null);
+ }
+ public PigletParser(java.io.InputStream stream, String encoding) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
+ token_source = new PigletParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ static public void ReInit(java.io.InputStream stream) {
+ ReInit(stream, null);
+ }
+ static public void ReInit(java.io.InputStream stream, String encoding) {
+ try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ public PigletParser(java.io.Reader stream) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ jj_input_stream = new JavaCharStream(stream, 1, 1);
+ token_source = new PigletParserTokenManager(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ static public void ReInit(java.io.Reader stream) {
+ jj_input_stream.ReInit(stream, 1, 1);
+ token_source.ReInit(jj_input_stream);
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ public PigletParser(PigletParserTokenManager tm) {
+ if (jj_initialized_once) {
+ System.out.println("ERROR: Second call to constructor of static parser. You must");
+ System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
+ System.out.println(" during parser generation.");
+ throw new Error();
+ }
+ jj_initialized_once = true;
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ public void ReInit(PigletParserTokenManager tm) {
+ token_source = tm;
+ token = new Token();
+ jj_ntk = -1;
+ jj_gen = 0;
+ for (int i = 0; i < 7; i++) jj_la1[i] = -1;
+ }
+
+ static final private Token jj_consume_token(int kind) throws ParseException {
+ Token oldToken;
+ if ((oldToken = token).next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ if (token.kind == kind) {
+ jj_gen++;
+ return token;
+ }
+ token = oldToken;
+ jj_kind = kind;
+ throw generateParseException();
+ }
+
+ static final public Token getNextToken() {
+ if (token.next != null) token = token.next;
+ else token = token.next = token_source.getNextToken();
+ jj_ntk = -1;
+ jj_gen++;
+ return token;
+ }
+
+ static final public Token getToken(int index) {
+ Token t = token;
+ for (int i = 0; i < index; i++) {
+ if (t.next != null) t = t.next;
+ else t = t.next = token_source.getNextToken();
+ }
+ return t;
+ }
+
+ static final private int jj_ntk() {
+ if ((jj_nt=token.next) == null)
+ return (jj_ntk = (token.next=token_source.getNextToken()).kind);
+ else
+ return (jj_ntk = jj_nt.kind);
+ }
+
+ static private java.util.Vector jj_expentries = new java.util.Vector();
+ static private int[] jj_expentry;
+ static private int jj_kind = -1;
+
+ static public ParseException generateParseException() {
+ jj_expentries.removeAllElements();
+ boolean[] la1tokens = new boolean[50];
+ for (int i = 0; i < 50; i++) {
+ la1tokens[i] = false;
+ }
+ if (jj_kind >= 0) {
+ la1tokens[jj_kind] = true;
+ jj_kind = -1;
+ }
+ for (int i = 0; i < 7; i++) {
+ if (jj_la1[i] == jj_gen) {
+ for (int j = 0; j < 32; j++) {
+ if ((jj_la1_0[i] & (1<<j)) != 0) {
+ la1tokens[j] = true;
+ }
+ if ((jj_la1_1[i] & (1<<j)) != 0) {
+ la1tokens[32+j] = true;
+ }
+ }
+ }
+ }
+ for (int i = 0; i < 50; i++) {
+ if (la1tokens[i]) {
+ jj_expentry = new int[1];
+ jj_expentry[0] = i;
+ jj_expentries.addElement(jj_expentry);
+ }
+ }
+ int[][] exptokseq = new int[jj_expentries.size()][];
+ for (int i = 0; i < jj_expentries.size(); i++) {
+ exptokseq[i] = (int[])jj_expentries.elementAt(i);
+ }
+ return new ParseException(token, exptokseq, tokenImage);
+ }
+
+ static final public void enable_tracing() {
+ }
+
+ static final public void disable_tracing() {
+ }
+
+}
+
+class JTBToolkit {
+ static NodeToken makeNodeToken(Token t) {
+ return new NodeToken(t.image.intern(), t.kind, t.beginLine, t.beginColumn, t.endLine, t.endColumn);
+ }
+}
diff --git a/src/piglet/PigletParserConstants.java b/src/piglet/PigletParserConstants.java
new file mode 100644
index 0000000..d552fd5
--- /dev/null
+++ b/src/piglet/PigletParserConstants.java
@@ -0,0 +1,106 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. PigletParserConstants.java */
+public interface PigletParserConstants {
+
+ int EOF = 0;
+ int SINGLE_LINE_COMMENT = 6;
+ int FORMAL_COMMENT = 7;
+ int MULTI_LINE_COMMENT = 8;
+ int LPAREN = 9;
+ int RPAREN = 10;
+ int LBRACE = 11;
+ int RBRACE = 12;
+ int LSQPAREN = 13;
+ int RSQPAREN = 14;
+ int DOT = 15;
+ int LT = 16;
+ int LE = 17;
+ int GT = 18;
+ int GE = 19;
+ int NE = 20;
+ int EQ = 21;
+ int PLUS = 22;
+ int MINUS = 23;
+ int AND = 24;
+ int OR = 25;
+ int NOT = 26;
+ int TIMES = 27;
+ int MAIN = 28;
+ int CODE = 29;
+ int HALLOCATE = 30;
+ int END = 31;
+ int NOOP = 32;
+ int MOVE = 33;
+ int CALL = 34;
+ int ERROR = 35;
+ int PRINT = 36;
+ int BEGIN = 37;
+ int RETURN = 38;
+ int JUMP = 39;
+ int CJUMP = 40;
+ int HSTORE = 41;
+ int HLOAD = 42;
+ int MEM = 43;
+ int TEMP = 44;
+ int ARG = 45;
+ int INTEGER_LITERAL = 46;
+ int IDENTIFIER = 47;
+ int LETTER = 48;
+ int DIGIT = 49;
+
+ int DEFAULT = 0;
+
+ String[] tokenImage = {
+ "<EOF>",
+ "\" \"",
+ "\"\\t\"",
+ "\"\\n\"",
+ "\"\\r\"",
+ "\"\\f\"",
+ "<SINGLE_LINE_COMMENT>",
+ "<FORMAL_COMMENT>",
+ "<MULTI_LINE_COMMENT>",
+ "\"(\"",
+ "\")\"",
+ "\"{\"",
+ "\"}\"",
+ "\"[\"",
+ "\"]\"",
+ "\".\"",
+ "\"LT\"",
+ "\"LE\"",
+ "\"GT\"",
+ "\"GE\"",
+ "\"NE\"",
+ "\"EQ\"",
+ "\"PLUS\"",
+ "\"MINUS\"",
+ "\"AND\"",
+ "\"OR\"",
+ "\"NOT\"",
+ "\"TIMES\"",
+ "\"MAIN\"",
+ "\"CODE\"",
+ "\"HALLOCATE\"",
+ "\"END\"",
+ "\"NOOP\"",
+ "\"MOVE\"",
+ "\"CALL\"",
+ "\"ERROR\"",
+ "\"PRINT\"",
+ "\"BEGIN\"",
+ "\"RETURN\"",
+ "\"JUMP\"",
+ "\"CJUMP\"",
+ "\"HSTORE\"",
+ "\"HLOAD\"",
+ "\"MEM\"",
+ "\"TEMP\"",
+ "\"ARG\"",
+ "<INTEGER_LITERAL>",
+ "<IDENTIFIER>",
+ "<LETTER>",
+ "<DIGIT>",
+ };
+
+}
diff --git a/src/piglet/PigletParserTokenManager.java b/src/piglet/PigletParserTokenManager.java
new file mode 100644
index 0000000..34b879d
--- /dev/null
+++ b/src/piglet/PigletParserTokenManager.java
@@ -0,0 +1,925 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. PigletParserTokenManager.java */
+
+
+public class PigletParserTokenManager implements PigletParserConstants
+{
+ public static java.io.PrintStream debugStream = System.out;
+ public static void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
+private static final int jjStopStringLiteralDfa_0(int pos, long active0)
+{
+ switch (pos)
+ {
+ case 0:
+ if ((active0 & 0x3fffffff0000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ return 4;
+ }
+ return -1;
+ case 1:
+ if ((active0 & 0x3ffffdc00000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 1;
+ return 4;
+ }
+ if ((active0 & 0x23f0000L) != 0L)
+ return 4;
+ return -1;
+ case 2:
+ if ((active0 & 0x17ff78c00000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 2;
+ return 4;
+ }
+ if ((active0 & 0x280085000000L) != 0L)
+ return 4;
+ return -1;
+ case 3:
+ if ((active0 & 0x77848800000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 3;
+ return 4;
+ }
+ if ((active0 & 0x108730400000L) != 0L)
+ return 4;
+ return -1;
+ case 4:
+ if ((active0 & 0x53808800000L) != 0L)
+ return 4;
+ if ((active0 & 0x24040000000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 4;
+ return 4;
+ }
+ return -1;
+ case 5:
+ if ((active0 & 0x24000000000L) != 0L)
+ return 4;
+ if ((active0 & 0x40000000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 5;
+ return 4;
+ }
+ return -1;
+ case 6:
+ if ((active0 & 0x40000000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 6;
+ return 4;
+ }
+ return -1;
+ case 7:
+ if ((active0 & 0x40000000L) != 0L)
+ {
+ jjmatchedKind = 47;
+ jjmatchedPos = 7;
+ return 4;
+ }
+ return -1;
+ default :
+ return -1;
+ }
+}
+private static final int jjStartNfa_0(int pos, long active0)
+{
+ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
+}
+static private final int jjStopAtPos(int pos, int kind)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ return pos + 1;
+}
+static private final int jjStartNfaWithStates_0(int pos, int kind, int state)
+{
+ jjmatchedKind = kind;
+ jjmatchedPos = pos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return pos + 1; }
+ return jjMoveNfa_0(state, pos + 1);
+}
+static private final int jjMoveStringLiteralDfa0_0()
+{
+ switch(curChar)
+ {
+ case 40:
+ return jjStopAtPos(0, 9);
+ case 41:
+ return jjStopAtPos(0, 10);
+ case 46:
+ return jjStopAtPos(0, 15);
+ case 65:
+ return jjMoveStringLiteralDfa1_0(0x200001000000L);
+ case 66:
+ return jjMoveStringLiteralDfa1_0(0x2000000000L);
+ case 67:
+ return jjMoveStringLiteralDfa1_0(0x10420000000L);
+ case 69:
+ return jjMoveStringLiteralDfa1_0(0x880200000L);
+ case 71:
+ return jjMoveStringLiteralDfa1_0(0xc0000L);
+ case 72:
+ return jjMoveStringLiteralDfa1_0(0x60040000000L);
+ case 74:
+ return jjMoveStringLiteralDfa1_0(0x8000000000L);
+ case 76:
+ return jjMoveStringLiteralDfa1_0(0x30000L);
+ case 77:
+ return jjMoveStringLiteralDfa1_0(0x80210800000L);
+ case 78:
+ return jjMoveStringLiteralDfa1_0(0x104100000L);
+ case 79:
+ return jjMoveStringLiteralDfa1_0(0x2000000L);
+ case 80:
+ return jjMoveStringLiteralDfa1_0(0x1000400000L);
+ case 82:
+ return jjMoveStringLiteralDfa1_0(0x4000000000L);
+ case 84:
+ return jjMoveStringLiteralDfa1_0(0x100008000000L);
+ case 91:
+ return jjStopAtPos(0, 13);
+ case 93:
+ return jjStopAtPos(0, 14);
+ case 123:
+ return jjStopAtPos(0, 11);
+ case 125:
+ return jjStopAtPos(0, 12);
+ default :
+ return jjMoveNfa_0(0, 0);
+ }
+}
+static private final int jjMoveStringLiteralDfa1_0(long active0)
+{
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(0, active0);
+ return 1;
+ }
+ switch(curChar)
+ {
+ case 65:
+ return jjMoveStringLiteralDfa2_0(active0, 0x450000000L);
+ case 69:
+ if ((active0 & 0x20000L) != 0L)
+ return jjStartNfaWithStates_0(1, 17, 4);
+ else if ((active0 & 0x80000L) != 0L)
+ return jjStartNfaWithStates_0(1, 19, 4);
+ else if ((active0 & 0x100000L) != 0L)
+ return jjStartNfaWithStates_0(1, 20, 4);
+ return jjMoveStringLiteralDfa2_0(active0, 0x186000000000L);
+ case 73:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8800000L);
+ case 74:
+ return jjMoveStringLiteralDfa2_0(active0, 0x10000000000L);
+ case 76:
+ return jjMoveStringLiteralDfa2_0(active0, 0x40000400000L);
+ case 78:
+ return jjMoveStringLiteralDfa2_0(active0, 0x81000000L);
+ case 79:
+ return jjMoveStringLiteralDfa2_0(active0, 0x324000000L);
+ case 81:
+ if ((active0 & 0x200000L) != 0L)
+ return jjStartNfaWithStates_0(1, 21, 4);
+ break;
+ case 82:
+ if ((active0 & 0x2000000L) != 0L)
+ return jjStartNfaWithStates_0(1, 25, 4);
+ return jjMoveStringLiteralDfa2_0(active0, 0x201800000000L);
+ case 83:
+ return jjMoveStringLiteralDfa2_0(active0, 0x20000000000L);
+ case 84:
+ if ((active0 & 0x10000L) != 0L)
+ return jjStartNfaWithStates_0(1, 16, 4);
+ else if ((active0 & 0x40000L) != 0L)
+ return jjStartNfaWithStates_0(1, 18, 4);
+ break;
+ case 85:
+ return jjMoveStringLiteralDfa2_0(active0, 0x8000000000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(0, active0);
+}
+static private final int jjMoveStringLiteralDfa2_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(0, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(1, active0);
+ return 2;
+ }
+ switch(curChar)
+ {
+ case 68:
+ if ((active0 & 0x1000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 24, 4);
+ else if ((active0 & 0x80000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 31, 4);
+ return jjMoveStringLiteralDfa3_0(active0, 0x20000000L);
+ case 71:
+ if ((active0 & 0x200000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 45, 4);
+ return jjMoveStringLiteralDfa3_0(active0, 0x2000000000L);
+ case 73:
+ return jjMoveStringLiteralDfa3_0(active0, 0x1010000000L);
+ case 76:
+ return jjMoveStringLiteralDfa3_0(active0, 0x440000000L);
+ case 77:
+ if ((active0 & 0x80000000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 43, 4);
+ return jjMoveStringLiteralDfa3_0(active0, 0x108008000000L);
+ case 78:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000L);
+ case 79:
+ return jjMoveStringLiteralDfa3_0(active0, 0x40100000000L);
+ case 82:
+ return jjMoveStringLiteralDfa3_0(active0, 0x800000000L);
+ case 84:
+ if ((active0 & 0x4000000L) != 0L)
+ return jjStartNfaWithStates_0(2, 26, 4);
+ return jjMoveStringLiteralDfa3_0(active0, 0x24000000000L);
+ case 85:
+ return jjMoveStringLiteralDfa3_0(active0, 0x10000400000L);
+ case 86:
+ return jjMoveStringLiteralDfa3_0(active0, 0x200000000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(1, active0);
+}
+static private final int jjMoveStringLiteralDfa3_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(1, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(2, active0);
+ return 3;
+ }
+ switch(curChar)
+ {
+ case 65:
+ return jjMoveStringLiteralDfa4_0(active0, 0x40000000000L);
+ case 69:
+ if ((active0 & 0x20000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 29, 4);
+ else if ((active0 & 0x200000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 33, 4);
+ return jjMoveStringLiteralDfa4_0(active0, 0x8000000L);
+ case 73:
+ return jjMoveStringLiteralDfa4_0(active0, 0x2000000000L);
+ case 76:
+ if ((active0 & 0x400000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 34, 4);
+ return jjMoveStringLiteralDfa4_0(active0, 0x40000000L);
+ case 77:
+ return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L);
+ case 78:
+ if ((active0 & 0x10000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 28, 4);
+ return jjMoveStringLiteralDfa4_0(active0, 0x1000000000L);
+ case 79:
+ return jjMoveStringLiteralDfa4_0(active0, 0x20800000000L);
+ case 80:
+ if ((active0 & 0x100000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 32, 4);
+ else if ((active0 & 0x8000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 39, 4);
+ else if ((active0 & 0x100000000000L) != 0L)
+ return jjStartNfaWithStates_0(3, 44, 4);
+ break;
+ case 83:
+ if ((active0 & 0x400000L) != 0L)
+ return jjStartNfaWithStates_0(3, 22, 4);
+ break;
+ case 85:
+ return jjMoveStringLiteralDfa4_0(active0, 0x4000800000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(2, active0);
+}
+static private final int jjMoveStringLiteralDfa4_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(2, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(3, active0);
+ return 4;
+ }
+ switch(curChar)
+ {
+ case 68:
+ if ((active0 & 0x40000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 42, 4);
+ break;
+ case 78:
+ if ((active0 & 0x2000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 37, 4);
+ break;
+ case 79:
+ return jjMoveStringLiteralDfa5_0(active0, 0x40000000L);
+ case 80:
+ if ((active0 & 0x10000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 40, 4);
+ break;
+ case 82:
+ if ((active0 & 0x800000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 35, 4);
+ return jjMoveStringLiteralDfa5_0(active0, 0x24000000000L);
+ case 83:
+ if ((active0 & 0x800000L) != 0L)
+ return jjStartNfaWithStates_0(4, 23, 4);
+ else if ((active0 & 0x8000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 27, 4);
+ break;
+ case 84:
+ if ((active0 & 0x1000000000L) != 0L)
+ return jjStartNfaWithStates_0(4, 36, 4);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(3, active0);
+}
+static private final int jjMoveStringLiteralDfa5_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(3, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(4, active0);
+ return 5;
+ }
+ switch(curChar)
+ {
+ case 67:
+ return jjMoveStringLiteralDfa6_0(active0, 0x40000000L);
+ case 69:
+ if ((active0 & 0x20000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 41, 4);
+ break;
+ case 78:
+ if ((active0 & 0x4000000000L) != 0L)
+ return jjStartNfaWithStates_0(5, 38, 4);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(4, active0);
+}
+static private final int jjMoveStringLiteralDfa6_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(4, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(5, active0);
+ return 6;
+ }
+ switch(curChar)
+ {
+ case 65:
+ return jjMoveStringLiteralDfa7_0(active0, 0x40000000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(5, active0);
+}
+static private final int jjMoveStringLiteralDfa7_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(5, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(6, active0);
+ return 7;
+ }
+ switch(curChar)
+ {
+ case 84:
+ return jjMoveStringLiteralDfa8_0(active0, 0x40000000L);
+ default :
+ break;
+ }
+ return jjStartNfa_0(6, active0);
+}
+static private final int jjMoveStringLiteralDfa8_0(long old0, long active0)
+{
+ if (((active0 &= old0)) == 0L)
+ return jjStartNfa_0(6, old0);
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) {
+ jjStopStringLiteralDfa_0(7, active0);
+ return 8;
+ }
+ switch(curChar)
+ {
+ case 69:
+ if ((active0 & 0x40000000L) != 0L)
+ return jjStartNfaWithStates_0(8, 30, 4);
+ break;
+ default :
+ break;
+ }
+ return jjStartNfa_0(7, active0);
+}
+static private final void jjCheckNAdd(int state)
+{
+ if (jjrounds[state] != jjround)
+ {
+ jjstateSet[jjnewStateCnt++] = state;
+ jjrounds[state] = jjround;
+ }
+}
+static private final void jjAddStates(int start, int end)
+{
+ do {
+ jjstateSet[jjnewStateCnt++] = jjnextStates[start];
+ } while (start++ != end);
+}
+static private final void jjCheckNAddTwoStates(int state1, int state2)
+{
+ jjCheckNAdd(state1);
+ jjCheckNAdd(state2);
+}
+static private final void jjCheckNAddStates(int start, int end)
+{
+ do {
+ jjCheckNAdd(jjnextStates[start]);
+ } while (start++ != end);
+}
+static private final void jjCheckNAddStates(int start)
+{
+ jjCheckNAdd(jjnextStates[start]);
+ jjCheckNAdd(jjnextStates[start + 1]);
+}
+static final long[] jjbitVec0 = {
+ 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L
+};
+static final long[] jjbitVec2 = {
+ 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL
+};
+static final long[] jjbitVec3 = {
+ 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec4 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L
+};
+static final long[] jjbitVec5 = {
+ 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L
+};
+static final long[] jjbitVec6 = {
+ 0x3fffffffffffL, 0x0L, 0x0L, 0x0L
+};
+static final long[] jjbitVec7 = {
+ 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static final long[] jjbitVec8 = {
+ 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
+};
+static private final int jjMoveNfa_0(int startState, int curPos)
+{
+ int[] nextStates;
+ int startsAt = 0;
+ jjnewStateCnt = 24;
+ int i = 1;
+ jjstateSet[0] = startState;
+ int j, kind = 0x7fffffff;
+ for (;;)
+ {
+ if (++jjround == 0x7fffffff)
+ ReInitRounds();
+ if (curChar < 64)
+ {
+ long l = 1L << curChar;
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ if ((0x3fe000000000000L & l) != 0L)
+ {
+ if (kind > 46)
+ kind = 46;
+ jjCheckNAdd(1);
+ }
+ else if (curChar == 47)
+ jjAddStates(0, 2);
+ else if (curChar == 36)
+ {
+ if (kind > 47)
+ kind = 47;
+ jjCheckNAdd(4);
+ }
+ else if (curChar == 48)
+ {
+ if (kind > 46)
+ kind = 46;
+ }
+ break;
+ case 1:
+ if ((0x3ff000000000000L & l) == 0L)
+ break;
+ if (kind > 46)
+ kind = 46;
+ jjCheckNAdd(1);
+ break;
+ case 2:
+ if (curChar == 48 && kind > 46)
+ kind = 46;
+ break;
+ case 3:
+ if (curChar != 36)
+ break;
+ if (kind > 47)
+ kind = 47;
+ jjCheckNAdd(4);
+ break;
+ case 4:
+ if ((0x3ff001000000000L & l) == 0L)
+ break;
+ if (kind > 47)
+ kind = 47;
+ jjCheckNAdd(4);
+ break;
+ case 5:
+ if (curChar == 47)
+ jjAddStates(0, 2);
+ break;
+ case 6:
+ if (curChar == 47)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 7:
+ if ((0xffffffffffffdbffL & l) != 0L)
+ jjCheckNAddStates(3, 5);
+ break;
+ case 8:
+ if ((0x2400L & l) != 0L && kind > 6)
+ kind = 6;
+ break;
+ case 9:
+ if (curChar == 10 && kind > 6)
+ kind = 6;
+ break;
+ case 10:
+ if (curChar == 13)
+ jjstateSet[jjnewStateCnt++] = 9;
+ break;
+ case 11:
+ if (curChar == 42)
+ jjCheckNAddTwoStates(12, 13);
+ break;
+ case 12:
+ if ((0xfffffbffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(12, 13);
+ break;
+ case 13:
+ if (curChar == 42)
+ jjCheckNAddStates(6, 8);
+ break;
+ case 14:
+ if ((0xffff7bffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(15, 13);
+ break;
+ case 15:
+ if ((0xfffffbffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(15, 13);
+ break;
+ case 16:
+ if (curChar == 47 && kind > 7)
+ kind = 7;
+ break;
+ case 17:
+ if (curChar == 42)
+ jjstateSet[jjnewStateCnt++] = 11;
+ break;
+ case 18:
+ if (curChar == 42)
+ jjCheckNAddTwoStates(19, 20);
+ break;
+ case 19:
+ if ((0xfffffbffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(19, 20);
+ break;
+ case 20:
+ if (curChar == 42)
+ jjCheckNAddStates(9, 11);
+ break;
+ case 21:
+ if ((0xffff7bffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(22, 20);
+ break;
+ case 22:
+ if ((0xfffffbffffffffffL & l) != 0L)
+ jjCheckNAddTwoStates(22, 20);
+ break;
+ case 23:
+ if (curChar == 47 && kind > 8)
+ kind = 8;
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else if (curChar < 128)
+ {
+ long l = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ case 4:
+ if ((0x7fffffe87fffffeL & l) == 0L)
+ break;
+ if (kind > 47)
+ kind = 47;
+ jjCheckNAdd(4);
+ break;
+ case 7:
+ jjAddStates(3, 5);
+ break;
+ case 12:
+ jjCheckNAddTwoStates(12, 13);
+ break;
+ case 14:
+ case 15:
+ jjCheckNAddTwoStates(15, 13);
+ break;
+ case 19:
+ jjCheckNAddTwoStates(19, 20);
+ break;
+ case 21:
+ case 22:
+ jjCheckNAddTwoStates(22, 20);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ else
+ {
+ int hiByte = (int)(curChar >> 8);
+ int i1 = hiByte >> 6;
+ long l1 = 1L << (hiByte & 077);
+ int i2 = (curChar & 0xff) >> 6;
+ long l2 = 1L << (curChar & 077);
+ MatchLoop: do
+ {
+ switch(jjstateSet[--i])
+ {
+ case 0:
+ case 4:
+ if (!jjCanMove_0(hiByte, i1, i2, l1, l2))
+ break;
+ if (kind > 47)
+ kind = 47;
+ jjCheckNAdd(4);
+ break;
+ case 7:
+ if (jjCanMove_1(hiByte, i1, i2, l1, l2))
+ jjAddStates(3, 5);
+ break;
+ case 12:
+ if (jjCanMove_1(hiByte, i1, i2, l1, l2))
+ jjCheckNAddTwoStates(12, 13);
+ break;
+ case 14:
+ case 15:
+ if (jjCanMove_1(hiByte, i1, i2, l1, l2))
+ jjCheckNAddTwoStates(15, 13);
+ break;
+ case 19:
+ if (jjCanMove_1(hiByte, i1, i2, l1, l2))
+ jjCheckNAddTwoStates(19, 20);
+ break;
+ case 21:
+ case 22:
+ if (jjCanMove_1(hiByte, i1, i2, l1, l2))
+ jjCheckNAddTwoStates(22, 20);
+ break;
+ default : break;
+ }
+ } while(i != startsAt);
+ }
+ if (kind != 0x7fffffff)
+ {
+ jjmatchedKind = kind;
+ jjmatchedPos = curPos;
+ kind = 0x7fffffff;
+ }
+ ++curPos;
+ if ((i = jjnewStateCnt) == (startsAt = 24 - (jjnewStateCnt = startsAt)))
+ return curPos;
+ try { curChar = input_stream.readChar(); }
+ catch(java.io.IOException e) { return curPos; }
+ }
+}
+static final int[] jjnextStates = {
+ 6, 17, 18, 7, 8, 10, 13, 14, 16, 20, 21, 23,
+};
+private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec2[i2] & l2) != 0L);
+ case 48:
+ return ((jjbitVec3[i2] & l2) != 0L);
+ case 49:
+ return ((jjbitVec4[i2] & l2) != 0L);
+ case 51:
+ return ((jjbitVec5[i2] & l2) != 0L);
+ case 61:
+ return ((jjbitVec6[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec0[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2)
+{
+ switch(hiByte)
+ {
+ case 0:
+ return ((jjbitVec8[i2] & l2) != 0L);
+ default :
+ if ((jjbitVec7[i1] & l1) != 0L)
+ return true;
+ return false;
+ }
+}
+public static final String[] jjstrLiteralImages = {
+"", null, null, null, null, null, null, null, null, "\50", "\51", "\173",
+"\175", "\133", "\135", "\56", "\114\124", "\114\105", "\107\124", "\107\105",
+"\116\105", "\105\121", "\120\114\125\123", "\115\111\116\125\123", "\101\116\104",
+"\117\122", "\116\117\124", "\124\111\115\105\123", "\115\101\111\116",
+"\103\117\104\105", "\110\101\114\114\117\103\101\124\105", "\105\116\104", "\116\117\117\120",
+"\115\117\126\105", "\103\101\114\114", "\105\122\122\117\122", "\120\122\111\116\124",
+"\102\105\107\111\116", "\122\105\124\125\122\116", "\112\125\115\120", "\103\112\125\115\120",
+"\110\123\124\117\122\105", "\110\114\117\101\104", "\115\105\115", "\124\105\115\120", "\101\122\107",
+null, null, null, null, };
+public static final String[] lexStateNames = {
+ "DEFAULT",
+};
+static final long[] jjtoToken = {
+ 0xfffffffffe01L,
+};
+static final long[] jjtoSkip = {
+ 0x1feL,
+};
+static final long[] jjtoSpecial = {
+ 0x1c0L,
+};
+static protected JavaCharStream input_stream;
+static private final int[] jjrounds = new int[24];
+static private final int[] jjstateSet = new int[48];
+static protected char curChar;
+public PigletParserTokenManager(JavaCharStream stream){
+ if (input_stream != null)
+ throw new TokenMgrError("ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.", TokenMgrError.STATIC_LEXER_ERROR);
+ input_stream = stream;
+}
+public PigletParserTokenManager(JavaCharStream stream, int lexState){
+ this(stream);
+ SwitchTo(lexState);
+}
+static public void ReInit(JavaCharStream stream)
+{
+ jjmatchedPos = jjnewStateCnt = 0;
+ curLexState = defaultLexState;
+ input_stream = stream;
+ ReInitRounds();
+}
+static private final void ReInitRounds()
+{
+ int i;
+ jjround = 0x80000001;
+ for (i = 24; i-- > 0;)
+ jjrounds[i] = 0x80000000;
+}
+static public void ReInit(JavaCharStream stream, int lexState)
+{
+ ReInit(stream);
+ SwitchTo(lexState);
+}
+static public void SwitchTo(int lexState)
+{
+ if (lexState >= 1 || lexState < 0)
+ throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
+ else
+ curLexState = lexState;
+}
+
+static protected Token jjFillToken()
+{
+ Token t = Token.newToken(jjmatchedKind);
+ t.kind = jjmatchedKind;
+ String im = jjstrLiteralImages[jjmatchedKind];
+ t.image = (im == null) ? input_stream.GetImage() : im;
+ t.beginLine = input_stream.getBeginLine();
+ t.beginColumn = input_stream.getBeginColumn();
+ t.endLine = input_stream.getEndLine();
+ t.endColumn = input_stream.getEndColumn();
+ return t;
+}
+
+static int curLexState = 0;
+static int defaultLexState = 0;
+static int jjnewStateCnt;
+static int jjround;
+static int jjmatchedPos;
+static int jjmatchedKind;
+
+public static Token getNextToken()
+{
+ int kind;
+ Token specialToken = null;
+ Token matchedToken;
+ int curPos = 0;
+
+ EOFLoop :
+ for (;;)
+ {
+ try
+ {
+ curChar = input_stream.BeginToken();
+ }
+ catch(java.io.IOException e)
+ {
+ jjmatchedKind = 0;
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ return matchedToken;
+ }
+
+ try { input_stream.backup(0);
+ while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L)
+ curChar = input_stream.BeginToken();
+ }
+ catch (java.io.IOException e1) { continue EOFLoop; }
+ jjmatchedKind = 0x7fffffff;
+ jjmatchedPos = 0;
+ curPos = jjMoveStringLiteralDfa0_0();
+ if (jjmatchedKind != 0x7fffffff)
+ {
+ if (jjmatchedPos + 1 < curPos)
+ input_stream.backup(curPos - jjmatchedPos - 1);
+ if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ matchedToken.specialToken = specialToken;
+ return matchedToken;
+ }
+ else
+ {
+ if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
+ {
+ matchedToken = jjFillToken();
+ if (specialToken == null)
+ specialToken = matchedToken;
+ else
+ {
+ matchedToken.specialToken = specialToken;
+ specialToken = (specialToken.next = matchedToken);
+ }
+ }
+ continue EOFLoop;
+ }
+ }
+ int error_line = input_stream.getEndLine();
+ int error_column = input_stream.getEndColumn();
+ String error_after = null;
+ boolean EOFSeen = false;
+ try { input_stream.readChar(); input_stream.backup(1); }
+ catch (java.io.IOException e1) {
+ EOFSeen = true;
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ if (curChar == '\n' || curChar == '\r') {
+ error_line++;
+ error_column = 0;
+ }
+ else
+ error_column++;
+ }
+ if (!EOFSeen) {
+ input_stream.backup(1);
+ error_after = curPos <= 1 ? "" : input_stream.GetImage();
+ }
+ throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
+ }
+}
+
+}
diff --git a/src/piglet/Token.java b/src/piglet/Token.java
new file mode 100644
index 0000000..9714846
--- /dev/null
+++ b/src/piglet/Token.java
@@ -0,0 +1,80 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
+/**
+ * Describes the input token stream.
+ */
+
+public class Token {
+
+ /**
+ * An integer that describes the kind of this token. This numbering
+ * system is determined by JavaCCParser, and a table of these numbers is
+ * stored in the file ...Constants.java.
+ */
+ public int kind;
+
+ /**
+ * beginLine and beginColumn describe the position of the first character
+ * of this token; endLine and endColumn describe the position of the
+ * last character of this token.
+ */
+ public int beginLine, beginColumn, endLine, endColumn;
+
+ /**
+ * The string image of the token.
+ */
+ public String image;
+
+ /**
+ * A reference to the next regular (non-special) token from the input
+ * stream. If this is the last token from the input stream, or if the
+ * token manager has not read tokens beyond this one, this field is
+ * set to null. This is true only if this token is also a regular
+ * token. Otherwise, see below for a description of the contents of
+ * this field.
+ */
+ public Token next;
+
+ /**
+ * This field is used to access special tokens that occur prior to this
+ * token, but after the immediately preceding regular (non-special) token.
+ * If there are no such special tokens, this field is set to null.
+ * When there are more than one such special token, this field refers
+ * to the last of these special tokens, which in turn refers to the next
+ * previous special token through its specialToken field, and so on
+ * until the first special token (whose specialToken field is null).
+ * The next fields of special tokens refer to other special tokens that
+ * immediately follow it (without an intervening regular token). If there
+ * is no such token, this field is null.
+ */
+ public Token specialToken;
+
+ /**
+ * Returns the image.
+ */
+ public String toString()
+ {
+ return image;
+ }
+
+ /**
+ * Returns a new Token object, by default. However, if you want, you
+ * can create and return subclass objects based on the value of ofKind.
+ * Simply add the cases to the switch for all those special cases.
+ * For example, if you have a subclass of Token called IDToken that
+ * you want to create if ofKind is ID, simlpy add something like :
+ *
+ * case MyParserConstants.ID : return new IDToken();
+ *
+ * to the following switch statement. Then you can cast matchedToken
+ * variable to the appropriate type and use it in your lexical actions.
+ */
+ public static final Token newToken(int ofKind)
+ {
+ switch(ofKind)
+ {
+ default : return new Token();
+ }
+ }
+
+}
diff --git a/src/piglet/TokenMgrError.java b/src/piglet/TokenMgrError.java
new file mode 100644
index 0000000..daa3242
--- /dev/null
+++ b/src/piglet/TokenMgrError.java
@@ -0,0 +1,132 @@
+package piglet;
+/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
+public class TokenMgrError extends Error
+{
+ /*
+ * Ordinals for various reasons why an Error of this type can be thrown.
+ */
+
+ /**
+ * Lexical error occured.
+ */
+ static final int LEXICAL_ERROR = 0;
+
+ /**
+ * An attempt wass made to create a second instance of a static token manager.
+ */
+ static final int STATIC_LEXER_ERROR = 1;
+
+ /**
+ * Tried to change to an invalid lexical state.
+ */
+ static final int INVALID_LEXICAL_STATE = 2;
+
+ /**
+ * Detected (and bailed out of) an infinite loop in the token manager.
+ */
+ static final int LOOP_DETECTED = 3;
+
+ /**
+ * Indicates the reason why the exception is thrown. It will have
+ * one of the above 4 values.
+ */
+ int errorCode;
+
+ /**
+ * Replaces unprintable characters by their espaced (or unicode escaped)
+ * equivalents in the given string
+ */
+ protected static final String addEscapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
+ }
+ }
+ return retval.toString();
+ }
+
+ /**
+ * Returns a detailed message for the Error when it is thrown by the
+ * token manager to indicate a lexical error.
+ * Parameters :
+ * EOFSeen : indicates if EOF caused the lexicl error
+ * curLexState : lexical state in which this error occured
+ * errorLine : line number when the error occured
+ * errorColumn : column number when the error occured
+ * errorAfter : prefix that was seen before this error occured
+ * curchar : the offending character
+ * Note: You can customize the lexical error message by modifying this method.
+ */
+ protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
+ return("Lexical error at line " +
+ errorLine + ", column " +
+ errorColumn + ". Encountered: " +
+ (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
+ "after : \"" + addEscapes(errorAfter) + "\"");
+ }
+
+ /**
+ * You can also modify the body of this method to customize your error messages.
+ * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
+ * of end-users concern, so you can return something like :
+ *
+ * "Internal Error : Please file a bug report .... "
+ *
+ * from this method for such cases in the release version of your parser.
+ */
+ public String getMessage() {
+ return super.getMessage();
+ }
+
+ /*
+ * Constructors of various flavors follow.
+ */
+
+ public TokenMgrError() {
+ }
+
+ public TokenMgrError(String message, int reason) {
+ super(message);
+ errorCode = reason;
+ }
+
+ public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+ this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
+ }
+}
diff --git a/src/piglet/piglet2spiglet/Main.java b/src/piglet/piglet2spiglet/Main.java
new file mode 100644
index 0000000..db68b6a
--- /dev/null
+++ b/src/piglet/piglet2spiglet/Main.java
@@ -0,0 +1,38 @@
+package piglet.piglet2spiglet;
+
+
+import piglet.ParseException;
+import piglet.PigletParser;
+import piglet.TokenMgrError;
+import piglet.syntaxtree.Node;
+import piglet.visitor.GJDepthFirst;
+
+
+public class Main {
+
+ public static void main(String[] args) {
+ try {
+ Node root = new PigletParser(System.in).Goal();
+ /*
+ * TODO: Implement your own Visitors and other classes.
+ *
+ */
+ GJDepthFirst v = new GJDepthFirst<Object,Object>() {
+ };
+ //Traverse the Abstract Grammar Tree
+ root.accept(v,null);
+ }
+ catch(TokenMgrError e){
+ //Handle Lexical Errors
+ e.printStackTrace();
+ }
+ catch (ParseException e){
+ //Handle Grammar Errors
+ e.printStackTrace();
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/piglet/syntaxtree/BinOp.java b/src/piglet/syntaxtree/BinOp.java
new file mode 100644
index 0000000..4ef5e2c
--- /dev/null
+++ b/src/piglet/syntaxtree/BinOp.java
@@ -0,0 +1,37 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+public class BinOp implements Node {
+ public Operator f0;
+ public Exp f1;
+ public Exp f2;
+
+ public BinOp(Operator n0, Exp n1, Exp n2) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/CJumpStmt.java b/src/piglet/syntaxtree/CJumpStmt.java
new file mode 100644
index 0000000..68827ba
--- /dev/null
+++ b/src/piglet/syntaxtree/CJumpStmt.java
@@ -0,0 +1,43 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "CJUMP"
+ * f1 -> Exp()
+ * f2 -> Label()
+ */
+public class CJumpStmt implements Node {
+ public NodeToken f0;
+ public Exp f1;
+ public Label f2;
+
+ public CJumpStmt(NodeToken n0, Exp n1, Label n2) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ }
+
+ public CJumpStmt(Exp n0, Label n1) {
+ f0 = new NodeToken("CJUMP");
+ f1 = n0;
+ f2 = n1;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Call.java b/src/piglet/syntaxtree/Call.java
new file mode 100644
index 0000000..6592374
--- /dev/null
+++ b/src/piglet/syntaxtree/Call.java
@@ -0,0 +1,51 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "CALL"
+ * f1 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * f4 -> ")"
+ */
+public class Call implements Node {
+ public NodeToken f0;
+ public Exp f1;
+ public NodeToken f2;
+ public NodeListOptional f3;
+ public NodeToken f4;
+
+ public Call(NodeToken n0, Exp n1, NodeToken n2, NodeListOptional n3, NodeToken n4) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ f4 = n4;
+ }
+
+ public Call(Exp n0, NodeListOptional n1) {
+ f0 = new NodeToken("CALL");
+ f1 = n0;
+ f2 = new NodeToken("(");
+ f3 = n1;
+ f4 = new NodeToken(")");
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/ErrorStmt.java b/src/piglet/syntaxtree/ErrorStmt.java
new file mode 100644
index 0000000..7811766
--- /dev/null
+++ b/src/piglet/syntaxtree/ErrorStmt.java
@@ -0,0 +1,35 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "ERROR"
+ */
+public class ErrorStmt implements Node {
+ public NodeToken f0;
+
+ public ErrorStmt(NodeToken n0) {
+ f0 = n0;
+ }
+
+ public ErrorStmt() {
+ f0 = new NodeToken("ERROR");
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Exp.java b/src/piglet/syntaxtree/Exp.java
new file mode 100644
index 0000000..62f1fb0
--- /dev/null
+++ b/src/piglet/syntaxtree/Exp.java
@@ -0,0 +1,37 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+public class Exp implements Node {
+ public NodeChoice f0;
+
+ public Exp(NodeChoice n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Goal.java b/src/piglet/syntaxtree/Goal.java
new file mode 100644
index 0000000..43dc3be
--- /dev/null
+++ b/src/piglet/syntaxtree/Goal.java
@@ -0,0 +1,51 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "MAIN"
+ * f1 -> StmtList()
+ * f2 -> "END"
+ * f3 -> ( Procedure() )*
+ * f4 -> <EOF>
+ */
+public class Goal implements Node {
+ public NodeToken f0;
+ public StmtList f1;
+ public NodeToken f2;
+ public NodeListOptional f3;
+ public NodeToken f4;
+
+ public Goal(NodeToken n0, StmtList n1, NodeToken n2, NodeListOptional n3, NodeToken n4) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ f4 = n4;
+ }
+
+ public Goal(StmtList n0, NodeListOptional n1) {
+ f0 = new NodeToken("MAIN");
+ f1 = n0;
+ f2 = new NodeToken("END");
+ f3 = n1;
+ f4 = new NodeToken("");
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/HAllocate.java b/src/piglet/syntaxtree/HAllocate.java
new file mode 100644
index 0000000..495ef0e
--- /dev/null
+++ b/src/piglet/syntaxtree/HAllocate.java
@@ -0,0 +1,39 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "HALLOCATE"
+ * f1 -> Exp()
+ */
+public class HAllocate implements Node {
+ public NodeToken f0;
+ public Exp f1;
+
+ public HAllocate(NodeToken n0, Exp n1) {
+ f0 = n0;
+ f1 = n1;
+ }
+
+ public HAllocate(Exp n0) {
+ f0 = new NodeToken("HALLOCATE");
+ f1 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/HLoadStmt.java b/src/piglet/syntaxtree/HLoadStmt.java
new file mode 100644
index 0000000..423972c
--- /dev/null
+++ b/src/piglet/syntaxtree/HLoadStmt.java
@@ -0,0 +1,47 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ * f3 -> IntegerLiteral()
+ */
+public class HLoadStmt implements Node {
+ public NodeToken f0;
+ public Temp f1;
+ public Exp f2;
+ public IntegerLiteral f3;
+
+ public HLoadStmt(NodeToken n0, Temp n1, Exp n2, IntegerLiteral n3) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ }
+
+ public HLoadStmt(Temp n0, Exp n1, IntegerLiteral n2) {
+ f0 = new NodeToken("HLOAD");
+ f1 = n0;
+ f2 = n1;
+ f3 = n2;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/HStoreStmt.java b/src/piglet/syntaxtree/HStoreStmt.java
new file mode 100644
index 0000000..8384618
--- /dev/null
+++ b/src/piglet/syntaxtree/HStoreStmt.java
@@ -0,0 +1,47 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "HSTORE"
+ * f1 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+public class HStoreStmt implements Node {
+ public NodeToken f0;
+ public Exp f1;
+ public IntegerLiteral f2;
+ public Exp f3;
+
+ public HStoreStmt(NodeToken n0, Exp n1, IntegerLiteral n2, Exp n3) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ }
+
+ public HStoreStmt(Exp n0, IntegerLiteral n1, Exp n2) {
+ f0 = new NodeToken("HSTORE");
+ f1 = n0;
+ f2 = n1;
+ f3 = n2;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/IntegerLiteral.java b/src/piglet/syntaxtree/IntegerLiteral.java
new file mode 100644
index 0000000..2f50375
--- /dev/null
+++ b/src/piglet/syntaxtree/IntegerLiteral.java
@@ -0,0 +1,31 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> <INTEGER_LITERAL>
+ */
+public class IntegerLiteral implements Node {
+ public NodeToken f0;
+
+ public IntegerLiteral(NodeToken n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/JumpStmt.java b/src/piglet/syntaxtree/JumpStmt.java
new file mode 100644
index 0000000..759ffd6
--- /dev/null
+++ b/src/piglet/syntaxtree/JumpStmt.java
@@ -0,0 +1,39 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+public class JumpStmt implements Node {
+ public NodeToken f0;
+ public Label f1;
+
+ public JumpStmt(NodeToken n0, Label n1) {
+ f0 = n0;
+ f1 = n1;
+ }
+
+ public JumpStmt(Label n0) {
+ f0 = new NodeToken("JUMP");
+ f1 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Label.java b/src/piglet/syntaxtree/Label.java
new file mode 100644
index 0000000..4db8432
--- /dev/null
+++ b/src/piglet/syntaxtree/Label.java
@@ -0,0 +1,31 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> <IDENTIFIER>
+ */
+public class Label implements Node {
+ public NodeToken f0;
+
+ public Label(NodeToken n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/MoveStmt.java b/src/piglet/syntaxtree/MoveStmt.java
new file mode 100644
index 0000000..8a034c3
--- /dev/null
+++ b/src/piglet/syntaxtree/MoveStmt.java
@@ -0,0 +1,43 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+public class MoveStmt implements Node {
+ public NodeToken f0;
+ public Temp f1;
+ public Exp f2;
+
+ public MoveStmt(NodeToken n0, Temp n1, Exp n2) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ }
+
+ public MoveStmt(Temp n0, Exp n1) {
+ f0 = new NodeToken("MOVE");
+ f1 = n0;
+ f2 = n1;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/NoOpStmt.java b/src/piglet/syntaxtree/NoOpStmt.java
new file mode 100644
index 0000000..c5116f4
--- /dev/null
+++ b/src/piglet/syntaxtree/NoOpStmt.java
@@ -0,0 +1,35 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "NOOP"
+ */
+public class NoOpStmt implements Node {
+ public NodeToken f0;
+
+ public NoOpStmt(NodeToken n0) {
+ f0 = n0;
+ }
+
+ public NoOpStmt() {
+ f0 = new NodeToken("NOOP");
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Node.java b/src/piglet/syntaxtree/Node.java
new file mode 100644
index 0000000..3b31a93
--- /dev/null
+++ b/src/piglet/syntaxtree/Node.java
@@ -0,0 +1,16 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * The interface which all syntax tree classes must implement.
+ */
+public interface Node extends java.io.Serializable {
+ public void accept(piglet.visitor.Visitor v);
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu);
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v);
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu);
+}
+
diff --git a/src/piglet/syntaxtree/NodeChoice.java b/src/piglet/syntaxtree/NodeChoice.java
new file mode 100644
index 0000000..d6daa49
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeChoice.java
@@ -0,0 +1,36 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Represents a grammar choice, e.g. ( A | B )
+ */
+public class NodeChoice implements Node {
+ public NodeChoice(Node node) {
+ this(node, -1);
+ }
+
+ public NodeChoice(Node node, int whichChoice) {
+ choice = node;
+ which = whichChoice;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ choice.accept(v);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return choice.accept(v,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return choice.accept(v);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ choice.accept(v,argu);
+ }
+
+ public Node choice;
+ public int which;
+}
+
diff --git a/src/piglet/syntaxtree/NodeList.java b/src/piglet/syntaxtree/NodeList.java
new file mode 100644
index 0000000..c8b5c9d
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeList.java
@@ -0,0 +1,45 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Represents a grammar list, e.g. ( A )+
+ */
+public class NodeList implements NodeListInterface {
+ public NodeList() {
+ nodes = new Vector<Node>();
+ }
+
+ public NodeList(Node firstNode) {
+ nodes = new Vector<Node>();
+ addNode(firstNode);
+ }
+
+ public void addNode(Node n) {
+ nodes.addElement(n);
+ }
+
+ public Enumeration<Node> elements() { return nodes.elements(); }
+ public Node elementAt(int i) { return nodes.elementAt(i); }
+ public int size() { return nodes.size(); }
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+
+ public Vector<Node> nodes;
+}
+
diff --git a/src/piglet/syntaxtree/NodeListInterface.java b/src/piglet/syntaxtree/NodeListInterface.java
new file mode 100644
index 0000000..7fbd7a8
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeListInterface.java
@@ -0,0 +1,22 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * The interface which NodeList, NodeListOptional, and NodeSequence
+ * implement.
+ */
+public interface NodeListInterface extends Node {
+ public void addNode(Node n);
+ public Node elementAt(int i);
+ public java.util.Enumeration<Node> elements();
+ public int size();
+
+ public void accept(piglet.visitor.Visitor v);
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu);
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v);
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu);
+}
+
diff --git a/src/piglet/syntaxtree/NodeListOptional.java b/src/piglet/syntaxtree/NodeListOptional.java
new file mode 100644
index 0000000..975ccea
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeListOptional.java
@@ -0,0 +1,46 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Represents an optional grammar list, e.g. ( A )*
+ */
+public class NodeListOptional implements NodeListInterface {
+ public NodeListOptional() {
+ nodes = new Vector<Node>();
+ }
+
+ public NodeListOptional(Node firstNode) {
+ nodes = new Vector<Node>();
+ addNode(firstNode);
+ }
+
+ public void addNode(Node n) {
+ nodes.addElement(n);
+ }
+
+ public Enumeration<Node> elements() { return nodes.elements(); }
+ public Node elementAt(int i) { return nodes.elementAt(i); }
+ public int size() { return nodes.size(); }
+ public boolean present() { return nodes.size() != 0; }
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+
+ public Vector<Node> nodes;
+}
+
diff --git a/src/piglet/syntaxtree/NodeOptional.java b/src/piglet/syntaxtree/NodeOptional.java
new file mode 100644
index 0000000..160ba16
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeOptional.java
@@ -0,0 +1,41 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Represents an grammar optional node, e.g. ( A )? or [ A ]
+ */
+public class NodeOptional implements Node {
+ public NodeOptional() {
+ node = null;
+ }
+
+ public NodeOptional(Node n) {
+ addNode(n);
+ }
+
+ public void addNode(Node n) {
+ if ( node != null) // Oh oh!
+ throw new Error("Attempt to set optional node twice");
+
+ node = n;
+ }
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+ public boolean present() { return node != null; }
+
+ public Node node;
+}
+
diff --git a/src/piglet/syntaxtree/NodeSequence.java b/src/piglet/syntaxtree/NodeSequence.java
new file mode 100644
index 0000000..b935394
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeSequence.java
@@ -0,0 +1,46 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Represents a sequence of nodes nested within a choice, list,
+ * optional list, or optional, e.g. ( A B )+ or [ C D E ]
+ */
+public class NodeSequence implements NodeListInterface {
+ public NodeSequence(int n) {
+ nodes = new Vector<Node>(n);
+ }
+
+ public NodeSequence(Node firstNode) {
+ nodes = new Vector<Node>();
+ addNode(firstNode);
+ }
+
+ public void addNode(Node n) {
+ nodes.addElement(n);
+ }
+
+ public Node elementAt(int i) { return nodes.elementAt(i); }
+ public Enumeration<Node> elements() { return nodes.elements(); }
+ public int size() { return nodes.size(); }
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+
+ public Vector<Node> nodes;
+}
+
diff --git a/src/piglet/syntaxtree/NodeToken.java b/src/piglet/syntaxtree/NodeToken.java
new file mode 100644
index 0000000..5d9c6e6
--- /dev/null
+++ b/src/piglet/syntaxtree/NodeToken.java
@@ -0,0 +1,88 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+import java.util.Enumeration;
+import java.util.Vector;
+/**
+ * Represents a single token in the grammar. If the "-tk" option
+ * is used, also contains a Vector of preceding special tokens.
+ */
+public class NodeToken implements Node {
+ public NodeToken(String s) {
+ this(s, -1, -1, -1, -1, -1); }
+
+ public NodeToken(String s, int kind, int beginLine, int beginColumn, int endLine, int endColumn) {
+ tokenImage = s;
+ specialTokens = null;
+ this.kind = kind;
+ this.beginLine = beginLine;
+ this.beginColumn = beginColumn;
+ this.endLine = endLine;
+ this.endColumn = endColumn;
+ }
+
+ public NodeToken getSpecialAt(int i) {
+ if ( specialTokens == null )
+ throw new java.util.NoSuchElementException("No specials in token");
+ return specialTokens.elementAt(i);
+ }
+
+ public int numSpecials() {
+ if ( specialTokens == null ) return 0;
+ return specialTokens.size();
+ }
+
+ public void addSpecial(NodeToken s) {
+ if ( specialTokens == null ) specialTokens = new Vector<NodeToken>();
+ specialTokens.addElement(s);
+ }
+
+ public void trimSpecials() {
+ if ( specialTokens == null ) return;
+ specialTokens.trimToSize();
+ }
+
+ public String toString() { return tokenImage; }
+
+ public String withSpecials() {
+ if ( specialTokens == null )
+ return tokenImage;
+
+ StringBuffer buf = new StringBuffer();
+
+ for ( Enumeration<NodeToken> e = specialTokens.elements(); e.hasMoreElements(); )
+ buf.append(e.nextElement().toString());
+
+ buf.append(tokenImage);
+ return buf.toString();
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+
+ public String tokenImage;
+
+ // Stores a list of NodeTokens
+ public Vector<NodeToken> specialTokens;
+
+ // -1 for these ints means no position info is available.
+ public int beginLine, beginColumn, endLine, endColumn;
+
+ // Equal to the JavaCC token "kind" integer.
+ // -1 if not available.
+ public int kind;
+}
+
diff --git a/src/piglet/syntaxtree/Operator.java b/src/piglet/syntaxtree/Operator.java
new file mode 100644
index 0000000..15a3a4c
--- /dev/null
+++ b/src/piglet/syntaxtree/Operator.java
@@ -0,0 +1,34 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+public class Operator implements Node {
+ public NodeChoice f0;
+
+ public Operator(NodeChoice n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/PrintStmt.java b/src/piglet/syntaxtree/PrintStmt.java
new file mode 100644
index 0000000..0a61ea0
--- /dev/null
+++ b/src/piglet/syntaxtree/PrintStmt.java
@@ -0,0 +1,39 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "PRINT"
+ * f1 -> Exp()
+ */
+public class PrintStmt implements Node {
+ public NodeToken f0;
+ public Exp f1;
+
+ public PrintStmt(NodeToken n0, Exp n1) {
+ f0 = n0;
+ f1 = n1;
+ }
+
+ public PrintStmt(Exp n0) {
+ f0 = new NodeToken("PRINT");
+ f1 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Procedure.java b/src/piglet/syntaxtree/Procedure.java
new file mode 100644
index 0000000..99088cd
--- /dev/null
+++ b/src/piglet/syntaxtree/Procedure.java
@@ -0,0 +1,51 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> Label()
+ * f1 -> "["
+ * f2 -> IntegerLiteral()
+ * f3 -> "]"
+ * f4 -> StmtExp()
+ */
+public class Procedure implements Node {
+ public Label f0;
+ public NodeToken f1;
+ public IntegerLiteral f2;
+ public NodeToken f3;
+ public StmtExp f4;
+
+ public Procedure(Label n0, NodeToken n1, IntegerLiteral n2, NodeToken n3, StmtExp n4) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ f4 = n4;
+ }
+
+ public Procedure(Label n0, IntegerLiteral n1, StmtExp n2) {
+ f0 = n0;
+ f1 = new NodeToken("[");
+ f2 = n1;
+ f3 = new NodeToken("]");
+ f4 = n2;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Stmt.java b/src/piglet/syntaxtree/Stmt.java
new file mode 100644
index 0000000..de54076
--- /dev/null
+++ b/src/piglet/syntaxtree/Stmt.java
@@ -0,0 +1,38 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> NoOpStmt()
+ * | ErrorStmt()
+ * | CJumpStmt()
+ * | JumpStmt()
+ * | HStoreStmt()
+ * | HLoadStmt()
+ * | MoveStmt()
+ * | PrintStmt()
+ */
+public class Stmt implements Node {
+ public NodeChoice f0;
+
+ public Stmt(NodeChoice n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/StmtExp.java b/src/piglet/syntaxtree/StmtExp.java
new file mode 100644
index 0000000..3bdb951
--- /dev/null
+++ b/src/piglet/syntaxtree/StmtExp.java
@@ -0,0 +1,51 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * f4 -> "END"
+ */
+public class StmtExp implements Node {
+ public NodeToken f0;
+ public StmtList f1;
+ public NodeToken f2;
+ public Exp f3;
+ public NodeToken f4;
+
+ public StmtExp(NodeToken n0, StmtList n1, NodeToken n2, Exp n3, NodeToken n4) {
+ f0 = n0;
+ f1 = n1;
+ f2 = n2;
+ f3 = n3;
+ f4 = n4;
+ }
+
+ public StmtExp(StmtList n0, Exp n1) {
+ f0 = new NodeToken("BEGIN");
+ f1 = n0;
+ f2 = new NodeToken("RETURN");
+ f3 = n1;
+ f4 = new NodeToken("END");
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/StmtList.java b/src/piglet/syntaxtree/StmtList.java
new file mode 100644
index 0000000..ef87ebd
--- /dev/null
+++ b/src/piglet/syntaxtree/StmtList.java
@@ -0,0 +1,31 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> ( ( Label() )? Stmt() )*
+ */
+public class StmtList implements Node {
+ public NodeListOptional f0;
+
+ public StmtList(NodeListOptional n0) {
+ f0 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/syntaxtree/Temp.java b/src/piglet/syntaxtree/Temp.java
new file mode 100644
index 0000000..38d7fba
--- /dev/null
+++ b/src/piglet/syntaxtree/Temp.java
@@ -0,0 +1,39 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.syntaxtree;
+
+/**
+ * Grammar production:
+ * f0 -> "TEMP"
+ * f1 -> IntegerLiteral()
+ */
+public class Temp implements Node {
+ public NodeToken f0;
+ public IntegerLiteral f1;
+
+ public Temp(NodeToken n0, IntegerLiteral n1) {
+ f0 = n0;
+ f1 = n1;
+ }
+
+ public Temp(IntegerLiteral n0) {
+ f0 = new NodeToken("TEMP");
+ f1 = n0;
+ }
+
+ public void accept(piglet.visitor.Visitor v) {
+ v.visit(this);
+ }
+ public <R,A> R accept(piglet.visitor.GJVisitor<R,A> v, A argu) {
+ return v.visit(this,argu);
+ }
+ public <R> R accept(piglet.visitor.GJNoArguVisitor<R> v) {
+ return v.visit(this);
+ }
+ public <A> void accept(piglet.visitor.GJVoidVisitor<A> v, A argu) {
+ v.visit(this,argu);
+ }
+}
+
diff --git a/src/piglet/visitor/DepthFirstVisitor.java b/src/piglet/visitor/DepthFirstVisitor.java
new file mode 100644
index 0000000..630facf
--- /dev/null
+++ b/src/piglet/visitor/DepthFirstVisitor.java
@@ -0,0 +1,298 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import java.util.Enumeration;
+
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.Node;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * 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 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ 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 -> Exp()
+ * 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 -> Exp()
+ */
+ public void visit(PrintStmt n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(Exp n) {
+ n.f0.accept(this);
+ }
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * 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 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * 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 -> Exp()
+ */
+ public void visit(HAllocate n) {
+ n.f0.accept(this);
+ n.f1.accept(this);
+ }
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ 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"
+ * 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/piglet/visitor/GJDepthFirst.java b/src/piglet/visitor/GJDepthFirst.java
new file mode 100644
index 0000000..62e3b8a
--- /dev/null
+++ b/src/piglet/visitor/GJDepthFirst.java
@@ -0,0 +1,360 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import java.util.Enumeration;
+
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.Node;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * 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 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ 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 -> Exp()
+ * 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 -> Exp()
+ */
+ public R visit(PrintStmt n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(Exp n, A argu) {
+ R _ret=null;
+ n.f0.accept(this, argu);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * 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 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * 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 -> Exp()
+ */
+ 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 -> Exp()
+ * f2 -> Exp()
+ */
+ 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"
+ * 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/piglet/visitor/GJNoArguDepthFirst.java b/src/piglet/visitor/GJNoArguDepthFirst.java
new file mode 100644
index 0000000..f4a460e
--- /dev/null
+++ b/src/piglet/visitor/GJNoArguDepthFirst.java
@@ -0,0 +1,360 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import java.util.Enumeration;
+
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.Node;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * 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 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ 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 -> Exp()
+ * 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 -> Exp()
+ */
+ public R visit(PrintStmt n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(Exp n) {
+ R _ret=null;
+ n.f0.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * 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 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * 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 -> Exp()
+ */
+ public R visit(HAllocate n) {
+ R _ret=null;
+ n.f0.accept(this);
+ n.f1.accept(this);
+ return _ret;
+ }
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ 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"
+ * 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/piglet/visitor/GJNoArguVisitor.java b/src/piglet/visitor/GJNoArguVisitor.java
new file mode 100644
index 0000000..3801f67
--- /dev/null
+++ b/src/piglet/visitor/GJNoArguVisitor.java
@@ -0,0 +1,207 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n);
+
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n);
+
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ public R visit(HStoreStmt n);
+
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ * f3 -> IntegerLiteral()
+ */
+ public R visit(HLoadStmt n);
+
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public R visit(MoveStmt n);
+
+ /**
+ * f0 -> "PRINT"
+ * f1 -> Exp()
+ */
+ public R visit(PrintStmt n);
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(Exp n);
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp n);
+
+ /**
+ * f0 -> "CALL"
+ * f1 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call n);
+
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> Exp()
+ */
+ public R visit(HAllocate n);
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ public R visit(BinOp n);
+
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator 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/piglet/visitor/GJVisitor.java b/src/piglet/visitor/GJVisitor.java
new file mode 100644
index 0000000..ace5cac
--- /dev/null
+++ b/src/piglet/visitor/GJVisitor.java
@@ -0,0 +1,206 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * f2 -> Label()
+ */
+ public R visit(CJumpStmt n, A argu);
+
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public R visit(JumpStmt n, A argu);
+
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ public R visit(HStoreStmt n, A argu);
+
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ * 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 -> Exp()
+ */
+ public R visit(PrintStmt n, A argu);
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public R visit(Exp n, A argu);
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * f4 -> "END"
+ */
+ public R visit(StmtExp n, A argu);
+
+ /**
+ * f0 -> "CALL"
+ * f1 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * f4 -> ")"
+ */
+ public R visit(Call n, A argu);
+
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> Exp()
+ */
+ public R visit(HAllocate n, A argu);
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ public R visit(BinOp n, A argu);
+
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public R visit(Operator 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/piglet/visitor/GJVoidDepthFirst.java b/src/piglet/visitor/GJVoidDepthFirst.java
new file mode 100644
index 0000000..df106e3
--- /dev/null
+++ b/src/piglet/visitor/GJVoidDepthFirst.java
@@ -0,0 +1,308 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import java.util.Enumeration;
+
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.Node;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * 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 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ 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 -> Exp()
+ * 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 -> Exp()
+ */
+ public void visit(PrintStmt n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(Exp n, A argu) {
+ n.f0.accept(this, argu);
+ }
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * 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 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * 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 -> Exp()
+ */
+ public void visit(HAllocate n, A argu) {
+ n.f0.accept(this, argu);
+ n.f1.accept(this, argu);
+ }
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ 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"
+ * 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/piglet/visitor/GJVoidVisitor.java b/src/piglet/visitor/GJVoidVisitor.java
new file mode 100644
index 0000000..206778e
--- /dev/null
+++ b/src/piglet/visitor/GJVoidVisitor.java
@@ -0,0 +1,207 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n, A argu);
+
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n, A argu);
+
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ public void visit(HStoreStmt n, A argu);
+
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ * 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 -> Exp()
+ */
+ public void visit(PrintStmt n, A argu);
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(Exp n, A argu);
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp n, A argu);
+
+ /**
+ * f0 -> "CALL"
+ * f1 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call n, A argu);
+
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> Exp()
+ */
+ public void visit(HAllocate n, A argu);
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ public void visit(BinOp n, A argu);
+
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator 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/piglet/visitor/Visitor.java b/src/piglet/visitor/Visitor.java
new file mode 100644
index 0000000..e7ceed5
--- /dev/null
+++ b/src/piglet/visitor/Visitor.java
@@ -0,0 +1,207 @@
+//
+// Generated by JTB 1.3.2
+//
+
+package piglet.visitor;
+import piglet.syntaxtree.BinOp;
+import piglet.syntaxtree.CJumpStmt;
+import piglet.syntaxtree.Call;
+import piglet.syntaxtree.ErrorStmt;
+import piglet.syntaxtree.Exp;
+import piglet.syntaxtree.Goal;
+import piglet.syntaxtree.HAllocate;
+import piglet.syntaxtree.HLoadStmt;
+import piglet.syntaxtree.HStoreStmt;
+import piglet.syntaxtree.IntegerLiteral;
+import piglet.syntaxtree.JumpStmt;
+import piglet.syntaxtree.Label;
+import piglet.syntaxtree.MoveStmt;
+import piglet.syntaxtree.NoOpStmt;
+import piglet.syntaxtree.NodeList;
+import piglet.syntaxtree.NodeListOptional;
+import piglet.syntaxtree.NodeOptional;
+import piglet.syntaxtree.NodeSequence;
+import piglet.syntaxtree.NodeToken;
+import piglet.syntaxtree.Operator;
+import piglet.syntaxtree.PrintStmt;
+import piglet.syntaxtree.Procedure;
+import piglet.syntaxtree.Stmt;
+import piglet.syntaxtree.StmtExp;
+import piglet.syntaxtree.StmtList;
+import piglet.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 -> Exp()
+ * f2 -> Label()
+ */
+ public void visit(CJumpStmt n);
+
+ /**
+ * f0 -> "JUMP"
+ * f1 -> Label()
+ */
+ public void visit(JumpStmt n);
+
+ /**
+ * f0 -> "HSTORE"
+ * f1 -> Exp()
+ * f2 -> IntegerLiteral()
+ * f3 -> Exp()
+ */
+ public void visit(HStoreStmt n);
+
+ /**
+ * f0 -> "HLOAD"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ * f3 -> IntegerLiteral()
+ */
+ public void visit(HLoadStmt n);
+
+ /**
+ * f0 -> "MOVE"
+ * f1 -> Temp()
+ * f2 -> Exp()
+ */
+ public void visit(MoveStmt n);
+
+ /**
+ * f0 -> "PRINT"
+ * f1 -> Exp()
+ */
+ public void visit(PrintStmt n);
+
+ /**
+ * f0 -> StmtExp()
+ * | Call()
+ * | HAllocate()
+ * | BinOp()
+ * | Temp()
+ * | IntegerLiteral()
+ * | Label()
+ */
+ public void visit(Exp n);
+
+ /**
+ * f0 -> "BEGIN"
+ * f1 -> StmtList()
+ * f2 -> "RETURN"
+ * f3 -> Exp()
+ * f4 -> "END"
+ */
+ public void visit(StmtExp n);
+
+ /**
+ * f0 -> "CALL"
+ * f1 -> Exp()
+ * f2 -> "("
+ * f3 -> ( Exp() )*
+ * f4 -> ")"
+ */
+ public void visit(Call n);
+
+ /**
+ * f0 -> "HALLOCATE"
+ * f1 -> Exp()
+ */
+ public void visit(HAllocate n);
+
+ /**
+ * f0 -> Operator()
+ * f1 -> Exp()
+ * f2 -> Exp()
+ */
+ public void visit(BinOp n);
+
+ /**
+ * f0 -> "LT"
+ * | "PLUS"
+ * | "MINUS"
+ * | "TIMES"
+ */
+ public void visit(Operator 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);
+
+}
+