diff options
68 files changed, 10748 insertions, 4 deletions
@@ -1,4 +1,7 @@ *.class /javacc-6.0/ -/syntaxtree/ -/visitor/ +/notes.org +/documents/ +/jtb.out.jj +/jtb132.jar +/minijava.jj diff --git a/Typecheck.java b/Typecheck.java index d2639f5..f08e1e7 100644 --- a/Typecheck.java +++ b/Typecheck.java @@ -1,10 +1,11 @@ import java.io.*; import visitor.*; +import parse.*; import syntaxtree.*; import java.util.*; import st.*; -import typecheck.library.*; import misc.*; +import typecheck.library.*; public class Typecheck { public static void main(String[] args) { diff --git a/misc/PrintFilter.java b/misc/PrintFilter.java index 971ef04..e3be310 100644 --- a/misc/PrintFilter.java +++ b/misc/PrintFilter.java @@ -4,7 +4,7 @@ package misc; public class PrintFilter { public static void print(String message, boolean newline) { - boolean debug = true; + boolean debug = false; if (debug) { System.out.print(message); if (newline) diff --git a/parse/JavaCharStream.java b/parse/JavaCharStream.java new file mode 100644 index 0000000..bec46a9 --- /dev/null +++ b/parse/JavaCharStream.java @@ -0,0 +1,622 @@ +/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 6.0 */ +/* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package parse; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (with java-like unicode escape processing). + */ + +public class JavaCharStream { + /** Whether parser is static. */ + 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 + } + + /** Position in buffer. */ + 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 boolean trackLineColumn = true; + + static public void setTabSize(int i) { tabSize = i; } + static public int getTabSize() { 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]; + } + + /** @return starting character for token. */ + 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; + } + + /** Read a character. */ + 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()) == '\\') + { + if (trackLineColumn) { UpdateLineColumn(c); } + + int backSlashCnt = 1; + + for (;;) // Read all the backslashes + { + if (++bufpos == available) + AdjustBuffSize(); + + try + { + if ((buffer[bufpos] = c = ReadByte()) != '\\') + { + if (trackLineColumn) { 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) + { + // We are returning one backslash so we should only backup (count-1) + if (backSlashCnt > 1) + backup(backSlashCnt-1); + + return '\\'; + } + + if (trackLineColumn) { 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 + /** + * @deprecated + * @see #getEndColumn + */ + static public int getColumn() { + return bufcolumn[bufpos]; + } + + @Deprecated + /** + * @deprecated + * @see #getEndLine + */ + static public int getLine() { + return bufline[bufpos]; + } + + /** Get end column. */ + static public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get end line. */ + static public int getEndLine() { + return bufline[bufpos]; + } + + /** @return column of token start */ + static public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** @return line number of token start */ + static public int getBeginLine() { + return bufline[tokenBegin]; + } + + /** Retreat. */ + static public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + 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.\n" + + " You must 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]; + } + + /** Constructor. */ + public JavaCharStream(java.io.Reader dstream, + int startline, int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public JavaCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + /** Reinitialise. */ + 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; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Constructor. */ + 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); + } + + /** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + } + + /** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + /** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + /** Constructor. */ + public JavaCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + 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); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + + /** @return token image as String */ + 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); + } + + /** @return suffix */ + 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; + } + + /** Set buffers back to null when finished. */ + 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]; + } + static boolean getTrackLineColumn() { return trackLineColumn; } + static void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; } + +} +/* JavaCC - OriginalChecksum=389d53d5c1a39e7ce2e8eb33579d4710 (do not edit this line) */ diff --git a/parse/MiniJavaParser.java b/parse/MiniJavaParser.java new file mode 100644 index 0000000..cdc1490 --- /dev/null +++ b/parse/MiniJavaParser.java @@ -0,0 +1,2028 @@ +/* MiniJavaParser.java */ +/* Generated By:JavaCC: Do not edit this line. MiniJavaParser.java */ +package parse; + +import syntaxtree.*; +import java.util.Vector; + + +public class MiniJavaParser implements MiniJavaParserConstants { + + static final public Goal Goal() throws ParseException {MainClass n0; + NodeListOptional n1 = new NodeListOptional(); + TypeDeclaration n2; + NodeToken n3; + Token n4; + n0 = MainClass(); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS:{ + ; + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } + n2 = TypeDeclaration(); + n1.addNode(n2); + } + n1.nodes.trimToSize(); + n4 = jj_consume_token(0); + n4.beginColumn++; n4.endColumn++; + n3 = JTBToolkit.makeNodeToken(n4); + {if ("" != null) return new Goal(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public MainClass MainClass() throws ParseException {NodeToken n0; + Token n1; + Identifier n2; + NodeToken n3; + Token n4; + NodeToken n5; + Token n6; + NodeToken n7; + Token n8; + NodeToken n9; + Token n10; + NodeToken n11; + Token n12; + NodeToken n13; + Token n14; + NodeToken n15; + Token n16; + NodeToken n17; + Token n18; + NodeToken n19; + Token n20; + Identifier n21; + NodeToken n22; + Token n23; + NodeToken n24; + Token n25; + NodeListOptional n26 = new NodeListOptional(); + VarDeclaration n27; + NodeListOptional n28 = new NodeListOptional(); + Statement n29; + NodeToken n30; + Token n31; + NodeToken n32; + Token n33; + n1 = jj_consume_token(CLASS); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Identifier(); + n4 = jj_consume_token(LBRACE); + n3 = JTBToolkit.makeNodeToken(n4); + n6 = jj_consume_token(PUBLIC); + n5 = JTBToolkit.makeNodeToken(n6); + n8 = jj_consume_token(STATIC); + n7 = JTBToolkit.makeNodeToken(n8); + n10 = jj_consume_token(VOID); + n9 = JTBToolkit.makeNodeToken(n10); + n12 = jj_consume_token(MAIN); + n11 = JTBToolkit.makeNodeToken(n12); + n14 = jj_consume_token(LPAREN); + n13 = JTBToolkit.makeNodeToken(n14); + n16 = jj_consume_token(STRING); + n15 = JTBToolkit.makeNodeToken(n16); + n18 = jj_consume_token(LSQPAREN); + n17 = JTBToolkit.makeNodeToken(n18); + n20 = jj_consume_token(RSQPAREN); + n19 = JTBToolkit.makeNodeToken(n20); + n21 = Identifier(); + n23 = jj_consume_token(RPAREN); + n22 = JTBToolkit.makeNodeToken(n23); + n25 = jj_consume_token(LBRACE); + n24 = JTBToolkit.makeNodeToken(n25); + label_2: + while (true) { + if (jj_2_1(2)) { + ; + } else { + break label_2; + } + n27 = VarDeclaration(); + n26.addNode(n27); + } + n26.nodes.trimToSize(); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE: + case IF: + case WHILE: + case PRINT: + case IDENTIFIER:{ + ; + break; + } + default: + jj_la1[1] = jj_gen; + break label_3; + } + n29 = Statement(); + n28.addNode(n29); + } + n28.nodes.trimToSize(); + n31 = jj_consume_token(RBRACE); + n30 = JTBToolkit.makeNodeToken(n31); + n33 = jj_consume_token(RBRACE); + n32 = JTBToolkit.makeNodeToken(n33); + {if ("" != null) return new MainClass(n0,n2,n3,n5,n7,n9,n11,n13,n15,n17,n19,n21,n22,n24,n26,n28,n30,n32);} + throw new Error("Missing return statement in function"); + } + + static final public TypeDeclaration TypeDeclaration() throws ParseException {NodeChoice n0; + ClassDeclaration n1; + ClassExtendsDeclaration n2; + if (jj_2_2(3)) { + n1 = ClassDeclaration(); + n0 = new NodeChoice(n1, 0); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case CLASS:{ + n2 = ClassExtendsDeclaration(); + n0 = new NodeChoice(n2, 1); + break; + } + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + {if ("" != null) return new TypeDeclaration(n0);} + throw new Error("Missing return statement in function"); + } + + static final public ClassDeclaration ClassDeclaration() throws ParseException {NodeToken n0; + Token n1; + Identifier n2; + NodeToken n3; + Token n4; + NodeListOptional n5 = new NodeListOptional(); + VarDeclaration n6; + NodeListOptional n7 = new NodeListOptional(); + MethodDeclaration n8; + NodeToken n9; + Token n10; + n1 = jj_consume_token(CLASS); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Identifier(); + n4 = jj_consume_token(LBRACE); + n3 = JTBToolkit.makeNodeToken(n4); + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case INTEGER: + case IDENTIFIER:{ + ; + break; + } + default: + jj_la1[3] = jj_gen; + break label_4; + } + n6 = VarDeclaration(); + n5.addNode(n6); + } + n5.nodes.trimToSize(); + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PUBLIC:{ + ; + break; + } + default: + jj_la1[4] = jj_gen; + break label_5; + } + n8 = MethodDeclaration(); + n7.addNode(n8); + } + n7.nodes.trimToSize(); + n10 = jj_consume_token(RBRACE); + n9 = JTBToolkit.makeNodeToken(n10); + {if ("" != null) return new ClassDeclaration(n0,n2,n3,n5,n7,n9);} + throw new Error("Missing return statement in function"); + } + + static final public ClassExtendsDeclaration ClassExtendsDeclaration() throws ParseException {NodeToken n0; + Token n1; + Identifier n2; + NodeToken n3; + Token n4; + Identifier n5; + NodeToken n6; + Token n7; + NodeListOptional n8 = new NodeListOptional(); + VarDeclaration n9; + NodeListOptional n10 = new NodeListOptional(); + MethodDeclaration n11; + NodeToken n12; + Token n13; + n1 = jj_consume_token(CLASS); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Identifier(); + n4 = jj_consume_token(EXTENDS); + n3 = JTBToolkit.makeNodeToken(n4); + n5 = Identifier(); + n7 = jj_consume_token(LBRACE); + n6 = JTBToolkit.makeNodeToken(n7); + label_6: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case INTEGER: + case IDENTIFIER:{ + ; + break; + } + default: + jj_la1[5] = jj_gen; + break label_6; + } + n9 = VarDeclaration(); + n8.addNode(n9); + } + n8.nodes.trimToSize(); + label_7: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PUBLIC:{ + ; + break; + } + default: + jj_la1[6] = jj_gen; + break label_7; + } + n11 = MethodDeclaration(); + n10.addNode(n11); + } + n10.nodes.trimToSize(); + n13 = jj_consume_token(RBRACE); + n12 = JTBToolkit.makeNodeToken(n13); + {if ("" != null) return new ClassExtendsDeclaration(n0,n2,n3,n5,n6,n8,n10,n12);} + throw new Error("Missing return statement in function"); + } + + static final public VarDeclaration VarDeclaration() throws ParseException {Type n0; + Identifier n1; + NodeToken n2; + Token n3; + n0 = Type(); + n1 = Identifier(); + n3 = jj_consume_token(SEMICOLON); + n2 = JTBToolkit.makeNodeToken(n3); + {if ("" != null) return new VarDeclaration(n0,n1,n2);} + throw new Error("Missing return statement in function"); + } + + static final public MethodDeclaration MethodDeclaration() throws ParseException {NodeToken n0; + Token n1; + Type n2; + Identifier n3; + NodeToken n4; + Token n5; + NodeOptional n6 = new NodeOptional(); + FormalParameterList n7; + NodeToken n8; + Token n9; + NodeToken n10; + Token n11; + NodeListOptional n12 = new NodeListOptional(); + VarDeclaration n13; + NodeListOptional n14 = new NodeListOptional(); + Statement n15; + NodeToken n16; + Token n17; + Expression n18; + NodeToken n19; + Token n20; + NodeToken n21; + Token n22; + n1 = jj_consume_token(PUBLIC); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Type(); + n3 = Identifier(); + n5 = jj_consume_token(LPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN: + case INTEGER: + case IDENTIFIER:{ + n7 = FormalParameterList(); + n6.addNode(n7); + break; + } + default: + jj_la1[7] = jj_gen; + ; + } + n9 = jj_consume_token(RPAREN); + n8 = JTBToolkit.makeNodeToken(n9); + n11 = jj_consume_token(LBRACE); + n10 = JTBToolkit.makeNodeToken(n11); + label_8: + while (true) { + if (jj_2_3(2)) { + ; + } else { + break label_8; + } + n13 = VarDeclaration(); + n12.addNode(n13); + } + n12.nodes.trimToSize(); + label_9: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE: + case IF: + case WHILE: + case PRINT: + case IDENTIFIER:{ + ; + break; + } + default: + jj_la1[8] = jj_gen; + break label_9; + } + n15 = Statement(); + n14.addNode(n15); + } + n14.nodes.trimToSize(); + n17 = jj_consume_token(RETURN); + n16 = JTBToolkit.makeNodeToken(n17); + n18 = Expression(); + n20 = jj_consume_token(SEMICOLON); + n19 = JTBToolkit.makeNodeToken(n20); + n22 = jj_consume_token(RBRACE); + n21 = JTBToolkit.makeNodeToken(n22); + {if ("" != null) return new MethodDeclaration(n0,n2,n3,n4,n6,n8,n10,n12,n14,n16,n18,n19,n21);} + throw new Error("Missing return statement in function"); + } + + static final public FormalParameterList FormalParameterList() throws ParseException {FormalParameter n0; + NodeListOptional n1 = new NodeListOptional(); + FormalParameterRest n2; + n0 = FormalParameter(); + label_10: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 47:{ + ; + break; + } + default: + jj_la1[9] = jj_gen; + break label_10; + } + n2 = FormalParameterRest(); + n1.addNode(n2); + } + n1.nodes.trimToSize(); + {if ("" != null) return new FormalParameterList(n0,n1);} + throw new Error("Missing return statement in function"); + } + + static final public FormalParameter FormalParameter() throws ParseException {Type n0; + Identifier n1; + n0 = Type(); + n1 = Identifier(); + {if ("" != null) return new FormalParameter(n0,n1);} + throw new Error("Missing return statement in function"); + } + + static final public FormalParameterRest FormalParameterRest() throws ParseException {NodeToken n0; + Token n1; + FormalParameter n2; + n1 = jj_consume_token(47); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = FormalParameter(); + {if ("" != null) return new FormalParameterRest(n0,n2);} + throw new Error("Missing return statement in function"); + } + + static final public Type Type() throws ParseException {NodeChoice n0; + ArrayType n1; + BooleanType n2; + IntegerType n3; + Identifier n4; + if (jj_2_4(3)) { + n1 = ArrayType(); + n0 = new NodeChoice(n1, 0); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case BOOLEAN:{ + n2 = BooleanType(); + n0 = new NodeChoice(n2, 1); + break; + } + case INTEGER:{ + n3 = IntegerType(); + n0 = new NodeChoice(n3, 2); + break; + } + case IDENTIFIER:{ + n4 = Identifier(); + n0 = new NodeChoice(n4, 3); + break; + } + default: + jj_la1[10] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + {if ("" != null) return new Type(n0);} + throw new Error("Missing return statement in function"); + } + + static final public ArrayType ArrayType() throws ParseException {NodeToken n0; + Token n1; + NodeToken n2; + Token n3; + NodeToken n4; + Token n5; + n1 = jj_consume_token(INTEGER); + n0 = JTBToolkit.makeNodeToken(n1); + n3 = jj_consume_token(LSQPAREN); + n2 = JTBToolkit.makeNodeToken(n3); + n5 = jj_consume_token(RSQPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + {if ("" != null) return new ArrayType(n0,n2,n4);} + throw new Error("Missing return statement in function"); + } + + static final public BooleanType BooleanType() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(BOOLEAN); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new BooleanType(n0);} + throw new Error("Missing return statement in function"); + } + + static final public IntegerType IntegerType() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(INTEGER); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new IntegerType(n0);} + throw new Error("Missing return statement in function"); + } + + static final public Statement Statement() throws ParseException {NodeChoice n0; + Block n1; + AssignmentStatement n2; + ArrayAssignmentStatement n3; + IfStatement n4; + WhileStatement n5; + PrintStatement n6; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE:{ + n1 = Block(); + n0 = new NodeChoice(n1, 0); + break; + } + default: + jj_la1[11] = jj_gen; + if (jj_2_5(2)) { + n2 = AssignmentStatement(); + n0 = new NodeChoice(n2, 1); + } else if (jj_2_6(2)) { + n3 = ArrayAssignmentStatement(); + n0 = new NodeChoice(n3, 2); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case IF:{ + n4 = IfStatement(); + n0 = new NodeChoice(n4, 3); + break; + } + case WHILE:{ + n5 = WhileStatement(); + n0 = new NodeChoice(n5, 4); + break; + } + case PRINT:{ + n6 = PrintStatement(); + n0 = new NodeChoice(n6, 5); + break; + } + default: + jj_la1[12] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + {if ("" != null) return new Statement(n0);} + throw new Error("Missing return statement in function"); + } + + static final public Block Block() throws ParseException {NodeToken n0; + Token n1; + NodeListOptional n2 = new NodeListOptional(); + Statement n3; + NodeToken n4; + Token n5; + n1 = jj_consume_token(LBRACE); + n0 = JTBToolkit.makeNodeToken(n1); + label_11: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LBRACE: + case IF: + case WHILE: + case PRINT: + case IDENTIFIER:{ + ; + break; + } + default: + jj_la1[13] = jj_gen; + break label_11; + } + n3 = Statement(); + n2.addNode(n3); + } + n2.nodes.trimToSize(); + n5 = jj_consume_token(RBRACE); + n4 = JTBToolkit.makeNodeToken(n5); + {if ("" != null) return new Block(n0,n2,n4);} + throw new Error("Missing return statement in function"); + } + + static final public AssignmentStatement AssignmentStatement() throws ParseException {Identifier n0; + NodeToken n1; + Token n2; + Expression n3; + NodeToken n4; + Token n5; + n0 = Identifier(); + n2 = jj_consume_token(ASSIGN); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = Expression(); + n5 = jj_consume_token(SEMICOLON); + n4 = JTBToolkit.makeNodeToken(n5); + {if ("" != null) return new AssignmentStatement(n0,n1,n3,n4);} + throw new Error("Missing return statement in function"); + } + + static final public ArrayAssignmentStatement ArrayAssignmentStatement() throws ParseException {Identifier n0; + NodeToken n1; + Token n2; + Expression n3; + NodeToken n4; + Token n5; + NodeToken n6; + Token n7; + Expression n8; + NodeToken n9; + Token n10; + n0 = Identifier(); + n2 = jj_consume_token(LSQPAREN); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = Expression(); + n5 = jj_consume_token(RSQPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + n7 = jj_consume_token(ASSIGN); + n6 = JTBToolkit.makeNodeToken(n7); + n8 = Expression(); + n10 = jj_consume_token(SEMICOLON); + n9 = JTBToolkit.makeNodeToken(n10); + {if ("" != null) return new ArrayAssignmentStatement(n0,n1,n3,n4,n6,n8,n9);} + throw new Error("Missing return statement in function"); + } + + static final public IfStatement IfStatement() throws ParseException {NodeToken n0; + Token n1; + NodeToken n2; + Token n3; + Expression n4; + NodeToken n5; + Token n6; + Statement n7; + NodeToken n8; + Token n9; + Statement n10; + n1 = jj_consume_token(IF); + n0 = JTBToolkit.makeNodeToken(n1); + n3 = jj_consume_token(LPAREN); + n2 = JTBToolkit.makeNodeToken(n3); + n4 = Expression(); + n6 = jj_consume_token(RPAREN); + n5 = JTBToolkit.makeNodeToken(n6); + n7 = Statement(); + n9 = jj_consume_token(ELSE); + n8 = JTBToolkit.makeNodeToken(n9); + n10 = Statement(); + {if ("" != null) return new IfStatement(n0,n2,n4,n5,n7,n8,n10);} + throw new Error("Missing return statement in function"); + } + + static final public WhileStatement WhileStatement() throws ParseException {NodeToken n0; + Token n1; + NodeToken n2; + Token n3; + Expression n4; + NodeToken n5; + Token n6; + Statement n7; + n1 = jj_consume_token(WHILE); + n0 = JTBToolkit.makeNodeToken(n1); + n3 = jj_consume_token(LPAREN); + n2 = JTBToolkit.makeNodeToken(n3); + n4 = Expression(); + n6 = jj_consume_token(RPAREN); + n5 = JTBToolkit.makeNodeToken(n6); + n7 = Statement(); + {if ("" != null) return new WhileStatement(n0,n2,n4,n5,n7);} + throw new Error("Missing return statement in function"); + } + + static final public PrintStatement PrintStatement() throws ParseException {NodeToken n0; + Token n1; + NodeToken n2; + Token n3; + Expression n4; + NodeToken n5; + Token n6; + NodeToken n7; + Token n8; + n1 = jj_consume_token(PRINT); + n0 = JTBToolkit.makeNodeToken(n1); + n3 = jj_consume_token(LPAREN); + n2 = JTBToolkit.makeNodeToken(n3); + n4 = Expression(); + n6 = jj_consume_token(RPAREN); + n5 = JTBToolkit.makeNodeToken(n6); + n8 = jj_consume_token(SEMICOLON); + n7 = JTBToolkit.makeNodeToken(n8); + {if ("" != null) return new PrintStatement(n0,n2,n4,n5,n7);} + throw new Error("Missing return statement in function"); + } + + static final public Expression Expression() throws ParseException {NodeChoice n0; + AndExpression n1; + CompareExpression n2; + PlusExpression n3; + MinusExpression n4; + TimesExpression n5; + ArrayLookup n6; + ArrayLength n7; + MessageSend n8; + PrimaryExpression n9; + if (jj_2_7(2147483647)) { + n1 = AndExpression(); + n0 = new NodeChoice(n1, 0); + } else if (jj_2_8(2147483647)) { + n2 = CompareExpression(); + n0 = new NodeChoice(n2, 1); + } else if (jj_2_9(2147483647)) { + n3 = PlusExpression(); + n0 = new NodeChoice(n3, 2); + } else if (jj_2_10(2147483647)) { + n4 = MinusExpression(); + n0 = new NodeChoice(n4, 3); + } else if (jj_2_11(2147483647)) { + n5 = TimesExpression(); + n0 = new NodeChoice(n5, 4); + } else if (jj_2_12(2147483647)) { + n6 = ArrayLookup(); + n0 = new NodeChoice(n6, 5); + } else if (jj_2_13(2147483647)) { + n7 = ArrayLength(); + n0 = new NodeChoice(n7, 6); + } else if (jj_2_14(2147483647)) { + n8 = MessageSend(); + n0 = new NodeChoice(n8, 7); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN: + case NOT: + case FALSE: + case NEW: + case THIS: + case TRUE: + case INTEGER_LITERAL: + case IDENTIFIER:{ + n9 = PrimaryExpression(); + n0 = new NodeChoice(n9, 8); + break; + } + default: + jj_la1[14] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + {if ("" != null) return new Expression(n0);} + throw new Error("Missing return statement in function"); + } + + static final public AndExpression AndExpression() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + n0 = PrimaryExpression(); + n2 = jj_consume_token(AND); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + {if ("" != null) return new AndExpression(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public CompareExpression CompareExpression() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + n0 = PrimaryExpression(); + n2 = jj_consume_token(LT); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + {if ("" != null) return new CompareExpression(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public PlusExpression PlusExpression() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + n0 = PrimaryExpression(); + n2 = jj_consume_token(PLUS); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + {if ("" != null) return new PlusExpression(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public MinusExpression MinusExpression() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + n0 = PrimaryExpression(); + n2 = jj_consume_token(MINUS); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + {if ("" != null) return new MinusExpression(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public TimesExpression TimesExpression() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + n0 = PrimaryExpression(); + n2 = jj_consume_token(48); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + {if ("" != null) return new TimesExpression(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public ArrayLookup ArrayLookup() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + PrimaryExpression n3; + NodeToken n4; + Token n5; + n0 = PrimaryExpression(); + n2 = jj_consume_token(LSQPAREN); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = PrimaryExpression(); + n5 = jj_consume_token(RSQPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + {if ("" != null) return new ArrayLookup(n0,n1,n3,n4);} + throw new Error("Missing return statement in function"); + } + + static final public ArrayLength ArrayLength() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + NodeToken n3; + Token n4; + n0 = PrimaryExpression(); + n2 = jj_consume_token(DOT); + n1 = JTBToolkit.makeNodeToken(n2); + n4 = jj_consume_token(LENGTH); + n3 = JTBToolkit.makeNodeToken(n4); + {if ("" != null) return new ArrayLength(n0,n1,n3);} + throw new Error("Missing return statement in function"); + } + + static final public MessageSend MessageSend() throws ParseException {PrimaryExpression n0; + NodeToken n1; + Token n2; + Identifier n3; + NodeToken n4; + Token n5; + NodeOptional n6 = new NodeOptional(); + ExpressionList n7; + NodeToken n8; + Token n9; + n0 = PrimaryExpression(); + n2 = jj_consume_token(DOT); + n1 = JTBToolkit.makeNodeToken(n2); + n3 = Identifier(); + n5 = jj_consume_token(LPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case LPAREN: + case NOT: + case FALSE: + case NEW: + case THIS: + case TRUE: + case INTEGER_LITERAL: + case IDENTIFIER:{ + n7 = ExpressionList(); + n6.addNode(n7); + break; + } + default: + jj_la1[15] = jj_gen; + ; + } + n9 = jj_consume_token(RPAREN); + n8 = JTBToolkit.makeNodeToken(n9); + {if ("" != null) return new MessageSend(n0,n1,n3,n4,n6,n8);} + throw new Error("Missing return statement in function"); + } + + static final public ExpressionList ExpressionList() throws ParseException {Expression n0; + NodeListOptional n1 = new NodeListOptional(); + ExpressionRest n2; + n0 = Expression(); + label_12: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 47:{ + ; + break; + } + default: + jj_la1[16] = jj_gen; + break label_12; + } + n2 = ExpressionRest(); + n1.addNode(n2); + } + n1.nodes.trimToSize(); + {if ("" != null) return new ExpressionList(n0,n1);} + throw new Error("Missing return statement in function"); + } + + static final public ExpressionRest ExpressionRest() throws ParseException {NodeToken n0; + Token n1; + Expression n2; + n1 = jj_consume_token(47); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Expression(); + {if ("" != null) return new ExpressionRest(n0,n2);} + throw new Error("Missing return statement in function"); + } + + static final public PrimaryExpression PrimaryExpression() throws ParseException {NodeChoice n0; + IntegerLiteral n1; + TrueLiteral n2; + FalseLiteral n3; + Identifier n4; + ThisExpression n5; + ArrayAllocationExpression n6; + AllocationExpression n7; + NotExpression n8; + BracketExpression n9; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case INTEGER_LITERAL:{ + n1 = IntegerLiteral(); + n0 = new NodeChoice(n1, 0); + break; + } + case TRUE:{ + n2 = TrueLiteral(); + n0 = new NodeChoice(n2, 1); + break; + } + case FALSE:{ + n3 = FalseLiteral(); + n0 = new NodeChoice(n3, 2); + break; + } + case IDENTIFIER:{ + n4 = Identifier(); + n0 = new NodeChoice(n4, 3); + break; + } + case THIS:{ + n5 = ThisExpression(); + n0 = new NodeChoice(n5, 4); + break; + } + default: + jj_la1[17] = jj_gen; + if (jj_2_15(3)) { + n6 = ArrayAllocationExpression(); + n0 = new NodeChoice(n6, 5); + } else { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case NEW:{ + n7 = AllocationExpression(); + n0 = new NodeChoice(n7, 6); + break; + } + case NOT:{ + n8 = NotExpression(); + n0 = new NodeChoice(n8, 7); + break; + } + case LPAREN:{ + n9 = BracketExpression(); + n0 = new NodeChoice(n9, 8); + break; + } + default: + jj_la1[18] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + {if ("" != null) return new PrimaryExpression(n0);} + 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 ("" != null) return new IntegerLiteral(n0);} + throw new Error("Missing return statement in function"); + } + + static final public TrueLiteral TrueLiteral() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(TRUE); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new TrueLiteral(n0);} + throw new Error("Missing return statement in function"); + } + + static final public FalseLiteral FalseLiteral() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(FALSE); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new FalseLiteral(n0);} + throw new Error("Missing return statement in function"); + } + + static final public Identifier Identifier() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(IDENTIFIER); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new Identifier(n0);} + throw new Error("Missing return statement in function"); + } + + static final public ThisExpression ThisExpression() throws ParseException {NodeToken n0; + Token n1; + n1 = jj_consume_token(THIS); + n0 = JTBToolkit.makeNodeToken(n1); + {if ("" != null) return new ThisExpression(n0);} + throw new Error("Missing return statement in function"); + } + + static final public ArrayAllocationExpression ArrayAllocationExpression() throws ParseException {NodeToken n0; + Token n1; + NodeToken n2; + Token n3; + NodeToken n4; + Token n5; + Expression n6; + NodeToken n7; + Token n8; + n1 = jj_consume_token(NEW); + n0 = JTBToolkit.makeNodeToken(n1); + n3 = jj_consume_token(INTEGER); + n2 = JTBToolkit.makeNodeToken(n3); + n5 = jj_consume_token(LSQPAREN); + n4 = JTBToolkit.makeNodeToken(n5); + n6 = Expression(); + n8 = jj_consume_token(RSQPAREN); + n7 = JTBToolkit.makeNodeToken(n8); + {if ("" != null) return new ArrayAllocationExpression(n0,n2,n4,n6,n7);} + throw new Error("Missing return statement in function"); + } + + static final public AllocationExpression AllocationExpression() throws ParseException {NodeToken n0; + Token n1; + Identifier n2; + NodeToken n3; + Token n4; + NodeToken n5; + Token n6; + n1 = jj_consume_token(NEW); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Identifier(); + n4 = jj_consume_token(LPAREN); + n3 = JTBToolkit.makeNodeToken(n4); + n6 = jj_consume_token(RPAREN); + n5 = JTBToolkit.makeNodeToken(n6); + {if ("" != null) return new AllocationExpression(n0,n2,n3,n5);} + throw new Error("Missing return statement in function"); + } + + static final public NotExpression NotExpression() throws ParseException {NodeToken n0; + Token n1; + Expression n2; + n1 = jj_consume_token(NOT); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Expression(); + {if ("" != null) return new NotExpression(n0,n2);} + throw new Error("Missing return statement in function"); + } + + static final public BracketExpression BracketExpression() throws ParseException {NodeToken n0; + Token n1; + Expression n2; + NodeToken n3; + Token n4; + n1 = jj_consume_token(LPAREN); + n0 = JTBToolkit.makeNodeToken(n1); + n2 = Expression(); + n4 = jj_consume_token(RPAREN); + n3 = JTBToolkit.makeNodeToken(n4); + {if ("" != null) return new BracketExpression(n0,n2,n3);} + throw new Error("Missing return statement in function"); + } + + static private boolean jj_2_1(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + static private boolean jj_2_2(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + static private boolean jj_2_3(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + static private boolean jj_2_4(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + static private boolean jj_2_5(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + static private boolean jj_2_6(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + static private boolean jj_2_7(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_7(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + static private boolean jj_2_8(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_8(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + static private boolean jj_2_9(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_9(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + + static private boolean jj_2_10(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_10(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(9, xla); } + } + + static private boolean jj_2_11(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_11(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(10, xla); } + } + + static private boolean jj_2_12(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_12(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(11, xla); } + } + + static private boolean jj_2_13(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_13(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(12, xla); } + } + + static private boolean jj_2_14(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_14(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(13, xla); } + } + + static private boolean jj_2_15(int xla) + { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_15(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(14, xla); } + } + + static private boolean jj_3_15() + { + if (jj_3R_20()) return true; + return false; + } + + static private boolean jj_3R_20() + { + if (jj_scan_token(NEW)) return true; + if (jj_scan_token(INTEGER)) return true; + if (jj_scan_token(LSQPAREN)) return true; + if (jj_3R_42()) return true; + if (jj_scan_token(RSQPAREN)) return true; + return false; + } + + static private boolean jj_3R_26() + { + if (jj_3R_36()) return true; + return false; + } + + static private boolean jj_3R_53() + { + if (jj_3R_18()) return true; + if (jj_scan_token(LT)) return true; + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_40() + { + if (jj_scan_token(BOOLEAN)) return true; + return false; + } + + static private boolean jj_3R_25() + { + if (jj_3R_19()) return true; + return false; + } + + static private boolean jj_3_1() + { + if (jj_3R_13()) return true; + return false; + } + + static private boolean jj_3R_16() + { + if (jj_3R_19()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + static private boolean jj_3R_24() + { + if (jj_3R_35()) return true; + return false; + } + + static private boolean jj_3R_58() + { + if (jj_3R_18()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(LENGTH)) return true; + return false; + } + + static private boolean jj_3R_23() + { + if (jj_3R_34()) return true; + return false; + } + + static private boolean jj_3R_22() + { + if (jj_3R_33()) return true; + return false; + } + + static private boolean jj_3R_15() + { + if (jj_scan_token(INTEGER)) return true; + if (jj_scan_token(LSQPAREN)) return true; + if (jj_scan_token(RSQPAREN)) return true; + return false; + } + + static private boolean jj_3R_18() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_22()) { + jj_scanpos = xsp; + if (jj_3R_23()) { + jj_scanpos = xsp; + if (jj_3R_24()) { + jj_scanpos = xsp; + if (jj_3R_25()) { + jj_scanpos = xsp; + if (jj_3R_26()) { + jj_scanpos = xsp; + if (jj_3_15()) { + jj_scanpos = xsp; + if (jj_3R_27()) { + jj_scanpos = xsp; + if (jj_3R_28()) { + jj_scanpos = xsp; + if (jj_3R_29()) return true; + } + } + } + } + } + } + } + } + return false; + } + + static private boolean jj_3R_52() + { + if (jj_3R_18()) return true; + if (jj_scan_token(AND)) return true; + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_36() + { + if (jj_scan_token(THIS)) return true; + return false; + } + + static private boolean jj_3_3() + { + if (jj_3R_13()) return true; + return false; + } + + static private boolean jj_3R_57() + { + if (jj_3R_18()) return true; + if (jj_scan_token(LSQPAREN)) return true; + if (jj_3R_18()) return true; + if (jj_scan_token(RSQPAREN)) return true; + return false; + } + + static private boolean jj_3_14() + { + if (jj_3R_18()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_3R_19()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + static private boolean jj_3_13() + { + if (jj_3R_18()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(LENGTH)) return true; + return false; + } + + static private boolean jj_3R_19() + { + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + static private boolean jj_3R_51() + { + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_32() + { + if (jj_3R_19()) return true; + return false; + } + + static private boolean jj_3_12() + { + if (jj_3R_18()) return true; + if (jj_scan_token(LSQPAREN)) return true; + return false; + } + + static private boolean jj_3R_31() + { + if (jj_3R_41()) return true; + return false; + } + + static private boolean jj_3R_50() + { + if (jj_3R_59()) return true; + return false; + } + + static private boolean jj_3R_39() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_42()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + static private boolean jj_3R_63() + { + if (jj_scan_token(47)) return true; + if (jj_3R_42()) return true; + return false; + } + + static private boolean jj_3R_30() + { + if (jj_3R_40()) return true; + return false; + } + + static private boolean jj_3_11() + { + if (jj_3R_18()) return true; + if (jj_scan_token(48)) return true; + return false; + } + + static private boolean jj_3R_49() + { + if (jj_3R_58()) return true; + return false; + } + + static private boolean jj_3_4() + { + if (jj_3R_15()) return true; + return false; + } + + static private boolean jj_3_10() + { + if (jj_3R_18()) return true; + if (jj_scan_token(MINUS)) return true; + return false; + } + + static private boolean jj_3R_48() + { + if (jj_3R_57()) return true; + return false; + } + + static private boolean jj_3R_35() + { + if (jj_scan_token(FALSE)) return true; + return false; + } + + static private boolean jj_3R_56() + { + if (jj_3R_18()) return true; + if (jj_scan_token(48)) return true; + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_21() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_4()) { + jj_scanpos = xsp; + if (jj_3R_30()) { + jj_scanpos = xsp; + if (jj_3R_31()) { + jj_scanpos = xsp; + if (jj_3R_32()) return true; + } + } + } + return false; + } + + static private boolean jj_3_9() + { + if (jj_3R_18()) return true; + if (jj_scan_token(PLUS)) return true; + return false; + } + + static private boolean jj_3R_47() + { + if (jj_3R_56()) return true; + return false; + } + + static private boolean jj_3R_14() + { + if (jj_scan_token(CLASS)) return true; + if (jj_3R_19()) return true; + if (jj_scan_token(LBRACE)) return true; + return false; + } + + static private boolean jj_3_8() + { + if (jj_3R_18()) return true; + if (jj_scan_token(LT)) return true; + return false; + } + + static private boolean jj_3R_62() + { + if (jj_3R_63()) return true; + return false; + } + + static private boolean jj_3R_46() + { + if (jj_3R_55()) return true; + return false; + } + + static private boolean jj_3R_38() + { + if (jj_scan_token(NOT)) return true; + if (jj_3R_42()) return true; + return false; + } + + static private boolean jj_3_6() + { + if (jj_3R_17()) return true; + return false; + } + + static private boolean jj_3_7() + { + if (jj_3R_18()) return true; + if (jj_scan_token(AND)) return true; + return false; + } + + static private boolean jj_3R_45() + { + if (jj_3R_54()) return true; + return false; + } + + static private boolean jj_3R_61() + { + if (jj_3R_42()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_62()) { jj_scanpos = xsp; break; } + } + return false; + } + + static private boolean jj_3R_34() + { + if (jj_scan_token(TRUE)) return true; + return false; + } + + static private boolean jj_3_5() + { + if (jj_3R_16()) return true; + return false; + } + + static private boolean jj_3R_44() + { + if (jj_3R_53()) return true; + return false; + } + + static private boolean jj_3R_55() + { + if (jj_3R_18()) return true; + if (jj_scan_token(MINUS)) return true; + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_43() + { + if (jj_3R_52()) return true; + return false; + } + + static private boolean jj_3R_42() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_43()) { + jj_scanpos = xsp; + if (jj_3R_44()) { + jj_scanpos = xsp; + if (jj_3R_45()) { + jj_scanpos = xsp; + if (jj_3R_46()) { + jj_scanpos = xsp; + if (jj_3R_47()) { + jj_scanpos = xsp; + if (jj_3R_48()) { + jj_scanpos = xsp; + if (jj_3R_49()) { + jj_scanpos = xsp; + if (jj_3R_50()) { + jj_scanpos = xsp; + if (jj_3R_51()) return true; + } + } + } + } + } + } + } + } + return false; + } + + static private boolean jj_3R_33() + { + if (jj_scan_token(INTEGER_LITERAL)) return true; + return false; + } + + static private boolean jj_3R_60() + { + if (jj_3R_61()) return true; + return false; + } + + static private boolean jj_3R_37() + { + if (jj_scan_token(NEW)) return true; + if (jj_3R_19()) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + static private boolean jj_3_2() + { + if (jj_3R_14()) return true; + return false; + } + + static private boolean jj_3R_13() + { + if (jj_3R_21()) return true; + if (jj_3R_19()) return true; + return false; + } + + static private boolean jj_3R_17() + { + if (jj_3R_19()) return true; + if (jj_scan_token(LSQPAREN)) return true; + return false; + } + + static private boolean jj_3R_59() + { + if (jj_3R_18()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_3R_19()) return true; + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_60()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + static private boolean jj_3R_54() + { + if (jj_3R_18()) return true; + if (jj_scan_token(PLUS)) return true; + if (jj_3R_18()) return true; + return false; + } + + static private boolean jj_3R_29() + { + if (jj_3R_39()) return true; + return false; + } + + static private boolean jj_3R_41() + { + if (jj_scan_token(INTEGER)) return true; + return false; + } + + static private boolean jj_3R_28() + { + if (jj_3R_38()) return true; + return false; + } + + static private boolean jj_3R_27() + { + if (jj_3R_37()) return true; + return false; + } + + static private boolean jj_initialized_once = false; + /** Generated Token Manager. */ + static public MiniJavaParserTokenManager token_source; + static JavaCharStream jj_input_stream; + /** Current token. */ + static public Token token; + /** Next token. */ + static public Token jj_nt; + static private int jj_ntk; + static private Token jj_scanpos, jj_lastpos; + static private int jj_la; + static private int jj_gen; + static final private int[] jj_la1 = new int[19]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static { + jj_la1_init_0(); + jj_la1_init_1(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x1000000,0x60002000,0x1000000,0x80800000,0x0,0x80800000,0x0,0x80800000,0x60002000,0x0,0x80800000,0x2000,0x60000000,0x60002000,0x10400200,0x10400200,0x0,0x10000000,0x400200,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x1200,0x0,0x1000,0x8,0x1000,0x8,0x1000,0x1200,0x8000,0x1000,0x0,0x200,0x1200,0x1984,0x1984,0x8000,0x1980,0x4,}; + } + static final private JJCalls[] jj_2_rtns = new JJCalls[15]; + static private boolean jj_rescan = false; + static private int jj_gc = 0; + + /** Constructor with InputStream. */ + public MiniJavaParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public MiniJavaParser(java.io.InputStream stream, String encoding) { + if (jj_initialized_once) { + System.out.println("ERROR: Second call to constructor of static parser. "); + System.out.println(" You must 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 MiniJavaParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + static public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + 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 < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public MiniJavaParser(java.io.Reader stream) { + if (jj_initialized_once) { + System.out.println("ERROR: Second call to constructor of static parser. "); + System.out.println(" You must 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 MiniJavaParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + 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 < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public MiniJavaParser(MiniJavaParserTokenManager tm) { + if (jj_initialized_once) { + System.out.println("ERROR: Second call to constructor of static parser. "); + System.out.println(" You must 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 < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(MiniJavaParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 19; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + static 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++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + @SuppressWarnings("serial") + static private final class LookaheadSuccess extends java.lang.Error { } + static final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + static private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + + /** Get the next Token. */ + 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; + } + + /** Get the specific 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 private int jj_ntk_f() { + 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.List<int[]> jj_expentries = new java.util.ArrayList<int[]>(); + static private int[] jj_expentry; + static private int jj_kind = -1; + static private int[] jj_lasttokens = new int[100]; + static private int jj_endpos; + + static private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + static public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[49]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 19; 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 < 49; i++) { + if (la1tokens[i]) { + jj_expentry = new int[1]; + jj_expentry[0] = i; + jj_expentries.add(jj_expentry); + } + } + jj_endpos = 0; + jj_rescan_token(); + jj_add_error_token(0, 0); + int[][] exptokseq = new int[jj_expentries.size()][]; + for (int i = 0; i < jj_expentries.size(); i++) { + exptokseq[i] = jj_expentries.get(i); + } + return new ParseException(token, exptokseq, tokenImage); + } + + /** Enable tracing. */ + static final public void enable_tracing() { + } + + /** Disable tracing. */ + static final public void disable_tracing() { + } + + static private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 15; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + case 8: jj_3_9(); break; + case 9: jj_3_10(); break; + case 10: jj_3_11(); break; + case 11: jj_3_12(); break; + case 12: jj_3_13(); break; + case 13: jj_3_14(); break; + case 14: jj_3_15(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + static private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} + +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/parse/MiniJavaParserConstants.java b/parse/MiniJavaParserConstants.java new file mode 100644 index 0000000..d4392b1 --- /dev/null +++ b/parse/MiniJavaParserConstants.java @@ -0,0 +1,151 @@ +/* Generated By:JavaCC: Do not edit this line. MiniJavaParserConstants.java */ +package parse; + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface MiniJavaParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 6; + /** RegularExpression Id. */ + int FORMAL_COMMENT = 7; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 8; + /** RegularExpression Id. */ + int LPAREN = 9; + /** RegularExpression Id. */ + int RPAREN = 10; + /** RegularExpression Id. */ + int LSQPAREN = 11; + /** RegularExpression Id. */ + int RSQPAREN = 12; + /** RegularExpression Id. */ + int LBRACE = 13; + /** RegularExpression Id. */ + int RBRACE = 14; + /** RegularExpression Id. */ + int SEMICOLON = 15; + /** RegularExpression Id. */ + int DOT = 16; + /** RegularExpression Id. */ + int ASSIGN = 17; + /** RegularExpression Id. */ + int LT = 18; + /** RegularExpression Id. */ + int PLUS = 19; + /** RegularExpression Id. */ + int MINUS = 20; + /** RegularExpression Id. */ + int AND = 21; + /** RegularExpression Id. */ + int NOT = 22; + /** RegularExpression Id. */ + int BOOLEAN = 23; + /** RegularExpression Id. */ + int CLASS = 24; + /** RegularExpression Id. */ + int INTERFACE = 25; + /** RegularExpression Id. */ + int ELSE = 26; + /** RegularExpression Id. */ + int EXTENDS = 27; + /** RegularExpression Id. */ + int FALSE = 28; + /** RegularExpression Id. */ + int IF = 29; + /** RegularExpression Id. */ + int WHILE = 30; + /** RegularExpression Id. */ + int INTEGER = 31; + /** RegularExpression Id. */ + int LENGTH = 32; + /** RegularExpression Id. */ + int MAIN = 33; + /** RegularExpression Id. */ + int NEW = 34; + /** RegularExpression Id. */ + int PUBLIC = 35; + /** RegularExpression Id. */ + int RETURN = 36; + /** RegularExpression Id. */ + int STATIC = 37; + /** RegularExpression Id. */ + int STRING = 38; + /** RegularExpression Id. */ + int THIS = 39; + /** RegularExpression Id. */ + int TRUE = 40; + /** RegularExpression Id. */ + int PRINT = 41; + /** RegularExpression Id. */ + int VOID = 42; + /** RegularExpression Id. */ + int INTEGER_LITERAL = 43; + /** RegularExpression Id. */ + int IDENTIFIER = 44; + /** RegularExpression Id. */ + int LETTER = 45; + /** RegularExpression Id. */ + int DIGIT = 46; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "<EOF>", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"\\f\"", + "<SINGLE_LINE_COMMENT>", + "<FORMAL_COMMENT>", + "<MULTI_LINE_COMMENT>", + "\"(\"", + "\")\"", + "\"[\"", + "\"]\"", + "\"{\"", + "\"}\"", + "\";\"", + "\".\"", + "\"=\"", + "\"<\"", + "\"+\"", + "\"-\"", + "\"&&\"", + "\"!\"", + "\"boolean\"", + "\"class\"", + "\"interface\"", + "\"else\"", + "\"extends\"", + "\"false\"", + "\"if\"", + "\"while\"", + "\"int\"", + "\"length\"", + "\"main\"", + "\"new\"", + "\"public\"", + "\"return\"", + "\"static\"", + "\"String\"", + "\"this\"", + "\"true\"", + "\"System.out.println\"", + "\"void\"", + "<INTEGER_LITERAL>", + "<IDENTIFIER>", + "<LETTER>", + "<DIGIT>", + "\",\"", + "\"*\"", + }; + +} diff --git a/parse/MiniJavaParserTokenManager.java b/parse/MiniJavaParserTokenManager.java new file mode 100644 index 0000000..d0542d2 --- /dev/null +++ b/parse/MiniJavaParserTokenManager.java @@ -0,0 +1,1245 @@ +/* MiniJavaParserTokenManager.java */ +/* Generated By:JavaCC: Do not edit this line. MiniJavaParserTokenManager.java */ +package parse; + +import syntaxtree.*; +import java.util.Vector; + +/** Token Manager. */ +@SuppressWarnings("unused")public class MiniJavaParserTokenManager implements MiniJavaParserConstants { + + /** Debug output. */ + public static java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + 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 & 0x7ffff800000L) != 0L) + { + jjmatchedKind = 44; + return 4; + } + return -1; + case 1: + if ((active0 & 0x20000000L) != 0L) + return 4; + if ((active0 & 0x7ffdf800000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 1; + return 4; + } + return -1; + case 2: + if ((active0 & 0x482000000L) != 0L) + return 4; + if ((active0 & 0x7fb5d800000L) != 0L) + { + if (jjmatchedPos != 2) + { + jjmatchedKind = 44; + jjmatchedPos = 2; + } + return 4; + } + return -1; + case 3: + if ((active0 & 0x58204000000L) != 0L) + return 4; + if ((active0 & 0x2795b800000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 3; + return 4; + } + return -1; + case 4: + if ((active0 & 0x51000000L) != 0L) + return 4; + if ((active0 & 0x2790a800000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 4; + return 4; + } + return -1; + case 5: + if ((active0 & 0x7900000000L) != 0L) + return 4; + if ((active0 & 0x2000a800000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + return 4; + } + return -1; + case 6: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + if ((active0 & 0x8800000L) != 0L) + return 4; + if ((active0 & 0x2000000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 6; + return 4; + } + return -1; + case 7: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + if ((active0 & 0x2000000L) != 0L) + { + jjmatchedKind = 44; + jjmatchedPos = 7; + return 4; + } + return -1; + case 8: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + if ((active0 & 0x2000000L) != 0L) + return 4; + return -1; + case 9: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 10: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 11: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 12: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 13: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 14: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 15: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + return -1; + case 16: + if ((active0 & 0x20000000000L) != 0L) + { + if (jjmatchedPos < 5) + { + jjmatchedKind = 44; + jjmatchedPos = 5; + } + return -1; + } + 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 int jjStopAtPos(int pos, int kind) + { + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; + } + static private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case 33: + return jjStopAtPos(0, 22); + case 38: + return jjMoveStringLiteralDfa1_0(0x200000L); + case 40: + return jjStopAtPos(0, 9); + case 41: + return jjStopAtPos(0, 10); + case 42: + return jjStopAtPos(0, 48); + case 43: + return jjStopAtPos(0, 19); + case 44: + return jjStopAtPos(0, 47); + case 45: + return jjStopAtPos(0, 20); + case 46: + return jjStopAtPos(0, 16); + case 59: + return jjStopAtPos(0, 15); + case 60: + return jjStopAtPos(0, 18); + case 61: + return jjStopAtPos(0, 17); + case 83: + return jjMoveStringLiteralDfa1_0(0x24000000000L); + case 91: + return jjStopAtPos(0, 11); + case 93: + return jjStopAtPos(0, 12); + case 98: + return jjMoveStringLiteralDfa1_0(0x800000L); + case 99: + return jjMoveStringLiteralDfa1_0(0x1000000L); + case 101: + return jjMoveStringLiteralDfa1_0(0xc000000L); + case 102: + return jjMoveStringLiteralDfa1_0(0x10000000L); + case 105: + return jjMoveStringLiteralDfa1_0(0xa2000000L); + case 108: + return jjMoveStringLiteralDfa1_0(0x100000000L); + case 109: + return jjMoveStringLiteralDfa1_0(0x200000000L); + case 110: + return jjMoveStringLiteralDfa1_0(0x400000000L); + case 112: + return jjMoveStringLiteralDfa1_0(0x800000000L); + case 114: + return jjMoveStringLiteralDfa1_0(0x1000000000L); + case 115: + return jjMoveStringLiteralDfa1_0(0x2000000000L); + case 116: + return jjMoveStringLiteralDfa1_0(0x18000000000L); + case 118: + return jjMoveStringLiteralDfa1_0(0x40000000000L); + case 119: + return jjMoveStringLiteralDfa1_0(0x40000000L); + case 123: + return jjStopAtPos(0, 13); + case 125: + return jjStopAtPos(0, 14); + default : + return jjMoveNfa_0(0, 0); + } + } + static private int jjMoveStringLiteralDfa1_0(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 38: + if ((active0 & 0x200000L) != 0L) + return jjStopAtPos(1, 21); + break; + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x210000000L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x1500000000L); + case 102: + if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(1, 29, 4); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x8040000000L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x5000000L); + case 110: + return jjMoveStringLiteralDfa2_0(active0, 0x82000000L); + case 111: + return jjMoveStringLiteralDfa2_0(active0, 0x40000800000L); + case 114: + return jjMoveStringLiteralDfa2_0(active0, 0x10000000000L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0x6000000000L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x800000000L); + case 120: + return jjMoveStringLiteralDfa2_0(active0, 0x8000000L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(0, active0); + } + static private 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 97: + return jjMoveStringLiteralDfa3_0(active0, 0x2001000000L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x800000000L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0x48240000000L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x10000000L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x100000000L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x800000L); + case 114: + return jjMoveStringLiteralDfa3_0(active0, 0x4000000000L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x20004000000L); + case 116: + if ((active0 & 0x80000000L) != 0L) + { + jjmatchedKind = 31; + jjmatchedPos = 2; + } + return jjMoveStringLiteralDfa3_0(active0, 0x100a000000L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x10000000000L); + case 119: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(2, 34, 4); + break; + default : + break; + } + return jjStartNfa_0(1, active0); + } + static private 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 100: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(3, 42, 4); + break; + case 101: + if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(3, 26, 4); + else if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(3, 40, 4); + return jjMoveStringLiteralDfa4_0(active0, 0xa000000L); + case 103: + return jjMoveStringLiteralDfa4_0(active0, 0x100000000L); + case 105: + return jjMoveStringLiteralDfa4_0(active0, 0x4000000000L); + case 108: + return jjMoveStringLiteralDfa4_0(active0, 0x840800000L); + case 110: + if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(3, 33, 4); + break; + case 115: + if ((active0 & 0x8000000000L) != 0L) + return jjStartNfaWithStates_0(3, 39, 4); + return jjMoveStringLiteralDfa4_0(active0, 0x11000000L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x22000000000L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x1000000000L); + default : + break; + } + return jjStartNfa_0(2, active0); + } + static private 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 101: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(4, 28, 4); + else if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(4, 30, 4); + return jjMoveStringLiteralDfa5_0(active0, 0x20000800000L); + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x2800000000L); + case 110: + return jjMoveStringLiteralDfa5_0(active0, 0x4008000000L); + case 114: + return jjMoveStringLiteralDfa5_0(active0, 0x1002000000L); + case 115: + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(4, 24, 4); + break; + case 116: + return jjMoveStringLiteralDfa5_0(active0, 0x100000000L); + default : + break; + } + return jjStartNfa_0(3, active0); + } + static private 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 97: + return jjMoveStringLiteralDfa6_0(active0, 0x800000L); + case 99: + if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(5, 35, 4); + else if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(5, 37, 4); + break; + case 100: + return jjMoveStringLiteralDfa6_0(active0, 0x8000000L); + case 102: + return jjMoveStringLiteralDfa6_0(active0, 0x2000000L); + case 103: + if ((active0 & 0x4000000000L) != 0L) + return jjStartNfaWithStates_0(5, 38, 4); + break; + case 104: + if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(5, 32, 4); + break; + case 109: + return jjMoveStringLiteralDfa6_0(active0, 0x20000000000L); + case 110: + if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(5, 36, 4); + break; + default : + break; + } + return jjStartNfa_0(4, active0); + } + static private 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 46: + return jjMoveStringLiteralDfa7_0(active0, 0x20000000000L); + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000L); + case 110: + if ((active0 & 0x800000L) != 0L) + return jjStartNfaWithStates_0(6, 23, 4); + break; + case 115: + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(6, 27, 4); + break; + default : + break; + } + return jjStartNfa_0(5, active0); + } + static private 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 99: + return jjMoveStringLiteralDfa8_0(active0, 0x2000000L); + case 111: + return jjMoveStringLiteralDfa8_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(6, active0); + } + static private 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 101: + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(8, 25, 4); + break; + case 117: + return jjMoveStringLiteralDfa9_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(7, active0); + } + static private int jjMoveStringLiteralDfa9_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(7, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0); + return 9; + } + switch(curChar) + { + case 116: + return jjMoveStringLiteralDfa10_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(8, active0); + } + static private int jjMoveStringLiteralDfa10_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(8, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0); + return 10; + } + switch(curChar) + { + case 46: + return jjMoveStringLiteralDfa11_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(9, active0); + } + static private int jjMoveStringLiteralDfa11_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(9, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0); + return 11; + } + switch(curChar) + { + case 112: + return jjMoveStringLiteralDfa12_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(10, active0); + } + static private int jjMoveStringLiteralDfa12_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(10, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(11, active0); + return 12; + } + switch(curChar) + { + case 114: + return jjMoveStringLiteralDfa13_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(11, active0); + } + static private int jjMoveStringLiteralDfa13_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(11, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(12, active0); + return 13; + } + switch(curChar) + { + case 105: + return jjMoveStringLiteralDfa14_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(12, active0); + } + static private int jjMoveStringLiteralDfa14_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(12, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(13, active0); + return 14; + } + switch(curChar) + { + case 110: + return jjMoveStringLiteralDfa15_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(13, active0); + } + static private int jjMoveStringLiteralDfa15_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(13, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(14, active0); + return 15; + } + switch(curChar) + { + case 116: + return jjMoveStringLiteralDfa16_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(14, active0); + } + static private int jjMoveStringLiteralDfa16_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(14, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(15, active0); + return 16; + } + switch(curChar) + { + case 108: + return jjMoveStringLiteralDfa17_0(active0, 0x20000000000L); + default : + break; + } + return jjStartNfa_0(15, active0); + } + static private int jjMoveStringLiteralDfa17_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(15, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(16, active0); + return 17; + } + switch(curChar) + { + case 110: + if ((active0 & 0x20000000000L) != 0L) + return jjStopAtPos(17, 41); + break; + default : + break; + } + return jjStartNfa_0(16, active0); + } + static private 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 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 int jjMoveNfa_0(int startState, int curPos) + { + int startsAt = 0; + jjnewStateCnt = 24; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 43) + kind = 43; + { jjCheckNAdd(1); } + } + else if (curChar == 47) + { jjAddStates(0, 2); } + else if (curChar == 36) + { + if (kind > 44) + kind = 44; + { jjCheckNAdd(4); } + } + else if (curChar == 48) + { + if (kind > 43) + kind = 43; + } + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 43) + kind = 43; + { jjCheckNAdd(1); } + break; + case 2: + if (curChar == 48 && kind > 43) + kind = 43; + break; + case 3: + if (curChar != 36) + break; + if (kind > 44) + kind = 44; + { jjCheckNAdd(4); } + break; + case 4: + if ((0x3ff001000000000L & l) == 0L) + break; + if (kind > 44) + kind = 44; + { 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); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 4: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 44) + kind = 44; + { 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 = (curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 4: + if (!jjCanMove_0(hiByte, i1, i2, l1, l2)) + break; + if (kind > 44) + kind = 44; + { 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 : if (i1 == 0 || l1 == 0 || i2 == 0 || l2 == 0) break; else 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; + } + } + + /** Token literal values. */ + public static final String[] jjstrLiteralImages = { + "", null, null, null, null, null, null, null, null, "\50", "\51", "\133", + "\135", "\173", "\175", "\73", "\56", "\75", "\74", "\53", "\55", "\46\46", "\41", + "\142\157\157\154\145\141\156", "\143\154\141\163\163", "\151\156\164\145\162\146\141\143\145", + "\145\154\163\145", "\145\170\164\145\156\144\163", "\146\141\154\163\145", "\151\146", + "\167\150\151\154\145", "\151\156\164", "\154\145\156\147\164\150", "\155\141\151\156", + "\156\145\167", "\160\165\142\154\151\143", "\162\145\164\165\162\156", + "\163\164\141\164\151\143", "\123\164\162\151\156\147", "\164\150\151\163", "\164\162\165\145", + "\123\171\163\164\145\155\56\157\165\164\56\160\162\151\156\164\154\156", "\166\157\151\144", null, null, null, null, "\54", "\52", }; + static protected Token jjFillToken() + { + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; + } + + static int curLexState = 0; + static int defaultLexState = 0; + static int jjnewStateCnt; + static int jjround; + static int jjmatchedPos; + static int jjmatchedKind; + + /** Get the next Token. */ + public static Token getNextToken() + { + Token specialToken = null; + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + 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); + } + } + + static private void jjCheckNAdd(int state) + { + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } + } + static private void jjAddStates(int start, int end) + { + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); + } + static private void jjCheckNAddTwoStates(int state1, int state2) + { + jjCheckNAdd(state1); + jjCheckNAdd(state2); + } + + static private void jjCheckNAddStates(int start, int end) + { + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); + } + + /** Constructor. */ + public MiniJavaParserTokenManager(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; + } + + /** Constructor. */ + public MiniJavaParserTokenManager (JavaCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + static public void ReInit(JavaCharStream stream) + { + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + static private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 24; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + static public void ReInit(JavaCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + 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; + } + + /** Lexer state names. */ + public static final String[] lexStateNames = { + "DEFAULT", + }; + static final long[] jjtoToken = { + 0x19ffffffffe01L, + }; + 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[2 * 24]; + + + static protected char curChar; +} diff --git a/parse/ParseException.java b/parse/ParseException.java new file mode 100644 index 0000000..54ad2bb --- /dev/null +++ b/parse/ParseException.java @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 6.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package parse; + +/** + * 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 { + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * 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. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + 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(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * 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; + + /** + * 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) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + 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 += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + 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. + */ + static 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(); + } + +} +/* JavaCC - OriginalChecksum=26384494e096fff2d984212006e03bb2 (do not edit this line) */ diff --git a/parse/Token.java b/parse/Token.java new file mode 100644 index 0000000..df3ae15 --- /dev/null +++ b/parse/Token.java @@ -0,0 +1,131 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 6.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package parse; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * 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; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int 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; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * 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, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=6a36a0ff5e35e9c34d59cea00fbe5f35 (do not edit this line) */ diff --git a/parse/TokenMgrError.java b/parse/TokenMgrError.java new file mode 100644 index 0000000..0f6b576 --- /dev/null +++ b/parse/TokenMgrError.java @@ -0,0 +1,147 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 6.0 */ +/* JavaCCOptions: */ +package parse; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was 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 escaped (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 lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * 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. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + 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); + } +} +/* JavaCC - OriginalChecksum=8b56e5ccc811bb132c934e28fc35f6c5 (do not edit this line) */ diff --git a/syntaxtree/AllocationExpression.java b/syntaxtree/AllocationExpression.java new file mode 100644 index 0000000..dd3b00a --- /dev/null +++ b/syntaxtree/AllocationExpression.java @@ -0,0 +1,47 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ +public class AllocationExpression implements Node { + public NodeToken f0; + public Identifier f1; + public NodeToken f2; + public NodeToken f3; + + public AllocationExpression(NodeToken n0, Identifier n1, NodeToken n2, NodeToken n3) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + } + + public AllocationExpression(Identifier n0) { + f0 = new NodeToken("new"); + f1 = n0; + f2 = new NodeToken("("); + f3 = new NodeToken(")"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/AndExpression.java b/syntaxtree/AndExpression.java new file mode 100644 index 0000000..d5672c6 --- /dev/null +++ b/syntaxtree/AndExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ +public class AndExpression implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + + public AndExpression(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public AndExpression(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("&&"); + f2 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ArrayAllocationExpression.java b/syntaxtree/ArrayAllocationExpression.java new file mode 100644 index 0000000..09627cb --- /dev/null +++ b/syntaxtree/ArrayAllocationExpression.java @@ -0,0 +1,51 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ +public class ArrayAllocationExpression implements Node { + public NodeToken f0; + public NodeToken f1; + public NodeToken f2; + public Expression f3; + public NodeToken f4; + + public ArrayAllocationExpression(NodeToken n0, NodeToken n1, NodeToken n2, Expression n3, NodeToken n4) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + } + + public ArrayAllocationExpression(Expression n0) { + f0 = new NodeToken("new"); + f1 = new NodeToken("int"); + f2 = new NodeToken("["); + f3 = n0; + f4 = new NodeToken("]"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ArrayAssignmentStatement.java b/syntaxtree/ArrayAssignmentStatement.java new file mode 100644 index 0000000..2878980 --- /dev/null +++ b/syntaxtree/ArrayAssignmentStatement.java @@ -0,0 +1,59 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ +public class ArrayAssignmentStatement implements Node { + public Identifier f0; + public NodeToken f1; + public Expression f2; + public NodeToken f3; + public NodeToken f4; + public Expression f5; + public NodeToken f6; + + public ArrayAssignmentStatement(Identifier n0, NodeToken n1, Expression n2, NodeToken n3, NodeToken n4, Expression n5, NodeToken n6) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + f6 = n6; + } + + public ArrayAssignmentStatement(Identifier n0, Expression n1, Expression n2) { + f0 = n0; + f1 = new NodeToken("["); + f2 = n1; + f3 = new NodeToken("]"); + f4 = new NodeToken("="); + f5 = n2; + f6 = new NodeToken(";"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ArrayLength.java b/syntaxtree/ArrayLength.java new file mode 100644 index 0000000..6176f5c --- /dev/null +++ b/syntaxtree/ArrayLength.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ +public class ArrayLength implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public NodeToken f2; + + public ArrayLength(PrimaryExpression n0, NodeToken n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public ArrayLength(PrimaryExpression n0) { + f0 = n0; + f1 = new NodeToken("."); + f2 = new NodeToken("length"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ArrayLookup.java b/syntaxtree/ArrayLookup.java new file mode 100644 index 0000000..fb7484f --- /dev/null +++ b/syntaxtree/ArrayLookup.java @@ -0,0 +1,47 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ +public class ArrayLookup implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + public NodeToken f3; + + public ArrayLookup(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2, NodeToken n3) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + } + + public ArrayLookup(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("["); + f2 = n1; + f3 = new NodeToken("]"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ArrayType.java b/syntaxtree/ArrayType.java new file mode 100644 index 0000000..fb6145d --- /dev/null +++ b/syntaxtree/ArrayType.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ +public class ArrayType implements Node { + public NodeToken f0; + public NodeToken f1; + public NodeToken f2; + + public ArrayType(NodeToken n0, NodeToken n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public ArrayType() { + f0 = new NodeToken("int"); + f1 = new NodeToken("["); + f2 = new NodeToken("]"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/AssignmentStatement.java b/syntaxtree/AssignmentStatement.java new file mode 100644 index 0000000..ad135a1 --- /dev/null +++ b/syntaxtree/AssignmentStatement.java @@ -0,0 +1,47 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ +public class AssignmentStatement implements Node { + public Identifier f0; + public NodeToken f1; + public Expression f2; + public NodeToken f3; + + public AssignmentStatement(Identifier n0, NodeToken n1, Expression n2, NodeToken n3) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + } + + public AssignmentStatement(Identifier n0, Expression n1) { + f0 = n0; + f1 = new NodeToken("="); + f2 = n1; + f3 = new NodeToken(";"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Block.java b/syntaxtree/Block.java new file mode 100644 index 0000000..694c439 --- /dev/null +++ b/syntaxtree/Block.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ +public class Block implements Node { + public NodeToken f0; + public NodeListOptional f1; + public NodeToken f2; + + public Block(NodeToken n0, NodeListOptional n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public Block(NodeListOptional n0) { + f0 = new NodeToken("{"); + f1 = n0; + f2 = new NodeToken("}"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/BooleanType.java b/syntaxtree/BooleanType.java new file mode 100644 index 0000000..a606164 --- /dev/null +++ b/syntaxtree/BooleanType.java @@ -0,0 +1,35 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "boolean" + */ +public class BooleanType implements Node { + public NodeToken f0; + + public BooleanType(NodeToken n0) { + f0 = n0; + } + + public BooleanType() { + f0 = new NodeToken("boolean"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/BracketExpression.java b/syntaxtree/BracketExpression.java new file mode 100644 index 0000000..6116618 --- /dev/null +++ b/syntaxtree/BracketExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ +public class BracketExpression implements Node { + public NodeToken f0; + public Expression f1; + public NodeToken f2; + + public BracketExpression(NodeToken n0, Expression n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public BracketExpression(Expression n0) { + f0 = new NodeToken("("); + f1 = n0; + f2 = new NodeToken(")"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ClassDeclaration.java b/syntaxtree/ClassDeclaration.java new file mode 100644 index 0000000..5ad4840 --- /dev/null +++ b/syntaxtree/ClassDeclaration.java @@ -0,0 +1,55 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ +public class ClassDeclaration implements Node { + public NodeToken f0; + public Identifier f1; + public NodeToken f2; + public NodeListOptional f3; + public NodeListOptional f4; + public NodeToken f5; + + public ClassDeclaration(NodeToken n0, Identifier n1, NodeToken n2, NodeListOptional n3, NodeListOptional n4, NodeToken n5) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + } + + public ClassDeclaration(Identifier n0, NodeListOptional n1, NodeListOptional n2) { + f0 = new NodeToken("class"); + f1 = n0; + f2 = new NodeToken("{"); + f3 = n1; + f4 = n2; + f5 = new NodeToken("}"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ClassExtendsDeclaration.java b/syntaxtree/ClassExtendsDeclaration.java new file mode 100644 index 0000000..d9b6dbe --- /dev/null +++ b/syntaxtree/ClassExtendsDeclaration.java @@ -0,0 +1,63 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ +public class ClassExtendsDeclaration implements Node { + public NodeToken f0; + public Identifier f1; + public NodeToken f2; + public Identifier f3; + public NodeToken f4; + public NodeListOptional f5; + public NodeListOptional f6; + public NodeToken f7; + + public ClassExtendsDeclaration(NodeToken n0, Identifier n1, NodeToken n2, Identifier n3, NodeToken n4, NodeListOptional n5, NodeListOptional n6, NodeToken n7) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + f6 = n6; + f7 = n7; + } + + public ClassExtendsDeclaration(Identifier n0, Identifier n1, NodeListOptional n2, NodeListOptional n3) { + f0 = new NodeToken("class"); + f1 = n0; + f2 = new NodeToken("extends"); + f3 = n1; + f4 = new NodeToken("{"); + f5 = n2; + f6 = n3; + f7 = new NodeToken("}"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/CompareExpression.java b/syntaxtree/CompareExpression.java new file mode 100644 index 0000000..b5362f4 --- /dev/null +++ b/syntaxtree/CompareExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ +public class CompareExpression implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + + public CompareExpression(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public CompareExpression(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("<"); + f2 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Expression.java b/syntaxtree/Expression.java new file mode 100644 index 0000000..4e866c8 --- /dev/null +++ b/syntaxtree/Expression.java @@ -0,0 +1,39 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ +public class Expression implements Node { + public NodeChoice f0; + + public Expression(NodeChoice n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ExpressionList.java b/syntaxtree/ExpressionList.java new file mode 100644 index 0000000..1faa724 --- /dev/null +++ b/syntaxtree/ExpressionList.java @@ -0,0 +1,34 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ +public class ExpressionList implements Node { + public Expression f0; + public NodeListOptional f1; + + public ExpressionList(Expression n0, NodeListOptional n1) { + f0 = n0; + f1 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ExpressionRest.java b/syntaxtree/ExpressionRest.java new file mode 100644 index 0000000..e6929c9 --- /dev/null +++ b/syntaxtree/ExpressionRest.java @@ -0,0 +1,39 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "," + * f1 -> Expression() + */ +public class ExpressionRest implements Node { + public NodeToken f0; + public Expression f1; + + public ExpressionRest(NodeToken n0, Expression n1) { + f0 = n0; + f1 = n1; + } + + public ExpressionRest(Expression n0) { + f0 = new NodeToken(","); + f1 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/FalseLiteral.java b/syntaxtree/FalseLiteral.java new file mode 100644 index 0000000..2ce4696 --- /dev/null +++ b/syntaxtree/FalseLiteral.java @@ -0,0 +1,35 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "false" + */ +public class FalseLiteral implements Node { + public NodeToken f0; + + public FalseLiteral(NodeToken n0) { + f0 = n0; + } + + public FalseLiteral() { + f0 = new NodeToken("false"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/FormalParameter.java b/syntaxtree/FormalParameter.java new file mode 100644 index 0000000..51637e9 --- /dev/null +++ b/syntaxtree/FormalParameter.java @@ -0,0 +1,34 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Type() + * f1 -> Identifier() + */ +public class FormalParameter implements Node { + public Type f0; + public Identifier f1; + + public FormalParameter(Type n0, Identifier n1) { + f0 = n0; + f1 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/FormalParameterList.java b/syntaxtree/FormalParameterList.java new file mode 100644 index 0000000..65d4d80 --- /dev/null +++ b/syntaxtree/FormalParameterList.java @@ -0,0 +1,34 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ +public class FormalParameterList implements Node { + public FormalParameter f0; + public NodeListOptional f1; + + public FormalParameterList(FormalParameter n0, NodeListOptional n1) { + f0 = n0; + f1 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/FormalParameterRest.java b/syntaxtree/FormalParameterRest.java new file mode 100644 index 0000000..c7fa656 --- /dev/null +++ b/syntaxtree/FormalParameterRest.java @@ -0,0 +1,39 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "," + * f1 -> FormalParameter() + */ +public class FormalParameterRest implements Node { + public NodeToken f0; + public FormalParameter f1; + + public FormalParameterRest(NodeToken n0, FormalParameter n1) { + f0 = n0; + f1 = n1; + } + + public FormalParameterRest(FormalParameter n0) { + f0 = new NodeToken(","); + f1 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Goal.java b/syntaxtree/Goal.java new file mode 100644 index 0000000..77bc6c6 --- /dev/null +++ b/syntaxtree/Goal.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ +public class Goal implements Node { + public MainClass f0; + public NodeListOptional f1; + public NodeToken f2; + + public Goal(MainClass n0, NodeListOptional n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public Goal(MainClass n0, NodeListOptional n1) { + f0 = n0; + f1 = n1; + f2 = new NodeToken(""); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Identifier.java b/syntaxtree/Identifier.java new file mode 100644 index 0000000..5965a32 --- /dev/null +++ b/syntaxtree/Identifier.java @@ -0,0 +1,31 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> <IDENTIFIER> + */ +public class Identifier implements Node { + public NodeToken f0; + + public Identifier(NodeToken n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/IfStatement.java b/syntaxtree/IfStatement.java new file mode 100644 index 0000000..a6ab818 --- /dev/null +++ b/syntaxtree/IfStatement.java @@ -0,0 +1,59 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ +public class IfStatement implements Node { + public NodeToken f0; + public NodeToken f1; + public Expression f2; + public NodeToken f3; + public Statement f4; + public NodeToken f5; + public Statement f6; + + public IfStatement(NodeToken n0, NodeToken n1, Expression n2, NodeToken n3, Statement n4, NodeToken n5, Statement n6) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + f6 = n6; + } + + public IfStatement(Expression n0, Statement n1, Statement n2) { + f0 = new NodeToken("if"); + f1 = new NodeToken("("); + f2 = n0; + f3 = new NodeToken(")"); + f4 = n1; + f5 = new NodeToken("else"); + f6 = n2; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/IntegerLiteral.java b/syntaxtree/IntegerLiteral.java new file mode 100644 index 0000000..5e9882a --- /dev/null +++ b/syntaxtree/IntegerLiteral.java @@ -0,0 +1,31 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> <INTEGER_LITERAL> + */ +public class IntegerLiteral implements Node { + public NodeToken f0; + + public IntegerLiteral(NodeToken n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/IntegerType.java b/syntaxtree/IntegerType.java new file mode 100644 index 0000000..6dafa73 --- /dev/null +++ b/syntaxtree/IntegerType.java @@ -0,0 +1,35 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "int" + */ +public class IntegerType implements Node { + public NodeToken f0; + + public IntegerType(NodeToken n0) { + f0 = n0; + } + + public IntegerType() { + f0 = new NodeToken("int"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/MainClass.java b/syntaxtree/MainClass.java new file mode 100644 index 0000000..050cbc5 --- /dev/null +++ b/syntaxtree/MainClass.java @@ -0,0 +1,103 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ +public class MainClass implements Node { + public NodeToken f0; + public Identifier f1; + public NodeToken f2; + public NodeToken f3; + public NodeToken f4; + public NodeToken f5; + public NodeToken f6; + public NodeToken f7; + public NodeToken f8; + public NodeToken f9; + public NodeToken f10; + public Identifier f11; + public NodeToken f12; + public NodeToken f13; + public NodeListOptional f14; + public NodeListOptional f15; + public NodeToken f16; + public NodeToken f17; + + public MainClass(NodeToken n0, Identifier n1, NodeToken n2, NodeToken n3, NodeToken n4, NodeToken n5, NodeToken n6, NodeToken n7, NodeToken n8, NodeToken n9, NodeToken n10, Identifier n11, NodeToken n12, NodeToken n13, NodeListOptional n14, NodeListOptional n15, NodeToken n16, NodeToken n17) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + f6 = n6; + f7 = n7; + f8 = n8; + f9 = n9; + f10 = n10; + f11 = n11; + f12 = n12; + f13 = n13; + f14 = n14; + f15 = n15; + f16 = n16; + f17 = n17; + } + + public MainClass(Identifier n0, Identifier n1, NodeListOptional n2, NodeListOptional n3) { + f0 = new NodeToken("class"); + f1 = n0; + f2 = new NodeToken("{"); + f3 = new NodeToken("public"); + f4 = new NodeToken("static"); + f5 = new NodeToken("void"); + f6 = new NodeToken("main"); + f7 = new NodeToken("("); + f8 = new NodeToken("String"); + f9 = new NodeToken("["); + f10 = new NodeToken("]"); + f11 = n1; + f12 = new NodeToken(")"); + f13 = new NodeToken("{"); + f14 = n2; + f15 = n3; + f16 = new NodeToken("}"); + f17 = new NodeToken("}"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/MessageSend.java b/syntaxtree/MessageSend.java new file mode 100644 index 0000000..691e5dd --- /dev/null +++ b/syntaxtree/MessageSend.java @@ -0,0 +1,55 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ +public class MessageSend implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public Identifier f2; + public NodeToken f3; + public NodeOptional f4; + public NodeToken f5; + + public MessageSend(PrimaryExpression n0, NodeToken n1, Identifier n2, NodeToken n3, NodeOptional n4, NodeToken n5) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + } + + public MessageSend(PrimaryExpression n0, Identifier n1, NodeOptional n2) { + f0 = n0; + f1 = new NodeToken("."); + f2 = n1; + f3 = new NodeToken("("); + f4 = n2; + f5 = new NodeToken(")"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/MethodDeclaration.java b/syntaxtree/MethodDeclaration.java new file mode 100644 index 0000000..03a4d76 --- /dev/null +++ b/syntaxtree/MethodDeclaration.java @@ -0,0 +1,83 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ +public class MethodDeclaration implements Node { + public NodeToken f0; + public Type f1; + public Identifier f2; + public NodeToken f3; + public NodeOptional f4; + public NodeToken f5; + public NodeToken f6; + public NodeListOptional f7; + public NodeListOptional f8; + public NodeToken f9; + public Expression f10; + public NodeToken f11; + public NodeToken f12; + + public MethodDeclaration(NodeToken n0, Type n1, Identifier n2, NodeToken n3, NodeOptional n4, NodeToken n5, NodeToken n6, NodeListOptional n7, NodeListOptional n8, NodeToken n9, Expression n10, NodeToken n11, NodeToken n12) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + f5 = n5; + f6 = n6; + f7 = n7; + f8 = n8; + f9 = n9; + f10 = n10; + f11 = n11; + f12 = n12; + } + + public MethodDeclaration(Type n0, Identifier n1, NodeOptional n2, NodeListOptional n3, NodeListOptional n4, Expression n5) { + f0 = new NodeToken("public"); + f1 = n0; + f2 = n1; + f3 = new NodeToken("("); + f4 = n2; + f5 = new NodeToken(")"); + f6 = new NodeToken("{"); + f7 = n3; + f8 = n4; + f9 = new NodeToken("return"); + f10 = n5; + f11 = new NodeToken(";"); + f12 = new NodeToken("}"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/MinusExpression.java b/syntaxtree/MinusExpression.java new file mode 100644 index 0000000..920157d --- /dev/null +++ b/syntaxtree/MinusExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ +public class MinusExpression implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + + public MinusExpression(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public MinusExpression(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("-"); + f2 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Node.java b/syntaxtree/Node.java new file mode 100644 index 0000000..02a9bfa --- /dev/null +++ b/syntaxtree/Node.java @@ -0,0 +1,16 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * The interface which all syntax tree classes must implement. + */ +public interface Node extends java.io.Serializable { + public void accept(visitor.Visitor v); + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu); + public <R> R accept(visitor.GJNoArguVisitor<R> v); + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu); +} + diff --git a/syntaxtree/NodeChoice.java b/syntaxtree/NodeChoice.java new file mode 100644 index 0000000..9b8b5ed --- /dev/null +++ b/syntaxtree/NodeChoice.java @@ -0,0 +1,36 @@ +// +// Generated by JTB 1.3.2 +// + +package 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(visitor.Visitor v) { + choice.accept(v); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return choice.accept(v,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return choice.accept(v); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + choice.accept(v,argu); + } + + public Node choice; + public int which; +} + diff --git a/syntaxtree/NodeList.java b/syntaxtree/NodeList.java new file mode 100644 index 0000000..43c37c5 --- /dev/null +++ b/syntaxtree/NodeList.java @@ -0,0 +1,44 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +import java.util.*; + +/** + * 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(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } + + public Vector<Node> nodes; +} + diff --git a/syntaxtree/NodeListInterface.java b/syntaxtree/NodeListInterface.java new file mode 100644 index 0000000..7579bbf --- /dev/null +++ b/syntaxtree/NodeListInterface.java @@ -0,0 +1,22 @@ +// +// Generated by JTB 1.3.2 +// + +package 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(visitor.Visitor v); + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu); + public <R> R accept(visitor.GJNoArguVisitor<R> v); + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu); +} + diff --git a/syntaxtree/NodeListOptional.java b/syntaxtree/NodeListOptional.java new file mode 100644 index 0000000..135124b --- /dev/null +++ b/syntaxtree/NodeListOptional.java @@ -0,0 +1,45 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +import java.util.*; + +/** + * 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(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } + + public Vector<Node> nodes; +} + diff --git a/syntaxtree/NodeOptional.java b/syntaxtree/NodeOptional.java new file mode 100644 index 0000000..d9a8c43 --- /dev/null +++ b/syntaxtree/NodeOptional.java @@ -0,0 +1,41 @@ +// +// Generated by JTB 1.3.2 +// + +package 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(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } + public boolean present() { return node != null; } + + public Node node; +} + diff --git a/syntaxtree/NodeSequence.java b/syntaxtree/NodeSequence.java new file mode 100644 index 0000000..88096a9 --- /dev/null +++ b/syntaxtree/NodeSequence.java @@ -0,0 +1,45 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +import java.util.*; + +/** + * 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(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } + + public Vector<Node> nodes; +} + diff --git a/syntaxtree/NodeToken.java b/syntaxtree/NodeToken.java new file mode 100644 index 0000000..100169d --- /dev/null +++ b/syntaxtree/NodeToken.java @@ -0,0 +1,87 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +import java.util.*; +/** + * 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(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(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/syntaxtree/NotExpression.java b/syntaxtree/NotExpression.java new file mode 100644 index 0000000..53c239d --- /dev/null +++ b/syntaxtree/NotExpression.java @@ -0,0 +1,39 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "!" + * f1 -> Expression() + */ +public class NotExpression implements Node { + public NodeToken f0; + public Expression f1; + + public NotExpression(NodeToken n0, Expression n1) { + f0 = n0; + f1 = n1; + } + + public NotExpression(Expression n0) { + f0 = new NodeToken("!"); + f1 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/PlusExpression.java b/syntaxtree/PlusExpression.java new file mode 100644 index 0000000..a75ee24 --- /dev/null +++ b/syntaxtree/PlusExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ +public class PlusExpression implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + + public PlusExpression(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public PlusExpression(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("+"); + f2 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/PrimaryExpression.java b/syntaxtree/PrimaryExpression.java new file mode 100644 index 0000000..df06675 --- /dev/null +++ b/syntaxtree/PrimaryExpression.java @@ -0,0 +1,39 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ +public class PrimaryExpression implements Node { + public NodeChoice f0; + + public PrimaryExpression(NodeChoice n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/PrintStatement.java b/syntaxtree/PrintStatement.java new file mode 100644 index 0000000..cc4d084 --- /dev/null +++ b/syntaxtree/PrintStatement.java @@ -0,0 +1,51 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ +public class PrintStatement implements Node { + public NodeToken f0; + public NodeToken f1; + public Expression f2; + public NodeToken f3; + public NodeToken f4; + + public PrintStatement(NodeToken n0, NodeToken n1, Expression n2, NodeToken n3, NodeToken n4) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + } + + public PrintStatement(Expression n0) { + f0 = new NodeToken("System.out.println"); + f1 = new NodeToken("("); + f2 = n0; + f3 = new NodeToken(")"); + f4 = new NodeToken(";"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Statement.java b/syntaxtree/Statement.java new file mode 100644 index 0000000..b9846fa --- /dev/null +++ b/syntaxtree/Statement.java @@ -0,0 +1,36 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ +public class Statement implements Node { + public NodeChoice f0; + + public Statement(NodeChoice n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/ThisExpression.java b/syntaxtree/ThisExpression.java new file mode 100644 index 0000000..2768aa0 --- /dev/null +++ b/syntaxtree/ThisExpression.java @@ -0,0 +1,35 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "this" + */ +public class ThisExpression implements Node { + public NodeToken f0; + + public ThisExpression(NodeToken n0) { + f0 = n0; + } + + public ThisExpression() { + f0 = new NodeToken("this"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/TimesExpression.java b/syntaxtree/TimesExpression.java new file mode 100644 index 0000000..5e0d6f7 --- /dev/null +++ b/syntaxtree/TimesExpression.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ +public class TimesExpression implements Node { + public PrimaryExpression f0; + public NodeToken f1; + public PrimaryExpression f2; + + public TimesExpression(PrimaryExpression n0, NodeToken n1, PrimaryExpression n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public TimesExpression(PrimaryExpression n0, PrimaryExpression n1) { + f0 = n0; + f1 = new NodeToken("*"); + f2 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/TrueLiteral.java b/syntaxtree/TrueLiteral.java new file mode 100644 index 0000000..d6f80f9 --- /dev/null +++ b/syntaxtree/TrueLiteral.java @@ -0,0 +1,35 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "true" + */ +public class TrueLiteral implements Node { + public NodeToken f0; + + public TrueLiteral(NodeToken n0) { + f0 = n0; + } + + public TrueLiteral() { + f0 = new NodeToken("true"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/Type.java b/syntaxtree/Type.java new file mode 100644 index 0000000..049b094 --- /dev/null +++ b/syntaxtree/Type.java @@ -0,0 +1,34 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ +public class Type implements Node { + public NodeChoice f0; + + public Type(NodeChoice n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/TypeDeclaration.java b/syntaxtree/TypeDeclaration.java new file mode 100644 index 0000000..605777e --- /dev/null +++ b/syntaxtree/TypeDeclaration.java @@ -0,0 +1,32 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ +public class TypeDeclaration implements Node { + public NodeChoice f0; + + public TypeDeclaration(NodeChoice n0) { + f0 = n0; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/VarDeclaration.java b/syntaxtree/VarDeclaration.java new file mode 100644 index 0000000..9850fd3 --- /dev/null +++ b/syntaxtree/VarDeclaration.java @@ -0,0 +1,43 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ +public class VarDeclaration implements Node { + public Type f0; + public Identifier f1; + public NodeToken f2; + + public VarDeclaration(Type n0, Identifier n1, NodeToken n2) { + f0 = n0; + f1 = n1; + f2 = n2; + } + + public VarDeclaration(Type n0, Identifier n1) { + f0 = n0; + f1 = n1; + f2 = new NodeToken(";"); + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/syntaxtree/WhileStatement.java b/syntaxtree/WhileStatement.java new file mode 100644 index 0000000..ecdb7cc --- /dev/null +++ b/syntaxtree/WhileStatement.java @@ -0,0 +1,51 @@ +// +// Generated by JTB 1.3.2 +// + +package syntaxtree; + +/** + * Grammar production: + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ +public class WhileStatement implements Node { + public NodeToken f0; + public NodeToken f1; + public Expression f2; + public NodeToken f3; + public Statement f4; + + public WhileStatement(NodeToken n0, NodeToken n1, Expression n2, NodeToken n3, Statement n4) { + f0 = n0; + f1 = n1; + f2 = n2; + f3 = n3; + f4 = n4; + } + + public WhileStatement(Expression n0, Statement n1) { + f0 = new NodeToken("while"); + f1 = new NodeToken("("); + f2 = n0; + f3 = new NodeToken(")"); + f4 = n1; + } + + public void accept(visitor.Visitor v) { + v.visit(this); + } + public <R,A> R accept(visitor.GJVisitor<R,A> v, A argu) { + return v.visit(this,argu); + } + public <R> R accept(visitor.GJNoArguVisitor<R> v) { + return v.visit(this); + } + public <A> void accept(visitor.GJVoidVisitor<A> v, A argu) { + v.visit(this,argu); + } +} + diff --git a/visitor/DepthFirstVisitor.java b/visitor/DepthFirstVisitor.java new file mode 100644 index 0000000..a0a5749 --- /dev/null +++ b/visitor/DepthFirstVisitor.java @@ -0,0 +1,577 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * Provides default methods which visit each node in the tree in depth-first + * order. Your visitors may extend this class. + */ +public class DepthFirstVisitor implements Visitor { + // + // Auto class visitors--probably don't need to be overridden. + // + public void visit(NodeList n) { + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) + e.nextElement().accept(this); + } + + public void visit(NodeListOptional n) { + if ( n.present() ) + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) + e.nextElement().accept(this); + } + + public void visit(NodeOptional n) { + if ( n.present() ) + n.node.accept(this); + } + + public void visit(NodeSequence n) { + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) + e.nextElement().accept(this); + } + + public void visit(NodeToken n) { } + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public void visit(Goal n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public void visit(MainClass n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + n.f8.accept(this); + n.f9.accept(this); + n.f10.accept(this); + n.f11.accept(this); + n.f12.accept(this); + n.f13.accept(this); + n.f14.accept(this); + n.f15.accept(this); + n.f16.accept(this); + n.f17.accept(this); + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public void visit(TypeDeclaration n) { + n.f0.accept(this); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public void visit(ClassDeclaration n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public void visit(ClassExtendsDeclaration n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public void visit(VarDeclaration n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public void visit(MethodDeclaration n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + n.f8.accept(this); + n.f9.accept(this); + n.f10.accept(this); + n.f11.accept(this); + n.f12.accept(this); + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public void visit(FormalParameterList n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public void visit(FormalParameter n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public void visit(FormalParameterRest n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public void visit(Type n) { + n.f0.accept(this); + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public void visit(ArrayType n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> "boolean" + */ + public void visit(BooleanType n) { + n.f0.accept(this); + } + + /** + * f0 -> "int" + */ + public void visit(IntegerType n) { + n.f0.accept(this); + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public void visit(Statement n) { + n.f0.accept(this); + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public void visit(Block n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public void visit(AssignmentStatement n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public void visit(ArrayAssignmentStatement n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public void visit(IfStatement n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public void visit(WhileStatement n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public void visit(PrintStatement n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public void visit(Expression n) { + n.f0.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public void visit(AndExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public void visit(CompareExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public void visit(PlusExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public void visit(MinusExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public void visit(TimesExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public void visit(ArrayLookup n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public void visit(ArrayLength n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public void visit(MessageSend n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public void visit(ExpressionList n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public void visit(ExpressionRest n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public void visit(PrimaryExpression n) { + n.f0.accept(this); + } + + /** + * f0 -> <INTEGER_LITERAL> + */ + public void visit(IntegerLiteral n) { + n.f0.accept(this); + } + + /** + * f0 -> "true" + */ + public void visit(TrueLiteral n) { + n.f0.accept(this); + } + + /** + * f0 -> "false" + */ + public void visit(FalseLiteral n) { + n.f0.accept(this); + } + + /** + * f0 -> <IDENTIFIER> + */ + public void visit(Identifier n) { + n.f0.accept(this); + } + + /** + * f0 -> "this" + */ + public void visit(ThisExpression n) { + n.f0.accept(this); + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public void visit(ArrayAllocationExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public void visit(AllocationExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public void visit(NotExpression n) { + n.f0.accept(this); + n.f1.accept(this); + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public void visit(BracketExpression n) { + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + } + +} diff --git a/visitor/GJDepthFirst.java b/visitor/GJDepthFirst.java new file mode 100644 index 0000000..c555d29 --- /dev/null +++ b/visitor/GJDepthFirst.java @@ -0,0 +1,681 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; +// extend +/** + * Provides default methods which visit each node in the tree in depth-first + * order. Your visitors may extend this class. + */ +public class GJDepthFirst<R,A> implements GJVisitor<R,A> { + // + // Auto class visitors--probably don't need to be overridden. + // + public R visit(NodeList n, A argu) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public R visit(NodeListOptional n, A argu) { + if ( n.present() ) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + else + return null; + } + + public R visit(NodeOptional n, A argu) { + if ( n.present() ) + return n.node.accept(this,argu); + else + return null; + } + + public R visit(NodeSequence n, A argu) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + return _ret; + } + + public R visit(NodeToken n, A argu) { return null; } + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public R visit(Goal n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public R visit(MainClass n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + n.f13.accept(this, argu); + n.f14.accept(this, argu); + n.f15.accept(this, argu); + n.f16.accept(this, argu); + n.f17.accept(this, argu); + return _ret; + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public R visit(TypeDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public R visit(ClassDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public R visit(ClassExtendsDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public R visit(VarDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public R visit(MethodDeclaration n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + return _ret; + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public R visit(FormalParameterList n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public R visit(FormalParameter n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public R visit(FormalParameterRest n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public R visit(Type n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public R visit(ArrayType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> "boolean" + */ + public R visit(BooleanType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "int" + */ + public R visit(IntegerType n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public R visit(Statement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public R visit(Block n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public R visit(AssignmentStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public R visit(ArrayAssignmentStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + return _ret; + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public R visit(IfStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + return _ret; + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public R visit(WhileStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public R visit(PrintStatement n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public R visit(Expression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public R visit(AndExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public R visit(CompareExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public R visit(PlusExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public R visit(MinusExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public R visit(TimesExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public R visit(ArrayLookup n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public R visit(ArrayLength n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public R visit(MessageSend n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + return _ret; + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public R visit(ExpressionList n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public R visit(ExpressionRest n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public R visit(PrimaryExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> <INTEGER_LITERAL> + */ + public R visit(IntegerLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "true" + */ + public R visit(TrueLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "false" + */ + public R visit(FalseLiteral n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> <IDENTIFIER> + */ + public R visit(Identifier n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "this" + */ + public R visit(ThisExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public R visit(ArrayAllocationExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public R visit(AllocationExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + return _ret; + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public R visit(NotExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + return _ret; + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public R visit(BracketExpression n, A argu) { + R _ret=null; + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + return _ret; + } + +} diff --git a/visitor/GJNoArguDepthFirst.java b/visitor/GJNoArguDepthFirst.java new file mode 100644 index 0000000..cd8214c --- /dev/null +++ b/visitor/GJNoArguDepthFirst.java @@ -0,0 +1,681 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * Provides default methods which visit each node in the tree in depth-first + * order. Your visitors may extend this class. + */ +public class GJNoArguDepthFirst<R> implements GJNoArguVisitor<R> { + // + // Auto class visitors--probably don't need to be overridden. + // + public R visit(NodeList n) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this); + _count++; + } + return _ret; + } + + public R visit(NodeListOptional n) { + if ( n.present() ) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this); + _count++; + } + return _ret; + } + else + return null; + } + + public R visit(NodeOptional n) { + if ( n.present() ) + return n.node.accept(this); + else + return null; + } + + public R visit(NodeSequence n) { + R _ret=null; + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this); + _count++; + } + return _ret; + } + + public R visit(NodeToken n) { return null; } + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public R visit(Goal n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public R visit(MainClass n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + n.f8.accept(this); + n.f9.accept(this); + n.f10.accept(this); + n.f11.accept(this); + n.f12.accept(this); + n.f13.accept(this); + n.f14.accept(this); + n.f15.accept(this); + n.f16.accept(this); + n.f17.accept(this); + return _ret; + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public R visit(TypeDeclaration n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public R visit(ClassDeclaration n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + return _ret; + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public R visit(ClassExtendsDeclaration n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public R visit(VarDeclaration n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public R visit(MethodDeclaration n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + n.f7.accept(this); + n.f8.accept(this); + n.f9.accept(this); + n.f10.accept(this); + n.f11.accept(this); + n.f12.accept(this); + return _ret; + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public R visit(FormalParameterList n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public R visit(FormalParameter n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public R visit(FormalParameterRest n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public R visit(Type n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public R visit(ArrayType n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> "boolean" + */ + public R visit(BooleanType n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "int" + */ + public R visit(IntegerType n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public R visit(Statement n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public R visit(Block n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public R visit(AssignmentStatement n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + return _ret; + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public R visit(ArrayAssignmentStatement n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + return _ret; + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public R visit(IfStatement n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + n.f6.accept(this); + return _ret; + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public R visit(WhileStatement n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + return _ret; + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public R visit(PrintStatement n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + return _ret; + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public R visit(Expression n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public R visit(AndExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public R visit(CompareExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public R visit(PlusExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public R visit(MinusExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public R visit(TimesExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public R visit(ArrayLookup n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public R visit(ArrayLength n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public R visit(MessageSend n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + n.f5.accept(this); + return _ret; + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public R visit(ExpressionList n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public R visit(ExpressionRest n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public R visit(PrimaryExpression n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> <INTEGER_LITERAL> + */ + public R visit(IntegerLiteral n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "true" + */ + public R visit(TrueLiteral n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "false" + */ + public R visit(FalseLiteral n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> <IDENTIFIER> + */ + public R visit(Identifier n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "this" + */ + public R visit(ThisExpression n) { + R _ret=null; + n.f0.accept(this); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public R visit(ArrayAllocationExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + n.f4.accept(this); + return _ret; + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public R visit(AllocationExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + n.f3.accept(this); + return _ret; + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public R visit(NotExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + return _ret; + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public R visit(BracketExpression n) { + R _ret=null; + n.f0.accept(this); + n.f1.accept(this); + n.f2.accept(this); + return _ret; + } + +} diff --git a/visitor/GJNoArguVisitor.java b/visitor/GJNoArguVisitor.java new file mode 100644 index 0000000..6a0f344 --- /dev/null +++ b/visitor/GJNoArguVisitor.java @@ -0,0 +1,372 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * All GJ visitors with no argument must implement this interface. + */ + +public interface GJNoArguVisitor<R> { + + // + // GJ Auto class visitors with no argument + // + + public R visit(NodeList n); + public R visit(NodeListOptional n); + public R visit(NodeOptional n); + public R visit(NodeSequence n); + public R visit(NodeToken n); + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public R visit(Goal n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public R visit(MainClass n); + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public R visit(TypeDeclaration n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public R visit(ClassDeclaration n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public R visit(ClassExtendsDeclaration n); + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public R visit(VarDeclaration n); + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public R visit(MethodDeclaration n); + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public R visit(FormalParameterList n); + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public R visit(FormalParameter n); + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public R visit(FormalParameterRest n); + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public R visit(Type n); + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public R visit(ArrayType n); + + /** + * f0 -> "boolean" + */ + public R visit(BooleanType n); + + /** + * f0 -> "int" + */ + public R visit(IntegerType n); + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public R visit(Statement n); + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public R visit(Block n); + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public R visit(AssignmentStatement n); + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public R visit(ArrayAssignmentStatement n); + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public R visit(IfStatement n); + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public R visit(WhileStatement n); + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public R visit(PrintStatement n); + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public R visit(Expression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public R visit(AndExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public R visit(CompareExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public R visit(PlusExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public R visit(MinusExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public R visit(TimesExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public R visit(ArrayLookup n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public R visit(ArrayLength n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public R visit(MessageSend n); + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public R visit(ExpressionList n); + + /** + * f0 -> "," + * f1 -> Expression() + */ + public R visit(ExpressionRest n); + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public R visit(PrimaryExpression n); + + /** + * f0 -> <INTEGER_LITERAL> + */ + public R visit(IntegerLiteral n); + + /** + * f0 -> "true" + */ + public R visit(TrueLiteral n); + + /** + * f0 -> "false" + */ + public R visit(FalseLiteral n); + + /** + * f0 -> <IDENTIFIER> + */ + public R visit(Identifier n); + + /** + * f0 -> "this" + */ + public R visit(ThisExpression n); + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public R visit(ArrayAllocationExpression n); + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public R visit(AllocationExpression n); + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public R visit(NotExpression n); + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public R visit(BracketExpression n); + +} + diff --git a/visitor/GJVisitor.java b/visitor/GJVisitor.java new file mode 100644 index 0000000..47af1a5 --- /dev/null +++ b/visitor/GJVisitor.java @@ -0,0 +1,371 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * All GJ visitors must implement this interface. + */ + +public interface GJVisitor<R,A> { + + // + // GJ Auto class visitors + // + + public R visit(NodeList n, A argu); + public R visit(NodeListOptional n, A argu); + public R visit(NodeOptional n, A argu); + public R visit(NodeSequence n, A argu); + public R visit(NodeToken n, A argu); + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public R visit(Goal n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public R visit(MainClass n, A argu); + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public R visit(TypeDeclaration n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public R visit(ClassDeclaration n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public R visit(ClassExtendsDeclaration n, A argu); + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public R visit(VarDeclaration n, A argu); + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public R visit(MethodDeclaration n, A argu); + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public R visit(FormalParameterList n, A argu); + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public R visit(FormalParameter n, A argu); + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public R visit(FormalParameterRest n, A argu); + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public R visit(Type n, A argu); + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public R visit(ArrayType n, A argu); + + /** + * f0 -> "boolean" + */ + public R visit(BooleanType n, A argu); + + /** + * f0 -> "int" + */ + public R visit(IntegerType n, A argu); + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public R visit(Statement n, A argu); + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public R visit(Block n, A argu); + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public R visit(AssignmentStatement n, A argu); + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public R visit(ArrayAssignmentStatement n, A argu); + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public R visit(IfStatement n, A argu); + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public R visit(WhileStatement n, A argu); + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public R visit(PrintStatement n, A argu); + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public R visit(Expression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public R visit(AndExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public R visit(CompareExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public R visit(PlusExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public R visit(MinusExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public R visit(TimesExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public R visit(ArrayLookup n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public R visit(ArrayLength n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public R visit(MessageSend n, A argu); + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public R visit(ExpressionList n, A argu); + + /** + * f0 -> "," + * f1 -> Expression() + */ + public R visit(ExpressionRest n, A argu); + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public R visit(PrimaryExpression n, A argu); + + /** + * f0 -> <INTEGER_LITERAL> + */ + public R visit(IntegerLiteral n, A argu); + + /** + * f0 -> "true" + */ + public R visit(TrueLiteral n, A argu); + + /** + * f0 -> "false" + */ + public R visit(FalseLiteral n, A argu); + + /** + * f0 -> <IDENTIFIER> + */ + public R visit(Identifier n, A argu); + + /** + * f0 -> "this" + */ + public R visit(ThisExpression n, A argu); + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public R visit(ArrayAllocationExpression n, A argu); + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public R visit(AllocationExpression n, A argu); + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public R visit(NotExpression n, A argu); + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public R visit(BracketExpression n, A argu); + +} diff --git a/visitor/GJVoidDepthFirst.java b/visitor/GJVoidDepthFirst.java new file mode 100644 index 0000000..4267259 --- /dev/null +++ b/visitor/GJVoidDepthFirst.java @@ -0,0 +1,587 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * Provides default methods which visit each node in the tree in depth-first + * order. Your visitors may extend this class. + */ +public class GJVoidDepthFirst<A> implements GJVoidVisitor<A> { + // + // Auto class visitors--probably don't need to be overridden. + // + public void visit(NodeList n, A argu) { + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + } + + public void visit(NodeListOptional n, A argu) { + if ( n.present() ) { + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + } + } + + public void visit(NodeOptional n, A argu) { + if ( n.present() ) + n.node.accept(this,argu); + } + + public void visit(NodeSequence n, A argu) { + int _count=0; + for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { + e.nextElement().accept(this,argu); + _count++; + } + } + + public void visit(NodeToken n, A argu) {} + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public void visit(Goal n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public void visit(MainClass n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + n.f13.accept(this, argu); + n.f14.accept(this, argu); + n.f15.accept(this, argu); + n.f16.accept(this, argu); + n.f17.accept(this, argu); + } + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public void visit(TypeDeclaration n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public void visit(ClassDeclaration n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + } + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public void visit(ClassExtendsDeclaration n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + } + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public void visit(VarDeclaration n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public void visit(MethodDeclaration n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + n.f7.accept(this, argu); + n.f8.accept(this, argu); + n.f9.accept(this, argu); + n.f10.accept(this, argu); + n.f11.accept(this, argu); + n.f12.accept(this, argu); + } + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public void visit(FormalParameterList n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public void visit(FormalParameter n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public void visit(FormalParameterRest n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public void visit(Type n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public void visit(ArrayType n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> "boolean" + */ + public void visit(BooleanType n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "int" + */ + public void visit(IntegerType n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public void visit(Statement n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public void visit(Block n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public void visit(AssignmentStatement n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + } + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public void visit(ArrayAssignmentStatement n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + } + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public void visit(IfStatement n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + n.f6.accept(this, argu); + } + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public void visit(WhileStatement n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + } + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public void visit(PrintStatement n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + } + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public void visit(Expression n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public void visit(AndExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public void visit(CompareExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public void visit(PlusExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public void visit(MinusExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public void visit(TimesExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public void visit(ArrayLookup n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public void visit(ArrayLength n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public void visit(MessageSend n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + n.f5.accept(this, argu); + } + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public void visit(ExpressionList n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> "," + * f1 -> Expression() + */ + public void visit(ExpressionRest n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public void visit(PrimaryExpression n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> <INTEGER_LITERAL> + */ + public void visit(IntegerLiteral n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "true" + */ + public void visit(TrueLiteral n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "false" + */ + public void visit(FalseLiteral n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> <IDENTIFIER> + */ + public void visit(Identifier n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "this" + */ + public void visit(ThisExpression n, A argu) { + n.f0.accept(this, argu); + } + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public void visit(ArrayAllocationExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + n.f4.accept(this, argu); + } + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public void visit(AllocationExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + n.f3.accept(this, argu); + } + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public void visit(NotExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + } + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public void visit(BracketExpression n, A argu) { + n.f0.accept(this, argu); + n.f1.accept(this, argu); + n.f2.accept(this, argu); + } + +} diff --git a/visitor/GJVoidVisitor.java b/visitor/GJVoidVisitor.java new file mode 100644 index 0000000..3655f02 --- /dev/null +++ b/visitor/GJVoidVisitor.java @@ -0,0 +1,372 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * All GJ void visitors must implement this interface. + */ + +public interface GJVoidVisitor<A> { + + // + // GJ void Auto class visitors + // + + public void visit(NodeList n, A argu); + public void visit(NodeListOptional n, A argu); + public void visit(NodeOptional n, A argu); + public void visit(NodeSequence n, A argu); + public void visit(NodeToken n, A argu); + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public void visit(Goal n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public void visit(MainClass n, A argu); + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public void visit(TypeDeclaration n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public void visit(ClassDeclaration n, A argu); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public void visit(ClassExtendsDeclaration n, A argu); + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public void visit(VarDeclaration n, A argu); + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public void visit(MethodDeclaration n, A argu); + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public void visit(FormalParameterList n, A argu); + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public void visit(FormalParameter n, A argu); + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public void visit(FormalParameterRest n, A argu); + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public void visit(Type n, A argu); + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public void visit(ArrayType n, A argu); + + /** + * f0 -> "boolean" + */ + public void visit(BooleanType n, A argu); + + /** + * f0 -> "int" + */ + public void visit(IntegerType n, A argu); + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public void visit(Statement n, A argu); + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public void visit(Block n, A argu); + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public void visit(AssignmentStatement n, A argu); + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public void visit(ArrayAssignmentStatement n, A argu); + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public void visit(IfStatement n, A argu); + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public void visit(WhileStatement n, A argu); + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public void visit(PrintStatement n, A argu); + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public void visit(Expression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public void visit(AndExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public void visit(CompareExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public void visit(PlusExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public void visit(MinusExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public void visit(TimesExpression n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public void visit(ArrayLookup n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public void visit(ArrayLength n, A argu); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public void visit(MessageSend n, A argu); + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public void visit(ExpressionList n, A argu); + + /** + * f0 -> "," + * f1 -> Expression() + */ + public void visit(ExpressionRest n, A argu); + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public void visit(PrimaryExpression n, A argu); + + /** + * f0 -> <INTEGER_LITERAL> + */ + public void visit(IntegerLiteral n, A argu); + + /** + * f0 -> "true" + */ + public void visit(TrueLiteral n, A argu); + + /** + * f0 -> "false" + */ + public void visit(FalseLiteral n, A argu); + + /** + * f0 -> <IDENTIFIER> + */ + public void visit(Identifier n, A argu); + + /** + * f0 -> "this" + */ + public void visit(ThisExpression n, A argu); + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public void visit(ArrayAllocationExpression n, A argu); + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public void visit(AllocationExpression n, A argu); + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public void visit(NotExpression n, A argu); + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public void visit(BracketExpression n, A argu); + +} + diff --git a/visitor/Visitor.java b/visitor/Visitor.java new file mode 100644 index 0000000..41804c1 --- /dev/null +++ b/visitor/Visitor.java @@ -0,0 +1,372 @@ +// +// Generated by JTB 1.3.2 +// + +package visitor; +import syntaxtree.*; +import java.util.*; + +/** + * All void visitors must implement this interface. + */ + +public interface Visitor { + + // + // void Auto class visitors + // + + public void visit(NodeList n); + public void visit(NodeListOptional n); + public void visit(NodeOptional n); + public void visit(NodeSequence n); + public void visit(NodeToken n); + + // + // User-generated visitor methods below + // + + /** + * f0 -> MainClass() + * f1 -> ( TypeDeclaration() )* + * f2 -> <EOF> + */ + public void visit(Goal n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public void visit(MainClass n); + + /** + * f0 -> ClassDeclaration() + * | ClassExtendsDeclaration() + */ + public void visit(TypeDeclaration n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> ( VarDeclaration() )* + * f4 -> ( MethodDeclaration() )* + * f5 -> "}" + */ + public void visit(ClassDeclaration n); + + /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "extends" + * f3 -> Identifier() + * f4 -> "{" + * f5 -> ( VarDeclaration() )* + * f6 -> ( MethodDeclaration() )* + * f7 -> "}" + */ + public void visit(ClassExtendsDeclaration n); + + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public void visit(VarDeclaration n); + + /** + * f0 -> "public" + * f1 -> Type() + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( FormalParameterList() )? + * f5 -> ")" + * f6 -> "{" + * f7 -> ( VarDeclaration() )* + * f8 -> ( Statement() )* + * f9 -> "return" + * f10 -> Expression() + * f11 -> ";" + * f12 -> "}" + */ + public void visit(MethodDeclaration n); + + /** + * f0 -> FormalParameter() + * f1 -> ( FormalParameterRest() )* + */ + public void visit(FormalParameterList n); + + /** + * f0 -> Type() + * f1 -> Identifier() + */ + public void visit(FormalParameter n); + + /** + * f0 -> "," + * f1 -> FormalParameter() + */ + public void visit(FormalParameterRest n); + + /** + * f0 -> ArrayType() + * | BooleanType() + * | IntegerType() + * | Identifier() + */ + public void visit(Type n); + + /** + * f0 -> "int" + * f1 -> "[" + * f2 -> "]" + */ + public void visit(ArrayType n); + + /** + * f0 -> "boolean" + */ + public void visit(BooleanType n); + + /** + * f0 -> "int" + */ + public void visit(IntegerType n); + + /** + * f0 -> Block() + * | AssignmentStatement() + * | ArrayAssignmentStatement() + * | IfStatement() + * | WhileStatement() + * | PrintStatement() + */ + public void visit(Statement n); + + /** + * f0 -> "{" + * f1 -> ( Statement() )* + * f2 -> "}" + */ + public void visit(Block n); + + /** + * f0 -> Identifier() + * f1 -> "=" + * f2 -> Expression() + * f3 -> ";" + */ + public void visit(AssignmentStatement n); + + /** + * f0 -> Identifier() + * f1 -> "[" + * f2 -> Expression() + * f3 -> "]" + * f4 -> "=" + * f5 -> Expression() + * f6 -> ";" + */ + public void visit(ArrayAssignmentStatement n); + + /** + * f0 -> "if" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + * f5 -> "else" + * f6 -> Statement() + */ + public void visit(IfStatement n); + + /** + * f0 -> "while" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> Statement() + */ + public void visit(WhileStatement n); + + /** + * f0 -> "System.out.println" + * f1 -> "(" + * f2 -> Expression() + * f3 -> ")" + * f4 -> ";" + */ + public void visit(PrintStatement n); + + /** + * f0 -> AndExpression() + * | CompareExpression() + * | PlusExpression() + * | MinusExpression() + * | TimesExpression() + * | ArrayLookup() + * | ArrayLength() + * | MessageSend() + * | PrimaryExpression() + */ + public void visit(Expression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "&&" + * f2 -> PrimaryExpression() + */ + public void visit(AndExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "<" + * f2 -> PrimaryExpression() + */ + public void visit(CompareExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "+" + * f2 -> PrimaryExpression() + */ + public void visit(PlusExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "-" + * f2 -> PrimaryExpression() + */ + public void visit(MinusExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "*" + * f2 -> PrimaryExpression() + */ + public void visit(TimesExpression n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "[" + * f2 -> PrimaryExpression() + * f3 -> "]" + */ + public void visit(ArrayLookup n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> "length" + */ + public void visit(ArrayLength n); + + /** + * f0 -> PrimaryExpression() + * f1 -> "." + * f2 -> Identifier() + * f3 -> "(" + * f4 -> ( ExpressionList() )? + * f5 -> ")" + */ + public void visit(MessageSend n); + + /** + * f0 -> Expression() + * f1 -> ( ExpressionRest() )* + */ + public void visit(ExpressionList n); + + /** + * f0 -> "," + * f1 -> Expression() + */ + public void visit(ExpressionRest n); + + /** + * f0 -> IntegerLiteral() + * | TrueLiteral() + * | FalseLiteral() + * | Identifier() + * | ThisExpression() + * | ArrayAllocationExpression() + * | AllocationExpression() + * | NotExpression() + * | BracketExpression() + */ + public void visit(PrimaryExpression n); + + /** + * f0 -> <INTEGER_LITERAL> + */ + public void visit(IntegerLiteral n); + + /** + * f0 -> "true" + */ + public void visit(TrueLiteral n); + + /** + * f0 -> "false" + */ + public void visit(FalseLiteral n); + + /** + * f0 -> <IDENTIFIER> + */ + public void visit(Identifier n); + + /** + * f0 -> "this" + */ + public void visit(ThisExpression n); + + /** + * f0 -> "new" + * f1 -> "int" + * f2 -> "[" + * f3 -> Expression() + * f4 -> "]" + */ + public void visit(ArrayAllocationExpression n); + + /** + * f0 -> "new" + * f1 -> Identifier() + * f2 -> "(" + * f3 -> ")" + */ + public void visit(AllocationExpression n); + + /** + * f0 -> "!" + * f1 -> Expression() + */ + public void visit(NotExpression n); + + /** + * f0 -> "(" + * f1 -> Expression() + * f2 -> ")" + */ + public void visit(BracketExpression n); + +} + |