From 12623821f77dff55bd4d14151af0cb7d463137ff Mon Sep 17 00:00:00 2001 From: Boolean-True Date: Tue, 30 Apr 2024 19:24:49 +0200 Subject: [PATCH] Generate Antlr and add Generators --- src/main/java/de/maishai/ASTGenerator.java | 74 + src/main/java/de/maishai/BlockGenerator.java | 18 + src/main/java/de/maishai/Compiler.java | 26 + .../java/de/maishai/ExpressionGenerator.java | 65 + .../java/de/maishai/StatementGenerator.java | 55 + .../java/de/maishai/VariableGenerator.java | 25 + src/main/java/de/maishai/antlr/Decaf.interp | 96 + src/main/java/de/maishai/antlr/Decaf.tokens | 62 + .../de/maishai/antlr/DecafBaseListener.java | 448 ++++ .../de/maishai/antlr/DecafBaseVisitor.java | 253 ++ .../java/de/maishai/antlr/DecafLexer.interp | 116 + .../java/de/maishai/antlr/DecafLexer.java | 257 ++ .../java/de/maishai/antlr/DecafLexer.tokens | 62 + .../java/de/maishai/antlr/DecafListener.java | 386 +++ .../java/de/maishai/antlr/DecafParser.java | 2099 +++++++++++++++++ .../java/de/maishai/antlr/DecafVisitor.java | 235 ++ 16 files changed, 4277 insertions(+) create mode 100644 src/main/java/de/maishai/ASTGenerator.java create mode 100644 src/main/java/de/maishai/BlockGenerator.java create mode 100644 src/main/java/de/maishai/Compiler.java create mode 100644 src/main/java/de/maishai/ExpressionGenerator.java create mode 100644 src/main/java/de/maishai/StatementGenerator.java create mode 100644 src/main/java/de/maishai/VariableGenerator.java create mode 100644 src/main/java/de/maishai/antlr/Decaf.interp create mode 100644 src/main/java/de/maishai/antlr/Decaf.tokens create mode 100644 src/main/java/de/maishai/antlr/DecafBaseListener.java create mode 100644 src/main/java/de/maishai/antlr/DecafBaseVisitor.java create mode 100644 src/main/java/de/maishai/antlr/DecafLexer.interp create mode 100644 src/main/java/de/maishai/antlr/DecafLexer.java create mode 100644 src/main/java/de/maishai/antlr/DecafLexer.tokens create mode 100644 src/main/java/de/maishai/antlr/DecafListener.java create mode 100644 src/main/java/de/maishai/antlr/DecafParser.java create mode 100644 src/main/java/de/maishai/antlr/DecafVisitor.java diff --git a/src/main/java/de/maishai/ASTGenerator.java b/src/main/java/de/maishai/ASTGenerator.java new file mode 100644 index 0000000..5691d63 --- /dev/null +++ b/src/main/java/de/maishai/ASTGenerator.java @@ -0,0 +1,74 @@ +package de.maishai; + +import de.maishai.antlr.DecafParser; +import de.maishai.ast.ReturnType; +import de.maishai.ast.Type; +import de.maishai.ast.records.*; +import de.maishai.ast.records.Class; + +import java.util.ArrayList; +import java.util.List; + +public class ASTGenerator { + + public static Program generateAST(DecafParser.ProgramContext parseTree){ + List classes = new ArrayList<>(); + for(DecafParser.ClassContext cctx : parseTree.class_()){ + classes.add(generateClass(cctx)); + } + return new Program(classes); + } + + public static Class generateClass(DecafParser.ClassContext ctx) { + List vars = new ArrayList<>(); + if(ctx.var() != null){ + vars = ctx.var().stream().map(ASTGenerator::generateVariable).toList(); + } + List meths = new ArrayList<>(); + if(ctx.meth() != null){ + meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList(); + } + Id classId = new Id(ctx.id().getText()); + return new Class(classId, vars, meths); + } + + public static Variable generateVariable(DecafParser.VarContext ctx) { + return new Variable(ctx.id().getText(), getType(ctx.type())); + } + + public static Parameter generateParameter(DecafParser.ParamContext ctx) { + return new Parameter(ctx.id().getText(), getType(ctx.type())); + } + + public static Method generateMethod(DecafParser.MethContext ctx) { + List params = new ArrayList<>(); + if(ctx.params() != null){ + params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList(); + } + Block block = new BlockGenerator().visit(ctx.block()); + Id methId = new Id(ctx.id().getText()); + return new Method(getReturnType(ctx.returntype()), methId, params, block); + } + + public static Type getType(DecafParser.TypeContext ctx){ + if(ctx.INT() != null) + return Type.INT; + if(ctx.BOOL() != null) + return Type.BOOL; + if(ctx.CHAR() != null) + return Type.CHAR; + throw new RuntimeException(); + } + + public static ReturnType getReturnType(DecafParser.ReturntypeContext ctx){ + if(ctx.type().INT() != null) + return ReturnType.INT; + if(ctx.type().BOOL() != null) + return ReturnType.BOOL; + if(ctx.type().CHAR() != null) + return ReturnType.CHAR; + if(ctx.VOID() != null) + return ReturnType.VOID; + throw new RuntimeException(); + } +} diff --git a/src/main/java/de/maishai/BlockGenerator.java b/src/main/java/de/maishai/BlockGenerator.java new file mode 100644 index 0000000..7d9e616 --- /dev/null +++ b/src/main/java/de/maishai/BlockGenerator.java @@ -0,0 +1,18 @@ +package de.maishai; + +import de.maishai.antlr.DecafBaseVisitor; +import de.maishai.antlr.DecafParser; +import de.maishai.ast.Statement; +import de.maishai.ast.records.Block; +import de.maishai.ast.records.Variable; + +import java.util.List; + +public class BlockGenerator extends DecafBaseVisitor { + @Override + public Block visitBlock(DecafParser.BlockContext ctx) { + List vars = ctx.var().stream().map(var -> new VariableGenerator().visit(var)).toList(); + List statements = ctx.stmt().stream().map(stmt -> new StatementGenerator().visit(stmt)).toList(); + return new Block(vars, statements); + } +} diff --git a/src/main/java/de/maishai/Compiler.java b/src/main/java/de/maishai/Compiler.java new file mode 100644 index 0000000..30cb545 --- /dev/null +++ b/src/main/java/de/maishai/Compiler.java @@ -0,0 +1,26 @@ +package de.maishai; + +import de.maishai.antlr.DecafLexer; +import de.maishai.antlr.DecafParser; +import de.maishai.ast.records.Program; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; + +/** + * Decaf language Compiler + */ +public class Compiler +{ + + public static Program generateAST(String fromSource){ + CharStream input = CharStreams.fromString(fromSource); + DecafLexer lexer = new DecafLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + DecafParser parser = new DecafParser(tokens); + DecafParser.ProgramContext tree = parser.program(); //Parsen + return ASTGenerator.generateAST(tree); + } + + +} diff --git a/src/main/java/de/maishai/ExpressionGenerator.java b/src/main/java/de/maishai/ExpressionGenerator.java new file mode 100644 index 0000000..812416a --- /dev/null +++ b/src/main/java/de/maishai/ExpressionGenerator.java @@ -0,0 +1,65 @@ +package de.maishai; + +import de.maishai.antlr.DecafBaseVisitor; +import de.maishai.antlr.DecafParser; +import de.maishai.ast.Expression; +import de.maishai.ast.Operator; +import de.maishai.ast.records.Binary; +import de.maishai.ast.records.BoolConstant; +import de.maishai.ast.records.IntConstant; +import de.maishai.ast.records.MethodCall; + +import java.util.ArrayList; +import java.util.List; + +public class ExpressionGenerator extends DecafBaseVisitor { + @Override + public Expression visitBinaryOperation(DecafParser.BinaryOperationContext ctx) { + return generateBinary(ctx); + } + + @Override + public Expression visitMethodCallExpression(DecafParser.MethodCallExpressionContext ctx) { + String functionName = ctx.methCall().id().getText(); + List args = new ArrayList<>(); + for(var expr : ctx.methCall().args().expr()){ + Expression astExpr = expr.accept(this); + args.add(astExpr); + } + return new MethodCall(functionName, args); + } + + @Override + public Expression visitConstant(DecafParser.ConstantContext ctx) { + return generateConstant(ctx.literal()); + } + + @Override + public Expression visitExpression(DecafParser.ExpressionContext ctx) { + //ParseTree for ( expr ) + //Just pass it down to the inner expr: + return this.visit(ctx.expr()); + } + + public static Expression generateConstant(DecafParser.LiteralContext ctx){ + if(ctx.NUMBER() != null) + return new IntConstant(Integer.valueOf(ctx.NUMBER().getText())); + if(ctx.boolean_() != null) + return new BoolConstant(Boolean.valueOf(ctx.boolean_().getText())); + throw new RuntimeException(); + } + + public static Binary generateBinary(DecafParser.BinaryOperationContext ctx){ + ExpressionGenerator eGen = new ExpressionGenerator(); + return new Binary(eGen.visit(ctx.expr().get(0)) // left side + , generateOperator(ctx.binaryOp()) //operator + , eGen.visit(ctx.expr().get(1))); //right side + } + + public static Operator generateOperator(DecafParser.BinaryOpContext ctx){ + if(ctx.ADD() != null)return Operator.ADD; + if(ctx.SUB() != null)return Operator.SUB; + if(ctx.MUL() != null)return Operator.MUL; + throw new RuntimeException(); + } +} diff --git a/src/main/java/de/maishai/StatementGenerator.java b/src/main/java/de/maishai/StatementGenerator.java new file mode 100644 index 0000000..9a361bf --- /dev/null +++ b/src/main/java/de/maishai/StatementGenerator.java @@ -0,0 +1,55 @@ +package de.maishai; + +import de.maishai.antlr.DecafBaseVisitor; +import de.maishai.antlr.DecafParser; +import de.maishai.ast.Expression; +import de.maishai.ast.Statement; +import de.maishai.ast.records.*; + +public class StatementGenerator extends DecafBaseVisitor { + @Override + public Statement visitAssign(DecafParser.AssignContext ctx) { + Id id = new Id(ctx.id().getText()); + Expression expr = new ExpressionGenerator().visit(ctx.expr()); + return new Assignment(id, expr); + } + + @Override + public Statement visitIf(DecafParser.IfContext ctx) { + Expression expr = new ExpressionGenerator().visit(ctx.expr()); + Block ifBlock = new BlockGenerator().visit(ctx.block(0)); + if(ctx.block().size() == 2){ + Block elseBlock = new BlockGenerator().visit(ctx.block(1)); + return new IfElse(expr, ifBlock, elseBlock); + } + return new IfElse(expr, ifBlock, null); + } + + @Override + public Statement visitWhile(DecafParser.WhileContext ctx) { + Expression expr = new ExpressionGenerator().visit(ctx.expr()); + Block block = new BlockGenerator().visit(ctx.block()); + return new While(expr, block); + } + + @Override + public Statement visitReturn(DecafParser.ReturnContext ctx) { + return new Return(new ExpressionGenerator().visit(ctx.expr())); + } + + @Override + public Statement visitReturnVoid(DecafParser.ReturnVoidContext ctx) { + return new ReturnVoid(); + } + + @Override + public Statement visitBreak(DecafParser.BreakContext ctx) { + return new Break(); + } + + @Override + public Statement visitContinue(DecafParser.ContinueContext ctx) { + return new Continue(); + } + +} diff --git a/src/main/java/de/maishai/VariableGenerator.java b/src/main/java/de/maishai/VariableGenerator.java new file mode 100644 index 0000000..894e7bf --- /dev/null +++ b/src/main/java/de/maishai/VariableGenerator.java @@ -0,0 +1,25 @@ +package de.maishai; + + +import de.maishai.antlr.DecafBaseVisitor; +import de.maishai.antlr.DecafParser; +import de.maishai.ast.Type; +import de.maishai.ast.records.Variable; + +public class VariableGenerator extends DecafBaseVisitor { + + @Override + public Variable visitVar(DecafParser.VarContext ctx) { + return new Variable(ctx.id().getText(), getType(ctx.type())); + } + + public static Type getType(DecafParser.TypeContext ctx){ + if(ctx.INT() != null) + return Type.INT; + if(ctx.BOOL() != null) + return Type.BOOL; + if(ctx.CHAR() != null) + return Type.CHAR; + throw new RuntimeException(); + } +} diff --git a/src/main/java/de/maishai/antlr/Decaf.interp b/src/main/java/de/maishai/antlr/Decaf.interp new file mode 100644 index 0000000..2171e2e --- /dev/null +++ b/src/main/java/de/maishai/antlr/Decaf.interp @@ -0,0 +1,96 @@ +token literal names: +null +'class' +'{' +'}' +';' +'=' +'(' +')' +'static' +'main' +'String[] args' +',' +'if' +'else' +'for' +'while' +'do' +'return' +'break' +'continue' +'true' +'false' +'public' +'new' +'-' +'+' +'*' +'int' +'boolean' +'void' +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 +PUBLIC +NEW +SUB +ADD +MUL +INT +BOOL +VOID +CHAR +IDENTIFIER +NUMBER +WS + +rule names: +program +class +var +returntype +type +meth +mainmeth +params +param +block +stmt +stmtexpr +expr +binaryOp +methCall +args +literal +boolean +id + + +atn: +[4, 1, 33, 231, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 1, 0, 4, 0, 40, 8, 0, 11, 0, 12, 0, 41, 1, 1, 3, 1, 45, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 52, 8, 1, 10, 1, 12, 1, 55, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 69, 8, 2, 1, 3, 1, 3, 3, 3, 73, 8, 3, 1, 4, 1, 4, 1, 5, 3, 5, 78, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 84, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 90, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 5, 7, 104, 8, 7, 10, 7, 12, 7, 107, 9, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 5, 9, 115, 8, 9, 10, 9, 12, 9, 118, 9, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 129, 8, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 165, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 179, 8, 11, 1, 11, 1, 11, 3, 11, 183, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 194, 8, 12, 1, 12, 1, 12, 1, 12, 1, 12, 5, 12, 200, 8, 12, 10, 12, 12, 12, 203, 9, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 3, 14, 210, 8, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 5, 15, 217, 8, 15, 10, 15, 12, 15, 220, 9, 15, 1, 16, 1, 16, 1, 16, 3, 16, 225, 8, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 0, 1, 24, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 0, 3, 2, 0, 27, 28, 30, 30, 1, 0, 24, 26, 1, 0, 20, 21, 244, 0, 39, 1, 0, 0, 0, 2, 44, 1, 0, 0, 0, 4, 68, 1, 0, 0, 0, 6, 72, 1, 0, 0, 0, 8, 74, 1, 0, 0, 0, 10, 89, 1, 0, 0, 0, 12, 91, 1, 0, 0, 0, 14, 100, 1, 0, 0, 0, 16, 108, 1, 0, 0, 0, 18, 111, 1, 0, 0, 0, 20, 164, 1, 0, 0, 0, 22, 182, 1, 0, 0, 0, 24, 193, 1, 0, 0, 0, 26, 204, 1, 0, 0, 0, 28, 206, 1, 0, 0, 0, 30, 213, 1, 0, 0, 0, 32, 224, 1, 0, 0, 0, 34, 226, 1, 0, 0, 0, 36, 228, 1, 0, 0, 0, 38, 40, 3, 2, 1, 0, 39, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 1, 1, 0, 0, 0, 43, 45, 5, 22, 0, 0, 44, 43, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 47, 5, 1, 0, 0, 47, 48, 3, 36, 18, 0, 48, 53, 5, 2, 0, 0, 49, 52, 3, 4, 2, 0, 50, 52, 3, 10, 5, 0, 51, 49, 1, 0, 0, 0, 51, 50, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 56, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 57, 5, 3, 0, 0, 57, 3, 1, 0, 0, 0, 58, 59, 3, 8, 4, 0, 59, 60, 3, 36, 18, 0, 60, 61, 5, 4, 0, 0, 61, 69, 1, 0, 0, 0, 62, 63, 3, 8, 4, 0, 63, 64, 3, 36, 18, 0, 64, 65, 5, 5, 0, 0, 65, 66, 3, 24, 12, 0, 66, 67, 5, 4, 0, 0, 67, 69, 1, 0, 0, 0, 68, 58, 1, 0, 0, 0, 68, 62, 1, 0, 0, 0, 69, 5, 1, 0, 0, 0, 70, 73, 3, 8, 4, 0, 71, 73, 5, 29, 0, 0, 72, 70, 1, 0, 0, 0, 72, 71, 1, 0, 0, 0, 73, 7, 1, 0, 0, 0, 74, 75, 7, 0, 0, 0, 75, 9, 1, 0, 0, 0, 76, 78, 5, 22, 0, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 80, 3, 6, 3, 0, 80, 81, 3, 36, 18, 0, 81, 83, 5, 6, 0, 0, 82, 84, 3, 14, 7, 0, 83, 82, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 86, 5, 7, 0, 0, 86, 87, 3, 18, 9, 0, 87, 90, 1, 0, 0, 0, 88, 90, 3, 12, 6, 0, 89, 77, 1, 0, 0, 0, 89, 88, 1, 0, 0, 0, 90, 11, 1, 0, 0, 0, 91, 92, 5, 22, 0, 0, 92, 93, 5, 8, 0, 0, 93, 94, 5, 29, 0, 0, 94, 95, 5, 9, 0, 0, 95, 96, 5, 6, 0, 0, 96, 97, 5, 10, 0, 0, 97, 98, 5, 7, 0, 0, 98, 99, 3, 18, 9, 0, 99, 13, 1, 0, 0, 0, 100, 105, 3, 16, 8, 0, 101, 102, 5, 11, 0, 0, 102, 104, 3, 16, 8, 0, 103, 101, 1, 0, 0, 0, 104, 107, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 15, 1, 0, 0, 0, 107, 105, 1, 0, 0, 0, 108, 109, 3, 8, 4, 0, 109, 110, 3, 36, 18, 0, 110, 17, 1, 0, 0, 0, 111, 116, 5, 2, 0, 0, 112, 115, 3, 4, 2, 0, 113, 115, 3, 20, 10, 0, 114, 112, 1, 0, 0, 0, 114, 113, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 119, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 119, 120, 5, 3, 0, 0, 120, 19, 1, 0, 0, 0, 121, 122, 5, 12, 0, 0, 122, 123, 5, 6, 0, 0, 123, 124, 3, 24, 12, 0, 124, 125, 5, 7, 0, 0, 125, 128, 3, 18, 9, 0, 126, 127, 5, 13, 0, 0, 127, 129, 3, 18, 9, 0, 128, 126, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 165, 1, 0, 0, 0, 130, 131, 5, 14, 0, 0, 131, 132, 5, 6, 0, 0, 132, 133, 3, 24, 12, 0, 133, 134, 5, 4, 0, 0, 134, 135, 3, 24, 12, 0, 135, 136, 5, 4, 0, 0, 136, 137, 3, 24, 12, 0, 137, 138, 5, 7, 0, 0, 138, 139, 3, 18, 9, 0, 139, 165, 1, 0, 0, 0, 140, 141, 5, 15, 0, 0, 141, 142, 5, 6, 0, 0, 142, 143, 3, 24, 12, 0, 143, 144, 5, 7, 0, 0, 144, 145, 3, 18, 9, 0, 145, 165, 1, 0, 0, 0, 146, 147, 5, 16, 0, 0, 147, 148, 3, 18, 9, 0, 148, 149, 5, 15, 0, 0, 149, 150, 5, 6, 0, 0, 150, 151, 3, 24, 12, 0, 151, 152, 5, 7, 0, 0, 152, 165, 1, 0, 0, 0, 153, 154, 5, 17, 0, 0, 154, 155, 3, 24, 12, 0, 155, 156, 5, 4, 0, 0, 156, 165, 1, 0, 0, 0, 157, 158, 5, 17, 0, 0, 158, 165, 5, 4, 0, 0, 159, 160, 5, 18, 0, 0, 160, 165, 5, 4, 0, 0, 161, 162, 5, 19, 0, 0, 162, 165, 5, 4, 0, 0, 163, 165, 3, 22, 11, 0, 164, 121, 1, 0, 0, 0, 164, 130, 1, 0, 0, 0, 164, 140, 1, 0, 0, 0, 164, 146, 1, 0, 0, 0, 164, 153, 1, 0, 0, 0, 164, 157, 1, 0, 0, 0, 164, 159, 1, 0, 0, 0, 164, 161, 1, 0, 0, 0, 164, 163, 1, 0, 0, 0, 165, 21, 1, 0, 0, 0, 166, 167, 3, 36, 18, 0, 167, 168, 5, 5, 0, 0, 168, 169, 3, 24, 12, 0, 169, 170, 5, 4, 0, 0, 170, 183, 1, 0, 0, 0, 171, 172, 3, 28, 14, 0, 172, 173, 5, 4, 0, 0, 173, 183, 1, 0, 0, 0, 174, 175, 5, 23, 0, 0, 175, 176, 3, 8, 4, 0, 176, 178, 5, 6, 0, 0, 177, 179, 3, 30, 15, 0, 178, 177, 1, 0, 0, 0, 178, 179, 1, 0, 0, 0, 179, 180, 1, 0, 0, 0, 180, 181, 5, 7, 0, 0, 181, 183, 1, 0, 0, 0, 182, 166, 1, 0, 0, 0, 182, 171, 1, 0, 0, 0, 182, 174, 1, 0, 0, 0, 183, 23, 1, 0, 0, 0, 184, 185, 6, 12, -1, 0, 185, 194, 3, 32, 16, 0, 186, 187, 5, 6, 0, 0, 187, 188, 3, 24, 12, 0, 188, 189, 5, 7, 0, 0, 189, 194, 1, 0, 0, 0, 190, 194, 3, 28, 14, 0, 191, 194, 3, 36, 18, 0, 192, 194, 3, 22, 11, 0, 193, 184, 1, 0, 0, 0, 193, 186, 1, 0, 0, 0, 193, 190, 1, 0, 0, 0, 193, 191, 1, 0, 0, 0, 193, 192, 1, 0, 0, 0, 194, 201, 1, 0, 0, 0, 195, 196, 10, 6, 0, 0, 196, 197, 3, 26, 13, 0, 197, 198, 3, 24, 12, 7, 198, 200, 1, 0, 0, 0, 199, 195, 1, 0, 0, 0, 200, 203, 1, 0, 0, 0, 201, 199, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 25, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 204, 205, 7, 1, 0, 0, 205, 27, 1, 0, 0, 0, 206, 207, 3, 36, 18, 0, 207, 209, 5, 6, 0, 0, 208, 210, 3, 30, 15, 0, 209, 208, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 211, 1, 0, 0, 0, 211, 212, 5, 7, 0, 0, 212, 29, 1, 0, 0, 0, 213, 218, 3, 24, 12, 0, 214, 215, 5, 11, 0, 0, 215, 217, 3, 24, 12, 0, 216, 214, 1, 0, 0, 0, 217, 220, 1, 0, 0, 0, 218, 216, 1, 0, 0, 0, 218, 219, 1, 0, 0, 0, 219, 31, 1, 0, 0, 0, 220, 218, 1, 0, 0, 0, 221, 225, 5, 32, 0, 0, 222, 225, 3, 34, 17, 0, 223, 225, 5, 30, 0, 0, 224, 221, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 224, 223, 1, 0, 0, 0, 225, 33, 1, 0, 0, 0, 226, 227, 7, 2, 0, 0, 227, 35, 1, 0, 0, 0, 228, 229, 5, 31, 0, 0, 229, 37, 1, 0, 0, 0, 21, 41, 44, 51, 53, 68, 72, 77, 83, 89, 105, 114, 116, 128, 164, 178, 182, 193, 201, 209, 218, 224] \ No newline at end of file diff --git a/src/main/java/de/maishai/antlr/Decaf.tokens b/src/main/java/de/maishai/antlr/Decaf.tokens new file mode 100644 index 0000000..2f81403 --- /dev/null +++ b/src/main/java/de/maishai/antlr/Decaf.tokens @@ -0,0 +1,62 @@ +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 +PUBLIC=22 +NEW=23 +SUB=24 +ADD=25 +MUL=26 +INT=27 +BOOL=28 +VOID=29 +CHAR=30 +IDENTIFIER=31 +NUMBER=32 +WS=33 +'class'=1 +'{'=2 +'}'=3 +';'=4 +'='=5 +'('=6 +')'=7 +'static'=8 +'main'=9 +'String[] args'=10 +','=11 +'if'=12 +'else'=13 +'for'=14 +'while'=15 +'do'=16 +'return'=17 +'break'=18 +'continue'=19 +'true'=20 +'false'=21 +'public'=22 +'new'=23 +'-'=24 +'+'=25 +'*'=26 +'int'=27 +'boolean'=28 +'void'=29 diff --git a/src/main/java/de/maishai/antlr/DecafBaseListener.java b/src/main/java/de/maishai/antlr/DecafBaseListener.java new file mode 100644 index 0000000..739b886 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafBaseListener.java @@ -0,0 +1,448 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; + +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 DecafListener}, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +@SuppressWarnings("CheckReturnValue") +public class DecafBaseListener implements DecafListener { + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterProgram(DecafParser.ProgramContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitProgram(DecafParser.ProgramContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterClass(DecafParser.ClassContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitClass(DecafParser.ClassContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterVar(DecafParser.VarContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitVar(DecafParser.VarContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterReturntype(DecafParser.ReturntypeContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitReturntype(DecafParser.ReturntypeContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterType(DecafParser.TypeContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitType(DecafParser.TypeContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMeth(DecafParser.MethContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMeth(DecafParser.MethContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMainmeth(DecafParser.MainmethContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMainmeth(DecafParser.MainmethContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterParams(DecafParser.ParamsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitParams(DecafParser.ParamsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterParam(DecafParser.ParamContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitParam(DecafParser.ParamContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBlock(DecafParser.BlockContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBlock(DecafParser.BlockContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterIf(DecafParser.IfContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitIf(DecafParser.IfContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterFor(DecafParser.ForContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitFor(DecafParser.ForContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterWhile(DecafParser.WhileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitWhile(DecafParser.WhileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterDoWhile(DecafParser.DoWhileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitDoWhile(DecafParser.DoWhileContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterReturn(DecafParser.ReturnContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitReturn(DecafParser.ReturnContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterReturnVoid(DecafParser.ReturnVoidContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitReturnVoid(DecafParser.ReturnVoidContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBreak(DecafParser.BreakContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBreak(DecafParser.BreakContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterContinue(DecafParser.ContinueContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitContinue(DecafParser.ContinueContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterAssign(DecafParser.AssignContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitAssign(DecafParser.AssignContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMethodCall(DecafParser.MethodCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMethodCall(DecafParser.MethodCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterNew(DecafParser.NewContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitNew(DecafParser.NewContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterIdentifier(DecafParser.IdentifierContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitIdentifier(DecafParser.IdentifierContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMethodCallExpression(DecafParser.MethodCallExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMethodCallExpression(DecafParser.MethodCallExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExpression(DecafParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExpression(DecafParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterConstant(DecafParser.ConstantContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitConstant(DecafParser.ConstantContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBinaryOperation(DecafParser.BinaryOperationContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBinaryOperation(DecafParser.BinaryOperationContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBinaryOp(DecafParser.BinaryOpContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBinaryOp(DecafParser.BinaryOpContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterMethCall(DecafParser.MethCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitMethCall(DecafParser.MethCallContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterArgs(DecafParser.ArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitArgs(DecafParser.ArgsContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterLiteral(DecafParser.LiteralContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitLiteral(DecafParser.LiteralContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterBoolean(DecafParser.BooleanContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitBoolean(DecafParser.BooleanContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterId(DecafParser.IdContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitId(DecafParser.IdContext ctx) { } + + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitTerminal(TerminalNode node) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitErrorNode(ErrorNode node) { } +} \ No newline at end of file diff --git a/src/main/java/de/maishai/antlr/DecafBaseVisitor.java b/src/main/java/de/maishai/antlr/DecafBaseVisitor.java new file mode 100644 index 0000000..ca4ed96 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafBaseVisitor.java @@ -0,0 +1,253 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * This class provides an empty implementation of {@link DecafVisitor}, + * which can be extended to create a visitor which only needs to handle a subset + * of the available methods. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +@SuppressWarnings("CheckReturnValue") +public class DecafBaseVisitor extends AbstractParseTreeVisitor implements DecafVisitor { + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitProgram(DecafParser.ProgramContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitClass(DecafParser.ClassContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitVar(DecafParser.VarContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitReturntype(DecafParser.ReturntypeContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitType(DecafParser.TypeContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMeth(DecafParser.MethContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMainmeth(DecafParser.MainmethContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitParams(DecafParser.ParamsContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitParam(DecafParser.ParamContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBlock(DecafParser.BlockContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitIf(DecafParser.IfContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitFor(DecafParser.ForContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitWhile(DecafParser.WhileContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitDoWhile(DecafParser.DoWhileContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitReturn(DecafParser.ReturnContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitReturnVoid(DecafParser.ReturnVoidContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBreak(DecafParser.BreakContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitContinue(DecafParser.ContinueContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitAssign(DecafParser.AssignContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMethodCall(DecafParser.MethodCallContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitNew(DecafParser.NewContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitIdentifier(DecafParser.IdentifierContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMethodCallExpression(DecafParser.MethodCallExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExpression(DecafParser.ExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitConstant(DecafParser.ConstantContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBinaryOperation(DecafParser.BinaryOperationContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBinaryOp(DecafParser.BinaryOpContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitMethCall(DecafParser.MethCallContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitArgs(DecafParser.ArgsContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitLiteral(DecafParser.LiteralContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitBoolean(DecafParser.BooleanContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitId(DecafParser.IdContext ctx) { return visitChildren(ctx); } +} \ No newline at end of file diff --git a/src/main/java/de/maishai/antlr/DecafLexer.interp b/src/main/java/de/maishai/antlr/DecafLexer.interp new file mode 100644 index 0000000..8a2ad20 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafLexer.interp @@ -0,0 +1,116 @@ +token literal names: +null +'class' +'{' +'}' +';' +'=' +'(' +')' +'static' +'main' +'String[] args' +',' +'if' +'else' +'for' +'while' +'do' +'return' +'break' +'continue' +'true' +'false' +'public' +'new' +'-' +'+' +'*' +'int' +'boolean' +'void' +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 +PUBLIC +NEW +SUB +ADD +MUL +INT +BOOL +VOID +CHAR +IDENTIFIER +NUMBER +WS + +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 +PUBLIC +NEW +SUB +ADD +MUL +INT +BOOL +VOID +CHAR +IDENTIFIER +NUMBER +WS + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[4, 0, 33, 219, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 29, 1, 30, 4, 30, 207, 8, 30, 11, 30, 12, 30, 208, 1, 31, 4, 31, 212, 8, 31, 11, 31, 12, 31, 213, 1, 32, 1, 32, 1, 32, 1, 32, 0, 0, 33, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 1, 0, 4, 1, 0, 39, 39, 2, 0, 65, 90, 97, 122, 1, 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 220, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 1, 67, 1, 0, 0, 0, 3, 73, 1, 0, 0, 0, 5, 75, 1, 0, 0, 0, 7, 77, 1, 0, 0, 0, 9, 79, 1, 0, 0, 0, 11, 81, 1, 0, 0, 0, 13, 83, 1, 0, 0, 0, 15, 85, 1, 0, 0, 0, 17, 92, 1, 0, 0, 0, 19, 97, 1, 0, 0, 0, 21, 111, 1, 0, 0, 0, 23, 113, 1, 0, 0, 0, 25, 116, 1, 0, 0, 0, 27, 121, 1, 0, 0, 0, 29, 125, 1, 0, 0, 0, 31, 131, 1, 0, 0, 0, 33, 134, 1, 0, 0, 0, 35, 141, 1, 0, 0, 0, 37, 147, 1, 0, 0, 0, 39, 156, 1, 0, 0, 0, 41, 161, 1, 0, 0, 0, 43, 167, 1, 0, 0, 0, 45, 174, 1, 0, 0, 0, 47, 178, 1, 0, 0, 0, 49, 180, 1, 0, 0, 0, 51, 182, 1, 0, 0, 0, 53, 184, 1, 0, 0, 0, 55, 188, 1, 0, 0, 0, 57, 196, 1, 0, 0, 0, 59, 201, 1, 0, 0, 0, 61, 206, 1, 0, 0, 0, 63, 211, 1, 0, 0, 0, 65, 215, 1, 0, 0, 0, 67, 68, 5, 99, 0, 0, 68, 69, 5, 108, 0, 0, 69, 70, 5, 97, 0, 0, 70, 71, 5, 115, 0, 0, 71, 72, 5, 115, 0, 0, 72, 2, 1, 0, 0, 0, 73, 74, 5, 123, 0, 0, 74, 4, 1, 0, 0, 0, 75, 76, 5, 125, 0, 0, 76, 6, 1, 0, 0, 0, 77, 78, 5, 59, 0, 0, 78, 8, 1, 0, 0, 0, 79, 80, 5, 61, 0, 0, 80, 10, 1, 0, 0, 0, 81, 82, 5, 40, 0, 0, 82, 12, 1, 0, 0, 0, 83, 84, 5, 41, 0, 0, 84, 14, 1, 0, 0, 0, 85, 86, 5, 115, 0, 0, 86, 87, 5, 116, 0, 0, 87, 88, 5, 97, 0, 0, 88, 89, 5, 116, 0, 0, 89, 90, 5, 105, 0, 0, 90, 91, 5, 99, 0, 0, 91, 16, 1, 0, 0, 0, 92, 93, 5, 109, 0, 0, 93, 94, 5, 97, 0, 0, 94, 95, 5, 105, 0, 0, 95, 96, 5, 110, 0, 0, 96, 18, 1, 0, 0, 0, 97, 98, 5, 83, 0, 0, 98, 99, 5, 116, 0, 0, 99, 100, 5, 114, 0, 0, 100, 101, 5, 105, 0, 0, 101, 102, 5, 110, 0, 0, 102, 103, 5, 103, 0, 0, 103, 104, 5, 91, 0, 0, 104, 105, 5, 93, 0, 0, 105, 106, 5, 32, 0, 0, 106, 107, 5, 97, 0, 0, 107, 108, 5, 114, 0, 0, 108, 109, 5, 103, 0, 0, 109, 110, 5, 115, 0, 0, 110, 20, 1, 0, 0, 0, 111, 112, 5, 44, 0, 0, 112, 22, 1, 0, 0, 0, 113, 114, 5, 105, 0, 0, 114, 115, 5, 102, 0, 0, 115, 24, 1, 0, 0, 0, 116, 117, 5, 101, 0, 0, 117, 118, 5, 108, 0, 0, 118, 119, 5, 115, 0, 0, 119, 120, 5, 101, 0, 0, 120, 26, 1, 0, 0, 0, 121, 122, 5, 102, 0, 0, 122, 123, 5, 111, 0, 0, 123, 124, 5, 114, 0, 0, 124, 28, 1, 0, 0, 0, 125, 126, 5, 119, 0, 0, 126, 127, 5, 104, 0, 0, 127, 128, 5, 105, 0, 0, 128, 129, 5, 108, 0, 0, 129, 130, 5, 101, 0, 0, 130, 30, 1, 0, 0, 0, 131, 132, 5, 100, 0, 0, 132, 133, 5, 111, 0, 0, 133, 32, 1, 0, 0, 0, 134, 135, 5, 114, 0, 0, 135, 136, 5, 101, 0, 0, 136, 137, 5, 116, 0, 0, 137, 138, 5, 117, 0, 0, 138, 139, 5, 114, 0, 0, 139, 140, 5, 110, 0, 0, 140, 34, 1, 0, 0, 0, 141, 142, 5, 98, 0, 0, 142, 143, 5, 114, 0, 0, 143, 144, 5, 101, 0, 0, 144, 145, 5, 97, 0, 0, 145, 146, 5, 107, 0, 0, 146, 36, 1, 0, 0, 0, 147, 148, 5, 99, 0, 0, 148, 149, 5, 111, 0, 0, 149, 150, 5, 110, 0, 0, 150, 151, 5, 116, 0, 0, 151, 152, 5, 105, 0, 0, 152, 153, 5, 110, 0, 0, 153, 154, 5, 117, 0, 0, 154, 155, 5, 101, 0, 0, 155, 38, 1, 0, 0, 0, 156, 157, 5, 116, 0, 0, 157, 158, 5, 114, 0, 0, 158, 159, 5, 117, 0, 0, 159, 160, 5, 101, 0, 0, 160, 40, 1, 0, 0, 0, 161, 162, 5, 102, 0, 0, 162, 163, 5, 97, 0, 0, 163, 164, 5, 108, 0, 0, 164, 165, 5, 115, 0, 0, 165, 166, 5, 101, 0, 0, 166, 42, 1, 0, 0, 0, 167, 168, 5, 112, 0, 0, 168, 169, 5, 117, 0, 0, 169, 170, 5, 98, 0, 0, 170, 171, 5, 108, 0, 0, 171, 172, 5, 105, 0, 0, 172, 173, 5, 99, 0, 0, 173, 44, 1, 0, 0, 0, 174, 175, 5, 110, 0, 0, 175, 176, 5, 101, 0, 0, 176, 177, 5, 119, 0, 0, 177, 46, 1, 0, 0, 0, 178, 179, 5, 45, 0, 0, 179, 48, 1, 0, 0, 0, 180, 181, 5, 43, 0, 0, 181, 50, 1, 0, 0, 0, 182, 183, 5, 42, 0, 0, 183, 52, 1, 0, 0, 0, 184, 185, 5, 105, 0, 0, 185, 186, 5, 110, 0, 0, 186, 187, 5, 116, 0, 0, 187, 54, 1, 0, 0, 0, 188, 189, 5, 98, 0, 0, 189, 190, 5, 111, 0, 0, 190, 191, 5, 111, 0, 0, 191, 192, 5, 108, 0, 0, 192, 193, 5, 101, 0, 0, 193, 194, 5, 97, 0, 0, 194, 195, 5, 110, 0, 0, 195, 56, 1, 0, 0, 0, 196, 197, 5, 118, 0, 0, 197, 198, 5, 111, 0, 0, 198, 199, 5, 105, 0, 0, 199, 200, 5, 100, 0, 0, 200, 58, 1, 0, 0, 0, 201, 202, 7, 0, 0, 0, 202, 203, 7, 1, 0, 0, 203, 204, 7, 0, 0, 0, 204, 60, 1, 0, 0, 0, 205, 207, 7, 1, 0, 0, 206, 205, 1, 0, 0, 0, 207, 208, 1, 0, 0, 0, 208, 206, 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 62, 1, 0, 0, 0, 210, 212, 7, 2, 0, 0, 211, 210, 1, 0, 0, 0, 212, 213, 1, 0, 0, 0, 213, 211, 1, 0, 0, 0, 213, 214, 1, 0, 0, 0, 214, 64, 1, 0, 0, 0, 215, 216, 7, 3, 0, 0, 216, 217, 1, 0, 0, 0, 217, 218, 6, 32, 0, 0, 218, 66, 1, 0, 0, 0, 3, 0, 208, 213, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/main/java/de/maishai/antlr/DecafLexer.java b/src/main/java/de/maishai/antlr/DecafLexer.java new file mode 100644 index 0000000..05dfaa1 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafLexer.java @@ -0,0 +1,257 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; +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", "CheckReturnValue", "this-escape"}) +public class DecafLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.13.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, PUBLIC=22, NEW=23, SUB=24, ADD=25, + MUL=26, INT=27, BOOL=28, VOID=29, CHAR=30, IDENTIFIER=31, NUMBER=32, WS=33; + 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", "PUBLIC", "NEW", "SUB", "ADD", "MUL", + "INT", "BOOL", "VOID", "CHAR", "IDENTIFIER", "NUMBER", "WS" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "'class'", "'{'", "'}'", "';'", "'='", "'('", "')'", "'static'", + "'main'", "'String[] args'", "','", "'if'", "'else'", "'for'", "'while'", + "'do'", "'return'", "'break'", "'continue'", "'true'", "'false'", "'public'", + "'new'", "'-'", "'+'", "'*'", "'int'", "'boolean'", "'void'" + }; + } + 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, "PUBLIC", + "NEW", "SUB", "ADD", "MUL", "INT", "BOOL", "VOID", "CHAR", "IDENTIFIER", + "NUMBER", "WS" + }; + } + 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] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public DecafLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "Decaf.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 = + "\u0004\u0000!\u00db\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ + "\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+ + "\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+ + "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+ + "\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0002"+ + "\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011\u0002"+ + "\u0012\u0007\u0012\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014\u0002"+ + "\u0015\u0007\u0015\u0002\u0016\u0007\u0016\u0002\u0017\u0007\u0017\u0002"+ + "\u0018\u0007\u0018\u0002\u0019\u0007\u0019\u0002\u001a\u0007\u001a\u0002"+ + "\u001b\u0007\u001b\u0002\u001c\u0007\u001c\u0002\u001d\u0007\u001d\u0002"+ + "\u001e\u0007\u001e\u0002\u001f\u0007\u001f\u0002 \u0007 \u0001\u0000\u0001"+ + "\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001"+ + "\u0001\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0004\u0001"+ + "\u0004\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0007\u0001"+ + "\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001"+ + "\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001\t\u0001\t\u0001"+ + "\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001"+ + "\t\u0001\n\u0001\n\u0001\u000b\u0001\u000b\u0001\u000b\u0001\f\u0001\f"+ + "\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r\u0001\r\u0001\r\u0001\u000e\u0001"+ + "\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000f\u0001"+ + "\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001\u0010\u0001\u0010\u0001"+ + "\u0010\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0011\u0001"+ + "\u0011\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0012\u0001"+ + "\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001"+ + "\u0013\u0001\u0013\u0001\u0013\u0001\u0013\u0001\u0013\u0001\u0014\u0001"+ + "\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015\u0001"+ + "\u0015\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0015\u0001"+ + "\u0016\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0017\u0001\u0017\u0001"+ + "\u0018\u0001\u0018\u0001\u0019\u0001\u0019\u0001\u001a\u0001\u001a\u0001"+ + "\u001a\u0001\u001a\u0001\u001b\u0001\u001b\u0001\u001b\u0001\u001b\u0001"+ + "\u001b\u0001\u001b\u0001\u001b\u0001\u001b\u0001\u001c\u0001\u001c\u0001"+ + "\u001c\u0001\u001c\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001d\u0001"+ + "\u001d\u0001\u001e\u0004\u001e\u00cf\b\u001e\u000b\u001e\f\u001e\u00d0"+ + "\u0001\u001f\u0004\u001f\u00d4\b\u001f\u000b\u001f\f\u001f\u00d5\u0001"+ + " \u0001 \u0001 \u0001 \u0000\u0000!\u0001\u0001\u0003\u0002\u0005\u0003"+ + "\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\t\u0013\n\u0015"+ + "\u000b\u0017\f\u0019\r\u001b\u000e\u001d\u000f\u001f\u0010!\u0011#\u0012"+ + "%\u0013\'\u0014)\u0015+\u0016-\u0017/\u00181\u00193\u001a5\u001b7\u001c"+ + "9\u001d;\u001e=\u001f? A!\u0001\u0000\u0004\u0001\u0000\'\'\u0002\u0000"+ + "AZaz\u0001\u000009\u0003\u0000\t\n\r\r \u00dc\u0000\u0001\u0001\u0000"+ + "\u0000\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000"+ + "\u0000\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000"+ + "\u0000\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000"+ + "\u0000\u000f\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000\u0000\u0000"+ + "\u0000\u0013\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000\u0000\u0000"+ + "\u0000\u0017\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000\u0000\u0000"+ + "\u0000\u001b\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000\u0000\u0000"+ + "\u0000\u001f\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000\u0000\u0000"+ + "#\u0001\u0000\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000\'\u0001"+ + "\u0000\u0000\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001\u0000\u0000"+ + "\u0000\u0000-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000\u0000\u0000"+ + "1\u0001\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u00005\u0001"+ + "\u0000\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001\u0000\u0000"+ + "\u0000\u0000;\u0001\u0000\u0000\u0000\u0000=\u0001\u0000\u0000\u0000\u0000"+ + "?\u0001\u0000\u0000\u0000\u0000A\u0001\u0000\u0000\u0000\u0001C\u0001"+ + "\u0000\u0000\u0000\u0003I\u0001\u0000\u0000\u0000\u0005K\u0001\u0000\u0000"+ + "\u0000\u0007M\u0001\u0000\u0000\u0000\tO\u0001\u0000\u0000\u0000\u000b"+ + "Q\u0001\u0000\u0000\u0000\rS\u0001\u0000\u0000\u0000\u000fU\u0001\u0000"+ + "\u0000\u0000\u0011\\\u0001\u0000\u0000\u0000\u0013a\u0001\u0000\u0000"+ + "\u0000\u0015o\u0001\u0000\u0000\u0000\u0017q\u0001\u0000\u0000\u0000\u0019"+ + "t\u0001\u0000\u0000\u0000\u001by\u0001\u0000\u0000\u0000\u001d}\u0001"+ + "\u0000\u0000\u0000\u001f\u0083\u0001\u0000\u0000\u0000!\u0086\u0001\u0000"+ + "\u0000\u0000#\u008d\u0001\u0000\u0000\u0000%\u0093\u0001\u0000\u0000\u0000"+ + "\'\u009c\u0001\u0000\u0000\u0000)\u00a1\u0001\u0000\u0000\u0000+\u00a7"+ + "\u0001\u0000\u0000\u0000-\u00ae\u0001\u0000\u0000\u0000/\u00b2\u0001\u0000"+ + "\u0000\u00001\u00b4\u0001\u0000\u0000\u00003\u00b6\u0001\u0000\u0000\u0000"+ + "5\u00b8\u0001\u0000\u0000\u00007\u00bc\u0001\u0000\u0000\u00009\u00c4"+ + "\u0001\u0000\u0000\u0000;\u00c9\u0001\u0000\u0000\u0000=\u00ce\u0001\u0000"+ + "\u0000\u0000?\u00d3\u0001\u0000\u0000\u0000A\u00d7\u0001\u0000\u0000\u0000"+ + "CD\u0005c\u0000\u0000DE\u0005l\u0000\u0000EF\u0005a\u0000\u0000FG\u0005"+ + "s\u0000\u0000GH\u0005s\u0000\u0000H\u0002\u0001\u0000\u0000\u0000IJ\u0005"+ + "{\u0000\u0000J\u0004\u0001\u0000\u0000\u0000KL\u0005}\u0000\u0000L\u0006"+ + "\u0001\u0000\u0000\u0000MN\u0005;\u0000\u0000N\b\u0001\u0000\u0000\u0000"+ + "OP\u0005=\u0000\u0000P\n\u0001\u0000\u0000\u0000QR\u0005(\u0000\u0000"+ + "R\f\u0001\u0000\u0000\u0000ST\u0005)\u0000\u0000T\u000e\u0001\u0000\u0000"+ + "\u0000UV\u0005s\u0000\u0000VW\u0005t\u0000\u0000WX\u0005a\u0000\u0000"+ + "XY\u0005t\u0000\u0000YZ\u0005i\u0000\u0000Z[\u0005c\u0000\u0000[\u0010"+ + "\u0001\u0000\u0000\u0000\\]\u0005m\u0000\u0000]^\u0005a\u0000\u0000^_"+ + "\u0005i\u0000\u0000_`\u0005n\u0000\u0000`\u0012\u0001\u0000\u0000\u0000"+ + "ab\u0005S\u0000\u0000bc\u0005t\u0000\u0000cd\u0005r\u0000\u0000de\u0005"+ + "i\u0000\u0000ef\u0005n\u0000\u0000fg\u0005g\u0000\u0000gh\u0005[\u0000"+ + "\u0000hi\u0005]\u0000\u0000ij\u0005 \u0000\u0000jk\u0005a\u0000\u0000"+ + "kl\u0005r\u0000\u0000lm\u0005g\u0000\u0000mn\u0005s\u0000\u0000n\u0014"+ + "\u0001\u0000\u0000\u0000op\u0005,\u0000\u0000p\u0016\u0001\u0000\u0000"+ + "\u0000qr\u0005i\u0000\u0000rs\u0005f\u0000\u0000s\u0018\u0001\u0000\u0000"+ + "\u0000tu\u0005e\u0000\u0000uv\u0005l\u0000\u0000vw\u0005s\u0000\u0000"+ + "wx\u0005e\u0000\u0000x\u001a\u0001\u0000\u0000\u0000yz\u0005f\u0000\u0000"+ + "z{\u0005o\u0000\u0000{|\u0005r\u0000\u0000|\u001c\u0001\u0000\u0000\u0000"+ + "}~\u0005w\u0000\u0000~\u007f\u0005h\u0000\u0000\u007f\u0080\u0005i\u0000"+ + "\u0000\u0080\u0081\u0005l\u0000\u0000\u0081\u0082\u0005e\u0000\u0000\u0082"+ + "\u001e\u0001\u0000\u0000\u0000\u0083\u0084\u0005d\u0000\u0000\u0084\u0085"+ + "\u0005o\u0000\u0000\u0085 \u0001\u0000\u0000\u0000\u0086\u0087\u0005r"+ + "\u0000\u0000\u0087\u0088\u0005e\u0000\u0000\u0088\u0089\u0005t\u0000\u0000"+ + "\u0089\u008a\u0005u\u0000\u0000\u008a\u008b\u0005r\u0000\u0000\u008b\u008c"+ + "\u0005n\u0000\u0000\u008c\"\u0001\u0000\u0000\u0000\u008d\u008e\u0005"+ + "b\u0000\u0000\u008e\u008f\u0005r\u0000\u0000\u008f\u0090\u0005e\u0000"+ + "\u0000\u0090\u0091\u0005a\u0000\u0000\u0091\u0092\u0005k\u0000\u0000\u0092"+ + "$\u0001\u0000\u0000\u0000\u0093\u0094\u0005c\u0000\u0000\u0094\u0095\u0005"+ + "o\u0000\u0000\u0095\u0096\u0005n\u0000\u0000\u0096\u0097\u0005t\u0000"+ + "\u0000\u0097\u0098\u0005i\u0000\u0000\u0098\u0099\u0005n\u0000\u0000\u0099"+ + "\u009a\u0005u\u0000\u0000\u009a\u009b\u0005e\u0000\u0000\u009b&\u0001"+ + "\u0000\u0000\u0000\u009c\u009d\u0005t\u0000\u0000\u009d\u009e\u0005r\u0000"+ + "\u0000\u009e\u009f\u0005u\u0000\u0000\u009f\u00a0\u0005e\u0000\u0000\u00a0"+ + "(\u0001\u0000\u0000\u0000\u00a1\u00a2\u0005f\u0000\u0000\u00a2\u00a3\u0005"+ + "a\u0000\u0000\u00a3\u00a4\u0005l\u0000\u0000\u00a4\u00a5\u0005s\u0000"+ + "\u0000\u00a5\u00a6\u0005e\u0000\u0000\u00a6*\u0001\u0000\u0000\u0000\u00a7"+ + "\u00a8\u0005p\u0000\u0000\u00a8\u00a9\u0005u\u0000\u0000\u00a9\u00aa\u0005"+ + "b\u0000\u0000\u00aa\u00ab\u0005l\u0000\u0000\u00ab\u00ac\u0005i\u0000"+ + "\u0000\u00ac\u00ad\u0005c\u0000\u0000\u00ad,\u0001\u0000\u0000\u0000\u00ae"+ + "\u00af\u0005n\u0000\u0000\u00af\u00b0\u0005e\u0000\u0000\u00b0\u00b1\u0005"+ + "w\u0000\u0000\u00b1.\u0001\u0000\u0000\u0000\u00b2\u00b3\u0005-\u0000"+ + "\u0000\u00b30\u0001\u0000\u0000\u0000\u00b4\u00b5\u0005+\u0000\u0000\u00b5"+ + "2\u0001\u0000\u0000\u0000\u00b6\u00b7\u0005*\u0000\u0000\u00b74\u0001"+ + "\u0000\u0000\u0000\u00b8\u00b9\u0005i\u0000\u0000\u00b9\u00ba\u0005n\u0000"+ + "\u0000\u00ba\u00bb\u0005t\u0000\u0000\u00bb6\u0001\u0000\u0000\u0000\u00bc"+ + "\u00bd\u0005b\u0000\u0000\u00bd\u00be\u0005o\u0000\u0000\u00be\u00bf\u0005"+ + "o\u0000\u0000\u00bf\u00c0\u0005l\u0000\u0000\u00c0\u00c1\u0005e\u0000"+ + "\u0000\u00c1\u00c2\u0005a\u0000\u0000\u00c2\u00c3\u0005n\u0000\u0000\u00c3"+ + "8\u0001\u0000\u0000\u0000\u00c4\u00c5\u0005v\u0000\u0000\u00c5\u00c6\u0005"+ + "o\u0000\u0000\u00c6\u00c7\u0005i\u0000\u0000\u00c7\u00c8\u0005d\u0000"+ + "\u0000\u00c8:\u0001\u0000\u0000\u0000\u00c9\u00ca\u0007\u0000\u0000\u0000"+ + "\u00ca\u00cb\u0007\u0001\u0000\u0000\u00cb\u00cc\u0007\u0000\u0000\u0000"+ + "\u00cc<\u0001\u0000\u0000\u0000\u00cd\u00cf\u0007\u0001\u0000\u0000\u00ce"+ + "\u00cd\u0001\u0000\u0000\u0000\u00cf\u00d0\u0001\u0000\u0000\u0000\u00d0"+ + "\u00ce\u0001\u0000\u0000\u0000\u00d0\u00d1\u0001\u0000\u0000\u0000\u00d1"+ + ">\u0001\u0000\u0000\u0000\u00d2\u00d4\u0007\u0002\u0000\u0000\u00d3\u00d2"+ + "\u0001\u0000\u0000\u0000\u00d4\u00d5\u0001\u0000\u0000\u0000\u00d5\u00d3"+ + "\u0001\u0000\u0000\u0000\u00d5\u00d6\u0001\u0000\u0000\u0000\u00d6@\u0001"+ + "\u0000\u0000\u0000\u00d7\u00d8\u0007\u0003\u0000\u0000\u00d8\u00d9\u0001"+ + "\u0000\u0000\u0000\u00d9\u00da\u0006 \u0000\u0000\u00daB\u0001\u0000\u0000"+ + "\u0000\u0003\u0000\u00d0\u00d5\u0001\u0006\u0000\u0000"; + 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/src/main/java/de/maishai/antlr/DecafLexer.tokens b/src/main/java/de/maishai/antlr/DecafLexer.tokens new file mode 100644 index 0000000..2f81403 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafLexer.tokens @@ -0,0 +1,62 @@ +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 +PUBLIC=22 +NEW=23 +SUB=24 +ADD=25 +MUL=26 +INT=27 +BOOL=28 +VOID=29 +CHAR=30 +IDENTIFIER=31 +NUMBER=32 +WS=33 +'class'=1 +'{'=2 +'}'=3 +';'=4 +'='=5 +'('=6 +')'=7 +'static'=8 +'main'=9 +'String[] args'=10 +','=11 +'if'=12 +'else'=13 +'for'=14 +'while'=15 +'do'=16 +'return'=17 +'break'=18 +'continue'=19 +'true'=20 +'false'=21 +'public'=22 +'new'=23 +'-'=24 +'+'=25 +'*'=26 +'int'=27 +'boolean'=28 +'void'=29 diff --git a/src/main/java/de/maishai/antlr/DecafListener.java b/src/main/java/de/maishai/antlr/DecafListener.java new file mode 100644 index 0000000..e6a6fed --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafListener.java @@ -0,0 +1,386 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; +import org.antlr.v4.runtime.tree.ParseTreeListener; + +/** + * This interface defines a complete listener for a parse tree produced by + * {@link DecafParser}. + */ +public interface DecafListener extends ParseTreeListener { + /** + * Enter a parse tree produced by {@link DecafParser#program}. + * @param ctx the parse tree + */ + void enterProgram(DecafParser.ProgramContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#program}. + * @param ctx the parse tree + */ + void exitProgram(DecafParser.ProgramContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#class}. + * @param ctx the parse tree + */ + void enterClass(DecafParser.ClassContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#class}. + * @param ctx the parse tree + */ + void exitClass(DecafParser.ClassContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#var}. + * @param ctx the parse tree + */ + void enterVar(DecafParser.VarContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#var}. + * @param ctx the parse tree + */ + void exitVar(DecafParser.VarContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#returntype}. + * @param ctx the parse tree + */ + void enterReturntype(DecafParser.ReturntypeContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#returntype}. + * @param ctx the parse tree + */ + void exitReturntype(DecafParser.ReturntypeContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#type}. + * @param ctx the parse tree + */ + void enterType(DecafParser.TypeContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#type}. + * @param ctx the parse tree + */ + void exitType(DecafParser.TypeContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#meth}. + * @param ctx the parse tree + */ + void enterMeth(DecafParser.MethContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#meth}. + * @param ctx the parse tree + */ + void exitMeth(DecafParser.MethContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#mainmeth}. + * @param ctx the parse tree + */ + void enterMainmeth(DecafParser.MainmethContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#mainmeth}. + * @param ctx the parse tree + */ + void exitMainmeth(DecafParser.MainmethContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#params}. + * @param ctx the parse tree + */ + void enterParams(DecafParser.ParamsContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#params}. + * @param ctx the parse tree + */ + void exitParams(DecafParser.ParamsContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#param}. + * @param ctx the parse tree + */ + void enterParam(DecafParser.ParamContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#param}. + * @param ctx the parse tree + */ + void exitParam(DecafParser.ParamContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#block}. + * @param ctx the parse tree + */ + void enterBlock(DecafParser.BlockContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#block}. + * @param ctx the parse tree + */ + void exitBlock(DecafParser.BlockContext ctx); + /** + * Enter a parse tree produced by the {@code If} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterIf(DecafParser.IfContext ctx); + /** + * Exit a parse tree produced by the {@code If} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitIf(DecafParser.IfContext ctx); + /** + * Enter a parse tree produced by the {@code For} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterFor(DecafParser.ForContext ctx); + /** + * Exit a parse tree produced by the {@code For} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitFor(DecafParser.ForContext ctx); + /** + * Enter a parse tree produced by the {@code While} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterWhile(DecafParser.WhileContext ctx); + /** + * Exit a parse tree produced by the {@code While} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitWhile(DecafParser.WhileContext ctx); + /** + * Enter a parse tree produced by the {@code DoWhile} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterDoWhile(DecafParser.DoWhileContext ctx); + /** + * Exit a parse tree produced by the {@code DoWhile} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitDoWhile(DecafParser.DoWhileContext ctx); + /** + * Enter a parse tree produced by the {@code Return} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterReturn(DecafParser.ReturnContext ctx); + /** + * Exit a parse tree produced by the {@code Return} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitReturn(DecafParser.ReturnContext ctx); + /** + * Enter a parse tree produced by the {@code ReturnVoid} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterReturnVoid(DecafParser.ReturnVoidContext ctx); + /** + * Exit a parse tree produced by the {@code ReturnVoid} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitReturnVoid(DecafParser.ReturnVoidContext ctx); + /** + * Enter a parse tree produced by the {@code Break} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterBreak(DecafParser.BreakContext ctx); + /** + * Exit a parse tree produced by the {@code Break} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitBreak(DecafParser.BreakContext ctx); + /** + * Enter a parse tree produced by the {@code Continue} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterContinue(DecafParser.ContinueContext ctx); + /** + * Exit a parse tree produced by the {@code Continue} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitContinue(DecafParser.ContinueContext ctx); + /** + * Enter a parse tree produced by the {@code StatementExpressionstmt} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void enterStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx); + /** + * Exit a parse tree produced by the {@code StatementExpressionstmt} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + */ + void exitStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx); + /** + * Enter a parse tree produced by the {@code Assign} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void enterAssign(DecafParser.AssignContext ctx); + /** + * Exit a parse tree produced by the {@code Assign} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void exitAssign(DecafParser.AssignContext ctx); + /** + * Enter a parse tree produced by the {@code MethodCall} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void enterMethodCall(DecafParser.MethodCallContext ctx); + /** + * Exit a parse tree produced by the {@code MethodCall} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void exitMethodCall(DecafParser.MethodCallContext ctx); + /** + * Enter a parse tree produced by the {@code New} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void enterNew(DecafParser.NewContext ctx); + /** + * Exit a parse tree produced by the {@code New} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + */ + void exitNew(DecafParser.NewContext ctx); + /** + * Enter a parse tree produced by the {@code Identifier} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterIdentifier(DecafParser.IdentifierContext ctx); + /** + * Exit a parse tree produced by the {@code Identifier} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitIdentifier(DecafParser.IdentifierContext ctx); + /** + * Enter a parse tree produced by the {@code MethodCallExpression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterMethodCallExpression(DecafParser.MethodCallExpressionContext ctx); + /** + * Exit a parse tree produced by the {@code MethodCallExpression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitMethodCallExpression(DecafParser.MethodCallExpressionContext ctx); + /** + * Enter a parse tree produced by the {@code Expression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterExpression(DecafParser.ExpressionContext ctx); + /** + * Exit a parse tree produced by the {@code Expression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitExpression(DecafParser.ExpressionContext ctx); + /** + * Enter a parse tree produced by the {@code Constant} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterConstant(DecafParser.ConstantContext ctx); + /** + * Exit a parse tree produced by the {@code Constant} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitConstant(DecafParser.ConstantContext ctx); + /** + * Enter a parse tree produced by the {@code BinaryOperation} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterBinaryOperation(DecafParser.BinaryOperationContext ctx); + /** + * Exit a parse tree produced by the {@code BinaryOperation} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitBinaryOperation(DecafParser.BinaryOperationContext ctx); + /** + * Enter a parse tree produced by the {@code StatementExpressionexpr} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void enterStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx); + /** + * Exit a parse tree produced by the {@code StatementExpressionexpr} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + */ + void exitStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#binaryOp}. + * @param ctx the parse tree + */ + void enterBinaryOp(DecafParser.BinaryOpContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#binaryOp}. + * @param ctx the parse tree + */ + void exitBinaryOp(DecafParser.BinaryOpContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#methCall}. + * @param ctx the parse tree + */ + void enterMethCall(DecafParser.MethCallContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#methCall}. + * @param ctx the parse tree + */ + void exitMethCall(DecafParser.MethCallContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#args}. + * @param ctx the parse tree + */ + void enterArgs(DecafParser.ArgsContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#args}. + * @param ctx the parse tree + */ + void exitArgs(DecafParser.ArgsContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#literal}. + * @param ctx the parse tree + */ + void enterLiteral(DecafParser.LiteralContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#literal}. + * @param ctx the parse tree + */ + void exitLiteral(DecafParser.LiteralContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#boolean}. + * @param ctx the parse tree + */ + void enterBoolean(DecafParser.BooleanContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#boolean}. + * @param ctx the parse tree + */ + void exitBoolean(DecafParser.BooleanContext ctx); + /** + * Enter a parse tree produced by {@link DecafParser#id}. + * @param ctx the parse tree + */ + void enterId(DecafParser.IdContext ctx); + /** + * Exit a parse tree produced by {@link DecafParser#id}. + * @param ctx the parse tree + */ + void exitId(DecafParser.IdContext ctx); +} \ No newline at end of file diff --git a/src/main/java/de/maishai/antlr/DecafParser.java b/src/main/java/de/maishai/antlr/DecafParser.java new file mode 100644 index 0000000..37e0da2 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafParser.java @@ -0,0 +1,2099 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; +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", "CheckReturnValue"}) +public class DecafParser extends Parser { + static { RuntimeMetaData.checkVersion("4.13.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, PUBLIC=22, NEW=23, SUB=24, ADD=25, + MUL=26, INT=27, BOOL=28, VOID=29, CHAR=30, IDENTIFIER=31, NUMBER=32, WS=33; + public static final int + RULE_program = 0, RULE_class = 1, RULE_var = 2, RULE_returntype = 3, RULE_type = 4, + RULE_meth = 5, RULE_mainmeth = 6, RULE_params = 7, RULE_param = 8, RULE_block = 9, + RULE_stmt = 10, RULE_stmtexpr = 11, RULE_expr = 12, RULE_binaryOp = 13, + RULE_methCall = 14, RULE_args = 15, RULE_literal = 16, RULE_boolean = 17, + RULE_id = 18; + private static String[] makeRuleNames() { + return new String[] { + "program", "class", "var", "returntype", "type", "meth", "mainmeth", + "params", "param", "block", "stmt", "stmtexpr", "expr", "binaryOp", "methCall", + "args", "literal", "boolean", "id" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, "'class'", "'{'", "'}'", "';'", "'='", "'('", "')'", "'static'", + "'main'", "'String[] args'", "','", "'if'", "'else'", "'for'", "'while'", + "'do'", "'return'", "'break'", "'continue'", "'true'", "'false'", "'public'", + "'new'", "'-'", "'+'", "'*'", "'int'", "'boolean'", "'void'" + }; + } + 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, "PUBLIC", + "NEW", "SUB", "ADD", "MUL", "INT", "BOOL", "VOID", "CHAR", "IDENTIFIER", + "NUMBER", "WS" + }; + } + 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] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { return "Decaf.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public ATN getATN() { return _ATN; } + + public DecafParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @SuppressWarnings("CheckReturnValue") + public static class ProgramContext extends ParserRuleContext { + public List class_() { + return getRuleContexts(ClassContext.class); + } + public ClassContext class_(int i) { + return getRuleContext(ClassContext.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 DecafListener ) ((DecafListener)listener).enterProgram(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitProgram(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)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(39); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(38); + class_(); + } + } + setState(41); + _errHandler.sync(this); + _la = _input.LA(1); + } while ( _la==T__0 || _la==PUBLIC ); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ClassContext extends ParserRuleContext { + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public TerminalNode PUBLIC() { return getToken(DecafParser.PUBLIC, 0); } + public List var() { + return getRuleContexts(VarContext.class); + } + public VarContext var(int i) { + return getRuleContext(VarContext.class,i); + } + public List meth() { + return getRuleContexts(MethContext.class); + } + public MethContext meth(int i) { + return getRuleContext(MethContext.class,i); + } + public ClassContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_class; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterClass(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitClass(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitClass(this); + else return visitor.visitChildren(this); + } + } + + public final ClassContext class_() throws RecognitionException { + ClassContext _localctx = new ClassContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_class); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(44); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==PUBLIC) { + { + setState(43); + match(PUBLIC); + } + } + + setState(46); + match(T__0); + setState(47); + id(); + setState(48); + match(T__1); + setState(53); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 2017460224L) != 0)) { + { + setState(51); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) { + case 1: + { + setState(49); + var(); + } + break; + case 2: + { + setState(50); + meth(); + } + break; + } + } + setState(55); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(56); + match(T__2); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class VarContext extends ParserRuleContext { + public TypeContext type() { + return getRuleContext(TypeContext.class,0); + } + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public VarContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_var; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterVar(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitVar(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitVar(this); + else return visitor.visitChildren(this); + } + } + + public final VarContext var() throws RecognitionException { + VarContext _localctx = new VarContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_var); + try { + setState(68); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(58); + type(); + setState(59); + id(); + setState(60); + match(T__3); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(62); + type(); + setState(63); + id(); + setState(64); + match(T__4); + setState(65); + expr(0); + setState(66); + match(T__3); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ReturntypeContext extends ParserRuleContext { + public TypeContext type() { + return getRuleContext(TypeContext.class,0); + } + public TerminalNode VOID() { return getToken(DecafParser.VOID, 0); } + public ReturntypeContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_returntype; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterReturntype(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitReturntype(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitReturntype(this); + else return visitor.visitChildren(this); + } + } + + public final ReturntypeContext returntype() throws RecognitionException { + ReturntypeContext _localctx = new ReturntypeContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_returntype); + try { + setState(72); + _errHandler.sync(this); + switch (_input.LA(1)) { + case INT: + case BOOL: + case CHAR: + enterOuterAlt(_localctx, 1); + { + setState(70); + type(); + } + break; + case VOID: + enterOuterAlt(_localctx, 2); + { + setState(71); + match(VOID); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class TypeContext extends ParserRuleContext { + public TerminalNode INT() { return getToken(DecafParser.INT, 0); } + public TerminalNode BOOL() { return getToken(DecafParser.BOOL, 0); } + public TerminalNode CHAR() { return getToken(DecafParser.CHAR, 0); } + public TypeContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_type; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterType(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitType(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitType(this); + else return visitor.visitChildren(this); + } + } + + public final TypeContext type() throws RecognitionException { + TypeContext _localctx = new TypeContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_type); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(74); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 1476395008L) != 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; + } + + @SuppressWarnings("CheckReturnValue") + public static class MethContext extends ParserRuleContext { + public ReturntypeContext returntype() { + return getRuleContext(ReturntypeContext.class,0); + } + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public BlockContext block() { + return getRuleContext(BlockContext.class,0); + } + public TerminalNode PUBLIC() { return getToken(DecafParser.PUBLIC, 0); } + public ParamsContext params() { + return getRuleContext(ParamsContext.class,0); + } + public MainmethContext mainmeth() { + return getRuleContext(MainmethContext.class,0); + } + public MethContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_meth; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterMeth(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitMeth(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitMeth(this); + else return visitor.visitChildren(this); + } + } + + public final MethContext meth() throws RecognitionException { + MethContext _localctx = new MethContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_meth); + int _la; + try { + setState(89); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,8,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(77); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==PUBLIC) { + { + setState(76); + match(PUBLIC); + } + } + + setState(79); + returntype(); + setState(80); + id(); + setState(81); + match(T__5); + setState(83); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 1476395008L) != 0)) { + { + setState(82); + params(); + } + } + + setState(85); + match(T__6); + setState(86); + block(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(88); + mainmeth(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class MainmethContext extends ParserRuleContext { + public TerminalNode PUBLIC() { return getToken(DecafParser.PUBLIC, 0); } + public TerminalNode VOID() { return getToken(DecafParser.VOID, 0); } + public BlockContext block() { + return getRuleContext(BlockContext.class,0); + } + public MainmethContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_mainmeth; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterMainmeth(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitMainmeth(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitMainmeth(this); + else return visitor.visitChildren(this); + } + } + + public final MainmethContext mainmeth() throws RecognitionException { + MainmethContext _localctx = new MainmethContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_mainmeth); + try { + enterOuterAlt(_localctx, 1); + { + setState(91); + match(PUBLIC); + setState(92); + match(T__7); + setState(93); + match(VOID); + setState(94); + match(T__8); + setState(95); + match(T__5); + setState(96); + match(T__9); + setState(97); + match(T__6); + setState(98); + block(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ParamsContext extends ParserRuleContext { + public List param() { + return getRuleContexts(ParamContext.class); + } + public ParamContext param(int i) { + return getRuleContext(ParamContext.class,i); + } + public ParamsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_params; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterParams(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitParams(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitParams(this); + else return visitor.visitChildren(this); + } + } + + public final ParamsContext params() throws RecognitionException { + ParamsContext _localctx = new ParamsContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_params); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(100); + param(); + setState(105); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==T__10) { + { + { + setState(101); + match(T__10); + setState(102); + param(); + } + } + setState(107); + _errHandler.sync(this); + _la = _input.LA(1); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ParamContext extends ParserRuleContext { + public TypeContext type() { + return getRuleContext(TypeContext.class,0); + } + public IdContext id() { + return getRuleContext(IdContext.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 DecafListener ) ((DecafListener)listener).enterParam(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitParam(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitParam(this); + else return visitor.visitChildren(this); + } + } + + public final ParamContext param() throws RecognitionException { + ParamContext _localctx = new ParamContext(_ctx, getState()); + enterRule(_localctx, 16, RULE_param); + try { + enterOuterAlt(_localctx, 1); + { + setState(108); + type(); + setState(109); + id(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class BlockContext extends ParserRuleContext { + public List var() { + return getRuleContexts(VarContext.class); + } + public VarContext var(int i) { + return getRuleContext(VarContext.class,i); + } + public List stmt() { + return getRuleContexts(StmtContext.class); + } + public StmtContext stmt(int i) { + return getRuleContext(StmtContext.class,i); + } + public BlockContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_block; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterBlock(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitBlock(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitBlock(this); + else return visitor.visitChildren(this); + } + } + + public final BlockContext block() throws RecognitionException { + BlockContext _localctx = new BlockContext(_ctx, getState()); + enterRule(_localctx, 18, RULE_block); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(111); + match(T__1); + setState(116); + _errHandler.sync(this); + _la = _input.LA(1); + while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 3633303552L) != 0)) { + { + setState(114); + _errHandler.sync(this); + switch (_input.LA(1)) { + case INT: + case BOOL: + case CHAR: + { + setState(112); + var(); + } + break; + case T__11: + case T__13: + case T__14: + case T__15: + case T__16: + case T__17: + case T__18: + case NEW: + case IDENTIFIER: + { + setState(113); + stmt(); + } + break; + default: + throw new NoViableAltException(this); + } + } + setState(118); + _errHandler.sync(this); + _la = _input.LA(1); + } + setState(119); + match(T__2); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class StmtContext extends ParserRuleContext { + public StmtContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_stmt; } + + public StmtContext() { } + public void copyFrom(StmtContext ctx) { + super.copyFrom(ctx); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ReturnVoidContext extends StmtContext { + public ReturnVoidContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterReturnVoid(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitReturnVoid(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitReturnVoid(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ReturnContext extends StmtContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public ReturnContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterReturn(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitReturn(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitReturn(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class StatementExpressionstmtContext extends StmtContext { + public StmtexprContext stmtexpr() { + return getRuleContext(StmtexprContext.class,0); + } + public StatementExpressionstmtContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterStatementExpressionstmt(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitStatementExpressionstmt(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitStatementExpressionstmt(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ForContext extends StmtContext { + public List expr() { + return getRuleContexts(ExprContext.class); + } + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class,i); + } + public BlockContext block() { + return getRuleContext(BlockContext.class,0); + } + public ForContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterFor(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitFor(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitFor(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class BreakContext extends StmtContext { + public BreakContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterBreak(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitBreak(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitBreak(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class DoWhileContext extends StmtContext { + public BlockContext block() { + return getRuleContext(BlockContext.class,0); + } + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public DoWhileContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterDoWhile(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitDoWhile(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitDoWhile(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class WhileContext extends StmtContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public BlockContext block() { + return getRuleContext(BlockContext.class,0); + } + public WhileContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterWhile(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitWhile(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitWhile(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ContinueContext extends StmtContext { + public ContinueContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterContinue(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitContinue(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitContinue(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class IfContext extends StmtContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public List block() { + return getRuleContexts(BlockContext.class); + } + public BlockContext block(int i) { + return getRuleContext(BlockContext.class,i); + } + public IfContext(StmtContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterIf(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitIf(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitIf(this); + else return visitor.visitChildren(this); + } + } + + public final StmtContext stmt() throws RecognitionException { + StmtContext _localctx = new StmtContext(_ctx, getState()); + enterRule(_localctx, 20, RULE_stmt); + int _la; + try { + setState(164); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,13,_ctx) ) { + case 1: + _localctx = new IfContext(_localctx); + enterOuterAlt(_localctx, 1); + { + setState(121); + match(T__11); + setState(122); + match(T__5); + setState(123); + expr(0); + setState(124); + match(T__6); + setState(125); + block(); + setState(128); + _errHandler.sync(this); + _la = _input.LA(1); + if (_la==T__12) { + { + setState(126); + match(T__12); + setState(127); + block(); + } + } + + } + break; + case 2: + _localctx = new ForContext(_localctx); + enterOuterAlt(_localctx, 2); + { + setState(130); + match(T__13); + setState(131); + match(T__5); + setState(132); + expr(0); + setState(133); + match(T__3); + setState(134); + expr(0); + setState(135); + match(T__3); + setState(136); + expr(0); + setState(137); + match(T__6); + setState(138); + block(); + } + break; + case 3: + _localctx = new WhileContext(_localctx); + enterOuterAlt(_localctx, 3); + { + setState(140); + match(T__14); + setState(141); + match(T__5); + setState(142); + expr(0); + setState(143); + match(T__6); + setState(144); + block(); + } + break; + case 4: + _localctx = new DoWhileContext(_localctx); + enterOuterAlt(_localctx, 4); + { + setState(146); + match(T__15); + setState(147); + block(); + setState(148); + match(T__14); + setState(149); + match(T__5); + setState(150); + expr(0); + setState(151); + match(T__6); + } + break; + case 5: + _localctx = new ReturnContext(_localctx); + enterOuterAlt(_localctx, 5); + { + setState(153); + match(T__16); + setState(154); + expr(0); + setState(155); + match(T__3); + } + break; + case 6: + _localctx = new ReturnVoidContext(_localctx); + enterOuterAlt(_localctx, 6); + { + setState(157); + match(T__16); + setState(158); + match(T__3); + } + break; + case 7: + _localctx = new BreakContext(_localctx); + enterOuterAlt(_localctx, 7); + { + setState(159); + match(T__17); + setState(160); + match(T__3); + } + break; + case 8: + _localctx = new ContinueContext(_localctx); + enterOuterAlt(_localctx, 8); + { + setState(161); + match(T__18); + setState(162); + match(T__3); + } + break; + case 9: + _localctx = new StatementExpressionstmtContext(_localctx); + enterOuterAlt(_localctx, 9); + { + setState(163); + stmtexpr(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class StmtexprContext extends ParserRuleContext { + public StmtexprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_stmtexpr; } + + public StmtexprContext() { } + public void copyFrom(StmtexprContext ctx) { + super.copyFrom(ctx); + } + } + @SuppressWarnings("CheckReturnValue") + public static class NewContext extends StmtexprContext { + public TerminalNode NEW() { return getToken(DecafParser.NEW, 0); } + public TypeContext type() { + return getRuleContext(TypeContext.class,0); + } + public ArgsContext args() { + return getRuleContext(ArgsContext.class,0); + } + public NewContext(StmtexprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterNew(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitNew(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitNew(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class AssignContext extends StmtexprContext { + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public AssignContext(StmtexprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterAssign(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitAssign(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitAssign(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class MethodCallContext extends StmtexprContext { + public MethCallContext methCall() { + return getRuleContext(MethCallContext.class,0); + } + public MethodCallContext(StmtexprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterMethodCall(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitMethodCall(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitMethodCall(this); + else return visitor.visitChildren(this); + } + } + + public final StmtexprContext stmtexpr() throws RecognitionException { + StmtexprContext _localctx = new StmtexprContext(_ctx, getState()); + enterRule(_localctx, 22, RULE_stmtexpr); + int _la; + try { + setState(182); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,15,_ctx) ) { + case 1: + _localctx = new AssignContext(_localctx); + enterOuterAlt(_localctx, 1); + { + setState(166); + id(); + setState(167); + match(T__4); + setState(168); + expr(0); + setState(169); + match(T__3); + } + break; + case 2: + _localctx = new MethodCallContext(_localctx); + enterOuterAlt(_localctx, 2); + { + setState(171); + methCall(); + setState(172); + match(T__3); + } + break; + case 3: + _localctx = new NewContext(_localctx); + enterOuterAlt(_localctx, 3); + { + setState(174); + match(NEW); + setState(175); + type(); + setState(176); + match(T__5); + setState(178); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7527727168L) != 0)) { + { + setState(177); + args(); + } + } + + setState(180); + match(T__6); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ExprContext extends ParserRuleContext { + public ExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_expr; } + + public ExprContext() { } + public void copyFrom(ExprContext ctx) { + super.copyFrom(ctx); + } + } + @SuppressWarnings("CheckReturnValue") + public static class IdentifierContext extends ExprContext { + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public IdentifierContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterIdentifier(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitIdentifier(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitIdentifier(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class MethodCallExpressionContext extends ExprContext { + public MethCallContext methCall() { + return getRuleContext(MethCallContext.class,0); + } + public MethodCallExpressionContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterMethodCallExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitMethodCallExpression(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitMethodCallExpression(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ExpressionContext extends ExprContext { + public ExprContext expr() { + return getRuleContext(ExprContext.class,0); + } + public ExpressionContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitExpression(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitExpression(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class ConstantContext extends ExprContext { + public LiteralContext literal() { + return getRuleContext(LiteralContext.class,0); + } + public ConstantContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterConstant(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitConstant(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitConstant(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class BinaryOperationContext extends ExprContext { + public List expr() { + return getRuleContexts(ExprContext.class); + } + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class,i); + } + public BinaryOpContext binaryOp() { + return getRuleContext(BinaryOpContext.class,0); + } + public BinaryOperationContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterBinaryOperation(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitBinaryOperation(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitBinaryOperation(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class StatementExpressionexprContext extends ExprContext { + public StmtexprContext stmtexpr() { + return getRuleContext(StmtexprContext.class,0); + } + public StatementExpressionexprContext(ExprContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterStatementExpressionexpr(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitStatementExpressionexpr(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitStatementExpressionexpr(this); + else return visitor.visitChildren(this); + } + } + + public final ExprContext expr() throws RecognitionException { + return expr(0); + } + + private ExprContext expr(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + ExprContext _localctx = new ExprContext(_ctx, _parentState); + ExprContext _prevctx = _localctx; + int _startState = 24; + enterRecursionRule(_localctx, 24, RULE_expr, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(193); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,16,_ctx) ) { + case 1: + { + _localctx = new ConstantContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + + setState(185); + literal(); + } + break; + case 2: + { + _localctx = new ExpressionContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(186); + match(T__5); + setState(187); + expr(0); + setState(188); + match(T__6); + } + break; + case 3: + { + _localctx = new MethodCallExpressionContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(190); + methCall(); + } + break; + case 4: + { + _localctx = new IdentifierContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(191); + id(); + } + break; + case 5: + { + _localctx = new StatementExpressionexprContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(192); + stmtexpr(); + } + break; + } + _ctx.stop = _input.LT(-1); + setState(201); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,17,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + if ( _parseListeners!=null ) triggerExitRuleEvent(); + _prevctx = _localctx; + { + { + _localctx = new BinaryOperationContext(new ExprContext(_parentctx, _parentState)); + pushNewRecursionContext(_localctx, _startState, RULE_expr); + setState(195); + if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); + setState(196); + binaryOp(); + setState(197); + expr(7); + } + } + } + setState(203); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,17,_ctx); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class BinaryOpContext extends ParserRuleContext { + public TerminalNode ADD() { return getToken(DecafParser.ADD, 0); } + public TerminalNode SUB() { return getToken(DecafParser.SUB, 0); } + public TerminalNode MUL() { return getToken(DecafParser.MUL, 0); } + public BinaryOpContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_binaryOp; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterBinaryOp(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitBinaryOp(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitBinaryOp(this); + else return visitor.visitChildren(this); + } + } + + public final BinaryOpContext binaryOp() throws RecognitionException { + BinaryOpContext _localctx = new BinaryOpContext(_ctx, getState()); + enterRule(_localctx, 26, RULE_binaryOp); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(204); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 117440512L) != 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; + } + + @SuppressWarnings("CheckReturnValue") + public static class MethCallContext extends ParserRuleContext { + public IdContext id() { + return getRuleContext(IdContext.class,0); + } + public ArgsContext args() { + return getRuleContext(ArgsContext.class,0); + } + public MethCallContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_methCall; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterMethCall(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitMethCall(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitMethCall(this); + else return visitor.visitChildren(this); + } + } + + public final MethCallContext methCall() throws RecognitionException { + MethCallContext _localctx = new MethCallContext(_ctx, getState()); + enterRule(_localctx, 28, RULE_methCall); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(206); + id(); + setState(207); + match(T__5); + setState(209); + _errHandler.sync(this); + _la = _input.LA(1); + if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 7527727168L) != 0)) { + { + setState(208); + args(); + } + } + + setState(211); + match(T__6); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ArgsContext extends ParserRuleContext { + public List expr() { + return getRuleContexts(ExprContext.class); + } + public ExprContext expr(int i) { + return getRuleContext(ExprContext.class,i); + } + public ArgsContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_args; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterArgs(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitArgs(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitArgs(this); + else return visitor.visitChildren(this); + } + } + + public final ArgsContext args() throws RecognitionException { + ArgsContext _localctx = new ArgsContext(_ctx, getState()); + enterRule(_localctx, 30, RULE_args); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(213); + expr(0); + setState(218); + _errHandler.sync(this); + _la = _input.LA(1); + while (_la==T__10) { + { + { + setState(214); + match(T__10); + setState(215); + expr(0); + } + } + setState(220); + _errHandler.sync(this); + _la = _input.LA(1); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class LiteralContext extends ParserRuleContext { + public TerminalNode NUMBER() { return getToken(DecafParser.NUMBER, 0); } + public BooleanContext boolean_() { + return getRuleContext(BooleanContext.class,0); + } + public TerminalNode CHAR() { return getToken(DecafParser.CHAR, 0); } + public LiteralContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_literal; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterLiteral(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitLiteral(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitLiteral(this); + else return visitor.visitChildren(this); + } + } + + public final LiteralContext literal() throws RecognitionException { + LiteralContext _localctx = new LiteralContext(_ctx, getState()); + enterRule(_localctx, 32, RULE_literal); + try { + setState(224); + _errHandler.sync(this); + switch (_input.LA(1)) { + case NUMBER: + enterOuterAlt(_localctx, 1); + { + setState(221); + match(NUMBER); + } + break; + case T__19: + case T__20: + enterOuterAlt(_localctx, 2); + { + setState(222); + boolean_(); + } + break; + case CHAR: + enterOuterAlt(_localctx, 3); + { + setState(223); + match(CHAR); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class BooleanContext extends ParserRuleContext { + public BooleanContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_boolean; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterBoolean(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitBoolean(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitBoolean(this); + else return visitor.visitChildren(this); + } + } + + public final BooleanContext boolean_() throws RecognitionException { + BooleanContext _localctx = new BooleanContext(_ctx, getState()); + enterRule(_localctx, 34, RULE_boolean); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(226); + _la = _input.LA(1); + if ( !(_la==T__19 || _la==T__20) ) { + _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; + } + + @SuppressWarnings("CheckReturnValue") + public static class IdContext extends ParserRuleContext { + public TerminalNode IDENTIFIER() { return getToken(DecafParser.IDENTIFIER, 0); } + public IdContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_id; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).enterId(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof DecafListener ) ((DecafListener)listener).exitId(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof DecafVisitor ) return ((DecafVisitor)visitor).visitId(this); + else return visitor.visitChildren(this); + } + } + + public final IdContext id() throws RecognitionException { + IdContext _localctx = new IdContext(_ctx, getState()); + enterRule(_localctx, 36, RULE_id); + try { + enterOuterAlt(_localctx, 1); + { + setState(228); + match(IDENTIFIER); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { + switch (ruleIndex) { + case 12: + return expr_sempred((ExprContext)_localctx, predIndex); + } + return true; + } + private boolean expr_sempred(ExprContext _localctx, int predIndex) { + switch (predIndex) { + case 0: + return precpred(_ctx, 6); + } + return true; + } + + public static final String _serializedATN = + "\u0004\u0001!\u00e7\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ + "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+ + "\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+ + "\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b\u0007\u000b\u0002"+ + "\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0002\u000f\u0007\u000f"+ + "\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011\u0002\u0012\u0007\u0012"+ + "\u0001\u0000\u0004\u0000(\b\u0000\u000b\u0000\f\u0000)\u0001\u0001\u0003"+ + "\u0001-\b\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+ + "\u0001\u0005\u00014\b\u0001\n\u0001\f\u00017\t\u0001\u0001\u0001\u0001"+ + "\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001"+ + "\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002E\b"+ + "\u0002\u0001\u0003\u0001\u0003\u0003\u0003I\b\u0003\u0001\u0004\u0001"+ + "\u0004\u0001\u0005\u0003\u0005N\b\u0005\u0001\u0005\u0001\u0005\u0001"+ + "\u0005\u0001\u0005\u0003\u0005T\b\u0005\u0001\u0005\u0001\u0005\u0001"+ + "\u0005\u0001\u0005\u0003\u0005Z\b\u0005\u0001\u0006\u0001\u0006\u0001"+ + "\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001"+ + "\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0005\u0007h\b\u0007\n\u0007"+ + "\f\u0007k\t\u0007\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001\t\u0005"+ + "\ts\b\t\n\t\f\tv\t\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0003\n\u0081\b\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0003\n\u00a5\b\n\u0001\u000b\u0001\u000b\u0001\u000b"+ + "\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b"+ + "\u0001\u000b\u0001\u000b\u0001\u000b\u0003\u000b\u00b3\b\u000b\u0001\u000b"+ + "\u0001\u000b\u0003\u000b\u00b7\b\u000b\u0001\f\u0001\f\u0001\f\u0001\f"+ + "\u0001\f\u0001\f\u0001\f\u0001\f\u0001\f\u0003\f\u00c2\b\f\u0001\f\u0001"+ + "\f\u0001\f\u0001\f\u0005\f\u00c8\b\f\n\f\f\f\u00cb\t\f\u0001\r\u0001\r"+ + "\u0001\u000e\u0001\u000e\u0001\u000e\u0003\u000e\u00d2\b\u000e\u0001\u000e"+ + "\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u000f\u0005\u000f\u00d9\b\u000f"+ + "\n\u000f\f\u000f\u00dc\t\u000f\u0001\u0010\u0001\u0010\u0001\u0010\u0003"+ + "\u0010\u00e1\b\u0010\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001"+ + "\u0012\u0000\u0001\u0018\u0013\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010"+ + "\u0012\u0014\u0016\u0018\u001a\u001c\u001e \"$\u0000\u0003\u0002\u0000"+ + "\u001b\u001c\u001e\u001e\u0001\u0000\u0018\u001a\u0001\u0000\u0014\u0015"+ + "\u00f4\u0000\'\u0001\u0000\u0000\u0000\u0002,\u0001\u0000\u0000\u0000"+ + "\u0004D\u0001\u0000\u0000\u0000\u0006H\u0001\u0000\u0000\u0000\bJ\u0001"+ + "\u0000\u0000\u0000\nY\u0001\u0000\u0000\u0000\f[\u0001\u0000\u0000\u0000"+ + "\u000ed\u0001\u0000\u0000\u0000\u0010l\u0001\u0000\u0000\u0000\u0012o"+ + "\u0001\u0000\u0000\u0000\u0014\u00a4\u0001\u0000\u0000\u0000\u0016\u00b6"+ + "\u0001\u0000\u0000\u0000\u0018\u00c1\u0001\u0000\u0000\u0000\u001a\u00cc"+ + "\u0001\u0000\u0000\u0000\u001c\u00ce\u0001\u0000\u0000\u0000\u001e\u00d5"+ + "\u0001\u0000\u0000\u0000 \u00e0\u0001\u0000\u0000\u0000\"\u00e2\u0001"+ + "\u0000\u0000\u0000$\u00e4\u0001\u0000\u0000\u0000&(\u0003\u0002\u0001"+ + "\u0000\'&\u0001\u0000\u0000\u0000()\u0001\u0000\u0000\u0000)\'\u0001\u0000"+ + "\u0000\u0000)*\u0001\u0000\u0000\u0000*\u0001\u0001\u0000\u0000\u0000"+ + "+-\u0005\u0016\u0000\u0000,+\u0001\u0000\u0000\u0000,-\u0001\u0000\u0000"+ + "\u0000-.\u0001\u0000\u0000\u0000./\u0005\u0001\u0000\u0000/0\u0003$\u0012"+ + "\u000005\u0005\u0002\u0000\u000014\u0003\u0004\u0002\u000024\u0003\n\u0005"+ + "\u000031\u0001\u0000\u0000\u000032\u0001\u0000\u0000\u000047\u0001\u0000"+ + "\u0000\u000053\u0001\u0000\u0000\u000056\u0001\u0000\u0000\u000068\u0001"+ + "\u0000\u0000\u000075\u0001\u0000\u0000\u000089\u0005\u0003\u0000\u0000"+ + "9\u0003\u0001\u0000\u0000\u0000:;\u0003\b\u0004\u0000;<\u0003$\u0012\u0000"+ + "<=\u0005\u0004\u0000\u0000=E\u0001\u0000\u0000\u0000>?\u0003\b\u0004\u0000"+ + "?@\u0003$\u0012\u0000@A\u0005\u0005\u0000\u0000AB\u0003\u0018\f\u0000"+ + "BC\u0005\u0004\u0000\u0000CE\u0001\u0000\u0000\u0000D:\u0001\u0000\u0000"+ + "\u0000D>\u0001\u0000\u0000\u0000E\u0005\u0001\u0000\u0000\u0000FI\u0003"+ + "\b\u0004\u0000GI\u0005\u001d\u0000\u0000HF\u0001\u0000\u0000\u0000HG\u0001"+ + "\u0000\u0000\u0000I\u0007\u0001\u0000\u0000\u0000JK\u0007\u0000\u0000"+ + "\u0000K\t\u0001\u0000\u0000\u0000LN\u0005\u0016\u0000\u0000ML\u0001\u0000"+ + "\u0000\u0000MN\u0001\u0000\u0000\u0000NO\u0001\u0000\u0000\u0000OP\u0003"+ + "\u0006\u0003\u0000PQ\u0003$\u0012\u0000QS\u0005\u0006\u0000\u0000RT\u0003"+ + "\u000e\u0007\u0000SR\u0001\u0000\u0000\u0000ST\u0001\u0000\u0000\u0000"+ + "TU\u0001\u0000\u0000\u0000UV\u0005\u0007\u0000\u0000VW\u0003\u0012\t\u0000"+ + "WZ\u0001\u0000\u0000\u0000XZ\u0003\f\u0006\u0000YM\u0001\u0000\u0000\u0000"+ + "YX\u0001\u0000\u0000\u0000Z\u000b\u0001\u0000\u0000\u0000[\\\u0005\u0016"+ + "\u0000\u0000\\]\u0005\b\u0000\u0000]^\u0005\u001d\u0000\u0000^_\u0005"+ + "\t\u0000\u0000_`\u0005\u0006\u0000\u0000`a\u0005\n\u0000\u0000ab\u0005"+ + "\u0007\u0000\u0000bc\u0003\u0012\t\u0000c\r\u0001\u0000\u0000\u0000di"+ + "\u0003\u0010\b\u0000ef\u0005\u000b\u0000\u0000fh\u0003\u0010\b\u0000g"+ + "e\u0001\u0000\u0000\u0000hk\u0001\u0000\u0000\u0000ig\u0001\u0000\u0000"+ + "\u0000ij\u0001\u0000\u0000\u0000j\u000f\u0001\u0000\u0000\u0000ki\u0001"+ + "\u0000\u0000\u0000lm\u0003\b\u0004\u0000mn\u0003$\u0012\u0000n\u0011\u0001"+ + "\u0000\u0000\u0000ot\u0005\u0002\u0000\u0000ps\u0003\u0004\u0002\u0000"+ + "qs\u0003\u0014\n\u0000rp\u0001\u0000\u0000\u0000rq\u0001\u0000\u0000\u0000"+ + "sv\u0001\u0000\u0000\u0000tr\u0001\u0000\u0000\u0000tu\u0001\u0000\u0000"+ + "\u0000uw\u0001\u0000\u0000\u0000vt\u0001\u0000\u0000\u0000wx\u0005\u0003"+ + "\u0000\u0000x\u0013\u0001\u0000\u0000\u0000yz\u0005\f\u0000\u0000z{\u0005"+ + "\u0006\u0000\u0000{|\u0003\u0018\f\u0000|}\u0005\u0007\u0000\u0000}\u0080"+ + "\u0003\u0012\t\u0000~\u007f\u0005\r\u0000\u0000\u007f\u0081\u0003\u0012"+ + "\t\u0000\u0080~\u0001\u0000\u0000\u0000\u0080\u0081\u0001\u0000\u0000"+ + "\u0000\u0081\u00a5\u0001\u0000\u0000\u0000\u0082\u0083\u0005\u000e\u0000"+ + "\u0000\u0083\u0084\u0005\u0006\u0000\u0000\u0084\u0085\u0003\u0018\f\u0000"+ + "\u0085\u0086\u0005\u0004\u0000\u0000\u0086\u0087\u0003\u0018\f\u0000\u0087"+ + "\u0088\u0005\u0004\u0000\u0000\u0088\u0089\u0003\u0018\f\u0000\u0089\u008a"+ + "\u0005\u0007\u0000\u0000\u008a\u008b\u0003\u0012\t\u0000\u008b\u00a5\u0001"+ + "\u0000\u0000\u0000\u008c\u008d\u0005\u000f\u0000\u0000\u008d\u008e\u0005"+ + "\u0006\u0000\u0000\u008e\u008f\u0003\u0018\f\u0000\u008f\u0090\u0005\u0007"+ + "\u0000\u0000\u0090\u0091\u0003\u0012\t\u0000\u0091\u00a5\u0001\u0000\u0000"+ + "\u0000\u0092\u0093\u0005\u0010\u0000\u0000\u0093\u0094\u0003\u0012\t\u0000"+ + "\u0094\u0095\u0005\u000f\u0000\u0000\u0095\u0096\u0005\u0006\u0000\u0000"+ + "\u0096\u0097\u0003\u0018\f\u0000\u0097\u0098\u0005\u0007\u0000\u0000\u0098"+ + "\u00a5\u0001\u0000\u0000\u0000\u0099\u009a\u0005\u0011\u0000\u0000\u009a"+ + "\u009b\u0003\u0018\f\u0000\u009b\u009c\u0005\u0004\u0000\u0000\u009c\u00a5"+ + "\u0001\u0000\u0000\u0000\u009d\u009e\u0005\u0011\u0000\u0000\u009e\u00a5"+ + "\u0005\u0004\u0000\u0000\u009f\u00a0\u0005\u0012\u0000\u0000\u00a0\u00a5"+ + "\u0005\u0004\u0000\u0000\u00a1\u00a2\u0005\u0013\u0000\u0000\u00a2\u00a5"+ + "\u0005\u0004\u0000\u0000\u00a3\u00a5\u0003\u0016\u000b\u0000\u00a4y\u0001"+ + "\u0000\u0000\u0000\u00a4\u0082\u0001\u0000\u0000\u0000\u00a4\u008c\u0001"+ + "\u0000\u0000\u0000\u00a4\u0092\u0001\u0000\u0000\u0000\u00a4\u0099\u0001"+ + "\u0000\u0000\u0000\u00a4\u009d\u0001\u0000\u0000\u0000\u00a4\u009f\u0001"+ + "\u0000\u0000\u0000\u00a4\u00a1\u0001\u0000\u0000\u0000\u00a4\u00a3\u0001"+ + "\u0000\u0000\u0000\u00a5\u0015\u0001\u0000\u0000\u0000\u00a6\u00a7\u0003"+ + "$\u0012\u0000\u00a7\u00a8\u0005\u0005\u0000\u0000\u00a8\u00a9\u0003\u0018"+ + "\f\u0000\u00a9\u00aa\u0005\u0004\u0000\u0000\u00aa\u00b7\u0001\u0000\u0000"+ + "\u0000\u00ab\u00ac\u0003\u001c\u000e\u0000\u00ac\u00ad\u0005\u0004\u0000"+ + "\u0000\u00ad\u00b7\u0001\u0000\u0000\u0000\u00ae\u00af\u0005\u0017\u0000"+ + "\u0000\u00af\u00b0\u0003\b\u0004\u0000\u00b0\u00b2\u0005\u0006\u0000\u0000"+ + "\u00b1\u00b3\u0003\u001e\u000f\u0000\u00b2\u00b1\u0001\u0000\u0000\u0000"+ + "\u00b2\u00b3\u0001\u0000\u0000\u0000\u00b3\u00b4\u0001\u0000\u0000\u0000"+ + "\u00b4\u00b5\u0005\u0007\u0000\u0000\u00b5\u00b7\u0001\u0000\u0000\u0000"+ + "\u00b6\u00a6\u0001\u0000\u0000\u0000\u00b6\u00ab\u0001\u0000\u0000\u0000"+ + "\u00b6\u00ae\u0001\u0000\u0000\u0000\u00b7\u0017\u0001\u0000\u0000\u0000"+ + "\u00b8\u00b9\u0006\f\uffff\uffff\u0000\u00b9\u00c2\u0003 \u0010\u0000"+ + "\u00ba\u00bb\u0005\u0006\u0000\u0000\u00bb\u00bc\u0003\u0018\f\u0000\u00bc"+ + "\u00bd\u0005\u0007\u0000\u0000\u00bd\u00c2\u0001\u0000\u0000\u0000\u00be"+ + "\u00c2\u0003\u001c\u000e\u0000\u00bf\u00c2\u0003$\u0012\u0000\u00c0\u00c2"+ + "\u0003\u0016\u000b\u0000\u00c1\u00b8\u0001\u0000\u0000\u0000\u00c1\u00ba"+ + "\u0001\u0000\u0000\u0000\u00c1\u00be\u0001\u0000\u0000\u0000\u00c1\u00bf"+ + "\u0001\u0000\u0000\u0000\u00c1\u00c0\u0001\u0000\u0000\u0000\u00c2\u00c9"+ + "\u0001\u0000\u0000\u0000\u00c3\u00c4\n\u0006\u0000\u0000\u00c4\u00c5\u0003"+ + "\u001a\r\u0000\u00c5\u00c6\u0003\u0018\f\u0007\u00c6\u00c8\u0001\u0000"+ + "\u0000\u0000\u00c7\u00c3\u0001\u0000\u0000\u0000\u00c8\u00cb\u0001\u0000"+ + "\u0000\u0000\u00c9\u00c7\u0001\u0000\u0000\u0000\u00c9\u00ca\u0001\u0000"+ + "\u0000\u0000\u00ca\u0019\u0001\u0000\u0000\u0000\u00cb\u00c9\u0001\u0000"+ + "\u0000\u0000\u00cc\u00cd\u0007\u0001\u0000\u0000\u00cd\u001b\u0001\u0000"+ + "\u0000\u0000\u00ce\u00cf\u0003$\u0012\u0000\u00cf\u00d1\u0005\u0006\u0000"+ + "\u0000\u00d0\u00d2\u0003\u001e\u000f\u0000\u00d1\u00d0\u0001\u0000\u0000"+ + "\u0000\u00d1\u00d2\u0001\u0000\u0000\u0000\u00d2\u00d3\u0001\u0000\u0000"+ + "\u0000\u00d3\u00d4\u0005\u0007\u0000\u0000\u00d4\u001d\u0001\u0000\u0000"+ + "\u0000\u00d5\u00da\u0003\u0018\f\u0000\u00d6\u00d7\u0005\u000b\u0000\u0000"+ + "\u00d7\u00d9\u0003\u0018\f\u0000\u00d8\u00d6\u0001\u0000\u0000\u0000\u00d9"+ + "\u00dc\u0001\u0000\u0000\u0000\u00da\u00d8\u0001\u0000\u0000\u0000\u00da"+ + "\u00db\u0001\u0000\u0000\u0000\u00db\u001f\u0001\u0000\u0000\u0000\u00dc"+ + "\u00da\u0001\u0000\u0000\u0000\u00dd\u00e1\u0005 \u0000\u0000\u00de\u00e1"+ + "\u0003\"\u0011\u0000\u00df\u00e1\u0005\u001e\u0000\u0000\u00e0\u00dd\u0001"+ + "\u0000\u0000\u0000\u00e0\u00de\u0001\u0000\u0000\u0000\u00e0\u00df\u0001"+ + "\u0000\u0000\u0000\u00e1!\u0001\u0000\u0000\u0000\u00e2\u00e3\u0007\u0002"+ + "\u0000\u0000\u00e3#\u0001\u0000\u0000\u0000\u00e4\u00e5\u0005\u001f\u0000"+ + "\u0000\u00e5%\u0001\u0000\u0000\u0000\u0015),35DHMSYirt\u0080\u00a4\u00b2"+ + "\u00b6\u00c1\u00c9\u00d1\u00da\u00e0"; + 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/src/main/java/de/maishai/antlr/DecafVisitor.java b/src/main/java/de/maishai/antlr/DecafVisitor.java new file mode 100644 index 0000000..2704c63 --- /dev/null +++ b/src/main/java/de/maishai/antlr/DecafVisitor.java @@ -0,0 +1,235 @@ +// Generated from C:/dev/Compilerbau/CompilerULTIMATE/src/main/antlr/Decaf.g4 by ANTLR 4.13.1 +package de.maishai.antlr; +import org.antlr.v4.runtime.tree.ParseTreeVisitor; + +/** + * This interface defines a complete generic visitor for a parse tree produced + * by {@link DecafParser}. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public interface DecafVisitor extends ParseTreeVisitor { + /** + * Visit a parse tree produced by {@link DecafParser#program}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitProgram(DecafParser.ProgramContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#class}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitClass(DecafParser.ClassContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#var}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitVar(DecafParser.VarContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#returntype}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitReturntype(DecafParser.ReturntypeContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#type}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitType(DecafParser.TypeContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#meth}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMeth(DecafParser.MethContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#mainmeth}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMainmeth(DecafParser.MainmethContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#params}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitParams(DecafParser.ParamsContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#param}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitParam(DecafParser.ParamContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#block}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBlock(DecafParser.BlockContext ctx); + /** + * Visit a parse tree produced by the {@code If} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitIf(DecafParser.IfContext ctx); + /** + * Visit a parse tree produced by the {@code For} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFor(DecafParser.ForContext ctx); + /** + * Visit a parse tree produced by the {@code While} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitWhile(DecafParser.WhileContext ctx); + /** + * Visit a parse tree produced by the {@code DoWhile} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitDoWhile(DecafParser.DoWhileContext ctx); + /** + * Visit a parse tree produced by the {@code Return} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitReturn(DecafParser.ReturnContext ctx); + /** + * Visit a parse tree produced by the {@code ReturnVoid} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitReturnVoid(DecafParser.ReturnVoidContext ctx); + /** + * Visit a parse tree produced by the {@code Break} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBreak(DecafParser.BreakContext ctx); + /** + * Visit a parse tree produced by the {@code Continue} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitContinue(DecafParser.ContinueContext ctx); + /** + * Visit a parse tree produced by the {@code StatementExpressionstmt} + * labeled alternative in {@link DecafParser#stmt}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitStatementExpressionstmt(DecafParser.StatementExpressionstmtContext ctx); + /** + * Visit a parse tree produced by the {@code Assign} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitAssign(DecafParser.AssignContext ctx); + /** + * Visit a parse tree produced by the {@code MethodCall} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMethodCall(DecafParser.MethodCallContext ctx); + /** + * Visit a parse tree produced by the {@code New} + * labeled alternative in {@link DecafParser#stmtexpr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitNew(DecafParser.NewContext ctx); + /** + * Visit a parse tree produced by the {@code Identifier} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitIdentifier(DecafParser.IdentifierContext ctx); + /** + * Visit a parse tree produced by the {@code MethodCallExpression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMethodCallExpression(DecafParser.MethodCallExpressionContext ctx); + /** + * Visit a parse tree produced by the {@code Expression} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExpression(DecafParser.ExpressionContext ctx); + /** + * Visit a parse tree produced by the {@code Constant} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitConstant(DecafParser.ConstantContext ctx); + /** + * Visit a parse tree produced by the {@code BinaryOperation} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBinaryOperation(DecafParser.BinaryOperationContext ctx); + /** + * Visit a parse tree produced by the {@code StatementExpressionexpr} + * labeled alternative in {@link DecafParser#expr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitStatementExpressionexpr(DecafParser.StatementExpressionexprContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#binaryOp}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBinaryOp(DecafParser.BinaryOpContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#methCall}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitMethCall(DecafParser.MethCallContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#args}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitArgs(DecafParser.ArgsContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#literal}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitLiteral(DecafParser.LiteralContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#boolean}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitBoolean(DecafParser.BooleanContext ctx); + /** + * Visit a parse tree produced by {@link DecafParser#id}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitId(DecafParser.IdContext ctx); +} \ No newline at end of file