diff options
Diffstat (limited to 'Homework/cs5300/p4-formatter')
55 files changed, 5948 insertions, 0 deletions
diff --git a/Homework/cs5300/p4-formatter/antlr-4.9.1-complete.jar b/Homework/cs5300/p4-formatter/antlr-4.9.1-complete.jar Binary files differnew file mode 100644 index 0000000..1bb7e8c --- /dev/null +++ b/Homework/cs5300/p4-formatter/antlr-4.9.1-complete.jar diff --git a/Homework/cs5300/p4-formatter/data/test0.c b/Homework/cs5300/p4-formatter/data/test0.c new file mode 100644 index 0000000..1198b0e --- /dev/null +++ b/Homework/cs5300/p4-formatter/data/test0.c @@ -0,0 +1,29 @@ +int + + + a + , b; +int c[ 3 + +]; + +int fie () { + +print(a); + } + +int foo(int a) { + print(a); +} + +int add(int a[], int b) { + int c, z; + c -= 3; + if (c || b<3 || !!!(false) || b >12 +z < 14+3-2*1) { + c -= 3 + 8; + b--; + {} + z = (a[0] + c[2] - (b+a*3)); + } +} + diff --git a/Homework/cs5300/p4-formatter/data/test0.out b/Homework/cs5300/p4-formatter/data/test0.out new file mode 100644 index 0000000..12b25f6 --- /dev/null +++ b/Homework/cs5300/p4-formatter/data/test0.out @@ -0,0 +1,40 @@ +Parsing data/test0.c + + + +Building abstract syntax tree + +Undefined symbol on line 12: print +Undefined symbol on line 16: print + +Formatted code: + +int a, b; +int c[3]; + +int fie() +{ + print(a); +} + +int foo(int a) +{ + print(a); +} + +int add(int a[], int b) +{ + int c, z; + c -= 3; + if (c || b < 3 || !!!(false) || b > 12 + z < 14 + 3 - 2 * 1) + { + c -= 3 + 8; + b--; + { + } + z = (a[0] + c[2] - (b + a * 3)); + } +} + + +Process finished with exit code 0 diff --git a/Homework/cs5300/p4-formatter/data/test1.c b/Homework/cs5300/p4-formatter/data/test1.c new file mode 100644 index 0000000..bad6240 --- /dev/null +++ b/Homework/cs5300/p4-formatter/data/test1.c @@ -0,0 +1,65 @@ +int a, b; +int c[3]; + +int add(int a[], int b) { + int c, z; + c -= 3; + if (c || b<3) { + c -= 3; + } else + c *= 3; + while (b > 0) { + int d; + b = a; + } + b = a; + z = a; + return b; +} + +void nothing(char c) { + // do nothing + add(1, 3); +} + +int ant(int bat, int cat[], bool dog, bool elk, int fox) +{ + int gnu, hog[100]; + gnu = hog[2] = 3**cat; + if (dog && elk || bat > cat[3]) dog = !dog; + else fox++; + if (bat <= fox) { + while (dog) { + int hog; // hog in new scope + hog = fox; + // undefined symbol error + dog = fred(fox++, cat)>666; + if (hog>bat) break; + else if (fox!=0) fox += 7; + } + } + return (fox+bat*cat[bat])/-fox; +} + +int main() { + int a; + a = 0; + while (a + < 3 +) a++; + + + b = 3; + c *= (18 / (3-1)-3) ; + c ++; + // Should give an undefined symbol error + z++; + break ; + + // Should give an underfined symbol error + fie(); + return + + 0; + +} diff --git a/Homework/cs5300/p4-formatter/data/test1.out b/Homework/cs5300/p4-formatter/data/test1.out new file mode 100644 index 0000000..1daaaea --- /dev/null +++ b/Homework/cs5300/p4-formatter/data/test1.out @@ -0,0 +1,82 @@ + +Parsing data/test1.c + + + +Building abstract syntax tree + +Undefined symbol on line 36: fred +Undefined symbol on line 56: z +Undefined symbol on line 60: fie + +Formatted code: + +int a, b; +int c[3]; + +int add(int a[], int b) +{ + int c, z; + c -= 3; + if (c || b < 3) + { + c -= 3; + } + else + c *= 3; + while (b > 0) + { + int d; + b = a; + } + b = a; + z = a; + return b; +} + +void nothing(char c) +{ + add(1, 3); +} + +int ant(int bat, int cat[], bool dog, bool elk, int fox) +{ + int gnu, hog[100]; + gnu = hog[2] = 3 * *cat; + if (dog && elk || bat > cat[3]) + dog = !dog; + else + fox++; + if (bat <= fox) + { + while (dog) + { + int hog; + hog = fox; + dog = fred(fox++, cat) > 666; + if (hog > bat) + break; + else + if (fox != 0) + fox += 7; + } + } + return (fox + bat * cat[bat]) / -fox; +} + +int main() +{ + int a; + a = 0; + while (a < 3) + a++; + b = 3; + c *= (18 / (3 - 1) - 3); + c++; + z++; + break; + fie(); + return 0; +} + + diff --git a/Homework/cs5300/p4-formatter/grammar/Cminus.g4 b/Homework/cs5300/p4-formatter/grammar/Cminus.g4 new file mode 100644 index 0000000..9538eea --- /dev/null +++ b/Homework/cs5300/p4-formatter/grammar/Cminus.g4 @@ -0,0 +1,91 @@ +grammar Cminus; + +program : declaration+ ; + +declaration : varDeclaration | funDeclaration ; + +varDeclaration : typeSpecifier varDeclId (',' varDeclId)* ';' ; + +varDeclId : ID | ID '[' NUMCONST ']' ; + +funDeclaration : ('void' | typeSpecifier) ID '(' param? (',' param)* ')' statement ; +//funDeclaration : ('void' | typeSpecifier) ID '(' param? (',' param)* ')' compoundStatement ; + +typeSpecifier : 'int' | 'bool' | 'char' ; + +param : typeSpecifier paramId ; + +paramId : ID | ID '[]' ; + +statement : expressionStmt | compoundStmt | ifStmt + | whileStmt | returnStmt | breakStmt ; + +compoundStmt : '{' varDeclaration* statement* '}' ; + +expressionStmt : expression ';' | ';' ; + +ifStmt : 'if' '(' simpleExpression ')' statement + | 'if' '(' simpleExpression ')' statement 'else' statement + ; + +whileStmt : 'while' '(' simpleExpression ')' statement ; + +returnStmt : 'return' ';' | 'return' expression ';' ; + +breakStmt : 'break' ';' ; + +expression : mutable '=' expression + | mutable '+=' expression | mutable '-=' expression + | mutable '*=' expression | mutable '/=' expression + | mutable '++' | mutable '--' | simpleExpression + ; + +simpleExpression : orExpression ; + +orExpression : (andExpression '||')* andExpression ; + +andExpression : (unaryRelExpression '&&')* unaryRelExpression ; + +unaryRelExpression : BANG* relExpression ; + +relExpression : (sumExpression relop)* sumExpression ; + +relop : '<=' | '<' | '>' | '>=' | '==' | '!=' ; + +sumExpression : (termExpression sumop)* termExpression ; + +sumop : '+' | '-' ; + +termExpression : (unaryExpression mulop)* unaryExpression ; + +mulop : '*' | '/' | '%' ; + +unaryExpression : unaryop* factor ; + +unaryop : '-' | '*' | '?' ; + +factor : immutable | mutable ; + +mutable : ID | ID '[' expression ']' ; + +immutable : '(' expression ')' | call | constant ; + +call : ID '(' (expression ',')* expression? ')' ; + +constant : NUMCONST | CHARCONST | STRINGCONST | 'true' | 'false' ; + +ID : LETTER (LETTER | DIGIT)* ; +NUMCONST : DIGIT+ ; +STRINGCONST : '"' ('\\"'|~'"')*? '"' ; +CHARCONST : '"' ('\\"'|~'"') '"' ; +BANG : '!' ; + +WS : (' ' | '\t' | '\n' | '\r' | '\f')+ -> skip ; +COMMENT + : ( '//' ~[\r\n]* '\r'? '\n' + | '/*' .*? '*/' + ) -> skip + ; + +fragment LETTER : ('a'..'z' | 'A'..'Z'); +fragment DIGIT : ('0'..'9'); diff --git a/Homework/cs5300/p4-formatter/main/Main.java b/Homework/cs5300/p4-formatter/main/Main.java new file mode 100644 index 0000000..7eb7d72 --- /dev/null +++ b/Homework/cs5300/p4-formatter/main/Main.java @@ -0,0 +1,76 @@ +package main; + +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import parser.CminusLexer; +import parser.CminusParser; +import submit.ASTVisitor; +import org.antlr.v4.runtime.Parser; +import submit.ast.Node; + +import java.io.IOException; +import java.util.Properties; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Main { + private static Logger LOGGER; + + /** + * @param args the command line arguments + * @throws java.io.IOException + */ + public static void main(String[] args) throws IOException { + // Logging setup + Level level = Level.INFO; + + // TODO Enable trace-level code as needed. When true, LOGGER.fine() statements + // will be visible. + final boolean trace = true; + if (trace) { + level = Level.ALL; + } + + Properties props = System.getProperties(); + props.setProperty("java.util.logging.SimpleFormatter.format", "%5$s%6$s%n"); + Logger.getLogger("").setLevel(level); + for (Handler handler : Logger.getLogger("").getHandlers()) { + handler.setLevel(level); + } + LOGGER = Logger.getLogger(Parser.class.getName()); + + // TODO Update the filename as needed + final String filename = "data/test1.c"; + + LOGGER.info(""); + LOGGER.info("Parsing " + filename + "\n"); + LOGGER.info(""); + final CharStream charStream = CharStreams.fromFileName(filename); + CminusLexer lexer = new CminusLexer(charStream); + CommonTokenStream tokens = new CommonTokenStream(lexer); + CminusParser parser = new CminusParser(tokens); + parser.setBuildParseTree(true); + CminusParser.ProgramContext programCtx = parser.program(); + + // TODO Implement building of the parse tree + LOGGER.info(""); + LOGGER.info("Building abstract syntax tree"); + LOGGER.info(""); + ASTVisitor v = new ASTVisitor(LOGGER); + Node ast = v.visitProgram(programCtx); + + // TODO Output formatted code + LOGGER.info(""); + LOGGER.info("Formatted code:"); + LOGGER.info(""); + StringBuilder builder = new StringBuilder(); + try { + ast.toCminus(builder, ""); + } finally { + LOGGER.info(builder.toString()); + } + } + +} diff --git a/Homework/cs5300/p4-formatter/parser/Cminus.interp b/Homework/cs5300/p4-formatter/parser/Cminus.interp new file mode 100644 index 0000000..af140be --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/Cminus.interp @@ -0,0 +1,140 @@ +token literal names: +null +',' +';' +'[' +']' +'void' +'(' +')' +'int' +'bool' +'char' +'[]' +'{' +'}' +'if' +'else' +'while' +'return' +'break' +'=' +'+=' +'-=' +'*=' +'/=' +'++' +'--' +'||' +'&&' +'<=' +'<' +'>' +'>=' +'==' +'!=' +'+' +'-' +'*' +'/' +'%' +'?' +'true' +'false' +null +null +null +null +'!' +null +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +ID +NUMCONST +STRINGCONST +CHARCONST +BANG +WS +COMMENT + +rule names: +program +declaration +varDeclaration +varDeclId +funDeclaration +typeSpecifier +param +paramId +statement +compoundStmt +expressionStmt +ifStmt +whileStmt +returnStmt +breakStmt +expression +simpleExpression +orExpression +andExpression +unaryRelExpression +relExpression +relop +sumExpression +sumop +termExpression +mulop +unaryExpression +unaryop +factor +mutable +immutable +call +constant + + +atn: +[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 50, 329, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 4, 34, 9, 34, 3, 2, 6, 2, 70, 10, 2, 13, 2, 14, 2, 71, 3, 3, 3, 3, 5, 3, 76, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 7, 4, 82, 10, 4, 12, 4, 14, 4, 85, 11, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 94, 10, 5, 3, 6, 3, 6, 5, 6, 98, 10, 6, 3, 6, 3, 6, 3, 6, 5, 6, 103, 10, 6, 3, 6, 3, 6, 7, 6, 107, 10, 6, 12, 6, 14, 6, 110, 11, 6, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 5, 9, 123, 10, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 5, 10, 131, 10, 10, 3, 11, 3, 11, 7, 11, 135, 10, 11, 12, 11, 14, 11, 138, 11, 11, 3, 11, 7, 11, 141, 10, 11, 12, 11, 14, 11, 144, 11, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 152, 10, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 5, 13, 168, 10, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 5, 15, 182, 10, 15, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 5, 17, 214, 10, 17, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 7, 19, 221, 10, 19, 12, 19, 14, 19, 224, 11, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 7, 20, 231, 10, 20, 12, 20, 14, 20, 234, 11, 20, 3, 20, 3, 20, 3, 21, 7, 21, 239, 10, 21, 12, 21, 14, 21, 242, 11, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 7, 22, 249, 10, 22, 12, 22, 14, 22, 252, 11, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 7, 24, 261, 10, 24, 12, 24, 14, 24, 264, 11, 24, 3, 24, 3, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 7, 26, 273, 10, 26, 12, 26, 14, 26, 276, 11, 26, 3, 26, 3, 26, 3, 27, 3, 27, 3, 28, 7, 28, 283, 10, 28, 12, 28, 14, 28, 286, 11, 28, 3, 28, 3, 28, 3, 29, 3, 29, 3, 30, 3, 30, 5, 30, 294, 10, 30, 3, 31, 3, 31, 3, 31, 3, 31, 3, 31, 3, 31, 5, 31, 302, 10, 31, 3, 32, 3, 32, 3, 32, 3, 32, 3, 32, 3, 32, 5, 32, 310, 10, 32, 3, 33, 3, 33, 3, 33, 3, 33, 3, 33, 7, 33, 317, 10, 33, 12, 33, 14, 33, 320, 11, 33, 3, 33, 5, 33, 323, 10, 33, 3, 33, 3, 33, 3, 34, 3, 34, 3, 34, 2, 2, 35, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 2, 8, 3, 2, 10, 12, 3, 2, 30, 35, 3, 2, 36, 37, 3, 2, 38, 40, 4, 2, 37, 38, 41, 41, 4, 2, 42, 43, 45, 47, 2, 333, 2, 69, 3, 2, 2, 2, 4, 75, 3, 2, 2, 2, 6, 77, 3, 2, 2, 2, 8, 93, 3, 2, 2, 2, 10, 97, 3, 2, 2, 2, 12, 114, 3, 2, 2, 2, 14, 116, 3, 2, 2, 2, 16, 122, 3, 2, 2, 2, 18, 130, 3, 2, 2, 2, 20, 132, 3, 2, 2, 2, 22, 151, 3, 2, 2, 2, 24, 167, 3, 2, 2, 2, 26, 169, 3, 2, 2, 2, 28, 181, 3, 2, 2, 2, 30, 183, 3, 2, 2, 2, 32, 213, 3, 2, 2, 2, 34, 215, 3, 2, 2, 2, 36, 222, 3, 2, 2, 2, 38, 232, 3, 2, 2, 2, 40, 240, 3, 2, 2, 2, 42, 250, 3, 2, 2, 2, 44, 255, 3, 2, 2, 2, 46, 262, 3, 2, 2, 2, 48, 267, 3, 2, 2, 2, 50, 274, 3, 2, 2, 2, 52, 279, 3, 2, 2, 2, 54, 284, 3, 2, 2, 2, 56, 289, 3, 2, 2, 2, 58, 293, 3, 2, 2, 2, 60, 301, 3, 2, 2, 2, 62, 309, 3, 2, 2, 2, 64, 311, 3, 2, 2, 2, 66, 326, 3, 2, 2, 2, 68, 70, 5, 4, 3, 2, 69, 68, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 69, 3, 2, 2, 2, 71, 72, 3, 2, 2, 2, 72, 3, 3, 2, 2, 2, 73, 76, 5, 6, 4, 2, 74, 76, 5, 10, 6, 2, 75, 73, 3, 2, 2, 2, 75, 74, 3, 2, 2, 2, 76, 5, 3, 2, 2, 2, 77, 78, 5, 12, 7, 2, 78, 83, 5, 8, 5, 2, 79, 80, 7, 3, 2, 2, 80, 82, 5, 8, 5, 2, 81, 79, 3, 2, 2, 2, 82, 85, 3, 2, 2, 2, 83, 81, 3, 2, 2, 2, 83, 84, 3, 2, 2, 2, 84, 86, 3, 2, 2, 2, 85, 83, 3, 2, 2, 2, 86, 87, 7, 4, 2, 2, 87, 7, 3, 2, 2, 2, 88, 94, 7, 44, 2, 2, 89, 90, 7, 44, 2, 2, 90, 91, 7, 5, 2, 2, 91, 92, 7, 45, 2, 2, 92, 94, 7, 6, 2, 2, 93, 88, 3, 2, 2, 2, 93, 89, 3, 2, 2, 2, 94, 9, 3, 2, 2, 2, 95, 98, 7, 7, 2, 2, 96, 98, 5, 12, 7, 2, 97, 95, 3, 2, 2, 2, 97, 96, 3, 2, 2, 2, 98, 99, 3, 2, 2, 2, 99, 100, 7, 44, 2, 2, 100, 102, 7, 8, 2, 2, 101, 103, 5, 14, 8, 2, 102, 101, 3, 2, 2, 2, 102, 103, 3, 2, 2, 2, 103, 108, 3, 2, 2, 2, 104, 105, 7, 3, 2, 2, 105, 107, 5, 14, 8, 2, 106, 104, 3, 2, 2, 2, 107, 110, 3, 2, 2, 2, 108, 106, 3, 2, 2, 2, 108, 109, 3, 2, 2, 2, 109, 111, 3, 2, 2, 2, 110, 108, 3, 2, 2, 2, 111, 112, 7, 9, 2, 2, 112, 113, 5, 18, 10, 2, 113, 11, 3, 2, 2, 2, 114, 115, 9, 2, 2, 2, 115, 13, 3, 2, 2, 2, 116, 117, 5, 12, 7, 2, 117, 118, 5, 16, 9, 2, 118, 15, 3, 2, 2, 2, 119, 123, 7, 44, 2, 2, 120, 121, 7, 44, 2, 2, 121, 123, 7, 13, 2, 2, 122, 119, 3, 2, 2, 2, 122, 120, 3, 2, 2, 2, 123, 17, 3, 2, 2, 2, 124, 131, 5, 22, 12, 2, 125, 131, 5, 20, 11, 2, 126, 131, 5, 24, 13, 2, 127, 131, 5, 26, 14, 2, 128, 131, 5, 28, 15, 2, 129, 131, 5, 30, 16, 2, 130, 124, 3, 2, 2, 2, 130, 125, 3, 2, 2, 2, 130, 126, 3, 2, 2, 2, 130, 127, 3, 2, 2, 2, 130, 128, 3, 2, 2, 2, 130, 129, 3, 2, 2, 2, 131, 19, 3, 2, 2, 2, 132, 136, 7, 14, 2, 2, 133, 135, 5, 6, 4, 2, 134, 133, 3, 2, 2, 2, 135, 138, 3, 2, 2, 2, 136, 134, 3, 2, 2, 2, 136, 137, 3, 2, 2, 2, 137, 142, 3, 2, 2, 2, 138, 136, 3, 2, 2, 2, 139, 141, 5, 18, 10, 2, 140, 139, 3, 2, 2, 2, 141, 144, 3, 2, 2, 2, 142, 140, 3, 2, 2, 2, 142, 143, 3, 2, 2, 2, 143, 145, 3, 2, 2, 2, 144, 142, 3, 2, 2, 2, 145, 146, 7, 15, 2, 2, 146, 21, 3, 2, 2, 2, 147, 148, 5, 32, 17, 2, 148, 149, 7, 4, 2, 2, 149, 152, 3, 2, 2, 2, 150, 152, 7, 4, 2, 2, 151, 147, 3, 2, 2, 2, 151, 150, 3, 2, 2, 2, 152, 23, 3, 2, 2, 2, 153, 154, 7, 16, 2, 2, 154, 155, 7, 8, 2, 2, 155, 156, 5, 34, 18, 2, 156, 157, 7, 9, 2, 2, 157, 158, 5, 18, 10, 2, 158, 168, 3, 2, 2, 2, 159, 160, 7, 16, 2, 2, 160, 161, 7, 8, 2, 2, 161, 162, 5, 34, 18, 2, 162, 163, 7, 9, 2, 2, 163, 164, 5, 18, 10, 2, 164, 165, 7, 17, 2, 2, 165, 166, 5, 18, 10, 2, 166, 168, 3, 2, 2, 2, 167, 153, 3, 2, 2, 2, 167, 159, 3, 2, 2, 2, 168, 25, 3, 2, 2, 2, 169, 170, 7, 18, 2, 2, 170, 171, 7, 8, 2, 2, 171, 172, 5, 34, 18, 2, 172, 173, 7, 9, 2, 2, 173, 174, 5, 18, 10, 2, 174, 27, 3, 2, 2, 2, 175, 176, 7, 19, 2, 2, 176, 182, 7, 4, 2, 2, 177, 178, 7, 19, 2, 2, 178, 179, 5, 32, 17, 2, 179, 180, 7, 4, 2, 2, 180, 182, 3, 2, 2, 2, 181, 175, 3, 2, 2, 2, 181, 177, 3, 2, 2, 2, 182, 29, 3, 2, 2, 2, 183, 184, 7, 20, 2, 2, 184, 185, 7, 4, 2, 2, 185, 31, 3, 2, 2, 2, 186, 187, 5, 60, 31, 2, 187, 188, 7, 21, 2, 2, 188, 189, 5, 32, 17, 2, 189, 214, 3, 2, 2, 2, 190, 191, 5, 60, 31, 2, 191, 192, 7, 22, 2, 2, 192, 193, 5, 32, 17, 2, 193, 214, 3, 2, 2, 2, 194, 195, 5, 60, 31, 2, 195, 196, 7, 23, 2, 2, 196, 197, 5, 32, 17, 2, 197, 214, 3, 2, 2, 2, 198, 199, 5, 60, 31, 2, 199, 200, 7, 24, 2, 2, 200, 201, 5, 32, 17, 2, 201, 214, 3, 2, 2, 2, 202, 203, 5, 60, 31, 2, 203, 204, 7, 25, 2, 2, 204, 205, 5, 32, 17, 2, 205, 214, 3, 2, 2, 2, 206, 207, 5, 60, 31, 2, 207, 208, 7, 26, 2, 2, 208, 214, 3, 2, 2, 2, 209, 210, 5, 60, 31, 2, 210, 211, 7, 27, 2, 2, 211, 214, 3, 2, 2, 2, 212, 214, 5, 34, 18, 2, 213, 186, 3, 2, 2, 2, 213, 190, 3, 2, 2, 2, 213, 194, 3, 2, 2, 2, 213, 198, 3, 2, 2, 2, 213, 202, 3, 2, 2, 2, 213, 206, 3, 2, 2, 2, 213, 209, 3, 2, 2, 2, 213, 212, 3, 2, 2, 2, 214, 33, 3, 2, 2, 2, 215, 216, 5, 36, 19, 2, 216, 35, 3, 2, 2, 2, 217, 218, 5, 38, 20, 2, 218, 219, 7, 28, 2, 2, 219, 221, 3, 2, 2, 2, 220, 217, 3, 2, 2, 2, 221, 224, 3, 2, 2, 2, 222, 220, 3, 2, 2, 2, 222, 223, 3, 2, 2, 2, 223, 225, 3, 2, 2, 2, 224, 222, 3, 2, 2, 2, 225, 226, 5, 38, 20, 2, 226, 37, 3, 2, 2, 2, 227, 228, 5, 40, 21, 2, 228, 229, 7, 29, 2, 2, 229, 231, 3, 2, 2, 2, 230, 227, 3, 2, 2, 2, 231, 234, 3, 2, 2, 2, 232, 230, 3, 2, 2, 2, 232, 233, 3, 2, 2, 2, 233, 235, 3, 2, 2, 2, 234, 232, 3, 2, 2, 2, 235, 236, 5, 40, 21, 2, 236, 39, 3, 2, 2, 2, 237, 239, 7, 48, 2, 2, 238, 237, 3, 2, 2, 2, 239, 242, 3, 2, 2, 2, 240, 238, 3, 2, 2, 2, 240, 241, 3, 2, 2, 2, 241, 243, 3, 2, 2, 2, 242, 240, 3, 2, 2, 2, 243, 244, 5, 42, 22, 2, 244, 41, 3, 2, 2, 2, 245, 246, 5, 46, 24, 2, 246, 247, 5, 44, 23, 2, 247, 249, 3, 2, 2, 2, 248, 245, 3, 2, 2, 2, 249, 252, 3, 2, 2, 2, 250, 248, 3, 2, 2, 2, 250, 251, 3, 2, 2, 2, 251, 253, 3, 2, 2, 2, 252, 250, 3, 2, 2, 2, 253, 254, 5, 46, 24, 2, 254, 43, 3, 2, 2, 2, 255, 256, 9, 3, 2, 2, 256, 45, 3, 2, 2, 2, 257, 258, 5, 50, 26, 2, 258, 259, 5, 48, 25, 2, 259, 261, 3, 2, 2, 2, 260, 257, 3, 2, 2, 2, 261, 264, 3, 2, 2, 2, 262, 260, 3, 2, 2, 2, 262, 263, 3, 2, 2, 2, 263, 265, 3, 2, 2, 2, 264, 262, 3, 2, 2, 2, 265, 266, 5, 50, 26, 2, 266, 47, 3, 2, 2, 2, 267, 268, 9, 4, 2, 2, 268, 49, 3, 2, 2, 2, 269, 270, 5, 54, 28, 2, 270, 271, 5, 52, 27, 2, 271, 273, 3, 2, 2, 2, 272, 269, 3, 2, 2, 2, 273, 276, 3, 2, 2, 2, 274, 272, 3, 2, 2, 2, 274, 275, 3, 2, 2, 2, 275, 277, 3, 2, 2, 2, 276, 274, 3, 2, 2, 2, 277, 278, 5, 54, 28, 2, 278, 51, 3, 2, 2, 2, 279, 280, 9, 5, 2, 2, 280, 53, 3, 2, 2, 2, 281, 283, 5, 56, 29, 2, 282, 281, 3, 2, 2, 2, 283, 286, 3, 2, 2, 2, 284, 282, 3, 2, 2, 2, 284, 285, 3, 2, 2, 2, 285, 287, 3, 2, 2, 2, 286, 284, 3, 2, 2, 2, 287, 288, 5, 58, 30, 2, 288, 55, 3, 2, 2, 2, 289, 290, 9, 6, 2, 2, 290, 57, 3, 2, 2, 2, 291, 294, 5, 62, 32, 2, 292, 294, 5, 60, 31, 2, 293, 291, 3, 2, 2, 2, 293, 292, 3, 2, 2, 2, 294, 59, 3, 2, 2, 2, 295, 302, 7, 44, 2, 2, 296, 297, 7, 44, 2, 2, 297, 298, 7, 5, 2, 2, 298, 299, 5, 32, 17, 2, 299, 300, 7, 6, 2, 2, 300, 302, 3, 2, 2, 2, 301, 295, 3, 2, 2, 2, 301, 296, 3, 2, 2, 2, 302, 61, 3, 2, 2, 2, 303, 304, 7, 8, 2, 2, 304, 305, 5, 32, 17, 2, 305, 306, 7, 9, 2, 2, 306, 310, 3, 2, 2, 2, 307, 310, 5, 64, 33, 2, 308, 310, 5, 66, 34, 2, 309, 303, 3, 2, 2, 2, 309, 307, 3, 2, 2, 2, 309, 308, 3, 2, 2, 2, 310, 63, 3, 2, 2, 2, 311, 312, 7, 44, 2, 2, 312, 318, 7, 8, 2, 2, 313, 314, 5, 32, 17, 2, 314, 315, 7, 3, 2, 2, 315, 317, 3, 2, 2, 2, 316, 313, 3, 2, 2, 2, 317, 320, 3, 2, 2, 2, 318, 316, 3, 2, 2, 2, 318, 319, 3, 2, 2, 2, 319, 322, 3, 2, 2, 2, 320, 318, 3, 2, 2, 2, 321, 323, 5, 32, 17, 2, 322, 321, 3, 2, 2, 2, 322, 323, 3, 2, 2, 2, 323, 324, 3, 2, 2, 2, 324, 325, 7, 9, 2, 2, 325, 65, 3, 2, 2, 2, 326, 327, 9, 7, 2, 2, 327, 67, 3, 2, 2, 2, 29, 71, 75, 83, 93, 97, 102, 108, 122, 130, 136, 142, 151, 167, 181, 213, 222, 232, 240, 250, 262, 274, 284, 293, 301, 309, 318, 322]
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/Cminus.tokens b/Homework/cs5300/p4-formatter/parser/Cminus.tokens new file mode 100644 index 0000000..ae5a5c0 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/Cminus.tokens @@ -0,0 +1,90 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +T__12=13 +T__13=14 +T__14=15 +T__15=16 +T__16=17 +T__17=18 +T__18=19 +T__19=20 +T__20=21 +T__21=22 +T__22=23 +T__23=24 +T__24=25 +T__25=26 +T__26=27 +T__27=28 +T__28=29 +T__29=30 +T__30=31 +T__31=32 +T__32=33 +T__33=34 +T__34=35 +T__35=36 +T__36=37 +T__37=38 +T__38=39 +T__39=40 +T__40=41 +ID=42 +NUMCONST=43 +STRINGCONST=44 +CHARCONST=45 +BANG=46 +WS=47 +COMMENT=48 +','=1 +';'=2 +'['=3 +']'=4 +'void'=5 +'('=6 +')'=7 +'int'=8 +'bool'=9 +'char'=10 +'[]'=11 +'{'=12 +'}'=13 +'if'=14 +'else'=15 +'while'=16 +'return'=17 +'break'=18 +'='=19 +'+='=20 +'-='=21 +'*='=22 +'/='=23 +'++'=24 +'--'=25 +'||'=26 +'&&'=27 +'<='=28 +'<'=29 +'>'=30 +'>='=31 +'=='=32 +'!='=33 +'+'=34 +'-'=35 +'*'=36 +'/'=37 +'%'=38 +'?'=39 +'true'=40 +'false'=41 +'!'=46 diff --git a/Homework/cs5300/p4-formatter/parser/CminusBaseListener.java b/Homework/cs5300/p4-formatter/parser/CminusBaseListener.java new file mode 100644 index 0000000..65a3493 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusBaseListener.java @@ -0,0 +1,435 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.TerminalNode; + +/** + * This class provides an empty implementation of {@link CminusListener}, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +public class CminusBaseListener implements CminusListener { + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterProgram(CminusParser.ProgramContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitProgram(CminusParser.ProgramContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterDeclaration(CminusParser.DeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitDeclaration(CminusParser.DeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterVarDeclaration(CminusParser.VarDeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitVarDeclaration(CminusParser.VarDeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterVarDeclId(CminusParser.VarDeclIdContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitVarDeclId(CminusParser.VarDeclIdContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterFunDeclaration(CminusParser.FunDeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitFunDeclaration(CminusParser.FunDeclarationContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterTypeSpecifier(CminusParser.TypeSpecifierContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitTypeSpecifier(CminusParser.TypeSpecifierContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterParam(CminusParser.ParamContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitParam(CminusParser.ParamContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterParamId(CminusParser.ParamIdContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitParamId(CminusParser.ParamIdContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterStatement(CminusParser.StatementContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitStatement(CminusParser.StatementContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterCompoundStmt(CminusParser.CompoundStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitCompoundStmt(CminusParser.CompoundStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterExpressionStmt(CminusParser.ExpressionStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitExpressionStmt(CminusParser.ExpressionStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterIfStmt(CminusParser.IfStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitIfStmt(CminusParser.IfStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterWhileStmt(CminusParser.WhileStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitWhileStmt(CminusParser.WhileStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterReturnStmt(CminusParser.ReturnStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitReturnStmt(CminusParser.ReturnStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterBreakStmt(CminusParser.BreakStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitBreakStmt(CminusParser.BreakStmtContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterExpression(CminusParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitExpression(CminusParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterSimpleExpression(CminusParser.SimpleExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitSimpleExpression(CminusParser.SimpleExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterOrExpression(CminusParser.OrExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitOrExpression(CminusParser.OrExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterAndExpression(CminusParser.AndExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitAndExpression(CminusParser.AndExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterRelExpression(CminusParser.RelExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitRelExpression(CminusParser.RelExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterRelop(CminusParser.RelopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitRelop(CminusParser.RelopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterSumExpression(CminusParser.SumExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitSumExpression(CminusParser.SumExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterSumop(CminusParser.SumopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitSumop(CminusParser.SumopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterTermExpression(CminusParser.TermExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitTermExpression(CminusParser.TermExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterMulop(CminusParser.MulopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitMulop(CminusParser.MulopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterUnaryExpression(CminusParser.UnaryExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitUnaryExpression(CminusParser.UnaryExpressionContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterUnaryop(CminusParser.UnaryopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitUnaryop(CminusParser.UnaryopContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterFactor(CminusParser.FactorContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitFactor(CminusParser.FactorContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterMutable(CminusParser.MutableContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitMutable(CminusParser.MutableContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterImmutable(CminusParser.ImmutableContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitImmutable(CminusParser.ImmutableContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterCall(CminusParser.CallContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitCall(CminusParser.CallContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterConstant(CminusParser.ConstantContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitConstant(CminusParser.ConstantContext ctx) { } + + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void enterEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void exitEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void visitTerminal(TerminalNode node) { } + /** + * {@inheritDoc} + * + * <p>The default implementation does nothing.</p> + */ + @Override public void visitErrorNode(ErrorNode node) { } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusBaseVisitor.java b/Homework/cs5300/p4-formatter/parser/CminusBaseVisitor.java new file mode 100644 index 0000000..150f316 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusBaseVisitor.java @@ -0,0 +1,245 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * This class provides an empty implementation of {@link CminusVisitor}, + * which can be extended to create a visitor which only needs to handle a subset + * of the available methods. + * + * @param <T> The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public class CminusBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements CminusVisitor<T> { + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitProgram(CminusParser.ProgramContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitDeclaration(CminusParser.DeclarationContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitVarDeclaration(CminusParser.VarDeclarationContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitVarDeclId(CminusParser.VarDeclIdContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitFunDeclaration(CminusParser.FunDeclarationContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitTypeSpecifier(CminusParser.TypeSpecifierContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitParam(CminusParser.ParamContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitParamId(CminusParser.ParamIdContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitStatement(CminusParser.StatementContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitCompoundStmt(CminusParser.CompoundStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitExpressionStmt(CminusParser.ExpressionStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitIfStmt(CminusParser.IfStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitWhileStmt(CminusParser.WhileStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitReturnStmt(CminusParser.ReturnStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitBreakStmt(CminusParser.BreakStmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitExpression(CminusParser.ExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitSimpleExpression(CminusParser.SimpleExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitOrExpression(CminusParser.OrExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitAndExpression(CminusParser.AndExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitRelExpression(CminusParser.RelExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitRelop(CminusParser.RelopContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitSumExpression(CminusParser.SumExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitSumop(CminusParser.SumopContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitTermExpression(CminusParser.TermExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitMulop(CminusParser.MulopContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitUnaryExpression(CminusParser.UnaryExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitUnaryop(CminusParser.UnaryopContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitFactor(CminusParser.FactorContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitMutable(CminusParser.MutableContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitImmutable(CminusParser.ImmutableContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitCall(CminusParser.CallContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + * <p>The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.</p> + */ + @Override public T visitConstant(CminusParser.ConstantContext ctx) { return visitChildren(ctx); } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusLexer.interp b/Homework/cs5300/p4-formatter/parser/CminusLexer.interp new file mode 100644 index 0000000..a9dc30a --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusLexer.interp @@ -0,0 +1,163 @@ +token literal names: +null +',' +';' +'[' +']' +'void' +'(' +')' +'int' +'bool' +'char' +'[]' +'{' +'}' +'if' +'else' +'while' +'return' +'break' +'=' +'+=' +'-=' +'*=' +'/=' +'++' +'--' +'||' +'&&' +'<=' +'<' +'>' +'>=' +'==' +'!=' +'+' +'-' +'*' +'/' +'%' +'?' +'true' +'false' +null +null +null +null +'!' +null +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +ID +NUMCONST +STRINGCONST +CHARCONST +BANG +WS +COMMENT + +rule names: +T__0 +T__1 +T__2 +T__3 +T__4 +T__5 +T__6 +T__7 +T__8 +T__9 +T__10 +T__11 +T__12 +T__13 +T__14 +T__15 +T__16 +T__17 +T__18 +T__19 +T__20 +T__21 +T__22 +T__23 +T__24 +T__25 +T__26 +T__27 +T__28 +T__29 +T__30 +T__31 +T__32 +T__33 +T__34 +T__35 +T__36 +T__37 +T__38 +T__39 +T__40 +ID +NUMCONST +STRINGCONST +CHARCONST +BANG +WS +COMMENT +LETTER +DIGIT + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 50, 306, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 4, 34, 9, 34, 4, 35, 9, 35, 4, 36, 9, 36, 4, 37, 9, 37, 4, 38, 9, 38, 4, 39, 9, 39, 4, 40, 9, 40, 4, 41, 9, 41, 4, 42, 9, 42, 4, 43, 9, 43, 4, 44, 9, 44, 4, 45, 9, 45, 4, 46, 9, 46, 4, 47, 9, 47, 4, 48, 9, 48, 4, 49, 9, 49, 4, 50, 9, 50, 4, 51, 9, 51, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 3, 25, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 3, 27, 3, 27, 3, 27, 3, 28, 3, 28, 3, 28, 3, 29, 3, 29, 3, 29, 3, 30, 3, 30, 3, 31, 3, 31, 3, 32, 3, 32, 3, 32, 3, 33, 3, 33, 3, 33, 3, 34, 3, 34, 3, 34, 3, 35, 3, 35, 3, 36, 3, 36, 3, 37, 3, 37, 3, 38, 3, 38, 3, 39, 3, 39, 3, 40, 3, 40, 3, 41, 3, 41, 3, 41, 3, 41, 3, 41, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 42, 3, 43, 3, 43, 3, 43, 7, 43, 237, 10, 43, 12, 43, 14, 43, 240, 11, 43, 3, 44, 6, 44, 243, 10, 44, 13, 44, 14, 44, 244, 3, 45, 3, 45, 3, 45, 3, 45, 7, 45, 251, 10, 45, 12, 45, 14, 45, 254, 11, 45, 3, 45, 3, 45, 3, 46, 3, 46, 3, 46, 3, 46, 5, 46, 262, 10, 46, 3, 46, 3, 46, 3, 47, 3, 47, 3, 48, 6, 48, 269, 10, 48, 13, 48, 14, 48, 270, 3, 48, 3, 48, 3, 49, 3, 49, 3, 49, 3, 49, 7, 49, 279, 10, 49, 12, 49, 14, 49, 282, 11, 49, 3, 49, 5, 49, 285, 10, 49, 3, 49, 3, 49, 3, 49, 3, 49, 3, 49, 7, 49, 292, 10, 49, 12, 49, 14, 49, 295, 11, 49, 3, 49, 3, 49, 5, 49, 299, 10, 49, 3, 49, 3, 49, 3, 50, 3, 50, 3, 51, 3, 51, 4, 252, 293, 2, 52, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 24, 47, 25, 49, 26, 51, 27, 53, 28, 55, 29, 57, 30, 59, 31, 61, 32, 63, 33, 65, 34, 67, 35, 69, 36, 71, 37, 73, 38, 75, 39, 77, 40, 79, 41, 81, 42, 83, 43, 85, 44, 87, 45, 89, 46, 91, 47, 93, 48, 95, 49, 97, 50, 99, 2, 101, 2, 3, 2, 6, 3, 2, 36, 36, 5, 2, 11, 12, 14, 15, 34, 34, 4, 2, 12, 12, 15, 15, 4, 2, 67, 92, 99, 124, 2, 314, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 2, 57, 3, 2, 2, 2, 2, 59, 3, 2, 2, 2, 2, 61, 3, 2, 2, 2, 2, 63, 3, 2, 2, 2, 2, 65, 3, 2, 2, 2, 2, 67, 3, 2, 2, 2, 2, 69, 3, 2, 2, 2, 2, 71, 3, 2, 2, 2, 2, 73, 3, 2, 2, 2, 2, 75, 3, 2, 2, 2, 2, 77, 3, 2, 2, 2, 2, 79, 3, 2, 2, 2, 2, 81, 3, 2, 2, 2, 2, 83, 3, 2, 2, 2, 2, 85, 3, 2, 2, 2, 2, 87, 3, 2, 2, 2, 2, 89, 3, 2, 2, 2, 2, 91, 3, 2, 2, 2, 2, 93, 3, 2, 2, 2, 2, 95, 3, 2, 2, 2, 2, 97, 3, 2, 2, 2, 3, 103, 3, 2, 2, 2, 5, 105, 3, 2, 2, 2, 7, 107, 3, 2, 2, 2, 9, 109, 3, 2, 2, 2, 11, 111, 3, 2, 2, 2, 13, 116, 3, 2, 2, 2, 15, 118, 3, 2, 2, 2, 17, 120, 3, 2, 2, 2, 19, 124, 3, 2, 2, 2, 21, 129, 3, 2, 2, 2, 23, 134, 3, 2, 2, 2, 25, 137, 3, 2, 2, 2, 27, 139, 3, 2, 2, 2, 29, 141, 3, 2, 2, 2, 31, 144, 3, 2, 2, 2, 33, 149, 3, 2, 2, 2, 35, 155, 3, 2, 2, 2, 37, 162, 3, 2, 2, 2, 39, 168, 3, 2, 2, 2, 41, 170, 3, 2, 2, 2, 43, 173, 3, 2, 2, 2, 45, 176, 3, 2, 2, 2, 47, 179, 3, 2, 2, 2, 49, 182, 3, 2, 2, 2, 51, 185, 3, 2, 2, 2, 53, 188, 3, 2, 2, 2, 55, 191, 3, 2, 2, 2, 57, 194, 3, 2, 2, 2, 59, 197, 3, 2, 2, 2, 61, 199, 3, 2, 2, 2, 63, 201, 3, 2, 2, 2, 65, 204, 3, 2, 2, 2, 67, 207, 3, 2, 2, 2, 69, 210, 3, 2, 2, 2, 71, 212, 3, 2, 2, 2, 73, 214, 3, 2, 2, 2, 75, 216, 3, 2, 2, 2, 77, 218, 3, 2, 2, 2, 79, 220, 3, 2, 2, 2, 81, 222, 3, 2, 2, 2, 83, 227, 3, 2, 2, 2, 85, 233, 3, 2, 2, 2, 87, 242, 3, 2, 2, 2, 89, 246, 3, 2, 2, 2, 91, 257, 3, 2, 2, 2, 93, 265, 3, 2, 2, 2, 95, 268, 3, 2, 2, 2, 97, 298, 3, 2, 2, 2, 99, 302, 3, 2, 2, 2, 101, 304, 3, 2, 2, 2, 103, 104, 7, 46, 2, 2, 104, 4, 3, 2, 2, 2, 105, 106, 7, 61, 2, 2, 106, 6, 3, 2, 2, 2, 107, 108, 7, 93, 2, 2, 108, 8, 3, 2, 2, 2, 109, 110, 7, 95, 2, 2, 110, 10, 3, 2, 2, 2, 111, 112, 7, 120, 2, 2, 112, 113, 7, 113, 2, 2, 113, 114, 7, 107, 2, 2, 114, 115, 7, 102, 2, 2, 115, 12, 3, 2, 2, 2, 116, 117, 7, 42, 2, 2, 117, 14, 3, 2, 2, 2, 118, 119, 7, 43, 2, 2, 119, 16, 3, 2, 2, 2, 120, 121, 7, 107, 2, 2, 121, 122, 7, 112, 2, 2, 122, 123, 7, 118, 2, 2, 123, 18, 3, 2, 2, 2, 124, 125, 7, 100, 2, 2, 125, 126, 7, 113, 2, 2, 126, 127, 7, 113, 2, 2, 127, 128, 7, 110, 2, 2, 128, 20, 3, 2, 2, 2, 129, 130, 7, 101, 2, 2, 130, 131, 7, 106, 2, 2, 131, 132, 7, 99, 2, 2, 132, 133, 7, 116, 2, 2, 133, 22, 3, 2, 2, 2, 134, 135, 7, 93, 2, 2, 135, 136, 7, 95, 2, 2, 136, 24, 3, 2, 2, 2, 137, 138, 7, 125, 2, 2, 138, 26, 3, 2, 2, 2, 139, 140, 7, 127, 2, 2, 140, 28, 3, 2, 2, 2, 141, 142, 7, 107, 2, 2, 142, 143, 7, 104, 2, 2, 143, 30, 3, 2, 2, 2, 144, 145, 7, 103, 2, 2, 145, 146, 7, 110, 2, 2, 146, 147, 7, 117, 2, 2, 147, 148, 7, 103, 2, 2, 148, 32, 3, 2, 2, 2, 149, 150, 7, 121, 2, 2, 150, 151, 7, 106, 2, 2, 151, 152, 7, 107, 2, 2, 152, 153, 7, 110, 2, 2, 153, 154, 7, 103, 2, 2, 154, 34, 3, 2, 2, 2, 155, 156, 7, 116, 2, 2, 156, 157, 7, 103, 2, 2, 157, 158, 7, 118, 2, 2, 158, 159, 7, 119, 2, 2, 159, 160, 7, 116, 2, 2, 160, 161, 7, 112, 2, 2, 161, 36, 3, 2, 2, 2, 162, 163, 7, 100, 2, 2, 163, 164, 7, 116, 2, 2, 164, 165, 7, 103, 2, 2, 165, 166, 7, 99, 2, 2, 166, 167, 7, 109, 2, 2, 167, 38, 3, 2, 2, 2, 168, 169, 7, 63, 2, 2, 169, 40, 3, 2, 2, 2, 170, 171, 7, 45, 2, 2, 171, 172, 7, 63, 2, 2, 172, 42, 3, 2, 2, 2, 173, 174, 7, 47, 2, 2, 174, 175, 7, 63, 2, 2, 175, 44, 3, 2, 2, 2, 176, 177, 7, 44, 2, 2, 177, 178, 7, 63, 2, 2, 178, 46, 3, 2, 2, 2, 179, 180, 7, 49, 2, 2, 180, 181, 7, 63, 2, 2, 181, 48, 3, 2, 2, 2, 182, 183, 7, 45, 2, 2, 183, 184, 7, 45, 2, 2, 184, 50, 3, 2, 2, 2, 185, 186, 7, 47, 2, 2, 186, 187, 7, 47, 2, 2, 187, 52, 3, 2, 2, 2, 188, 189, 7, 126, 2, 2, 189, 190, 7, 126, 2, 2, 190, 54, 3, 2, 2, 2, 191, 192, 7, 40, 2, 2, 192, 193, 7, 40, 2, 2, 193, 56, 3, 2, 2, 2, 194, 195, 7, 62, 2, 2, 195, 196, 7, 63, 2, 2, 196, 58, 3, 2, 2, 2, 197, 198, 7, 62, 2, 2, 198, 60, 3, 2, 2, 2, 199, 200, 7, 64, 2, 2, 200, 62, 3, 2, 2, 2, 201, 202, 7, 64, 2, 2, 202, 203, 7, 63, 2, 2, 203, 64, 3, 2, 2, 2, 204, 205, 7, 63, 2, 2, 205, 206, 7, 63, 2, 2, 206, 66, 3, 2, 2, 2, 207, 208, 7, 35, 2, 2, 208, 209, 7, 63, 2, 2, 209, 68, 3, 2, 2, 2, 210, 211, 7, 45, 2, 2, 211, 70, 3, 2, 2, 2, 212, 213, 7, 47, 2, 2, 213, 72, 3, 2, 2, 2, 214, 215, 7, 44, 2, 2, 215, 74, 3, 2, 2, 2, 216, 217, 7, 49, 2, 2, 217, 76, 3, 2, 2, 2, 218, 219, 7, 39, 2, 2, 219, 78, 3, 2, 2, 2, 220, 221, 7, 65, 2, 2, 221, 80, 3, 2, 2, 2, 222, 223, 7, 118, 2, 2, 223, 224, 7, 116, 2, 2, 224, 225, 7, 119, 2, 2, 225, 226, 7, 103, 2, 2, 226, 82, 3, 2, 2, 2, 227, 228, 7, 104, 2, 2, 228, 229, 7, 99, 2, 2, 229, 230, 7, 110, 2, 2, 230, 231, 7, 117, 2, 2, 231, 232, 7, 103, 2, 2, 232, 84, 3, 2, 2, 2, 233, 238, 5, 99, 50, 2, 234, 237, 5, 99, 50, 2, 235, 237, 5, 101, 51, 2, 236, 234, 3, 2, 2, 2, 236, 235, 3, 2, 2, 2, 237, 240, 3, 2, 2, 2, 238, 236, 3, 2, 2, 2, 238, 239, 3, 2, 2, 2, 239, 86, 3, 2, 2, 2, 240, 238, 3, 2, 2, 2, 241, 243, 5, 101, 51, 2, 242, 241, 3, 2, 2, 2, 243, 244, 3, 2, 2, 2, 244, 242, 3, 2, 2, 2, 244, 245, 3, 2, 2, 2, 245, 88, 3, 2, 2, 2, 246, 252, 7, 36, 2, 2, 247, 248, 7, 94, 2, 2, 248, 251, 7, 36, 2, 2, 249, 251, 10, 2, 2, 2, 250, 247, 3, 2, 2, 2, 250, 249, 3, 2, 2, 2, 251, 254, 3, 2, 2, 2, 252, 253, 3, 2, 2, 2, 252, 250, 3, 2, 2, 2, 253, 255, 3, 2, 2, 2, 254, 252, 3, 2, 2, 2, 255, 256, 7, 36, 2, 2, 256, 90, 3, 2, 2, 2, 257, 261, 7, 36, 2, 2, 258, 259, 7, 94, 2, 2, 259, 262, 7, 36, 2, 2, 260, 262, 10, 2, 2, 2, 261, 258, 3, 2, 2, 2, 261, 260, 3, 2, 2, 2, 262, 263, 3, 2, 2, 2, 263, 264, 7, 36, 2, 2, 264, 92, 3, 2, 2, 2, 265, 266, 7, 35, 2, 2, 266, 94, 3, 2, 2, 2, 267, 269, 9, 3, 2, 2, 268, 267, 3, 2, 2, 2, 269, 270, 3, 2, 2, 2, 270, 268, 3, 2, 2, 2, 270, 271, 3, 2, 2, 2, 271, 272, 3, 2, 2, 2, 272, 273, 8, 48, 2, 2, 273, 96, 3, 2, 2, 2, 274, 275, 7, 49, 2, 2, 275, 276, 7, 49, 2, 2, 276, 280, 3, 2, 2, 2, 277, 279, 10, 4, 2, 2, 278, 277, 3, 2, 2, 2, 279, 282, 3, 2, 2, 2, 280, 278, 3, 2, 2, 2, 280, 281, 3, 2, 2, 2, 281, 284, 3, 2, 2, 2, 282, 280, 3, 2, 2, 2, 283, 285, 7, 15, 2, 2, 284, 283, 3, 2, 2, 2, 284, 285, 3, 2, 2, 2, 285, 286, 3, 2, 2, 2, 286, 299, 7, 12, 2, 2, 287, 288, 7, 49, 2, 2, 288, 289, 7, 44, 2, 2, 289, 293, 3, 2, 2, 2, 290, 292, 11, 2, 2, 2, 291, 290, 3, 2, 2, 2, 292, 295, 3, 2, 2, 2, 293, 294, 3, 2, 2, 2, 293, 291, 3, 2, 2, 2, 294, 296, 3, 2, 2, 2, 295, 293, 3, 2, 2, 2, 296, 297, 7, 44, 2, 2, 297, 299, 7, 49, 2, 2, 298, 274, 3, 2, 2, 2, 298, 287, 3, 2, 2, 2, 299, 300, 3, 2, 2, 2, 300, 301, 8, 49, 2, 2, 301, 98, 3, 2, 2, 2, 302, 303, 9, 5, 2, 2, 303, 100, 3, 2, 2, 2, 304, 305, 4, 50, 59, 2, 305, 102, 3, 2, 2, 2, 14, 2, 236, 238, 244, 250, 252, 261, 270, 280, 284, 293, 298, 3, 8, 2, 2]
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusLexer.java b/Homework/cs5300/p4-formatter/parser/CminusLexer.java new file mode 100644 index 0000000..8224ed8 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusLexer.java @@ -0,0 +1,232 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class CminusLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, + T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, + T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, + T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, + T__38=39, T__39=40, T__40=41, ID=42, NUMCONST=43, STRINGCONST=44, CHARCONST=45, + BANG=46, WS=47, COMMENT=48; + public static String[] channelNames = { + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }; + + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + private static String[] makeRuleNames() { + return new String[] { + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", + "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", + "T__25", "T__26", "T__27", "T__28", "T__29", "T__30", "T__31", "T__32", + "T__33", "T__34", "T__35", "T__36", "T__37", "T__38", "T__39", "T__40", + "ID", "NUMCONST", "STRINGCONST", "CHARCONST", "BANG", "WS", "COMMENT", + "LETTER", "DIGIT" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "','", "';'", "'['", "']'", "'void'", "'('", "')'", "'int'", "'bool'", + "'char'", "'[]'", "'{'", "'}'", "'if'", "'else'", "'while'", "'return'", + "'break'", "'='", "'+='", "'-='", "'*='", "'/='", "'++'", "'--'", "'||'", + "'&&'", "'<='", "'<'", "'>'", "'>='", "'=='", "'!='", "'+'", "'-'", "'*'", + "'/'", "'%'", "'?'", "'true'", "'false'", null, null, null, null, "'!'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, "ID", "NUMCONST", "STRINGCONST", + "CHARCONST", "BANG", "WS", "COMMENT" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = "<INVALID>"; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public CminusLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "Cminus.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public String[] getChannelNames() { return channelNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + public static final String _serializedATN = + "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\62\u0132\b\1\4\2"+ + "\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4"+ + "\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+ + "\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31"+ + "\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t"+ + " \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t"+ + "+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\3\2"+ + "\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3"+ + "\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\13\3\13\3\f\3\f\3\f\3"+ + "\r\3\r\3\16\3\16\3\17\3\17\3\17\3\20\3\20\3\20\3\20\3\20\3\21\3\21\3\21"+ + "\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\23\3\23\3\23\3\23"+ + "\3\23\3\23\3\24\3\24\3\25\3\25\3\25\3\26\3\26\3\26\3\27\3\27\3\27\3\30"+ + "\3\30\3\30\3\31\3\31\3\31\3\32\3\32\3\32\3\33\3\33\3\33\3\34\3\34\3\34"+ + "\3\35\3\35\3\35\3\36\3\36\3\37\3\37\3 \3 \3 \3!\3!\3!\3\"\3\"\3\"\3#\3"+ + "#\3$\3$\3%\3%\3&\3&\3\'\3\'\3(\3(\3)\3)\3)\3)\3)\3*\3*\3*\3*\3*\3*\3+"+ + "\3+\3+\7+\u00ed\n+\f+\16+\u00f0\13+\3,\6,\u00f3\n,\r,\16,\u00f4\3-\3-"+ + "\3-\3-\7-\u00fb\n-\f-\16-\u00fe\13-\3-\3-\3.\3.\3.\3.\5.\u0106\n.\3.\3"+ + ".\3/\3/\3\60\6\60\u010d\n\60\r\60\16\60\u010e\3\60\3\60\3\61\3\61\3\61"+ + "\3\61\7\61\u0117\n\61\f\61\16\61\u011a\13\61\3\61\5\61\u011d\n\61\3\61"+ + "\3\61\3\61\3\61\3\61\7\61\u0124\n\61\f\61\16\61\u0127\13\61\3\61\3\61"+ + "\5\61\u012b\n\61\3\61\3\61\3\62\3\62\3\63\3\63\4\u00fc\u0125\2\64\3\3"+ + "\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35\20\37\21"+ + "!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33\65\34\67\359\36;\37= ?!"+ + "A\"C#E$G%I&K\'M(O)Q*S+U,W-Y.[/]\60_\61a\62c\2e\2\3\2\6\3\2$$\5\2\13\f"+ + "\16\17\"\"\4\2\f\f\17\17\4\2C\\c|\2\u013a\2\3\3\2\2\2\2\5\3\2\2\2\2\7"+ + "\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2"+ + "\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2"+ + "\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2"+ + "\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2"+ + "\2\65\3\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2\2\2"+ + "\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2G\3\2\2\2\2I\3\2\2\2\2K\3\2\2\2\2M"+ + "\3\2\2\2\2O\3\2\2\2\2Q\3\2\2\2\2S\3\2\2\2\2U\3\2\2\2\2W\3\2\2\2\2Y\3\2"+ + "\2\2\2[\3\2\2\2\2]\3\2\2\2\2_\3\2\2\2\2a\3\2\2\2\3g\3\2\2\2\5i\3\2\2\2"+ + "\7k\3\2\2\2\tm\3\2\2\2\13o\3\2\2\2\rt\3\2\2\2\17v\3\2\2\2\21x\3\2\2\2"+ + "\23|\3\2\2\2\25\u0081\3\2\2\2\27\u0086\3\2\2\2\31\u0089\3\2\2\2\33\u008b"+ + "\3\2\2\2\35\u008d\3\2\2\2\37\u0090\3\2\2\2!\u0095\3\2\2\2#\u009b\3\2\2"+ + "\2%\u00a2\3\2\2\2\'\u00a8\3\2\2\2)\u00aa\3\2\2\2+\u00ad\3\2\2\2-\u00b0"+ + "\3\2\2\2/\u00b3\3\2\2\2\61\u00b6\3\2\2\2\63\u00b9\3\2\2\2\65\u00bc\3\2"+ + "\2\2\67\u00bf\3\2\2\29\u00c2\3\2\2\2;\u00c5\3\2\2\2=\u00c7\3\2\2\2?\u00c9"+ + "\3\2\2\2A\u00cc\3\2\2\2C\u00cf\3\2\2\2E\u00d2\3\2\2\2G\u00d4\3\2\2\2I"+ + "\u00d6\3\2\2\2K\u00d8\3\2\2\2M\u00da\3\2\2\2O\u00dc\3\2\2\2Q\u00de\3\2"+ + "\2\2S\u00e3\3\2\2\2U\u00e9\3\2\2\2W\u00f2\3\2\2\2Y\u00f6\3\2\2\2[\u0101"+ + "\3\2\2\2]\u0109\3\2\2\2_\u010c\3\2\2\2a\u012a\3\2\2\2c\u012e\3\2\2\2e"+ + "\u0130\3\2\2\2gh\7.\2\2h\4\3\2\2\2ij\7=\2\2j\6\3\2\2\2kl\7]\2\2l\b\3\2"+ + "\2\2mn\7_\2\2n\n\3\2\2\2op\7x\2\2pq\7q\2\2qr\7k\2\2rs\7f\2\2s\f\3\2\2"+ + "\2tu\7*\2\2u\16\3\2\2\2vw\7+\2\2w\20\3\2\2\2xy\7k\2\2yz\7p\2\2z{\7v\2"+ + "\2{\22\3\2\2\2|}\7d\2\2}~\7q\2\2~\177\7q\2\2\177\u0080\7n\2\2\u0080\24"+ + "\3\2\2\2\u0081\u0082\7e\2\2\u0082\u0083\7j\2\2\u0083\u0084\7c\2\2\u0084"+ + "\u0085\7t\2\2\u0085\26\3\2\2\2\u0086\u0087\7]\2\2\u0087\u0088\7_\2\2\u0088"+ + "\30\3\2\2\2\u0089\u008a\7}\2\2\u008a\32\3\2\2\2\u008b\u008c\7\177\2\2"+ + "\u008c\34\3\2\2\2\u008d\u008e\7k\2\2\u008e\u008f\7h\2\2\u008f\36\3\2\2"+ + "\2\u0090\u0091\7g\2\2\u0091\u0092\7n\2\2\u0092\u0093\7u\2\2\u0093\u0094"+ + "\7g\2\2\u0094 \3\2\2\2\u0095\u0096\7y\2\2\u0096\u0097\7j\2\2\u0097\u0098"+ + "\7k\2\2\u0098\u0099\7n\2\2\u0099\u009a\7g\2\2\u009a\"\3\2\2\2\u009b\u009c"+ + "\7t\2\2\u009c\u009d\7g\2\2\u009d\u009e\7v\2\2\u009e\u009f\7w\2\2\u009f"+ + "\u00a0\7t\2\2\u00a0\u00a1\7p\2\2\u00a1$\3\2\2\2\u00a2\u00a3\7d\2\2\u00a3"+ + "\u00a4\7t\2\2\u00a4\u00a5\7g\2\2\u00a5\u00a6\7c\2\2\u00a6\u00a7\7m\2\2"+ + "\u00a7&\3\2\2\2\u00a8\u00a9\7?\2\2\u00a9(\3\2\2\2\u00aa\u00ab\7-\2\2\u00ab"+ + "\u00ac\7?\2\2\u00ac*\3\2\2\2\u00ad\u00ae\7/\2\2\u00ae\u00af\7?\2\2\u00af"+ + ",\3\2\2\2\u00b0\u00b1\7,\2\2\u00b1\u00b2\7?\2\2\u00b2.\3\2\2\2\u00b3\u00b4"+ + "\7\61\2\2\u00b4\u00b5\7?\2\2\u00b5\60\3\2\2\2\u00b6\u00b7\7-\2\2\u00b7"+ + "\u00b8\7-\2\2\u00b8\62\3\2\2\2\u00b9\u00ba\7/\2\2\u00ba\u00bb\7/\2\2\u00bb"+ + "\64\3\2\2\2\u00bc\u00bd\7~\2\2\u00bd\u00be\7~\2\2\u00be\66\3\2\2\2\u00bf"+ + "\u00c0\7(\2\2\u00c0\u00c1\7(\2\2\u00c18\3\2\2\2\u00c2\u00c3\7>\2\2\u00c3"+ + "\u00c4\7?\2\2\u00c4:\3\2\2\2\u00c5\u00c6\7>\2\2\u00c6<\3\2\2\2\u00c7\u00c8"+ + "\7@\2\2\u00c8>\3\2\2\2\u00c9\u00ca\7@\2\2\u00ca\u00cb\7?\2\2\u00cb@\3"+ + "\2\2\2\u00cc\u00cd\7?\2\2\u00cd\u00ce\7?\2\2\u00ceB\3\2\2\2\u00cf\u00d0"+ + "\7#\2\2\u00d0\u00d1\7?\2\2\u00d1D\3\2\2\2\u00d2\u00d3\7-\2\2\u00d3F\3"+ + "\2\2\2\u00d4\u00d5\7/\2\2\u00d5H\3\2\2\2\u00d6\u00d7\7,\2\2\u00d7J\3\2"+ + "\2\2\u00d8\u00d9\7\61\2\2\u00d9L\3\2\2\2\u00da\u00db\7\'\2\2\u00dbN\3"+ + "\2\2\2\u00dc\u00dd\7A\2\2\u00ddP\3\2\2\2\u00de\u00df\7v\2\2\u00df\u00e0"+ + "\7t\2\2\u00e0\u00e1\7w\2\2\u00e1\u00e2\7g\2\2\u00e2R\3\2\2\2\u00e3\u00e4"+ + "\7h\2\2\u00e4\u00e5\7c\2\2\u00e5\u00e6\7n\2\2\u00e6\u00e7\7u\2\2\u00e7"+ + "\u00e8\7g\2\2\u00e8T\3\2\2\2\u00e9\u00ee\5c\62\2\u00ea\u00ed\5c\62\2\u00eb"+ + "\u00ed\5e\63\2\u00ec\u00ea\3\2\2\2\u00ec\u00eb\3\2\2\2\u00ed\u00f0\3\2"+ + "\2\2\u00ee\u00ec\3\2\2\2\u00ee\u00ef\3\2\2\2\u00efV\3\2\2\2\u00f0\u00ee"+ + "\3\2\2\2\u00f1\u00f3\5e\63\2\u00f2\u00f1\3\2\2\2\u00f3\u00f4\3\2\2\2\u00f4"+ + "\u00f2\3\2\2\2\u00f4\u00f5\3\2\2\2\u00f5X\3\2\2\2\u00f6\u00fc\7$\2\2\u00f7"+ + "\u00f8\7^\2\2\u00f8\u00fb\7$\2\2\u00f9\u00fb\n\2\2\2\u00fa\u00f7\3\2\2"+ + "\2\u00fa\u00f9\3\2\2\2\u00fb\u00fe\3\2\2\2\u00fc\u00fd\3\2\2\2\u00fc\u00fa"+ + "\3\2\2\2\u00fd\u00ff\3\2\2\2\u00fe\u00fc\3\2\2\2\u00ff\u0100\7$\2\2\u0100"+ + "Z\3\2\2\2\u0101\u0105\7$\2\2\u0102\u0103\7^\2\2\u0103\u0106\7$\2\2\u0104"+ + "\u0106\n\2\2\2\u0105\u0102\3\2\2\2\u0105\u0104\3\2\2\2\u0106\u0107\3\2"+ + "\2\2\u0107\u0108\7$\2\2\u0108\\\3\2\2\2\u0109\u010a\7#\2\2\u010a^\3\2"+ + "\2\2\u010b\u010d\t\3\2\2\u010c\u010b\3\2\2\2\u010d\u010e\3\2\2\2\u010e"+ + "\u010c\3\2\2\2\u010e\u010f\3\2\2\2\u010f\u0110\3\2\2\2\u0110\u0111\b\60"+ + "\2\2\u0111`\3\2\2\2\u0112\u0113\7\61\2\2\u0113\u0114\7\61\2\2\u0114\u0118"+ + "\3\2\2\2\u0115\u0117\n\4\2\2\u0116\u0115\3\2\2\2\u0117\u011a\3\2\2\2\u0118"+ + "\u0116\3\2\2\2\u0118\u0119\3\2\2\2\u0119\u011c\3\2\2\2\u011a\u0118\3\2"+ + "\2\2\u011b\u011d\7\17\2\2\u011c\u011b\3\2\2\2\u011c\u011d\3\2\2\2\u011d"+ + "\u011e\3\2\2\2\u011e\u012b\7\f\2\2\u011f\u0120\7\61\2\2\u0120\u0121\7"+ + ",\2\2\u0121\u0125\3\2\2\2\u0122\u0124\13\2\2\2\u0123\u0122\3\2\2\2\u0124"+ + "\u0127\3\2\2\2\u0125\u0126\3\2\2\2\u0125\u0123\3\2\2\2\u0126\u0128\3\2"+ + "\2\2\u0127\u0125\3\2\2\2\u0128\u0129\7,\2\2\u0129\u012b\7\61\2\2\u012a"+ + "\u0112\3\2\2\2\u012a\u011f\3\2\2\2\u012b\u012c\3\2\2\2\u012c\u012d\b\61"+ + "\2\2\u012db\3\2\2\2\u012e\u012f\t\5\2\2\u012fd\3\2\2\2\u0130\u0131\4\62"+ + ";\2\u0131f\3\2\2\2\16\2\u00ec\u00ee\u00f4\u00fa\u00fc\u0105\u010e\u0118"+ + "\u011c\u0125\u012a\3\b\2\2"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusLexer.tokens b/Homework/cs5300/p4-formatter/parser/CminusLexer.tokens new file mode 100644 index 0000000..ae5a5c0 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusLexer.tokens @@ -0,0 +1,90 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +T__12=13 +T__13=14 +T__14=15 +T__15=16 +T__16=17 +T__17=18 +T__18=19 +T__19=20 +T__20=21 +T__21=22 +T__22=23 +T__23=24 +T__24=25 +T__25=26 +T__26=27 +T__27=28 +T__28=29 +T__29=30 +T__30=31 +T__31=32 +T__32=33 +T__33=34 +T__34=35 +T__35=36 +T__36=37 +T__37=38 +T__38=39 +T__39=40 +T__40=41 +ID=42 +NUMCONST=43 +STRINGCONST=44 +CHARCONST=45 +BANG=46 +WS=47 +COMMENT=48 +','=1 +';'=2 +'['=3 +']'=4 +'void'=5 +'('=6 +')'=7 +'int'=8 +'bool'=9 +'char'=10 +'[]'=11 +'{'=12 +'}'=13 +'if'=14 +'else'=15 +'while'=16 +'return'=17 +'break'=18 +'='=19 +'+='=20 +'-='=21 +'*='=22 +'/='=23 +'++'=24 +'--'=25 +'||'=26 +'&&'=27 +'<='=28 +'<'=29 +'>'=30 +'>='=31 +'=='=32 +'!='=33 +'+'=34 +'-'=35 +'*'=36 +'/'=37 +'%'=38 +'?'=39 +'true'=40 +'false'=41 +'!'=46 diff --git a/Homework/cs5300/p4-formatter/parser/CminusListener.java b/Homework/cs5300/p4-formatter/parser/CminusListener.java new file mode 100644 index 0000000..bd141e3 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusListener.java @@ -0,0 +1,340 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; +import org.antlr.v4.runtime.tree.ParseTreeListener; + +/** + * This interface defines a complete listener for a parse tree produced by + * {@link CminusParser}. + */ +public interface CminusListener extends ParseTreeListener { + /** + * Enter a parse tree produced by {@link CminusParser#program}. + * @param ctx the parse tree + */ + void enterProgram(CminusParser.ProgramContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#program}. + * @param ctx the parse tree + */ + void exitProgram(CminusParser.ProgramContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#declaration}. + * @param ctx the parse tree + */ + void enterDeclaration(CminusParser.DeclarationContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#declaration}. + * @param ctx the parse tree + */ + void exitDeclaration(CminusParser.DeclarationContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#varDeclaration}. + * @param ctx the parse tree + */ + void enterVarDeclaration(CminusParser.VarDeclarationContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#varDeclaration}. + * @param ctx the parse tree + */ + void exitVarDeclaration(CminusParser.VarDeclarationContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#varDeclId}. + * @param ctx the parse tree + */ + void enterVarDeclId(CminusParser.VarDeclIdContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#varDeclId}. + * @param ctx the parse tree + */ + void exitVarDeclId(CminusParser.VarDeclIdContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#funDeclaration}. + * @param ctx the parse tree + */ + void enterFunDeclaration(CminusParser.FunDeclarationContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#funDeclaration}. + * @param ctx the parse tree + */ + void exitFunDeclaration(CminusParser.FunDeclarationContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#typeSpecifier}. + * @param ctx the parse tree + */ + void enterTypeSpecifier(CminusParser.TypeSpecifierContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#typeSpecifier}. + * @param ctx the parse tree + */ + void exitTypeSpecifier(CminusParser.TypeSpecifierContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#param}. + * @param ctx the parse tree + */ + void enterParam(CminusParser.ParamContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#param}. + * @param ctx the parse tree + */ + void exitParam(CminusParser.ParamContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#paramId}. + * @param ctx the parse tree + */ + void enterParamId(CminusParser.ParamIdContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#paramId}. + * @param ctx the parse tree + */ + void exitParamId(CminusParser.ParamIdContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#statement}. + * @param ctx the parse tree + */ + void enterStatement(CminusParser.StatementContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#statement}. + * @param ctx the parse tree + */ + void exitStatement(CminusParser.StatementContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#compoundStmt}. + * @param ctx the parse tree + */ + void enterCompoundStmt(CminusParser.CompoundStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#compoundStmt}. + * @param ctx the parse tree + */ + void exitCompoundStmt(CminusParser.CompoundStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#expressionStmt}. + * @param ctx the parse tree + */ + void enterExpressionStmt(CminusParser.ExpressionStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#expressionStmt}. + * @param ctx the parse tree + */ + void exitExpressionStmt(CminusParser.ExpressionStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#ifStmt}. + * @param ctx the parse tree + */ + void enterIfStmt(CminusParser.IfStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#ifStmt}. + * @param ctx the parse tree + */ + void exitIfStmt(CminusParser.IfStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#whileStmt}. + * @param ctx the parse tree + */ + void enterWhileStmt(CminusParser.WhileStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#whileStmt}. + * @param ctx the parse tree + */ + void exitWhileStmt(CminusParser.WhileStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#returnStmt}. + * @param ctx the parse tree + */ + void enterReturnStmt(CminusParser.ReturnStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#returnStmt}. + * @param ctx the parse tree + */ + void exitReturnStmt(CminusParser.ReturnStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#breakStmt}. + * @param ctx the parse tree + */ + void enterBreakStmt(CminusParser.BreakStmtContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#breakStmt}. + * @param ctx the parse tree + */ + void exitBreakStmt(CminusParser.BreakStmtContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#expression}. + * @param ctx the parse tree + */ + void enterExpression(CminusParser.ExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#expression}. + * @param ctx the parse tree + */ + void exitExpression(CminusParser.ExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#simpleExpression}. + * @param ctx the parse tree + */ + void enterSimpleExpression(CminusParser.SimpleExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#simpleExpression}. + * @param ctx the parse tree + */ + void exitSimpleExpression(CminusParser.SimpleExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#orExpression}. + * @param ctx the parse tree + */ + void enterOrExpression(CminusParser.OrExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#orExpression}. + * @param ctx the parse tree + */ + void exitOrExpression(CminusParser.OrExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#andExpression}. + * @param ctx the parse tree + */ + void enterAndExpression(CminusParser.AndExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#andExpression}. + * @param ctx the parse tree + */ + void exitAndExpression(CminusParser.AndExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#unaryRelExpression}. + * @param ctx the parse tree + */ + void enterUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#unaryRelExpression}. + * @param ctx the parse tree + */ + void exitUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#relExpression}. + * @param ctx the parse tree + */ + void enterRelExpression(CminusParser.RelExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#relExpression}. + * @param ctx the parse tree + */ + void exitRelExpression(CminusParser.RelExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#relop}. + * @param ctx the parse tree + */ + void enterRelop(CminusParser.RelopContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#relop}. + * @param ctx the parse tree + */ + void exitRelop(CminusParser.RelopContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#sumExpression}. + * @param ctx the parse tree + */ + void enterSumExpression(CminusParser.SumExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#sumExpression}. + * @param ctx the parse tree + */ + void exitSumExpression(CminusParser.SumExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#sumop}. + * @param ctx the parse tree + */ + void enterSumop(CminusParser.SumopContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#sumop}. + * @param ctx the parse tree + */ + void exitSumop(CminusParser.SumopContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#termExpression}. + * @param ctx the parse tree + */ + void enterTermExpression(CminusParser.TermExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#termExpression}. + * @param ctx the parse tree + */ + void exitTermExpression(CminusParser.TermExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#mulop}. + * @param ctx the parse tree + */ + void enterMulop(CminusParser.MulopContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#mulop}. + * @param ctx the parse tree + */ + void exitMulop(CminusParser.MulopContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#unaryExpression}. + * @param ctx the parse tree + */ + void enterUnaryExpression(CminusParser.UnaryExpressionContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#unaryExpression}. + * @param ctx the parse tree + */ + void exitUnaryExpression(CminusParser.UnaryExpressionContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#unaryop}. + * @param ctx the parse tree + */ + void enterUnaryop(CminusParser.UnaryopContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#unaryop}. + * @param ctx the parse tree + */ + void exitUnaryop(CminusParser.UnaryopContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#factor}. + * @param ctx the parse tree + */ + void enterFactor(CminusParser.FactorContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#factor}. + * @param ctx the parse tree + */ + void exitFactor(CminusParser.FactorContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#mutable}. + * @param ctx the parse tree + */ + void enterMutable(CminusParser.MutableContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#mutable}. + * @param ctx the parse tree + */ + void exitMutable(CminusParser.MutableContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#immutable}. + * @param ctx the parse tree + */ + void enterImmutable(CminusParser.ImmutableContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#immutable}. + * @param ctx the parse tree + */ + void exitImmutable(CminusParser.ImmutableContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#call}. + * @param ctx the parse tree + */ + void enterCall(CminusParser.CallContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#call}. + * @param ctx the parse tree + */ + void exitCall(CminusParser.CallContext ctx); + /** + * Enter a parse tree produced by {@link CminusParser#constant}. + * @param ctx the parse tree + */ + void enterConstant(CminusParser.ConstantContext ctx); + /** + * Exit a parse tree produced by {@link CminusParser#constant}. + * @param ctx the parse tree + */ + void exitConstant(CminusParser.ConstantContext ctx); +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusParser.java b/Homework/cs5300/p4-formatter/parser/CminusParser.java new file mode 100644 index 0000000..6749b21 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusParser.java @@ -0,0 +1,2454 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) +public class CminusParser extends Parser { + static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, + T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, + T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, T__23=24, + T__24=25, T__25=26, T__26=27, T__27=28, T__28=29, T__29=30, T__30=31, + T__31=32, T__32=33, T__33=34, T__34=35, T__35=36, T__36=37, T__37=38, + T__38=39, T__39=40, T__40=41, ID=42, NUMCONST=43, STRINGCONST=44, CHARCONST=45, + BANG=46, WS=47, COMMENT=48; + public static final int + RULE_program = 0, RULE_declaration = 1, RULE_varDeclaration = 2, RULE_varDeclId = 3, + RULE_funDeclaration = 4, RULE_typeSpecifier = 5, RULE_param = 6, RULE_paramId = 7, + RULE_statement = 8, RULE_compoundStmt = 9, RULE_expressionStmt = 10, RULE_ifStmt = 11, + RULE_whileStmt = 12, RULE_returnStmt = 13, RULE_breakStmt = 14, RULE_expression = 15, + RULE_simpleExpression = 16, RULE_orExpression = 17, RULE_andExpression = 18, + RULE_unaryRelExpression = 19, RULE_relExpression = 20, RULE_relop = 21, + RULE_sumExpression = 22, RULE_sumop = 23, RULE_termExpression = 24, RULE_mulop = 25, + RULE_unaryExpression = 26, RULE_unaryop = 27, RULE_factor = 28, RULE_mutable = 29, + RULE_immutable = 30, RULE_call = 31, RULE_constant = 32; + private static String[] makeRuleNames() { + return new String[] { + "program", "declaration", "varDeclaration", "varDeclId", "funDeclaration", + "typeSpecifier", "param", "paramId", "statement", "compoundStmt", "expressionStmt", + "ifStmt", "whileStmt", "returnStmt", "breakStmt", "expression", "simpleExpression", + "orExpression", "andExpression", "unaryRelExpression", "relExpression", + "relop", "sumExpression", "sumop", "termExpression", "mulop", "unaryExpression", + "unaryop", "factor", "mutable", "immutable", "call", "constant" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "','", "';'", "'['", "']'", "'void'", "'('", "')'", "'int'", "'bool'", + "'char'", "'[]'", "'{'", "'}'", "'if'", "'else'", "'while'", "'return'", + "'break'", "'='", "'+='", "'-='", "'*='", "'/='", "'++'", "'--'", "'||'", + "'&&'", "'<='", "'<'", "'>'", "'>='", "'=='", "'!='", "'+'", "'-'", "'*'", + "'/'", "'%'", "'?'", "'true'", "'false'", null, null, null, null, "'!'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, "ID", "NUMCONST", "STRINGCONST", + "CHARCONST", "BANG", "WS", "COMMENT" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = "<INVALID>"; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { return "Cminus.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public ATN getATN() { return _ATN; } + + public CminusParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + public static class ProgramContext extends ParserRuleContext { + public List<DeclarationContext> declaration() { + return getRuleContexts(DeclarationContext.class); + } + public DeclarationContext declaration(int i) { + return getRuleContext(DeclarationContext.class,i); + } + public ProgramContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_program; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterProgram(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitProgram(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitProgram(this); + else return visitor.visitChildren(this); + } + } + + public final ProgramContext program() throws RecognitionException { + ProgramContext _localctx = new ProgramContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_program); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(67); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(66); + declaration(); + } + } + setState(69); + _errHandler.sync(this); + _la = _input.LA(1); + } while ( (((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__4) | (1L << T__7) | (1L << T__8) | (1L << T__9))) != 0) ); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class DeclarationContext extends ParserRuleContext { + public VarDeclarationContext varDeclaration() { + return getRuleContext(VarDeclarationContext.class,0); + } + public FunDeclarationContext funDeclaration() { + return getRuleContext(FunDeclarationContext.class,0); + } + public DeclarationContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_declaration; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterDeclaration(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitDeclaration(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitDeclaration(this); + else return visitor.visitChildren(this); + } + } + + public final DeclarationContext declaration() throws RecognitionException { + DeclarationContext _localctx = new DeclarationContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_declaration); + try { + setState(73); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(71); + varDeclaration(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(72); + funDeclaration(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class VarDeclarationContext extends ParserRuleContext { + public TypeSpecifierContext typeSpecifier() { + return getRuleContext(TypeSpecifierContext.class,0); + } + public List<VarDeclIdContext> varDeclId() { + return getRuleContexts(VarDeclIdContext.class); + } + public VarDeclIdContext varDeclId(int i) { + return getRuleContext(VarDeclIdContext.class,i); + } + public VarDeclarationContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_varDeclaration; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterVarDeclaration(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitVarDeclaration(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitVarDeclaration(this); + else return visitor.visitChildren(this); + } + } + + public final VarDeclarationContext varDeclaration() throws RecognitionException { + VarDeclarationContext _localctx = new VarDeclarationContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_varDeclaration); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(75); + typeSpecifier(); + setState(76); + varDeclId(); + setState(81); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==T__0) { + { + { + setState(77); + match(T__0); + setState(78); + varDeclId(); + } + } + setState(83); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(84); + match(T__1); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class VarDeclIdContext extends ParserRuleContext { + public TerminalNode ID() { return getToken(CminusParser.ID, 0); } + public TerminalNode NUMCONST() { return getToken(CminusParser.NUMCONST, 0); } + public VarDeclIdContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_varDeclId; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterVarDeclId(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitVarDeclId(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitVarDeclId(this); + else return visitor.visitChildren(this); + } + } + + public final VarDeclIdContext varDeclId() throws RecognitionException { + VarDeclIdContext _localctx = new VarDeclIdContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_varDeclId); + try { + setState(91); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(86); + match(ID); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(87); + match(ID); + setState(88); + match(T__2); + setState(89); + match(NUMCONST); + setState(90); + match(T__3); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class FunDeclarationContext extends ParserRuleContext { + public TerminalNode ID() { return getToken(CminusParser.ID, 0); } + public StatementContext statement() { + return getRuleContext(StatementContext.class,0); + } + public TypeSpecifierContext typeSpecifier() { + return getRuleContext(TypeSpecifierContext.class,0); + } + public List<ParamContext> param() { + return getRuleContexts(ParamContext.class); + } + public ParamContext param(int i) { + return getRuleContext(ParamContext.class,i); + } + public FunDeclarationContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_funDeclaration; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterFunDeclaration(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitFunDeclaration(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitFunDeclaration(this); + else return visitor.visitChildren(this); + } + } + + public final FunDeclarationContext funDeclaration() throws RecognitionException { + FunDeclarationContext _localctx = new FunDeclarationContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_funDeclaration); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(95); + _errHandler.sync(this); + switch (_input.LA(1)) { + case T__4: + { + setState(93); + match(T__4); + } + break; + case T__7: + case T__8: + case T__9: + { + setState(94); + typeSpecifier(); + } + break; + default: + throw new NoViableAltException(this); + } + setState(97); + match(ID); + setState(98); + match(T__5); + setState(100); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__7) | (1L << T__8) | (1L << T__9))) != 0)) { + { + setState(99); + param(); + } + } + + setState(106); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==T__0) { + { + { + setState(102); + match(T__0); + setState(103); + param(); + } + } + setState(108); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(109); + match(T__6); + setState(110); + statement(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class TypeSpecifierContext extends ParserRuleContext { + public TypeSpecifierContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_typeSpecifier; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterTypeSpecifier(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitTypeSpecifier(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitTypeSpecifier(this); + else return visitor.visitChildren(this); + } + } + + public final TypeSpecifierContext typeSpecifier() throws RecognitionException { + TypeSpecifierContext _localctx = new TypeSpecifierContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_typeSpecifier); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(112); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__7) | (1L << T__8) | (1L << T__9))) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ParamContext extends ParserRuleContext { + public TypeSpecifierContext typeSpecifier() { + return getRuleContext(TypeSpecifierContext.class,0); + } + public ParamIdContext paramId() { + return getRuleContext(ParamIdContext.class,0); + } + public ParamContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_param; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterParam(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitParam(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitParam(this); + else return visitor.visitChildren(this); + } + } + + public final ParamContext param() throws RecognitionException { + ParamContext _localctx = new ParamContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_param); + try { + enterOuterAlt(_localctx, 1); + { + setState(114); + typeSpecifier(); + setState(115); + paramId(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ParamIdContext extends ParserRuleContext { + public TerminalNode ID() { return getToken(CminusParser.ID, 0); } + public ParamIdContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_paramId; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterParamId(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitParamId(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitParamId(this); + else return visitor.visitChildren(this); + } + } + + public final ParamIdContext paramId() throws RecognitionException { + ParamIdContext _localctx = new ParamIdContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_paramId); + try { + setState(120); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,7,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(117); + match(ID); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(118); + match(ID); + setState(119); + match(T__10); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class StatementContext extends ParserRuleContext { + public ExpressionStmtContext expressionStmt() { + return getRuleContext(ExpressionStmtContext.class,0); + } + public CompoundStmtContext compoundStmt() { + return getRuleContext(CompoundStmtContext.class,0); + } + public IfStmtContext ifStmt() { + return getRuleContext(IfStmtContext.class,0); + } + public WhileStmtContext whileStmt() { + return getRuleContext(WhileStmtContext.class,0); + } + public ReturnStmtContext returnStmt() { + return getRuleContext(ReturnStmtContext.class,0); + } + public BreakStmtContext breakStmt() { + return getRuleContext(BreakStmtContext.class,0); + } + public StatementContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_statement; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterStatement(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitStatement(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitStatement(this); + else return visitor.visitChildren(this); + } + } + + public final StatementContext statement() throws RecognitionException { + StatementContext _localctx = new StatementContext(_ctx, getState()); + enterRule(_localctx, 16, RULE_statement); + try { + setState(128); + _errHandler.sync(this); + switch (_input.LA(1)) { + case T__1: + case T__5: + case T__34: + case T__35: + case T__38: + case T__39: + case T__40: + case ID: + case NUMCONST: + case STRINGCONST: + case CHARCONST: + case BANG: + enterOuterAlt(_localctx, 1); + { + setState(122); + expressionStmt(); + } + break; + case T__11: + enterOuterAlt(_localctx, 2); + { + setState(123); + compoundStmt(); + } + break; + case T__13: + enterOuterAlt(_localctx, 3); + { + setState(124); + ifStmt(); + } + break; + case T__15: + enterOuterAlt(_localctx, 4); + { + setState(125); + whileStmt(); + } + break; + case T__16: + enterOuterAlt(_localctx, 5); + { + setState(126); + returnStmt(); + } + break; + case T__17: + enterOuterAlt(_localctx, 6); + { + setState(127); + breakStmt(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class CompoundStmtContext extends ParserRuleContext { + public List<VarDeclarationContext> varDeclaration() { + return getRuleContexts(VarDeclarationContext.class); + } + public VarDeclarationContext varDeclaration(int i) { + return getRuleContext(VarDeclarationContext.class,i); + } + public List<StatementContext> statement() { + return getRuleContexts(StatementContext.class); + } + public StatementContext statement(int i) { + return getRuleContext(StatementContext.class,i); + } + public CompoundStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_compoundStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterCompoundStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitCompoundStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitCompoundStmt(this); + else return visitor.visitChildren(this); + } + } + + public final CompoundStmtContext compoundStmt() throws RecognitionException { + CompoundStmtContext _localctx = new CompoundStmtContext(_ctx, getState()); + enterRule(_localctx, 18, RULE_compoundStmt); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(130); + match(T__11); + setState(134); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__7) | (1L << T__8) | (1L << T__9))) != 0)) { + { + { + setState(131); + varDeclaration(); + } + } + setState(136); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(140); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__1) | (1L << T__5) | (1L << T__11) | (1L << T__13) | (1L << T__15) | (1L << T__16) | (1L << T__17) | (1L << T__34) | (1L << T__35) | (1L << T__38) | (1L << T__39) | (1L << T__40) | (1L << ID) | (1L << NUMCONST) | (1L << STRINGCONST) | (1L << CHARCONST) | (1L << BANG))) != 0)) { + { + { + setState(137); + statement(); + } + } + setState(142); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(143); + match(T__12); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExpressionStmtContext extends ParserRuleContext { + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public ExpressionStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_expressionStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterExpressionStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitExpressionStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitExpressionStmt(this); + else return visitor.visitChildren(this); + } + } + + public final ExpressionStmtContext expressionStmt() throws RecognitionException { + ExpressionStmtContext _localctx = new ExpressionStmtContext(_ctx, getState()); + enterRule(_localctx, 20, RULE_expressionStmt); + try { + setState(149); + _errHandler.sync(this); + switch (_input.LA(1)) { + case T__5: + case T__34: + case T__35: + case T__38: + case T__39: + case T__40: + case ID: + case NUMCONST: + case STRINGCONST: + case CHARCONST: + case BANG: + enterOuterAlt(_localctx, 1); + { + setState(145); + expression(); + setState(146); + match(T__1); + } + break; + case T__1: + enterOuterAlt(_localctx, 2); + { + setState(148); + match(T__1); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class IfStmtContext extends ParserRuleContext { + public SimpleExpressionContext simpleExpression() { + return getRuleContext(SimpleExpressionContext.class,0); + } + public List<StatementContext> statement() { + return getRuleContexts(StatementContext.class); + } + public StatementContext statement(int i) { + return getRuleContext(StatementContext.class,i); + } + public IfStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_ifStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterIfStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitIfStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitIfStmt(this); + else return visitor.visitChildren(this); + } + } + + public final IfStmtContext ifStmt() throws RecognitionException { + IfStmtContext _localctx = new IfStmtContext(_ctx, getState()); + enterRule(_localctx, 22, RULE_ifStmt); + try { + setState(165); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,12,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(151); + match(T__13); + setState(152); + match(T__5); + setState(153); + simpleExpression(); + setState(154); + match(T__6); + setState(155); + statement(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(157); + match(T__13); + setState(158); + match(T__5); + setState(159); + simpleExpression(); + setState(160); + match(T__6); + setState(161); + statement(); + setState(162); + match(T__14); + setState(163); + statement(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class WhileStmtContext extends ParserRuleContext { + public SimpleExpressionContext simpleExpression() { + return getRuleContext(SimpleExpressionContext.class,0); + } + public StatementContext statement() { + return getRuleContext(StatementContext.class,0); + } + public WhileStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_whileStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterWhileStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitWhileStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitWhileStmt(this); + else return visitor.visitChildren(this); + } + } + + public final WhileStmtContext whileStmt() throws RecognitionException { + WhileStmtContext _localctx = new WhileStmtContext(_ctx, getState()); + enterRule(_localctx, 24, RULE_whileStmt); + try { + enterOuterAlt(_localctx, 1); + { + setState(167); + match(T__15); + setState(168); + match(T__5); + setState(169); + simpleExpression(); + setState(170); + match(T__6); + setState(171); + statement(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ReturnStmtContext extends ParserRuleContext { + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public ReturnStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_returnStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterReturnStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitReturnStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitReturnStmt(this); + else return visitor.visitChildren(this); + } + } + + public final ReturnStmtContext returnStmt() throws RecognitionException { + ReturnStmtContext _localctx = new ReturnStmtContext(_ctx, getState()); + enterRule(_localctx, 26, RULE_returnStmt); + try { + setState(179); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,13,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(173); + match(T__16); + setState(174); + match(T__1); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(175); + match(T__16); + setState(176); + expression(); + setState(177); + match(T__1); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class BreakStmtContext extends ParserRuleContext { + public BreakStmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_breakStmt; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterBreakStmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitBreakStmt(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitBreakStmt(this); + else return visitor.visitChildren(this); + } + } + + public final BreakStmtContext breakStmt() throws RecognitionException { + BreakStmtContext _localctx = new BreakStmtContext(_ctx, getState()); + enterRule(_localctx, 28, RULE_breakStmt); + try { + enterOuterAlt(_localctx, 1); + { + setState(181); + match(T__17); + setState(182); + match(T__1); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ExpressionContext extends ParserRuleContext { + public MutableContext mutable() { + return getRuleContext(MutableContext.class,0); + } + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public SimpleExpressionContext simpleExpression() { + return getRuleContext(SimpleExpressionContext.class,0); + } + public ExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_expression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitExpression(this); + else return visitor.visitChildren(this); + } + } + + public final ExpressionContext expression() throws RecognitionException { + ExpressionContext _localctx = new ExpressionContext(_ctx, getState()); + enterRule(_localctx, 30, RULE_expression); + try { + setState(211); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,14,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(184); + mutable(); + setState(185); + match(T__18); + setState(186); + expression(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(188); + mutable(); + setState(189); + match(T__19); + setState(190); + expression(); + } + break; + case 3: + enterOuterAlt(_localctx, 3); + { + setState(192); + mutable(); + setState(193); + match(T__20); + setState(194); + expression(); + } + break; + case 4: + enterOuterAlt(_localctx, 4); + { + setState(196); + mutable(); + setState(197); + match(T__21); + setState(198); + expression(); + } + break; + case 5: + enterOuterAlt(_localctx, 5); + { + setState(200); + mutable(); + setState(201); + match(T__22); + setState(202); + expression(); + } + break; + case 6: + enterOuterAlt(_localctx, 6); + { + setState(204); + mutable(); + setState(205); + match(T__23); + } + break; + case 7: + enterOuterAlt(_localctx, 7); + { + setState(207); + mutable(); + setState(208); + match(T__24); + } + break; + case 8: + enterOuterAlt(_localctx, 8); + { + setState(210); + simpleExpression(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class SimpleExpressionContext extends ParserRuleContext { + public OrExpressionContext orExpression() { + return getRuleContext(OrExpressionContext.class,0); + } + public SimpleExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_simpleExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterSimpleExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitSimpleExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitSimpleExpression(this); + else return visitor.visitChildren(this); + } + } + + public final SimpleExpressionContext simpleExpression() throws RecognitionException { + SimpleExpressionContext _localctx = new SimpleExpressionContext(_ctx, getState()); + enterRule(_localctx, 32, RULE_simpleExpression); + try { + enterOuterAlt(_localctx, 1); + { + setState(213); + orExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class OrExpressionContext extends ParserRuleContext { + public List<AndExpressionContext> andExpression() { + return getRuleContexts(AndExpressionContext.class); + } + public AndExpressionContext andExpression(int i) { + return getRuleContext(AndExpressionContext.class,i); + } + public OrExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_orExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterOrExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitOrExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitOrExpression(this); + else return visitor.visitChildren(this); + } + } + + public final OrExpressionContext orExpression() throws RecognitionException { + OrExpressionContext _localctx = new OrExpressionContext(_ctx, getState()); + enterRule(_localctx, 34, RULE_orExpression); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(220); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,15,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(215); + andExpression(); + setState(216); + match(T__25); + } + } + } + setState(222); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,15,_ctx); + } + setState(223); + andExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class AndExpressionContext extends ParserRuleContext { + public List<UnaryRelExpressionContext> unaryRelExpression() { + return getRuleContexts(UnaryRelExpressionContext.class); + } + public UnaryRelExpressionContext unaryRelExpression(int i) { + return getRuleContext(UnaryRelExpressionContext.class,i); + } + public AndExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_andExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterAndExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitAndExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitAndExpression(this); + else return visitor.visitChildren(this); + } + } + + public final AndExpressionContext andExpression() throws RecognitionException { + AndExpressionContext _localctx = new AndExpressionContext(_ctx, getState()); + enterRule(_localctx, 36, RULE_andExpression); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(230); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,16,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(225); + unaryRelExpression(); + setState(226); + match(T__26); + } + } + } + setState(232); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,16,_ctx); + } + setState(233); + unaryRelExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class UnaryRelExpressionContext extends ParserRuleContext { + public RelExpressionContext relExpression() { + return getRuleContext(RelExpressionContext.class,0); + } + public List<TerminalNode> BANG() { return getTokens(CminusParser.BANG); } + public TerminalNode BANG(int i) { + return getToken(CminusParser.BANG, i); + } + public UnaryRelExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_unaryRelExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterUnaryRelExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitUnaryRelExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitUnaryRelExpression(this); + else return visitor.visitChildren(this); + } + } + + public final UnaryRelExpressionContext unaryRelExpression() throws RecognitionException { + UnaryRelExpressionContext _localctx = new UnaryRelExpressionContext(_ctx, getState()); + enterRule(_localctx, 38, RULE_unaryRelExpression); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(238); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==BANG) { + { + { + setState(235); + match(BANG); + } + } + setState(240); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(241); + relExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class RelExpressionContext extends ParserRuleContext { + public List<SumExpressionContext> sumExpression() { + return getRuleContexts(SumExpressionContext.class); + } + public SumExpressionContext sumExpression(int i) { + return getRuleContext(SumExpressionContext.class,i); + } + public List<RelopContext> relop() { + return getRuleContexts(RelopContext.class); + } + public RelopContext relop(int i) { + return getRuleContext(RelopContext.class,i); + } + public RelExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_relExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterRelExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitRelExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitRelExpression(this); + else return visitor.visitChildren(this); + } + } + + public final RelExpressionContext relExpression() throws RecognitionException { + RelExpressionContext _localctx = new RelExpressionContext(_ctx, getState()); + enterRule(_localctx, 40, RULE_relExpression); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(248); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,18,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(243); + sumExpression(); + setState(244); + relop(); + } + } + } + setState(250); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,18,_ctx); + } + setState(251); + sumExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class RelopContext extends ParserRuleContext { + public RelopContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_relop; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterRelop(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitRelop(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitRelop(this); + else return visitor.visitChildren(this); + } + } + + public final RelopContext relop() throws RecognitionException { + RelopContext _localctx = new RelopContext(_ctx, getState()); + enterRule(_localctx, 42, RULE_relop); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(253); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__27) | (1L << T__28) | (1L << T__29) | (1L << T__30) | (1L << T__31) | (1L << T__32))) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class SumExpressionContext extends ParserRuleContext { + public List<TermExpressionContext> termExpression() { + return getRuleContexts(TermExpressionContext.class); + } + public TermExpressionContext termExpression(int i) { + return getRuleContext(TermExpressionContext.class,i); + } + public List<SumopContext> sumop() { + return getRuleContexts(SumopContext.class); + } + public SumopContext sumop(int i) { + return getRuleContext(SumopContext.class,i); + } + public SumExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_sumExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterSumExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitSumExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitSumExpression(this); + else return visitor.visitChildren(this); + } + } + + public final SumExpressionContext sumExpression() throws RecognitionException { + SumExpressionContext _localctx = new SumExpressionContext(_ctx, getState()); + enterRule(_localctx, 44, RULE_sumExpression); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(260); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,19,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(255); + termExpression(); + setState(256); + sumop(); + } + } + } + setState(262); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,19,_ctx); + } + setState(263); + termExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class SumopContext extends ParserRuleContext { + public SumopContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_sumop; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterSumop(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitSumop(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitSumop(this); + else return visitor.visitChildren(this); + } + } + + public final SumopContext sumop() throws RecognitionException { + SumopContext _localctx = new SumopContext(_ctx, getState()); + enterRule(_localctx, 46, RULE_sumop); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(265); + _la = _input.LA(1); + if ( !(_la==T__33 || _la==T__34) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class TermExpressionContext extends ParserRuleContext { + public List<UnaryExpressionContext> unaryExpression() { + return getRuleContexts(UnaryExpressionContext.class); + } + public UnaryExpressionContext unaryExpression(int i) { + return getRuleContext(UnaryExpressionContext.class,i); + } + public List<MulopContext> mulop() { + return getRuleContexts(MulopContext.class); + } + public MulopContext mulop(int i) { + return getRuleContext(MulopContext.class,i); + } + public TermExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_termExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterTermExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitTermExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitTermExpression(this); + else return visitor.visitChildren(this); + } + } + + public final TermExpressionContext termExpression() throws RecognitionException { + TermExpressionContext _localctx = new TermExpressionContext(_ctx, getState()); + enterRule(_localctx, 48, RULE_termExpression); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(272); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,20,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(267); + unaryExpression(); + setState(268); + mulop(); + } + } + } + setState(274); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,20,_ctx); + } + setState(275); + unaryExpression(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class MulopContext extends ParserRuleContext { + public MulopContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_mulop; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterMulop(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitMulop(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitMulop(this); + else return visitor.visitChildren(this); + } + } + + public final MulopContext mulop() throws RecognitionException { + MulopContext _localctx = new MulopContext(_ctx, getState()); + enterRule(_localctx, 50, RULE_mulop); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(277); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__35) | (1L << T__36) | (1L << T__37))) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class UnaryExpressionContext extends ParserRuleContext { + public FactorContext factor() { + return getRuleContext(FactorContext.class,0); + } + public List<UnaryopContext> unaryop() { + return getRuleContexts(UnaryopContext.class); + } + public UnaryopContext unaryop(int i) { + return getRuleContext(UnaryopContext.class,i); + } + public UnaryExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_unaryExpression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterUnaryExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitUnaryExpression(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitUnaryExpression(this); + else return visitor.visitChildren(this); + } + } + + public final UnaryExpressionContext unaryExpression() throws RecognitionException { + UnaryExpressionContext _localctx = new UnaryExpressionContext(_ctx, getState()); + enterRule(_localctx, 52, RULE_unaryExpression); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(282); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__34) | (1L << T__35) | (1L << T__38))) != 0)) { + { + { + setState(279); + unaryop(); + } + } + setState(284); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(285); + factor(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class UnaryopContext extends ParserRuleContext { + public UnaryopContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_unaryop; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterUnaryop(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitUnaryop(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitUnaryop(this); + else return visitor.visitChildren(this); + } + } + + public final UnaryopContext unaryop() throws RecognitionException { + UnaryopContext _localctx = new UnaryopContext(_ctx, getState()); + enterRule(_localctx, 54, RULE_unaryop); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(287); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__34) | (1L << T__35) | (1L << T__38))) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class FactorContext extends ParserRuleContext { + public ImmutableContext immutable() { + return getRuleContext(ImmutableContext.class,0); + } + public MutableContext mutable() { + return getRuleContext(MutableContext.class,0); + } + public FactorContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_factor; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterFactor(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitFactor(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitFactor(this); + else return visitor.visitChildren(this); + } + } + + public final FactorContext factor() throws RecognitionException { + FactorContext _localctx = new FactorContext(_ctx, getState()); + enterRule(_localctx, 56, RULE_factor); + try { + setState(291); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,22,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(289); + immutable(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(290); + mutable(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class MutableContext extends ParserRuleContext { + public TerminalNode ID() { return getToken(CminusParser.ID, 0); } + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public MutableContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_mutable; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterMutable(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitMutable(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitMutable(this); + else return visitor.visitChildren(this); + } + } + + public final MutableContext mutable() throws RecognitionException { + MutableContext _localctx = new MutableContext(_ctx, getState()); + enterRule(_localctx, 58, RULE_mutable); + try { + setState(299); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,23,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(293); + match(ID); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(294); + match(ID); + setState(295); + match(T__2); + setState(296); + expression(); + setState(297); + match(T__3); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ImmutableContext extends ParserRuleContext { + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public CallContext call() { + return getRuleContext(CallContext.class,0); + } + public ConstantContext constant() { + return getRuleContext(ConstantContext.class,0); + } + public ImmutableContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_immutable; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterImmutable(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitImmutable(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitImmutable(this); + else return visitor.visitChildren(this); + } + } + + public final ImmutableContext immutable() throws RecognitionException { + ImmutableContext _localctx = new ImmutableContext(_ctx, getState()); + enterRule(_localctx, 60, RULE_immutable); + try { + setState(307); + _errHandler.sync(this); + switch (_input.LA(1)) { + case T__5: + enterOuterAlt(_localctx, 1); + { + setState(301); + match(T__5); + setState(302); + expression(); + setState(303); + match(T__6); + } + break; + case ID: + enterOuterAlt(_localctx, 2); + { + setState(305); + call(); + } + break; + case T__39: + case T__40: + case NUMCONST: + case STRINGCONST: + case CHARCONST: + enterOuterAlt(_localctx, 3); + { + setState(306); + constant(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class CallContext extends ParserRuleContext { + public TerminalNode ID() { return getToken(CminusParser.ID, 0); } + public List<ExpressionContext> expression() { + return getRuleContexts(ExpressionContext.class); + } + public ExpressionContext expression(int i) { + return getRuleContext(ExpressionContext.class,i); + } + public CallContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_call; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterCall(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitCall(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitCall(this); + else return visitor.visitChildren(this); + } + } + + public final CallContext call() throws RecognitionException { + CallContext _localctx = new CallContext(_ctx, getState()); + enterRule(_localctx, 62, RULE_call); + int _la; + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(309); + match(ID); + setState(310); + match(T__5); + setState(316); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,25,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(311); + expression(); + setState(312); + match(T__0); + } + } + } + setState(318); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,25,_ctx); + } + setState(320); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__5) | (1L << T__34) | (1L << T__35) | (1L << T__38) | (1L << T__39) | (1L << T__40) | (1L << ID) | (1L << NUMCONST) | (1L << STRINGCONST) | (1L << CHARCONST) | (1L << BANG))) != 0)) { + { + setState(319); + expression(); + } + } + + setState(322); + match(T__6); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static class ConstantContext extends ParserRuleContext { + public TerminalNode NUMCONST() { return getToken(CminusParser.NUMCONST, 0); } + public TerminalNode CHARCONST() { return getToken(CminusParser.CHARCONST, 0); } + public TerminalNode STRINGCONST() { return getToken(CminusParser.STRINGCONST, 0); } + public ConstantContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_constant; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).enterConstant(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof CminusListener ) ((CminusListener)listener).exitConstant(this); + } + @Override + public <T> T accept(ParseTreeVisitor<? extends T> visitor) { + if ( visitor instanceof CminusVisitor ) return ((CminusVisitor<? extends T>)visitor).visitConstant(this); + else return visitor.visitChildren(this); + } + } + + public final ConstantContext constant() throws RecognitionException { + ConstantContext _localctx = new ConstantContext(_ctx, getState()); + enterRule(_localctx, 64, RULE_constant); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(324); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__39) | (1L << T__40) | (1L << NUMCONST) | (1L << STRINGCONST) | (1L << CHARCONST))) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static final String _serializedATN = + "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\62\u0149\4\2\t\2"+ + "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ + "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+ + "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+ + "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+ + "\t!\4\"\t\"\3\2\6\2F\n\2\r\2\16\2G\3\3\3\3\5\3L\n\3\3\4\3\4\3\4\3\4\7"+ + "\4R\n\4\f\4\16\4U\13\4\3\4\3\4\3\5\3\5\3\5\3\5\3\5\5\5^\n\5\3\6\3\6\5"+ + "\6b\n\6\3\6\3\6\3\6\5\6g\n\6\3\6\3\6\7\6k\n\6\f\6\16\6n\13\6\3\6\3\6\3"+ + "\6\3\7\3\7\3\b\3\b\3\b\3\t\3\t\3\t\5\t{\n\t\3\n\3\n\3\n\3\n\3\n\3\n\5"+ + "\n\u0083\n\n\3\13\3\13\7\13\u0087\n\13\f\13\16\13\u008a\13\13\3\13\7\13"+ + "\u008d\n\13\f\13\16\13\u0090\13\13\3\13\3\13\3\f\3\f\3\f\3\f\5\f\u0098"+ + "\n\f\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\5\r\u00a8"+ + "\n\r\3\16\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3\17\3\17\5\17"+ + "\u00b6\n\17\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21"+ + "\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21"+ + "\3\21\3\21\3\21\3\21\5\21\u00d6\n\21\3\22\3\22\3\23\3\23\3\23\7\23\u00dd"+ + "\n\23\f\23\16\23\u00e0\13\23\3\23\3\23\3\24\3\24\3\24\7\24\u00e7\n\24"+ + "\f\24\16\24\u00ea\13\24\3\24\3\24\3\25\7\25\u00ef\n\25\f\25\16\25\u00f2"+ + "\13\25\3\25\3\25\3\26\3\26\3\26\7\26\u00f9\n\26\f\26\16\26\u00fc\13\26"+ + "\3\26\3\26\3\27\3\27\3\30\3\30\3\30\7\30\u0105\n\30\f\30\16\30\u0108\13"+ + "\30\3\30\3\30\3\31\3\31\3\32\3\32\3\32\7\32\u0111\n\32\f\32\16\32\u0114"+ + "\13\32\3\32\3\32\3\33\3\33\3\34\7\34\u011b\n\34\f\34\16\34\u011e\13\34"+ + "\3\34\3\34\3\35\3\35\3\36\3\36\5\36\u0126\n\36\3\37\3\37\3\37\3\37\3\37"+ + "\3\37\5\37\u012e\n\37\3 \3 \3 \3 \3 \3 \5 \u0136\n \3!\3!\3!\3!\3!\7!"+ + "\u013d\n!\f!\16!\u0140\13!\3!\5!\u0143\n!\3!\3!\3\"\3\"\3\"\2\2#\2\4\6"+ + "\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\668:<>@B\2\b\3\2\n"+ + "\f\3\2\36#\3\2$%\3\2&(\4\2%&))\4\2*+-/\2\u014d\2E\3\2\2\2\4K\3\2\2\2\6"+ + "M\3\2\2\2\b]\3\2\2\2\na\3\2\2\2\fr\3\2\2\2\16t\3\2\2\2\20z\3\2\2\2\22"+ + "\u0082\3\2\2\2\24\u0084\3\2\2\2\26\u0097\3\2\2\2\30\u00a7\3\2\2\2\32\u00a9"+ + "\3\2\2\2\34\u00b5\3\2\2\2\36\u00b7\3\2\2\2 \u00d5\3\2\2\2\"\u00d7\3\2"+ + "\2\2$\u00de\3\2\2\2&\u00e8\3\2\2\2(\u00f0\3\2\2\2*\u00fa\3\2\2\2,\u00ff"+ + "\3\2\2\2.\u0106\3\2\2\2\60\u010b\3\2\2\2\62\u0112\3\2\2\2\64\u0117\3\2"+ + "\2\2\66\u011c\3\2\2\28\u0121\3\2\2\2:\u0125\3\2\2\2<\u012d\3\2\2\2>\u0135"+ + "\3\2\2\2@\u0137\3\2\2\2B\u0146\3\2\2\2DF\5\4\3\2ED\3\2\2\2FG\3\2\2\2G"+ + "E\3\2\2\2GH\3\2\2\2H\3\3\2\2\2IL\5\6\4\2JL\5\n\6\2KI\3\2\2\2KJ\3\2\2\2"+ + "L\5\3\2\2\2MN\5\f\7\2NS\5\b\5\2OP\7\3\2\2PR\5\b\5\2QO\3\2\2\2RU\3\2\2"+ + "\2SQ\3\2\2\2ST\3\2\2\2TV\3\2\2\2US\3\2\2\2VW\7\4\2\2W\7\3\2\2\2X^\7,\2"+ + "\2YZ\7,\2\2Z[\7\5\2\2[\\\7-\2\2\\^\7\6\2\2]X\3\2\2\2]Y\3\2\2\2^\t\3\2"+ + "\2\2_b\7\7\2\2`b\5\f\7\2a_\3\2\2\2a`\3\2\2\2bc\3\2\2\2cd\7,\2\2df\7\b"+ + "\2\2eg\5\16\b\2fe\3\2\2\2fg\3\2\2\2gl\3\2\2\2hi\7\3\2\2ik\5\16\b\2jh\3"+ + "\2\2\2kn\3\2\2\2lj\3\2\2\2lm\3\2\2\2mo\3\2\2\2nl\3\2\2\2op\7\t\2\2pq\5"+ + "\22\n\2q\13\3\2\2\2rs\t\2\2\2s\r\3\2\2\2tu\5\f\7\2uv\5\20\t\2v\17\3\2"+ + "\2\2w{\7,\2\2xy\7,\2\2y{\7\r\2\2zw\3\2\2\2zx\3\2\2\2{\21\3\2\2\2|\u0083"+ + "\5\26\f\2}\u0083\5\24\13\2~\u0083\5\30\r\2\177\u0083\5\32\16\2\u0080\u0083"+ + "\5\34\17\2\u0081\u0083\5\36\20\2\u0082|\3\2\2\2\u0082}\3\2\2\2\u0082~"+ + "\3\2\2\2\u0082\177\3\2\2\2\u0082\u0080\3\2\2\2\u0082\u0081\3\2\2\2\u0083"+ + "\23\3\2\2\2\u0084\u0088\7\16\2\2\u0085\u0087\5\6\4\2\u0086\u0085\3\2\2"+ + "\2\u0087\u008a\3\2\2\2\u0088\u0086\3\2\2\2\u0088\u0089\3\2\2\2\u0089\u008e"+ + "\3\2\2\2\u008a\u0088\3\2\2\2\u008b\u008d\5\22\n\2\u008c\u008b\3\2\2\2"+ + "\u008d\u0090\3\2\2\2\u008e\u008c\3\2\2\2\u008e\u008f\3\2\2\2\u008f\u0091"+ + "\3\2\2\2\u0090\u008e\3\2\2\2\u0091\u0092\7\17\2\2\u0092\25\3\2\2\2\u0093"+ + "\u0094\5 \21\2\u0094\u0095\7\4\2\2\u0095\u0098\3\2\2\2\u0096\u0098\7\4"+ + "\2\2\u0097\u0093\3\2\2\2\u0097\u0096\3\2\2\2\u0098\27\3\2\2\2\u0099\u009a"+ + "\7\20\2\2\u009a\u009b\7\b\2\2\u009b\u009c\5\"\22\2\u009c\u009d\7\t\2\2"+ + "\u009d\u009e\5\22\n\2\u009e\u00a8\3\2\2\2\u009f\u00a0\7\20\2\2\u00a0\u00a1"+ + "\7\b\2\2\u00a1\u00a2\5\"\22\2\u00a2\u00a3\7\t\2\2\u00a3\u00a4\5\22\n\2"+ + "\u00a4\u00a5\7\21\2\2\u00a5\u00a6\5\22\n\2\u00a6\u00a8\3\2\2\2\u00a7\u0099"+ + "\3\2\2\2\u00a7\u009f\3\2\2\2\u00a8\31\3\2\2\2\u00a9\u00aa\7\22\2\2\u00aa"+ + "\u00ab\7\b\2\2\u00ab\u00ac\5\"\22\2\u00ac\u00ad\7\t\2\2\u00ad\u00ae\5"+ + "\22\n\2\u00ae\33\3\2\2\2\u00af\u00b0\7\23\2\2\u00b0\u00b6\7\4\2\2\u00b1"+ + "\u00b2\7\23\2\2\u00b2\u00b3\5 \21\2\u00b3\u00b4\7\4\2\2\u00b4\u00b6\3"+ + "\2\2\2\u00b5\u00af\3\2\2\2\u00b5\u00b1\3\2\2\2\u00b6\35\3\2\2\2\u00b7"+ + "\u00b8\7\24\2\2\u00b8\u00b9\7\4\2\2\u00b9\37\3\2\2\2\u00ba\u00bb\5<\37"+ + "\2\u00bb\u00bc\7\25\2\2\u00bc\u00bd\5 \21\2\u00bd\u00d6\3\2\2\2\u00be"+ + "\u00bf\5<\37\2\u00bf\u00c0\7\26\2\2\u00c0\u00c1\5 \21\2\u00c1\u00d6\3"+ + "\2\2\2\u00c2\u00c3\5<\37\2\u00c3\u00c4\7\27\2\2\u00c4\u00c5\5 \21\2\u00c5"+ + "\u00d6\3\2\2\2\u00c6\u00c7\5<\37\2\u00c7\u00c8\7\30\2\2\u00c8\u00c9\5"+ + " \21\2\u00c9\u00d6\3\2\2\2\u00ca\u00cb\5<\37\2\u00cb\u00cc\7\31\2\2\u00cc"+ + "\u00cd\5 \21\2\u00cd\u00d6\3\2\2\2\u00ce\u00cf\5<\37\2\u00cf\u00d0\7\32"+ + "\2\2\u00d0\u00d6\3\2\2\2\u00d1\u00d2\5<\37\2\u00d2\u00d3\7\33\2\2\u00d3"+ + "\u00d6\3\2\2\2\u00d4\u00d6\5\"\22\2\u00d5\u00ba\3\2\2\2\u00d5\u00be\3"+ + "\2\2\2\u00d5\u00c2\3\2\2\2\u00d5\u00c6\3\2\2\2\u00d5\u00ca\3\2\2\2\u00d5"+ + "\u00ce\3\2\2\2\u00d5\u00d1\3\2\2\2\u00d5\u00d4\3\2\2\2\u00d6!\3\2\2\2"+ + "\u00d7\u00d8\5$\23\2\u00d8#\3\2\2\2\u00d9\u00da\5&\24\2\u00da\u00db\7"+ + "\34\2\2\u00db\u00dd\3\2\2\2\u00dc\u00d9\3\2\2\2\u00dd\u00e0\3\2\2\2\u00de"+ + "\u00dc\3\2\2\2\u00de\u00df\3\2\2\2\u00df\u00e1\3\2\2\2\u00e0\u00de\3\2"+ + "\2\2\u00e1\u00e2\5&\24\2\u00e2%\3\2\2\2\u00e3\u00e4\5(\25\2\u00e4\u00e5"+ + "\7\35\2\2\u00e5\u00e7\3\2\2\2\u00e6\u00e3\3\2\2\2\u00e7\u00ea\3\2\2\2"+ + "\u00e8\u00e6\3\2\2\2\u00e8\u00e9\3\2\2\2\u00e9\u00eb\3\2\2\2\u00ea\u00e8"+ + "\3\2\2\2\u00eb\u00ec\5(\25\2\u00ec\'\3\2\2\2\u00ed\u00ef\7\60\2\2\u00ee"+ + "\u00ed\3\2\2\2\u00ef\u00f2\3\2\2\2\u00f0\u00ee\3\2\2\2\u00f0\u00f1\3\2"+ + "\2\2\u00f1\u00f3\3\2\2\2\u00f2\u00f0\3\2\2\2\u00f3\u00f4\5*\26\2\u00f4"+ + ")\3\2\2\2\u00f5\u00f6\5.\30\2\u00f6\u00f7\5,\27\2\u00f7\u00f9\3\2\2\2"+ + "\u00f8\u00f5\3\2\2\2\u00f9\u00fc\3\2\2\2\u00fa\u00f8\3\2\2\2\u00fa\u00fb"+ + "\3\2\2\2\u00fb\u00fd\3\2\2\2\u00fc\u00fa\3\2\2\2\u00fd\u00fe\5.\30\2\u00fe"+ + "+\3\2\2\2\u00ff\u0100\t\3\2\2\u0100-\3\2\2\2\u0101\u0102\5\62\32\2\u0102"+ + "\u0103\5\60\31\2\u0103\u0105\3\2\2\2\u0104\u0101\3\2\2\2\u0105\u0108\3"+ + "\2\2\2\u0106\u0104\3\2\2\2\u0106\u0107\3\2\2\2\u0107\u0109\3\2\2\2\u0108"+ + "\u0106\3\2\2\2\u0109\u010a\5\62\32\2\u010a/\3\2\2\2\u010b\u010c\t\4\2"+ + "\2\u010c\61\3\2\2\2\u010d\u010e\5\66\34\2\u010e\u010f\5\64\33\2\u010f"+ + "\u0111\3\2\2\2\u0110\u010d\3\2\2\2\u0111\u0114\3\2\2\2\u0112\u0110\3\2"+ + "\2\2\u0112\u0113\3\2\2\2\u0113\u0115\3\2\2\2\u0114\u0112\3\2\2\2\u0115"+ + "\u0116\5\66\34\2\u0116\63\3\2\2\2\u0117\u0118\t\5\2\2\u0118\65\3\2\2\2"+ + "\u0119\u011b\58\35\2\u011a\u0119\3\2\2\2\u011b\u011e\3\2\2\2\u011c\u011a"+ + "\3\2\2\2\u011c\u011d\3\2\2\2\u011d\u011f\3\2\2\2\u011e\u011c\3\2\2\2\u011f"+ + "\u0120\5:\36\2\u0120\67\3\2\2\2\u0121\u0122\t\6\2\2\u01229\3\2\2\2\u0123"+ + "\u0126\5> \2\u0124\u0126\5<\37\2\u0125\u0123\3\2\2\2\u0125\u0124\3\2\2"+ + "\2\u0126;\3\2\2\2\u0127\u012e\7,\2\2\u0128\u0129\7,\2\2\u0129\u012a\7"+ + "\5\2\2\u012a\u012b\5 \21\2\u012b\u012c\7\6\2\2\u012c\u012e\3\2\2\2\u012d"+ + "\u0127\3\2\2\2\u012d\u0128\3\2\2\2\u012e=\3\2\2\2\u012f\u0130\7\b\2\2"+ + "\u0130\u0131\5 \21\2\u0131\u0132\7\t\2\2\u0132\u0136\3\2\2\2\u0133\u0136"+ + "\5@!\2\u0134\u0136\5B\"\2\u0135\u012f\3\2\2\2\u0135\u0133\3\2\2\2\u0135"+ + "\u0134\3\2\2\2\u0136?\3\2\2\2\u0137\u0138\7,\2\2\u0138\u013e\7\b\2\2\u0139"+ + "\u013a\5 \21\2\u013a\u013b\7\3\2\2\u013b\u013d\3\2\2\2\u013c\u0139\3\2"+ + "\2\2\u013d\u0140\3\2\2\2\u013e\u013c\3\2\2\2\u013e\u013f\3\2\2\2\u013f"+ + "\u0142\3\2\2\2\u0140\u013e\3\2\2\2\u0141\u0143\5 \21\2\u0142\u0141\3\2"+ + "\2\2\u0142\u0143\3\2\2\2\u0143\u0144\3\2\2\2\u0144\u0145\7\t\2\2\u0145"+ + "A\3\2\2\2\u0146\u0147\t\7\2\2\u0147C\3\2\2\2\35GKS]aflz\u0082\u0088\u008e"+ + "\u0097\u00a7\u00b5\u00d5\u00de\u00e8\u00f0\u00fa\u0106\u0112\u011c\u0125"+ + "\u012d\u0135\u013e\u0142"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/parser/CminusVisitor.java b/Homework/cs5300/p4-formatter/parser/CminusVisitor.java new file mode 100644 index 0000000..9088695 --- /dev/null +++ b/Homework/cs5300/p4-formatter/parser/CminusVisitor.java @@ -0,0 +1,211 @@ +// Generated from Cminus.g4 by ANTLR 4.9.1 +package parser; +import org.antlr.v4.runtime.tree.ParseTreeVisitor; + +/** + * This interface defines a complete generic visitor for a parse tree produced + * by {@link CminusParser}. + * + * @param <T> The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public interface CminusVisitor<T> extends ParseTreeVisitor<T> { + /** + * Visit a parse tree produced by {@link CminusParser#program}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitProgram(CminusParser.ProgramContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#declaration}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitDeclaration(CminusParser.DeclarationContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#varDeclaration}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitVarDeclaration(CminusParser.VarDeclarationContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#varDeclId}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitVarDeclId(CminusParser.VarDeclIdContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#funDeclaration}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFunDeclaration(CminusParser.FunDeclarationContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#typeSpecifier}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitTypeSpecifier(CminusParser.TypeSpecifierContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#param}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitParam(CminusParser.ParamContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#paramId}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitParamId(CminusParser.ParamIdContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#statement}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitStatement(CminusParser.StatementContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#compoundStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitCompoundStmt(CminusParser.CompoundStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#expressionStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExpressionStmt(CminusParser.ExpressionStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#ifStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitIfStmt(CminusParser.IfStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#whileStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitWhileStmt(CminusParser.WhileStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#returnStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitReturnStmt(CminusParser.ReturnStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#breakStmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBreakStmt(CminusParser.BreakStmtContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#expression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExpression(CminusParser.ExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#simpleExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitSimpleExpression(CminusParser.SimpleExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#orExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitOrExpression(CminusParser.OrExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#andExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitAndExpression(CminusParser.AndExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#unaryRelExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#relExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitRelExpression(CminusParser.RelExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#relop}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitRelop(CminusParser.RelopContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#sumExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitSumExpression(CminusParser.SumExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#sumop}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitSumop(CminusParser.SumopContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#termExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitTermExpression(CminusParser.TermExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#mulop}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMulop(CminusParser.MulopContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#unaryExpression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitUnaryExpression(CminusParser.UnaryExpressionContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#unaryop}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitUnaryop(CminusParser.UnaryopContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#factor}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFactor(CminusParser.FactorContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#mutable}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMutable(CminusParser.MutableContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#immutable}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitImmutable(CminusParser.ImmutableContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#call}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitCall(CminusParser.CallContext ctx); + /** + * Visit a parse tree produced by {@link CminusParser#constant}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitConstant(CminusParser.ConstantContext ctx); +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/submit.zip b/Homework/cs5300/p4-formatter/submit.zip Binary files differnew file mode 100644 index 0000000..bc671f4 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit.zip diff --git a/Homework/cs5300/p4-formatter/submit/ASTVisitor.java b/Homework/cs5300/p4-formatter/submit/ASTVisitor.java new file mode 100644 index 0000000..7f6d020 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ASTVisitor.java @@ -0,0 +1,239 @@ +package submit; + +import parser.CminusBaseVisitor; +import parser.CminusParser; +import submit.ast.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +public class ASTVisitor extends CminusBaseVisitor<Node> { + private final Logger LOGGER; + private SymbolTable symbolTable; + + public ASTVisitor(Logger LOGGER) { + this.LOGGER = LOGGER; + } + + private VarType getVarType(CminusParser.TypeSpecifierContext ctx) { + final String t = ctx.getText(); + return (t.equals("int")) ? VarType.INT : (t.equals("bool")) ? VarType.BOOL : VarType.CHAR; + } + + @Override + public Node visitProgram(CminusParser.ProgramContext ctx) { + symbolTable = new SymbolTable(); + List<Declaration> decls = new ArrayList<>(); + for (CminusParser.DeclarationContext d : ctx.declaration()) + decls.add((Declaration) visitDeclaration(d)); + return new Program(decls); + } + + @Override + public Node visitVarDeclaration(CminusParser.VarDeclarationContext ctx) { + VarType type = getVarType(ctx.typeSpecifier()); + List<String> ids = new ArrayList<>(); + List<Integer> arraySizes = new ArrayList<>(); + for (CminusParser.VarDeclIdContext v : ctx.varDeclId()) { + String id = v.ID().getText(); + ids.add(id); + symbolTable.addSymbol(id, new SymbolInfo(id, type, false)); + if (v.NUMCONST() != null) + arraySizes.add(Integer.parseInt(v.NUMCONST().getText())); + else + arraySizes.add(-1); + } + final boolean isStatic = false; + return new VarDeclaration(type, ids, arraySizes, isStatic); + } + + @Override + public Node visitReturnStmt(CminusParser.ReturnStmtContext ctx) { + if (ctx.expression() != null) + return new Return((Expression) visitExpression(ctx.expression())); + return new Return(null); + } + + @Override + public Node visitConstant(CminusParser.ConstantContext ctx) { + final Node node; + if (ctx.NUMCONST() != null) + node = new NumConstant(Integer.parseInt(ctx.NUMCONST().getText())); + else if (ctx.CHARCONST() != null) + node = new CharConstant(ctx.CHARCONST().getText().charAt(0)); + else if (ctx.STRINGCONST() != null) + node = new StringConstant(ctx.STRINGCONST().getText()); + else + node = new BoolConstant(ctx.getText().equals("true")); + return node; + } + + @Override + public Node visitFunDeclaration(CminusParser.FunDeclarationContext ctx) { + VarType rType = VarType.VOID; + if (ctx.typeSpecifier() != null) + rType = VarType.fromString(ctx.typeSpecifier().getText()); + String id = ctx.ID().getText(); + + symbolTable.addSymbol(id, new SymbolInfo(id, rType, true)); + symbolTable = symbolTable.createChild(); + + List<Param> params = ctx.param().stream().map(pCtx -> (Param) visitParam(pCtx)).collect(Collectors.toList()); + Statement statement = (Statement) visitStatement(ctx.statement()); + + symbolTable = symbolTable.getParent(); + return new FunctionDeclaration(rType, id, params, statement); + } + + @Override + public Node visitParam(CminusParser.ParamContext ctx) { + VarType pType = getVarType(ctx.typeSpecifier()); + + String pId = ctx.paramId().getText(); + Boolean isArray = pId.endsWith("[]"); + if (isArray) + pId = pId.substring(0, pId.length() - 2); + + symbolTable.addSymbol(pId, new SymbolInfo(pId, pType, false)); + + return new Param(pType, pId, isArray); + } + + @Override + public Node visitStatement(CminusParser.StatementContext ctx) { + if (ctx.expressionStmt() != null) + return new ExpressionStatement((Expression) visitExpression(ctx.expressionStmt().expression())); + if (ctx.compoundStmt() != null) { + CminusParser.CompoundStmtContext cCtx = ctx.compoundStmt(); + + symbolTable = symbolTable.createChild(); + + List<VarDeclaration> varDecls = cCtx.varDeclaration().stream() + .map(declCtx -> (VarDeclaration) visitVarDeclaration(declCtx)).collect(Collectors.toList()); + + List<Statement> statements = cCtx.statement().stream().map(stmtCtx -> (Statement) visitStatement(stmtCtx)) + .collect(Collectors.toList()); + + symbolTable = symbolTable.getParent(); + + return new CompoundStatement(varDecls, statements); + } + if (ctx.ifStmt() != null) { + List<Statement> statements = ctx.ifStmt().statement().stream() + .map(stmtCtx -> (Statement) visitStatement(stmtCtx)).collect(Collectors.toList()); + return new IfStatement((Expression) visitSimpleExpression(ctx.ifStmt().simpleExpression()), statements); + } + if (ctx.whileStmt() != null) + return new WhileStatement((Expression) visitSimpleExpression(ctx.whileStmt().simpleExpression()), + (Statement) visitStatement(ctx.whileStmt().statement())); + if (ctx.returnStmt() != null) { + if (ctx.returnStmt().expression() != null) + return new Return((Expression) visitExpression(ctx.returnStmt().expression())); + return new Return(null); + } + if (ctx.breakStmt() != null) + return new Break(); + return null; + } + + @Override + public Node visitExpression(CminusParser.ExpressionContext ctx) { + if (ctx.mutable() != null && ctx.expression() != null) + return new ExpressionExpression((Mutable) visitMutable(ctx.mutable()), + (Expression) visitExpression(ctx.expression()), ctx.getChild(1).getText()); + else if (ctx.mutable() != null) + return new ExpressionExpression((Mutable) visitMutable(ctx.mutable()), ctx.getChild(1).getText()); + return visitSimpleExpression(ctx.simpleExpression()); + } + + @Override + public Node visitMutable(CminusParser.MutableContext ctx) { + String id = ctx.ID().getText(); + + if (symbolTable.find(id) == null) + LOGGER.warning("Undefined symbol on line " + ctx.getStart().getLine() + ": " + id); + + return new Mutable(id, + ctx.expression() != null ? (Expression) visitExpression(ctx.expression()) : null); + } + + @Override + public Node visitOrExpression(CminusParser.OrExpressionContext ctx) { + List<AndExpression> andExpressions = ctx.andExpression().stream().map(andExpression -> { + List<UnaryRelExpression> uRE = andExpression.unaryRelExpression().stream() + .map(unaryRelExpressionCtx -> (UnaryRelExpression) visitUnaryRelExpression(unaryRelExpressionCtx)) + .collect(Collectors.toList()); + return new AndExpression(uRE); + }).collect(Collectors.toList()); + + return new OrExpression(andExpressions); + } + + @Override + public Node visitUnaryRelExpression(CminusParser.UnaryRelExpressionContext ctx) { + int bangs = ctx.BANG().size(); + RelExpression relExpression = (RelExpression) visitRelExpression(ctx.relExpression()); + return new UnaryRelExpression(bangs, relExpression); + } + + @Override + public Node visitRelExpression(CminusParser.RelExpressionContext ctx) { + List<BinaryOperatorType> relOps = ctx.relop().stream() + .map(operatorContext -> BinaryOperatorType.fromString(operatorContext.getText())) + .collect(Collectors.toList()); + List<SumExpression> sumExpressions = ctx.sumExpression().stream().map(sumExpressionCtx -> { + List<BinaryOperatorType> sumOps = sumExpressionCtx.sumop().stream() + .map(operatorContext -> BinaryOperatorType.fromString(operatorContext.getText())) + .collect(Collectors.toList()); + List<TermExpression> termExprs = sumExpressionCtx.termExpression().stream() + .map(termExprCtx -> (TermExpression) visitTermExpression(termExprCtx)).collect(Collectors.toList()); + return new SumExpression(sumOps, termExprs); + }).collect(Collectors.toList()); + + return new RelExpression(sumExpressions, relOps); + } + + public Node visitTermExpression(CminusParser.TermExpressionContext ctx) { + List<BinaryOperatorType> mulOps = ctx.mulop().stream() + .map(operatorContext -> BinaryOperatorType.fromString(operatorContext.getText())) + .collect(Collectors.toList()); + List<UnaryExpression> unaryExpressions = ctx.unaryExpression().stream().map(unaryExpressionCtx -> { + List<String> unaryOps = unaryExpressionCtx.unaryop().stream() + .map(operatorContext -> operatorContext.getText()) + .collect(Collectors.toList()); + Factor factor = (Factor) visitFactor(unaryExpressionCtx.factor()); + + return new UnaryExpression(unaryOps, factor); + }).collect(Collectors.toList()); + + return new TermExpression(unaryExpressions, mulOps); + } + + public Node visitFactor(CminusParser.FactorContext ctx) { + if (ctx.immutable() != null) + return new Factor((Immutable) visitImmutable(ctx.immutable())); + return new Factor((Mutable) visitMutable(ctx.mutable())); + } + + public Node visitImmutable(CminusParser.ImmutableContext ctx) { + if (ctx.constant() != null) + return new Immutable((Constant) visitConstant(ctx.constant())); + + if (ctx.call() != null) + return new Immutable((Call) visitCall(ctx.call()), true); + + return new Immutable((Expression) visitExpression(ctx.expression())); + } + + public Node visitCall(CminusParser.CallContext ctx) { + String id = ctx.ID().getText(); + + if (symbolTable.find(id) == null) + LOGGER.warning("Undefined symbol on line " + ctx.getStart().getLine() + ": " + id); + + return new Call(id, ctx.expression().stream() + .map(exprCtx -> (Expression) visitExpression(exprCtx)).collect(Collectors.toList())); + } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/submit/SymbolInfo.java b/Homework/cs5300/p4-formatter/submit/SymbolInfo.java new file mode 100644 index 0000000..19c3f9b --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/SymbolInfo.java @@ -0,0 +1,31 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit; + +import submit.ast.VarType; + +/** + * + * @author edwajohn + */ +public class SymbolInfo { + + private final String id; + // In the case of a function, type is the return type + private final VarType type; + private final boolean function; + + public SymbolInfo(String id, VarType type, boolean function) { + this.id = id; + this.type = type; + this.function = function; + } + + @Override + public String toString() { + return "<" + id + ", " + type + '>'; + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/SymbolTable.java b/Homework/cs5300/p4-formatter/submit/SymbolTable.java new file mode 100644 index 0000000..bfa531e --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/SymbolTable.java @@ -0,0 +1,55 @@ +package submit; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/* + * Code formatter project + * CS 4481 + */ +public class SymbolTable { + + private final HashMap<String, SymbolInfo> table; + private SymbolTable parent; + private final List<SymbolTable> children; + + public SymbolTable() { + table = new HashMap<>(); + parent = null; + children = new ArrayList<>(); + } + + public void addSymbol(String id, SymbolInfo symbol) { table.put(id, symbol); } + + /** + * Returns null if no symbol with that id is in this symbol table or an + * ancestor table. + * + * @param id + * @return + */ + public SymbolInfo find(String id) { + if (table.containsKey(id)) { + return table.get(id); + } + if (parent != null) { + return parent.find(id); + } + return null; + } + + /** + * Returns the new child. + * + * @return + */ + public SymbolTable createChild() { + SymbolTable child = new SymbolTable(); + children.add(child); + child.parent = this; + return child; + } + + public SymbolTable getParent() { return parent; } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/AndExpression.java b/Homework/cs5300/p4-formatter/submit/ast/AndExpression.java new file mode 100644 index 0000000..515dad9 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/AndExpression.java @@ -0,0 +1,18 @@ +package submit.ast; + +import java.util.List; +import java.util.ArrayList; + +public class AndExpression implements Expression { + private List<UnaryRelExpression> unaryRelExpressions; + + public AndExpression(List<UnaryRelExpression> unaryRelExpressions) { + this.unaryRelExpressions = new ArrayList<>(unaryRelExpressions); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + Expression.joinExpressions(BinaryOperatorType.AND, new ArrayList<Expression>(unaryRelExpressions), builder); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/BinaryOperator.java b/Homework/cs5300/p4-formatter/submit/ast/BinaryOperator.java new file mode 100644 index 0000000..747b3ba --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/BinaryOperator.java @@ -0,0 +1,35 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class BinaryOperator implements Expression { + + private final Expression lhs, rhs; + private final BinaryOperatorType type; + + public BinaryOperator(Expression lhs, BinaryOperatorType type, Expression rhs) { + this.lhs = lhs; + this.type = type; + this.rhs = rhs; + } + + public BinaryOperator(Expression lhs, String type, Expression rhs) { + this.lhs = lhs; + this.type = BinaryOperatorType.fromString(type); + this.rhs = rhs; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + lhs.toCminus(builder, prefix); + builder.append(" ").append(type).append(" "); + rhs.toCminus(builder, prefix); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/BinaryOperatorType.java b/Homework/cs5300/p4-formatter/submit/ast/BinaryOperatorType.java new file mode 100644 index 0000000..37235c8 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/BinaryOperatorType.java @@ -0,0 +1,37 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public enum BinaryOperatorType { + + OR("||"), AND("&&"), + LE("<="), LT("<"), GT(">"), GE(">="), EQ("=="), NE("!="), + PLUS("+"), MINUS("-"), TIMES("*"), DIVIDE("/"), MOD("%"); + + private final String value; + + private BinaryOperatorType(String value) { + this.value = value; + } + + public static BinaryOperatorType fromString(String s) { + for (BinaryOperatorType at : BinaryOperatorType.values()) { + if (at.value.equals(s)) { + return at; + } + } + throw new RuntimeException("Illegal string in OperatorType.fromString(): " + s); + } + + @Override + public String toString() { + return value; + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/BoolConstant.java b/Homework/cs5300/p4-formatter/submit/ast/BoolConstant.java new file mode 100644 index 0000000..01a7591 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/BoolConstant.java @@ -0,0 +1,27 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class BoolConstant implements Expression, Constant { + + private final boolean value; + + public BoolConstant(boolean value) { + this.value = value; + } + + public void toCminus(StringBuilder builder, final String prefix) { + if (value) { + builder.append("true"); + } else { + builder.append("false"); + } + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Break.java b/Homework/cs5300/p4-formatter/submit/ast/Break.java new file mode 100644 index 0000000..7e86a71 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Break.java @@ -0,0 +1,9 @@ +package submit.ast; + +public class Break implements Statement { + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + + builder.append("break;\n"); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Call.java b/Homework/cs5300/p4-formatter/submit/ast/Call.java new file mode 100644 index 0000000..b5c8a37 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Call.java @@ -0,0 +1,26 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class Call implements Expression { + ArrayList<Expression> expressions; + String id; + + public Call(String id, List<Expression> expressions) { + this.id = id; + this.expressions = new ArrayList<>(expressions); + } + + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + builder.append(id).append("("); + int numExpr = expressions.size(); + if (numExpr > 0) + expressions.get(0).toCminus(builder, ""); + if (numExpr > 1) + for (Expression expr : expressions.subList(1, numExpr)) + expr.toCminus(builder, ", "); + builder.append(")"); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/CharConstant.java b/Homework/cs5300/p4-formatter/submit/ast/CharConstant.java new file mode 100644 index 0000000..a0ccb37 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/CharConstant.java @@ -0,0 +1,23 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class CharConstant implements Expression, Constant { + + private final char value; + + public CharConstant(char value) { + this.value = value; + } + + public void toCminus(StringBuilder builder, final String prefix) { + builder.append("'").append(value).append("'"); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/CompoundStatement.java b/Homework/cs5300/p4-formatter/submit/ast/CompoundStatement.java new file mode 100644 index 0000000..02fa298 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/CompoundStatement.java @@ -0,0 +1,28 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class CompoundStatement implements Statement { + ArrayList<VarDeclaration> varDecls; + ArrayList<Statement> statements; + + public CompoundStatement(List<VarDeclaration> varDecls, List<Statement> statements) { + this.varDecls = new ArrayList<>(varDecls); + this.statements = new ArrayList<>(statements); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + builder.append("{").append("\n"); + for (VarDeclaration varDecl : varDecls) + varDecl.toCminus(builder, prefix + "\t"); + + for (Statement statement : statements) + statement.toCminus(builder, prefix + "\t"); + + builder.append(prefix).append("}").append("\n"); + + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Constant.java b/Homework/cs5300/p4-formatter/submit/ast/Constant.java new file mode 100644 index 0000000..bb30412 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Constant.java @@ -0,0 +1,5 @@ +package submit.ast; + +public interface Constant extends Node { + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Declaration.java b/Homework/cs5300/p4-formatter/submit/ast/Declaration.java new file mode 100644 index 0000000..c70e856 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Declaration.java @@ -0,0 +1,13 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public interface Declaration extends Statement, Node { + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Expression.java b/Homework/cs5300/p4-formatter/submit/ast/Expression.java new file mode 100644 index 0000000..1c2ba9b --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Expression.java @@ -0,0 +1,37 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * + * @author edwajohn, simponic :3 + */ +public interface Expression extends Node { + public static void joinExpressionOperatorLists(List<BinaryOperatorType> binaryOperatorTypes, List<Expression> exprs, + StringBuilder builder) { + int numExpr = exprs.size(); + Expression lhs = exprs.get(0); + if (numExpr == 1) + lhs.toCminus(builder, ""); + if (numExpr > 1) { + BinaryOperator binOp = null; + for (int i = 0; i < binaryOperatorTypes.size(); i++) { + binOp = new BinaryOperator(lhs, binaryOperatorTypes.get(i), exprs.get(i + 1)); + lhs = binOp; + } + binOp.toCminus(builder, ""); + } + } + + public static void joinExpressions(BinaryOperatorType binaryOperatorType, List<Expression> exprs, + StringBuilder builder) { + Expression.joinExpressionOperatorLists(Arrays.asList(new BinaryOperatorType[exprs.size() - 1]).stream() + .map(e -> binaryOperatorType).collect(Collectors.toList()), exprs, builder); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/ExpressionExpression.java b/Homework/cs5300/p4-formatter/submit/ast/ExpressionExpression.java new file mode 100644 index 0000000..cc79a1d --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/ExpressionExpression.java @@ -0,0 +1,31 @@ +package submit.ast; + +public class ExpressionExpression implements Expression { + private Mutable mutable; + private Expression expression; + private String op; + + public ExpressionExpression(Mutable mutable, Expression expression, String op) { + this.mutable = mutable; + this.expression = expression; + this.op = op; + } + + public ExpressionExpression(Mutable mutable, String op) { + this.mutable = mutable; + this.op = op; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + mutable.toCminus(builder, ""); + if (op != null && expression != null) + builder.append(" "); + builder.append(op); + if (expression != null) { + builder.append(" "); + expression.toCminus(builder, ""); + } + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/ExpressionStatement.java b/Homework/cs5300/p4-formatter/submit/ast/ExpressionStatement.java new file mode 100644 index 0000000..18feadf --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/ExpressionStatement.java @@ -0,0 +1,17 @@ +package submit.ast; + +public class ExpressionStatement implements Statement { + private Expression expression; + + public ExpressionStatement(Expression expression) { + this.expression = expression; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + if (expression != null) + expression.toCminus(builder, ""); + builder.append(";\n"); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Factor.java b/Homework/cs5300/p4-formatter/submit/ast/Factor.java new file mode 100644 index 0000000..bda0f53 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Factor.java @@ -0,0 +1,23 @@ +package submit.ast; + +public class Factor implements Node { + private Immutable immutable; + private Mutable mutable; + + public Factor(Immutable immutable) { + this.immutable = immutable; + } + + public Factor(Mutable mutable) { + this.mutable = mutable; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + if (mutable != null) + mutable.toCminus(builder, ""); + if (immutable != null) + immutable.toCminus(builder, ""); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/FunctionDeclaration.java b/Homework/cs5300/p4-formatter/submit/ast/FunctionDeclaration.java new file mode 100644 index 0000000..56abd14 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/FunctionDeclaration.java @@ -0,0 +1,36 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class FunctionDeclaration implements Declaration { + + private VarType rType; + private Statement statement; + private ArrayList<Param> params; + private String id; + + public FunctionDeclaration(VarType rType, String id, List<Param> params, + Statement statement) { + this.rType = rType; + this.id = id; + this.params = new ArrayList<>(params); + this.statement = statement; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append("\n").append(rType).append(" ").append(id).append("("); + int numParams = params.size(); + + if (numParams >= 1) + params.get(0).toCminus(builder, ""); + if (numParams > 1) + for (Param param : params.subList(1, numParams)) + param.toCminus(builder, ", "); + + builder.append(")").append("\n"); + + statement.toCminus(builder, ""); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/IfStatement.java b/Homework/cs5300/p4-formatter/submit/ast/IfStatement.java new file mode 100644 index 0000000..1f9b577 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/IfStatement.java @@ -0,0 +1,33 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class IfStatement implements Statement { + private ArrayList<Statement> statements; + private Expression simpleExpression; + + public IfStatement(Expression simpleExpression, List<Statement> statements) { + this.simpleExpression = simpleExpression; + this.statements = new ArrayList<>(statements); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + builder.append("if").append(" ("); + simpleExpression.toCminus(builder, ""); + builder.append(")\n"); + + Statement ifStmt = statements.get(0); + boolean isIfCompound = ifStmt.getClass() == CompoundStatement.class; + ifStmt.toCminus(builder, prefix + (isIfCompound ? "" : "\t")); + if (statements.size() == 2) { + Statement elseStmt = statements.get(1); + boolean isElseCompound = elseStmt.getClass() == CompoundStatement.class; + + builder.append(prefix).append("else\n"); + elseStmt.toCminus(builder, prefix + (isElseCompound ? "" : "\t")); + } + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Immutable.java b/Homework/cs5300/p4-formatter/submit/ast/Immutable.java new file mode 100644 index 0000000..d94ec2c --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Immutable.java @@ -0,0 +1,34 @@ +package submit.ast; + +public class Immutable implements Expression, Node { + private Expression expression; + private Call call; + private Constant constant; + + public Immutable(Expression expression) { + this.expression = expression; + } + + public Immutable(Call call, boolean isCall) { + this.call = call; + } + + public Immutable(Constant constant) { + this.constant = constant; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + if (constant != null) + constant.toCminus(builder, ""); + if (expression != null) { + builder.append("("); + expression.toCminus(builder, ""); + builder.append(")"); + } + if (call != null) + call.toCminus(builder, ""); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Mutable.java b/Homework/cs5300/p4-formatter/submit/ast/Mutable.java new file mode 100644 index 0000000..c7ef089 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Mutable.java @@ -0,0 +1,31 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class Mutable implements Expression, Node { + + private final String id; + private final Expression index; + + public Mutable(String id, Expression index) { + this.id = id; + this.index = index; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(id); + if (index != null) { + builder.append("["); + index.toCminus(builder, prefix); + builder.append("]"); + } + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Node.java b/Homework/cs5300/p4-formatter/submit/ast/Node.java new file mode 100644 index 0000000..455bb3f --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Node.java @@ -0,0 +1,5 @@ +package submit.ast; + +public interface Node { + void toCminus(StringBuilder builder, final String prefix); +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/NumConstant.java b/Homework/cs5300/p4-formatter/submit/ast/NumConstant.java new file mode 100644 index 0000000..c3eea3c --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/NumConstant.java @@ -0,0 +1,23 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class NumConstant implements Expression, Node, Constant { + + private final int value; + + public NumConstant(int value) { + this.value = value; + } + + public void toCminus(StringBuilder builder, final String prefix) { + builder.append(Integer.toString(value)); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/OrExpression.java b/Homework/cs5300/p4-formatter/submit/ast/OrExpression.java new file mode 100644 index 0000000..f4b4dd7 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/OrExpression.java @@ -0,0 +1,18 @@ +package submit.ast; + +import java.util.List; +import java.util.ArrayList; + +public class OrExpression implements Expression { + private ArrayList<AndExpression> andExpressions; + + public OrExpression(List<AndExpression> andExpressions) { + this.andExpressions = new ArrayList<>(andExpressions); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + Expression.joinExpressions(BinaryOperatorType.OR, new ArrayList<Expression>(andExpressions), builder); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Param.java b/Homework/cs5300/p4-formatter/submit/ast/Param.java new file mode 100644 index 0000000..2afa3d6 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Param.java @@ -0,0 +1,22 @@ +package submit.ast; + +public class Param implements Declaration { + private final VarType type; + private final String id; + private final Boolean isArray; + + public Param(VarType type, String id, Boolean isArray) { + this.type = type; + this.id = id; + this.isArray = isArray; + } + + @Override + public void toCminus(StringBuilder builder, final String prefix) { + builder.append(prefix); + builder.append(type).append(" ").append(id); + if (this.isArray) { + builder.append("[]"); + } + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Program.java b/Homework/cs5300/p4-formatter/submit/ast/Program.java new file mode 100644 index 0000000..96d1e22 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Program.java @@ -0,0 +1,35 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author edwajohn + */ +public class Program implements Node { + + private ArrayList<Declaration> declarations; + + public Program(List<Declaration> declarations) { + this.declarations = new ArrayList<>(declarations); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + toCminus(builder, ""); + return builder.toString(); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + for (Declaration declaration : declarations) { + declaration.toCminus(builder, ""); + } + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/RelExpression.java b/Homework/cs5300/p4-formatter/submit/ast/RelExpression.java new file mode 100644 index 0000000..8201dd8 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/RelExpression.java @@ -0,0 +1,20 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class RelExpression implements Expression { + private ArrayList<SumExpression> sumExpressions; + private ArrayList<BinaryOperatorType> relops; + + public RelExpression(List<SumExpression> sumExpressions, List<BinaryOperatorType> relops) { + this.sumExpressions = new ArrayList<>(sumExpressions); + this.relops = new ArrayList<>(relops); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + Expression.joinExpressionOperatorLists(relops, new ArrayList<Expression>(sumExpressions), builder); + } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/submit/ast/Return.java b/Homework/cs5300/p4-formatter/submit/ast/Return.java new file mode 100644 index 0000000..c1f9d4d --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Return.java @@ -0,0 +1,31 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class Return implements Statement { + + private final Expression expr; + + public Return(Expression expr) { + this.expr = expr; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + if (expr == null) { + builder.append("return;\n"); + } else { + builder.append("return "); + expr.toCminus(builder, prefix); + builder.append(";\n"); + } + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/Statement.java b/Homework/cs5300/p4-formatter/submit/ast/Statement.java new file mode 100644 index 0000000..c95db57 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/Statement.java @@ -0,0 +1,14 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +import java.util.ArrayList; + +/** + * + * @author edwajohn + */ +public interface Statement extends Node { +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/StringConstant.java b/Homework/cs5300/p4-formatter/submit/ast/StringConstant.java new file mode 100644 index 0000000..4bf3738 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/StringConstant.java @@ -0,0 +1,23 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public class StringConstant implements Expression, Constant { + + private final String value; + + public StringConstant(String value) { + this.value = value; + } + + public void toCminus(StringBuilder builder, final String prefix) { + builder.append("\"").append(value).append("\""); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/SumExpression.java b/Homework/cs5300/p4-formatter/submit/ast/SumExpression.java new file mode 100644 index 0000000..a7bebfb --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/SumExpression.java @@ -0,0 +1,20 @@ +package submit.ast; + +import java.util.List; +import java.util.ArrayList; + +public class SumExpression implements Expression { + private ArrayList<BinaryOperatorType> sumOps; + private ArrayList<TermExpression> termExpressions; + + public SumExpression(List<BinaryOperatorType> sumOps, List<TermExpression> termExpressions) { + this.sumOps = new ArrayList<>(sumOps); + this.termExpressions = new ArrayList<>(termExpressions); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + Expression.joinExpressionOperatorLists(sumOps, new ArrayList<Expression>(termExpressions), builder); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/TermExpression.java b/Homework/cs5300/p4-formatter/submit/ast/TermExpression.java new file mode 100644 index 0000000..47dc0b2 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/TermExpression.java @@ -0,0 +1,20 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class TermExpression implements Expression { + private ArrayList<UnaryExpression> unaryExpressions; + private ArrayList<BinaryOperatorType> mulOps; + + public TermExpression(List<UnaryExpression> unaryExpressions, List<BinaryOperatorType> mulOps) { + this.unaryExpressions = new ArrayList<>(unaryExpressions); + this.mulOps = new ArrayList<>(mulOps); + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + Expression.joinExpressionOperatorLists(mulOps, new ArrayList<Expression>(unaryExpressions), builder); + } +}
\ No newline at end of file diff --git a/Homework/cs5300/p4-formatter/submit/ast/UnaryExpression.java b/Homework/cs5300/p4-formatter/submit/ast/UnaryExpression.java new file mode 100644 index 0000000..0efdb13 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/UnaryExpression.java @@ -0,0 +1,22 @@ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +public class UnaryExpression implements Expression { + private ArrayList<String> unaryOperators; + private Factor factor; + + public UnaryExpression(List<String> unaryOperators, Factor factor) { + this.unaryOperators = new ArrayList<>(unaryOperators); + this.factor = factor; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + for (String unaryOperator : unaryOperators) + builder.append(unaryOperator); + factor.toCminus(builder, ""); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/UnaryRelExpression.java b/Homework/cs5300/p4-formatter/submit/ast/UnaryRelExpression.java new file mode 100644 index 0000000..621f9fb --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/UnaryRelExpression.java @@ -0,0 +1,20 @@ +package submit.ast; + +public class UnaryRelExpression implements Expression { + + private int bangs; + private RelExpression relExpression; + + public UnaryRelExpression(int bangs, RelExpression relExpression) { + this.bangs = bangs; + this.relExpression = relExpression; + } + + @Override + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + for (int i = 0; i < bangs; ++i) + builder.append("!"); + relExpression.toCminus(builder, ""); + } +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/VarDeclaration.java b/Homework/cs5300/p4-formatter/submit/ast/VarDeclaration.java new file mode 100644 index 0000000..90f8ea5 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/VarDeclaration.java @@ -0,0 +1,47 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author edwajohn + */ +public class VarDeclaration implements Declaration { + + private final VarType type; + private final List<String> ids; + private final List<Integer> arraySizes; + private final boolean isStatic; + + public VarDeclaration(VarType type, List<String> ids, List<Integer> arraySizes, boolean isStatic) { + this.type = type; + this.ids = new ArrayList<>(ids); + this.arraySizes = arraySizes; + this.isStatic = isStatic; + } + + public void toCminus(StringBuilder builder, final String prefix) { + builder.append(prefix); + if (isStatic) { + builder.append("static "); + } + builder.append(type).append(" "); + for (int i = 0; i < ids.size(); ++i) { + final String id = ids.get(i); + final int arraySize = arraySizes.get(i); + if (arraySize >= 0) { + builder.append(id).append("[").append(arraySize).append("]").append(", "); + } else { + builder.append(id).append(", "); + } + } + builder.delete(builder.length() - 2, builder.length()); + builder.append(";\n"); + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/VarType.java b/Homework/cs5300/p4-formatter/submit/ast/VarType.java new file mode 100644 index 0000000..85296d9 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/VarType.java @@ -0,0 +1,35 @@ +/* + * Code formatter project + * CS 4481 + */ +package submit.ast; + +/** + * + * @author edwajohn + */ +public enum VarType { + + VOID("void"), INT("int"), BOOL("bool"), CHAR("char"); + + private final String value; + + private VarType(String value) { + this.value = value; + } + + public static VarType fromString(String s) { + for (VarType vt : VarType.values()) { + if (vt.value.equals(s)) { + return vt; + } + } + throw new RuntimeException("Illegal string in VarType.fromString()"); + } + + @Override + public String toString() { + return value; + } + +} diff --git a/Homework/cs5300/p4-formatter/submit/ast/WhileStatement.java b/Homework/cs5300/p4-formatter/submit/ast/WhileStatement.java new file mode 100644 index 0000000..cd99d51 --- /dev/null +++ b/Homework/cs5300/p4-formatter/submit/ast/WhileStatement.java @@ -0,0 +1,22 @@ +package submit.ast; + +public class WhileStatement implements Statement { + Expression simpleExpression; + Statement statement; + + public WhileStatement(Expression simpleExpression, Statement statement) { + this.simpleExpression = simpleExpression; + this.statement = statement; + } + + public void toCminus(StringBuilder builder, String prefix) { + builder.append(prefix); + + builder.append("while ("); + simpleExpression.toCminus(builder, ""); + builder.append(")\n"); + + boolean isBodyCompound = statement.getClass() == CompoundStatement.class; + statement.toCminus(builder, prefix + (isBodyCompound ? "" : "\t")); + } +} |
