diff --git a/.idea/misc.xml b/.idea/misc.xml index ccb48ca..bb14756 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -6,10 +6,10 @@ diff --git a/src/main/java/ast/ClassNode.java b/src/main/java/ast/ClassNode.java index 3e8d740..c57a400 100644 --- a/src/main/java/ast/ClassNode.java +++ b/src/main/java/ast/ClassNode.java @@ -12,15 +12,14 @@ import typechecker.TypeCheckResult; import typechecker.Visitable; public class ClassNode extends ASTNode implements Visitable { - public IdentifierNode identifier; + public String identifier; public AccessTypeNode accessType; - public String name; public List members = new ArrayList<>(); public boolean hasConstructor = false; - public ClassNode(AccessTypeNode accessType, String name){ + public ClassNode(AccessTypeNode accessType, String identifier){ this.accessType = accessType; - this.name = name; + this.identifier = identifier; } public void addMember(MemberNode member) { @@ -32,7 +31,7 @@ public class ClassNode extends ASTNode implements Visitable { public void ensureConstructor(){ if(!hasConstructor) { - ConstructorNode constructor = new ConstructorNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), name); + ConstructorNode constructor = new ConstructorNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), identifier); members.add(0,constructor); } } diff --git a/src/main/java/ast/IdentifierNode.java b/src/main/java/ast/IdentifierNode.java deleted file mode 100644 index 992dc6b..0000000 --- a/src/main/java/ast/IdentifierNode.java +++ /dev/null @@ -1,35 +0,0 @@ -package ast; - -import semantic.SemanticVisitor; -import typechecker.TypeCheckResult; -import typechecker.Visitable; - -public class IdentifierNode extends ASTNode implements Visitable { - - private String name; - - public IdentifierNode(String name){ - this.name = name; - } - - public String getName(){ - return name; - } - - public boolean equals(Object obj) { - if(obj instanceof IdentifierNode){ - IdentifierNode identifier = (IdentifierNode) obj; - if(name.equals(identifier.getName())){ - return true; - } else { - return false; - } - } - return super.equals(obj); - } - - @Override - public TypeCheckResult accept(SemanticVisitor visitor) { - return visitor.typeCheck(this); - } -} diff --git a/src/main/java/ast/LiteralNode.java b/src/main/java/ast/LiteralNode.java index 14108ad..8fa060a 100644 --- a/src/main/java/ast/LiteralNode.java +++ b/src/main/java/ast/LiteralNode.java @@ -5,9 +5,19 @@ import ast.expression.ExpressionNode; public class LiteralNode extends ExpressionNode { int value; + private String type; public LiteralNode(int value) { this.value = value; } + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + } diff --git a/src/main/java/ast/VarNode.java b/src/main/java/ast/VarNode.java new file mode 100644 index 0000000..a3ac170 --- /dev/null +++ b/src/main/java/ast/VarNode.java @@ -0,0 +1,21 @@ +package ast; + +public class VarNode extends ASTNode{ + + private String identifier; + private String type; + + public VarNode(String type, String identifier){ + this.type = type; + this.identifier = identifier; + } + + public String getType(){ + return type; + } + + public String getIdentifier(){ + return identifier; + } + +} diff --git a/src/main/java/ast/expression/ExpressionNode.java b/src/main/java/ast/expression/ExpressionNode.java index eff9d29..8204bed 100644 --- a/src/main/java/ast/expression/ExpressionNode.java +++ b/src/main/java/ast/expression/ExpressionNode.java @@ -4,4 +4,6 @@ import ast.ASTNode; public class ExpressionNode extends ASTNode { + + } diff --git a/src/main/java/ast/member/FieldNode.java b/src/main/java/ast/member/FieldNode.java index 569cea0..cfefdfc 100644 --- a/src/main/java/ast/member/FieldNode.java +++ b/src/main/java/ast/member/FieldNode.java @@ -1,6 +1,5 @@ package ast.member; -import ast.IdentifierNode; import ast.type.AccessTypeNode; import ast.type.TypeNode; import semantic.SemanticVisitor; diff --git a/src/main/java/ast/member/MethodNode.java b/src/main/java/ast/member/MethodNode.java index 2d42cc2..122eb5e 100644 --- a/src/main/java/ast/member/MethodNode.java +++ b/src/main/java/ast/member/MethodNode.java @@ -1,6 +1,5 @@ package ast.member; -import ast.IdentifierNode; import ast.parameter.ParameterListNode; import ast.statement.StatementNode; import ast.type.AccessTypeNode; diff --git a/src/main/java/ast/statement/AssignmentStatementNode.java b/src/main/java/ast/statement/AssignmentStatementNode.java index 2b16143..b9158e7 100644 --- a/src/main/java/ast/statement/AssignmentStatementNode.java +++ b/src/main/java/ast/statement/AssignmentStatementNode.java @@ -1,14 +1,22 @@ package ast.statement; -import ast.IdentifierNode; +import ast.VarNode; import ast.expression.ExpressionNode; +import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; +import typechecker.Visitable; -public class AssignmentStatementNode extends StatementNode { - public IdentifierNode identifier; +public class AssignmentStatementNode extends StatementNode implements Visitable { + public VarNode varNode; public ExpressionNode expression; - public AssignmentStatementNode(String identifier, ExpressionNode expression) { - this.identifier = new IdentifierNode(identifier); + public AssignmentStatementNode(VarNode varNode, ExpressionNode expression) { + this.varNode = varNode; this.expression = expression; } + + @Override + public TypeCheckResult accept(SemanticVisitor visitor) { + return visitor.typeCheck(this); + } } diff --git a/src/main/java/ast/statement/VariableDeclarationStatementNode.java b/src/main/java/ast/statement/VariableDeclarationStatementNode.java index 7bdc1ae..e7f6e32 100644 --- a/src/main/java/ast/statement/VariableDeclarationStatementNode.java +++ b/src/main/java/ast/statement/VariableDeclarationStatementNode.java @@ -1,16 +1,15 @@ package ast.statement; -import ast.IdentifierNode; import ast.type.TypeNode; import ast.expression.ExpressionNode; public class VariableDeclarationStatementNode extends StatementNode { public TypeNode type; - public IdentifierNode identifier; + public String identifier; public ExpressionNode expression; public VariableDeclarationStatementNode(TypeNode type, String identifier, ExpressionNode expression) { this.type = type; - this.identifier = new IdentifierNode(identifier); + this.identifier = identifier; this.expression = expression; } } \ No newline at end of file diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index 1e931c0..3b10586 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -15,7 +15,7 @@ public class ClassCodeGen { public void generateClassCode(ClassNode classNode) { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); Mapper mapper = new Mapper(); - classWriter.visit(Opcodes.V1_8, mapper.mapAccesTypeToOpcode(classNode.accessType), classNode.name, null, + classWriter.visit(Opcodes.V1_8, mapper.mapAccesTypeToOpcode(classNode.accessType), classNode.identifier, null, "java/lang/Object", null); for (MemberNode memberNode : classNode.members) { @@ -29,7 +29,7 @@ public class ClassCodeGen { } classWriter.visitEnd(); - printIntoClassFile(classWriter.toByteArray(), classNode.identifier.getName()); + printIntoClassFile(classWriter.toByteArray(), classNode.identifier); classWriter.visitEnd(); } diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index 1596145..87b0238 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -16,11 +16,9 @@ import ast.type.EnumAccessTypeNode; import ast.type.EnumTypeNode; import ast.type.TypeNode; import org.antlr.v4.runtime.tree.TerminalNode; -import parser.generated.SimpleJavaBaseVisitor; -import parser.generated.SimpleJavaParser; - import java.util.ArrayList; import java.util.List; +import parser.generated.*; import parser.generated.SimpleJavaParser.LiteralContext; public class ASTBuilder extends SimpleJavaBaseVisitor { @@ -36,7 +34,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { @Override public ASTNode visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) { ClassNode classNode = new ClassNode((AccessTypeNode) visit(ctx.accessType()),ctx.IDENTIFIER().getText()); - classNode.identifier = new IdentifierNode(ctx.IDENTIFIER().getText()); + classNode.identifier = ctx.IDENTIFIER().getText(); for (SimpleJavaParser.MemberDeclarationContext member : ctx.memberDeclaration()) { classNode.addMember((MemberNode) visit(member)); } @@ -136,9 +134,14 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { @Override public ASTNode visitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx) { - String identifier = ctx.IDENTIFIER().getText(); + VarNode varNode = (VarNode) visit(ctx.var()); ExpressionNode expression = (ExpressionNode) visit(ctx.expression()); - return new AssignmentStatementNode(identifier, expression); + return new AssignmentStatementNode(varNode, expression); + } + + @Override + public ASTNode visitVar(SimpleJavaParser.VarContext ctx) { + return new VarNode("int", ctx.getText()); } @Override @@ -203,7 +206,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { LiteralContext literalContext = (LiteralContext) ctx; try { int intValue = Integer.parseInt(literalContext.getText()); - return new LiteralNode(intValue); + LiteralNode literalNode = new LiteralNode(intValue); + literalNode.setType("int"); + return literalNode; } catch (NumberFormatException ignored) {} return null; // Return null or throw an exception if no valid expression found diff --git a/src/main/java/parser/SimpleJava.g4 b/src/main/java/parser/SimpleJava.g4 index 3de3979..7d09aba 100644 --- a/src/main/java/parser/SimpleJava.g4 +++ b/src/main/java/parser/SimpleJava.g4 @@ -29,7 +29,9 @@ statement variableDeclarationStatement : type IDENTIFIER ('=' expression)? ';' ; -assignmentStatement : IDENTIFIER '=' expression ';' ; +assignmentStatement : var '=' expression ';' ; + +var: IDENTIFIER; ifStatement : 'if' '(' expression ')' statement ('else' statement)? ; diff --git a/src/main/java/parser/generated/SimpleJava.interp b/src/main/java/parser/generated/SimpleJava.interp index 00547cb..c3cff60 100644 --- a/src/main/java/parser/generated/SimpleJava.interp +++ b/src/main/java/parser/generated/SimpleJava.interp @@ -94,6 +94,7 @@ accessType statement variableDeclarationStatement assignmentStatement +var ifStatement whileStatement returnStatement @@ -105,4 +106,4 @@ charLiteral atn: -[4, 1, 38, 208, 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, 1, 0, 4, 0, 44, 8, 0, 11, 0, 12, 0, 45, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 53, 8, 1, 10, 1, 12, 1, 56, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 3, 2, 63, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 76, 8, 4, 1, 4, 1, 4, 1, 4, 5, 4, 81, 8, 4, 10, 4, 12, 4, 84, 9, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 92, 8, 5, 1, 5, 1, 5, 1, 5, 5, 5, 97, 8, 5, 10, 5, 12, 5, 100, 9, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 5, 6, 107, 8, 6, 10, 6, 12, 6, 110, 9, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 125, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 131, 8, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 3, 13, 147, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 3, 15, 157, 8, 15, 1, 15, 1, 15, 1, 16, 1, 16, 5, 16, 163, 8, 16, 10, 16, 12, 16, 166, 9, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 181, 8, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 5, 17, 192, 8, 17, 10, 17, 12, 17, 195, 9, 17, 1, 18, 1, 18, 1, 18, 3, 18, 200, 8, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 0, 1, 34, 21, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 0, 6, 1, 0, 9, 11, 1, 0, 12, 13, 1, 0, 19, 20, 1, 0, 21, 26, 1, 0, 27, 31, 1, 0, 33, 34, 213, 0, 43, 1, 0, 0, 0, 2, 47, 1, 0, 0, 0, 4, 62, 1, 0, 0, 0, 6, 64, 1, 0, 0, 0, 8, 69, 1, 0, 0, 0, 10, 87, 1, 0, 0, 0, 12, 103, 1, 0, 0, 0, 14, 111, 1, 0, 0, 0, 16, 114, 1, 0, 0, 0, 18, 116, 1, 0, 0, 0, 20, 124, 1, 0, 0, 0, 22, 126, 1, 0, 0, 0, 24, 134, 1, 0, 0, 0, 26, 139, 1, 0, 0, 0, 28, 148, 1, 0, 0, 0, 30, 154, 1, 0, 0, 0, 32, 160, 1, 0, 0, 0, 34, 180, 1, 0, 0, 0, 36, 199, 1, 0, 0, 0, 38, 201, 1, 0, 0, 0, 40, 203, 1, 0, 0, 0, 42, 44, 3, 2, 1, 0, 43, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 1, 1, 0, 0, 0, 47, 48, 3, 18, 9, 0, 48, 49, 5, 1, 0, 0, 49, 50, 5, 37, 0, 0, 50, 54, 5, 2, 0, 0, 51, 53, 3, 4, 2, 0, 52, 51, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 57, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 58, 5, 3, 0, 0, 58, 3, 1, 0, 0, 0, 59, 63, 3, 6, 3, 0, 60, 63, 3, 8, 4, 0, 61, 63, 3, 10, 5, 0, 62, 59, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 61, 1, 0, 0, 0, 63, 5, 1, 0, 0, 0, 64, 65, 3, 18, 9, 0, 65, 66, 3, 16, 8, 0, 66, 67, 5, 37, 0, 0, 67, 68, 5, 4, 0, 0, 68, 7, 1, 0, 0, 0, 69, 70, 3, 18, 9, 0, 70, 71, 5, 5, 0, 0, 71, 72, 3, 16, 8, 0, 72, 73, 5, 37, 0, 0, 73, 75, 5, 6, 0, 0, 74, 76, 3, 12, 6, 0, 75, 74, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 78, 5, 7, 0, 0, 78, 82, 5, 2, 0, 0, 79, 81, 3, 20, 10, 0, 80, 79, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 85, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 85, 86, 5, 3, 0, 0, 86, 9, 1, 0, 0, 0, 87, 88, 3, 18, 9, 0, 88, 89, 5, 37, 0, 0, 89, 91, 5, 6, 0, 0, 90, 92, 3, 12, 6, 0, 91, 90, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 94, 5, 7, 0, 0, 94, 98, 5, 2, 0, 0, 95, 97, 3, 20, 10, 0, 96, 95, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 101, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 102, 5, 3, 0, 0, 102, 11, 1, 0, 0, 0, 103, 108, 3, 14, 7, 0, 104, 105, 5, 8, 0, 0, 105, 107, 3, 14, 7, 0, 106, 104, 1, 0, 0, 0, 107, 110, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 108, 109, 1, 0, 0, 0, 109, 13, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 111, 112, 3, 16, 8, 0, 112, 113, 5, 37, 0, 0, 113, 15, 1, 0, 0, 0, 114, 115, 7, 0, 0, 0, 115, 17, 1, 0, 0, 0, 116, 117, 7, 1, 0, 0, 117, 19, 1, 0, 0, 0, 118, 125, 3, 22, 11, 0, 119, 125, 3, 24, 12, 0, 120, 125, 3, 26, 13, 0, 121, 125, 3, 28, 14, 0, 122, 125, 3, 30, 15, 0, 123, 125, 3, 32, 16, 0, 124, 118, 1, 0, 0, 0, 124, 119, 1, 0, 0, 0, 124, 120, 1, 0, 0, 0, 124, 121, 1, 0, 0, 0, 124, 122, 1, 0, 0, 0, 124, 123, 1, 0, 0, 0, 125, 21, 1, 0, 0, 0, 126, 127, 3, 16, 8, 0, 127, 130, 5, 37, 0, 0, 128, 129, 5, 14, 0, 0, 129, 131, 3, 34, 17, 0, 130, 128, 1, 0, 0, 0, 130, 131, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 133, 5, 4, 0, 0, 133, 23, 1, 0, 0, 0, 134, 135, 5, 37, 0, 0, 135, 136, 5, 14, 0, 0, 136, 137, 3, 34, 17, 0, 137, 138, 5, 4, 0, 0, 138, 25, 1, 0, 0, 0, 139, 140, 5, 15, 0, 0, 140, 141, 5, 6, 0, 0, 141, 142, 3, 34, 17, 0, 142, 143, 5, 7, 0, 0, 143, 146, 3, 20, 10, 0, 144, 145, 5, 16, 0, 0, 145, 147, 3, 20, 10, 0, 146, 144, 1, 0, 0, 0, 146, 147, 1, 0, 0, 0, 147, 27, 1, 0, 0, 0, 148, 149, 5, 17, 0, 0, 149, 150, 5, 6, 0, 0, 150, 151, 3, 34, 17, 0, 151, 152, 5, 7, 0, 0, 152, 153, 3, 20, 10, 0, 153, 29, 1, 0, 0, 0, 154, 156, 5, 18, 0, 0, 155, 157, 3, 34, 17, 0, 156, 155, 1, 0, 0, 0, 156, 157, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 159, 5, 4, 0, 0, 159, 31, 1, 0, 0, 0, 160, 164, 5, 2, 0, 0, 161, 163, 3, 20, 10, 0, 162, 161, 1, 0, 0, 0, 163, 166, 1, 0, 0, 0, 164, 162, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 167, 1, 0, 0, 0, 166, 164, 1, 0, 0, 0, 167, 168, 5, 3, 0, 0, 168, 33, 1, 0, 0, 0, 169, 170, 6, 17, -1, 0, 170, 171, 5, 28, 0, 0, 171, 181, 3, 34, 17, 5, 172, 173, 5, 32, 0, 0, 173, 181, 3, 34, 17, 4, 174, 175, 5, 6, 0, 0, 175, 176, 3, 34, 17, 0, 176, 177, 5, 7, 0, 0, 177, 181, 1, 0, 0, 0, 178, 181, 3, 36, 18, 0, 179, 181, 5, 37, 0, 0, 180, 169, 1, 0, 0, 0, 180, 172, 1, 0, 0, 0, 180, 174, 1, 0, 0, 0, 180, 178, 1, 0, 0, 0, 180, 179, 1, 0, 0, 0, 181, 193, 1, 0, 0, 0, 182, 183, 10, 8, 0, 0, 183, 184, 7, 2, 0, 0, 184, 192, 3, 34, 17, 9, 185, 186, 10, 7, 0, 0, 186, 187, 7, 3, 0, 0, 187, 192, 3, 34, 17, 8, 188, 189, 10, 6, 0, 0, 189, 190, 7, 4, 0, 0, 190, 192, 3, 34, 17, 7, 191, 182, 1, 0, 0, 0, 191, 185, 1, 0, 0, 0, 191, 188, 1, 0, 0, 0, 192, 195, 1, 0, 0, 0, 193, 191, 1, 0, 0, 0, 193, 194, 1, 0, 0, 0, 194, 35, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 196, 200, 5, 36, 0, 0, 197, 200, 3, 38, 19, 0, 198, 200, 3, 40, 20, 0, 199, 196, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 199, 198, 1, 0, 0, 0, 200, 37, 1, 0, 0, 0, 201, 202, 7, 5, 0, 0, 202, 39, 1, 0, 0, 0, 203, 204, 5, 35, 0, 0, 204, 205, 9, 0, 0, 0, 205, 206, 5, 35, 0, 0, 206, 41, 1, 0, 0, 0, 17, 45, 54, 62, 75, 82, 91, 98, 108, 124, 130, 146, 156, 164, 180, 191, 193, 199] \ No newline at end of file +[4, 1, 38, 212, 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, 1, 0, 4, 0, 46, 8, 0, 11, 0, 12, 0, 47, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 55, 8, 1, 10, 1, 12, 1, 58, 9, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 3, 2, 65, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 78, 8, 4, 1, 4, 1, 4, 1, 4, 5, 4, 83, 8, 4, 10, 4, 12, 4, 86, 9, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 94, 8, 5, 1, 5, 1, 5, 1, 5, 5, 5, 99, 8, 5, 10, 5, 12, 5, 102, 9, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 5, 6, 109, 8, 6, 10, 6, 12, 6, 112, 9, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 127, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 133, 8, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 3, 14, 151, 8, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 3, 16, 161, 8, 16, 1, 16, 1, 16, 1, 17, 1, 17, 5, 17, 167, 8, 17, 10, 17, 12, 17, 170, 9, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 185, 8, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 5, 18, 196, 8, 18, 10, 18, 12, 18, 199, 9, 18, 1, 19, 1, 19, 1, 19, 3, 19, 204, 8, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 0, 1, 36, 22, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 0, 6, 1, 0, 9, 11, 1, 0, 12, 13, 1, 0, 19, 20, 1, 0, 21, 26, 1, 0, 27, 31, 1, 0, 33, 34, 216, 0, 45, 1, 0, 0, 0, 2, 49, 1, 0, 0, 0, 4, 64, 1, 0, 0, 0, 6, 66, 1, 0, 0, 0, 8, 71, 1, 0, 0, 0, 10, 89, 1, 0, 0, 0, 12, 105, 1, 0, 0, 0, 14, 113, 1, 0, 0, 0, 16, 116, 1, 0, 0, 0, 18, 118, 1, 0, 0, 0, 20, 126, 1, 0, 0, 0, 22, 128, 1, 0, 0, 0, 24, 136, 1, 0, 0, 0, 26, 141, 1, 0, 0, 0, 28, 143, 1, 0, 0, 0, 30, 152, 1, 0, 0, 0, 32, 158, 1, 0, 0, 0, 34, 164, 1, 0, 0, 0, 36, 184, 1, 0, 0, 0, 38, 203, 1, 0, 0, 0, 40, 205, 1, 0, 0, 0, 42, 207, 1, 0, 0, 0, 44, 46, 3, 2, 1, 0, 45, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 45, 1, 0, 0, 0, 47, 48, 1, 0, 0, 0, 48, 1, 1, 0, 0, 0, 49, 50, 3, 18, 9, 0, 50, 51, 5, 1, 0, 0, 51, 52, 5, 37, 0, 0, 52, 56, 5, 2, 0, 0, 53, 55, 3, 4, 2, 0, 54, 53, 1, 0, 0, 0, 55, 58, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 59, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 59, 60, 5, 3, 0, 0, 60, 3, 1, 0, 0, 0, 61, 65, 3, 6, 3, 0, 62, 65, 3, 8, 4, 0, 63, 65, 3, 10, 5, 0, 64, 61, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 64, 63, 1, 0, 0, 0, 65, 5, 1, 0, 0, 0, 66, 67, 3, 18, 9, 0, 67, 68, 3, 16, 8, 0, 68, 69, 5, 37, 0, 0, 69, 70, 5, 4, 0, 0, 70, 7, 1, 0, 0, 0, 71, 72, 3, 18, 9, 0, 72, 73, 5, 5, 0, 0, 73, 74, 3, 16, 8, 0, 74, 75, 5, 37, 0, 0, 75, 77, 5, 6, 0, 0, 76, 78, 3, 12, 6, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 80, 5, 7, 0, 0, 80, 84, 5, 2, 0, 0, 81, 83, 3, 20, 10, 0, 82, 81, 1, 0, 0, 0, 83, 86, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 87, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 87, 88, 5, 3, 0, 0, 88, 9, 1, 0, 0, 0, 89, 90, 3, 18, 9, 0, 90, 91, 5, 37, 0, 0, 91, 93, 5, 6, 0, 0, 92, 94, 3, 12, 6, 0, 93, 92, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 96, 5, 7, 0, 0, 96, 100, 5, 2, 0, 0, 97, 99, 3, 20, 10, 0, 98, 97, 1, 0, 0, 0, 99, 102, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 100, 101, 1, 0, 0, 0, 101, 103, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 103, 104, 5, 3, 0, 0, 104, 11, 1, 0, 0, 0, 105, 110, 3, 14, 7, 0, 106, 107, 5, 8, 0, 0, 107, 109, 3, 14, 7, 0, 108, 106, 1, 0, 0, 0, 109, 112, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 110, 111, 1, 0, 0, 0, 111, 13, 1, 0, 0, 0, 112, 110, 1, 0, 0, 0, 113, 114, 3, 16, 8, 0, 114, 115, 5, 37, 0, 0, 115, 15, 1, 0, 0, 0, 116, 117, 7, 0, 0, 0, 117, 17, 1, 0, 0, 0, 118, 119, 7, 1, 0, 0, 119, 19, 1, 0, 0, 0, 120, 127, 3, 22, 11, 0, 121, 127, 3, 24, 12, 0, 122, 127, 3, 28, 14, 0, 123, 127, 3, 30, 15, 0, 124, 127, 3, 32, 16, 0, 125, 127, 3, 34, 17, 0, 126, 120, 1, 0, 0, 0, 126, 121, 1, 0, 0, 0, 126, 122, 1, 0, 0, 0, 126, 123, 1, 0, 0, 0, 126, 124, 1, 0, 0, 0, 126, 125, 1, 0, 0, 0, 127, 21, 1, 0, 0, 0, 128, 129, 3, 16, 8, 0, 129, 132, 5, 37, 0, 0, 130, 131, 5, 14, 0, 0, 131, 133, 3, 36, 18, 0, 132, 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 135, 5, 4, 0, 0, 135, 23, 1, 0, 0, 0, 136, 137, 3, 26, 13, 0, 137, 138, 5, 14, 0, 0, 138, 139, 3, 36, 18, 0, 139, 140, 5, 4, 0, 0, 140, 25, 1, 0, 0, 0, 141, 142, 5, 37, 0, 0, 142, 27, 1, 0, 0, 0, 143, 144, 5, 15, 0, 0, 144, 145, 5, 6, 0, 0, 145, 146, 3, 36, 18, 0, 146, 147, 5, 7, 0, 0, 147, 150, 3, 20, 10, 0, 148, 149, 5, 16, 0, 0, 149, 151, 3, 20, 10, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 29, 1, 0, 0, 0, 152, 153, 5, 17, 0, 0, 153, 154, 5, 6, 0, 0, 154, 155, 3, 36, 18, 0, 155, 156, 5, 7, 0, 0, 156, 157, 3, 20, 10, 0, 157, 31, 1, 0, 0, 0, 158, 160, 5, 18, 0, 0, 159, 161, 3, 36, 18, 0, 160, 159, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 163, 5, 4, 0, 0, 163, 33, 1, 0, 0, 0, 164, 168, 5, 2, 0, 0, 165, 167, 3, 20, 10, 0, 166, 165, 1, 0, 0, 0, 167, 170, 1, 0, 0, 0, 168, 166, 1, 0, 0, 0, 168, 169, 1, 0, 0, 0, 169, 171, 1, 0, 0, 0, 170, 168, 1, 0, 0, 0, 171, 172, 5, 3, 0, 0, 172, 35, 1, 0, 0, 0, 173, 174, 6, 18, -1, 0, 174, 175, 5, 28, 0, 0, 175, 185, 3, 36, 18, 5, 176, 177, 5, 32, 0, 0, 177, 185, 3, 36, 18, 4, 178, 179, 5, 6, 0, 0, 179, 180, 3, 36, 18, 0, 180, 181, 5, 7, 0, 0, 181, 185, 1, 0, 0, 0, 182, 185, 3, 38, 19, 0, 183, 185, 5, 37, 0, 0, 184, 173, 1, 0, 0, 0, 184, 176, 1, 0, 0, 0, 184, 178, 1, 0, 0, 0, 184, 182, 1, 0, 0, 0, 184, 183, 1, 0, 0, 0, 185, 197, 1, 0, 0, 0, 186, 187, 10, 8, 0, 0, 187, 188, 7, 2, 0, 0, 188, 196, 3, 36, 18, 9, 189, 190, 10, 7, 0, 0, 190, 191, 7, 3, 0, 0, 191, 196, 3, 36, 18, 8, 192, 193, 10, 6, 0, 0, 193, 194, 7, 4, 0, 0, 194, 196, 3, 36, 18, 7, 195, 186, 1, 0, 0, 0, 195, 189, 1, 0, 0, 0, 195, 192, 1, 0, 0, 0, 196, 199, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 197, 198, 1, 0, 0, 0, 198, 37, 1, 0, 0, 0, 199, 197, 1, 0, 0, 0, 200, 204, 5, 36, 0, 0, 201, 204, 3, 40, 20, 0, 202, 204, 3, 42, 21, 0, 203, 200, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 203, 202, 1, 0, 0, 0, 204, 39, 1, 0, 0, 0, 205, 206, 7, 5, 0, 0, 206, 41, 1, 0, 0, 0, 207, 208, 5, 35, 0, 0, 208, 209, 9, 0, 0, 0, 209, 210, 5, 35, 0, 0, 210, 43, 1, 0, 0, 0, 17, 47, 56, 64, 77, 84, 93, 100, 110, 126, 132, 150, 160, 168, 184, 195, 197, 203] \ No newline at end of file diff --git a/src/main/java/parser/generated/SimpleJavaBaseListener.java b/src/main/java/parser/generated/SimpleJavaBaseListener.java index d4d6ae5..342f385 100644 --- a/src/main/java/parser/generated/SimpleJavaBaseListener.java +++ b/src/main/java/parser/generated/SimpleJavaBaseListener.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.ParserRuleContext; @@ -168,6 +168,18 @@ public class SimpleJavaBaseListener implements SimpleJavaListener { *

The default implementation does nothing.

*/ @Override public void exitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

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

The default implementation does nothing.

+ */ + @Override public void exitVar(SimpleJavaParser.VarContext ctx) { } /** * {@inheritDoc} * diff --git a/src/main/java/parser/generated/SimpleJavaBaseVisitor.java b/src/main/java/parser/generated/SimpleJavaBaseVisitor.java index 5e96c5e..4feb7ea 100644 --- a/src/main/java/parser/generated/SimpleJavaBaseVisitor.java +++ b/src/main/java/parser/generated/SimpleJavaBaseVisitor.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; @@ -103,6 +103,13 @@ public class SimpleJavaBaseVisitor extends AbstractParseTreeVisitor implem * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

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

+ */ + @Override public T visitVar(SimpleJavaParser.VarContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} * diff --git a/src/main/java/parser/generated/SimpleJavaLexer.java b/src/main/java/parser/generated/SimpleJavaLexer.java index d0cafe6..979b0a4 100644 --- a/src/main/java/parser/generated/SimpleJavaLexer.java +++ b/src/main/java/parser/generated/SimpleJavaLexer.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.CharStream; diff --git a/src/main/java/parser/generated/SimpleJavaListener.java b/src/main/java/parser/generated/SimpleJavaListener.java index 3223932..6debbf6 100644 --- a/src/main/java/parser/generated/SimpleJavaListener.java +++ b/src/main/java/parser/generated/SimpleJavaListener.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.tree.ParseTreeListener; @@ -137,6 +137,16 @@ public interface SimpleJavaListener extends ParseTreeListener { * @param ctx the parse tree */ void exitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx); + /** + * Enter a parse tree produced by {@link SimpleJavaParser#var}. + * @param ctx the parse tree + */ + void enterVar(SimpleJavaParser.VarContext ctx); + /** + * Exit a parse tree produced by {@link SimpleJavaParser#var}. + * @param ctx the parse tree + */ + void exitVar(SimpleJavaParser.VarContext ctx); /** * Enter a parse tree produced by {@link SimpleJavaParser#ifStatement}. * @param ctx the parse tree diff --git a/src/main/java/parser/generated/SimpleJavaParser.java b/src/main/java/parser/generated/SimpleJavaParser.java index cfa95de..5b14132 100644 --- a/src/main/java/parser/generated/SimpleJavaParser.java +++ b/src/main/java/parser/generated/SimpleJavaParser.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; @@ -28,15 +28,15 @@ public class SimpleJavaParser extends Parser { RULE_fieldDeclaration = 3, RULE_methodDeclaration = 4, RULE_constructorDeclaration = 5, RULE_parameterList = 6, RULE_parameter = 7, RULE_type = 8, RULE_accessType = 9, RULE_statement = 10, RULE_variableDeclarationStatement = 11, RULE_assignmentStatement = 12, - RULE_ifStatement = 13, RULE_whileStatement = 14, RULE_returnStatement = 15, - RULE_block = 16, RULE_expression = 17, RULE_literal = 18, RULE_booleanLiteral = 19, - RULE_charLiteral = 20; + RULE_var = 13, RULE_ifStatement = 14, RULE_whileStatement = 15, RULE_returnStatement = 16, + RULE_block = 17, RULE_expression = 18, RULE_literal = 19, RULE_booleanLiteral = 20, + RULE_charLiteral = 21; private static String[] makeRuleNames() { return new String[] { "program", "classDeclaration", "memberDeclaration", "fieldDeclaration", "methodDeclaration", "constructorDeclaration", "parameterList", "parameter", "type", "accessType", "statement", "variableDeclarationStatement", "assignmentStatement", - "ifStatement", "whileStatement", "returnStatement", "block", "expression", + "var", "ifStatement", "whileStatement", "returnStatement", "block", "expression", "literal", "booleanLiteral", "charLiteral" }; } @@ -145,17 +145,17 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(43); + setState(45); _errHandler.sync(this); _la = _input.LA(1); do { { { - setState(42); + setState(44); classDeclaration(); } } - setState(45); + setState(47); _errHandler.sync(this); _la = _input.LA(1); } while ( _la==T__11 || _la==T__12 ); @@ -210,29 +210,29 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(47); - accessType(); - setState(48); - match(T__0); setState(49); - match(IDENTIFIER); + accessType(); setState(50); + match(T__0); + setState(51); + match(IDENTIFIER); + setState(52); match(T__1); - setState(54); + setState(56); _errHandler.sync(this); _la = _input.LA(1); while (_la==T__11 || _la==T__12) { { { - setState(51); + setState(53); memberDeclaration(); } } - setState(56); + setState(58); _errHandler.sync(this); _la = _input.LA(1); } - setState(57); + setState(59); match(T__2); } } @@ -281,27 +281,27 @@ public class SimpleJavaParser extends Parser { MemberDeclarationContext _localctx = new MemberDeclarationContext(_ctx, getState()); enterRule(_localctx, 4, RULE_memberDeclaration); try { - setState(62); + setState(64); _errHandler.sync(this); switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) { case 1: enterOuterAlt(_localctx, 1); { - setState(59); + setState(61); fieldDeclaration(); } break; case 2: enterOuterAlt(_localctx, 2); { - setState(60); + setState(62); methodDeclaration(); } break; case 3: enterOuterAlt(_localctx, 3); { - setState(61); + setState(63); constructorDeclaration(); } break; @@ -352,13 +352,13 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(64); - accessType(); - setState(65); - type(); setState(66); - match(IDENTIFIER); + accessType(); setState(67); + type(); + setState(68); + match(IDENTIFIER); + setState(69); match(T__3); } } @@ -417,45 +417,45 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(69); - accessType(); - setState(70); - match(T__4); setState(71); - type(); + accessType(); setState(72); - match(IDENTIFIER); + match(T__4); setState(73); - match(T__5); + type(); + setState(74); + match(IDENTIFIER); setState(75); + match(T__5); + setState(77); _errHandler.sync(this); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 3584L) != 0)) { { - setState(74); + setState(76); parameterList(); } } - setState(77); + setState(79); match(T__6); - setState(78); + setState(80); match(T__1); - setState(82); + setState(84); _errHandler.sync(this); _la = _input.LA(1); while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 137439383044L) != 0)) { { { - setState(79); + setState(81); statement(); } } - setState(84); + setState(86); _errHandler.sync(this); _la = _input.LA(1); } - setState(85); + setState(87); match(T__2); } } @@ -511,41 +511,41 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(87); - accessType(); - setState(88); - match(IDENTIFIER); setState(89); - match(T__5); + accessType(); + setState(90); + match(IDENTIFIER); setState(91); + match(T__5); + setState(93); _errHandler.sync(this); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 3584L) != 0)) { { - setState(90); + setState(92); parameterList(); } } - setState(93); + setState(95); match(T__6); - setState(94); + setState(96); match(T__1); - setState(98); + setState(100); _errHandler.sync(this); _la = _input.LA(1); while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 137439383044L) != 0)) { { { - setState(95); + setState(97); statement(); } } - setState(100); + setState(102); _errHandler.sync(this); _la = _input.LA(1); } - setState(101); + setState(103); match(T__2); } } @@ -594,21 +594,21 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(103); + setState(105); parameter(); - setState(108); + setState(110); _errHandler.sync(this); _la = _input.LA(1); while (_la==T__7) { { { - setState(104); + setState(106); match(T__7); - setState(105); + setState(107); parameter(); } } - setState(110); + setState(112); _errHandler.sync(this); _la = _input.LA(1); } @@ -656,9 +656,9 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(111); + setState(113); type(); - setState(112); + setState(114); match(IDENTIFIER); } } @@ -701,7 +701,7 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(114); + setState(116); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 3584L) != 0)) ) { _errHandler.recoverInline(this); @@ -752,7 +752,7 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(116); + setState(118); _la = _input.LA(1); if ( !(_la==T__11 || _la==T__12) ) { _errHandler.recoverInline(this); @@ -818,7 +818,7 @@ public class SimpleJavaParser extends Parser { StatementContext _localctx = new StatementContext(_ctx, getState()); enterRule(_localctx, 20, RULE_statement); try { - setState(124); + setState(126); _errHandler.sync(this); switch (_input.LA(1)) { case T__8: @@ -826,42 +826,42 @@ public class SimpleJavaParser extends Parser { case T__10: enterOuterAlt(_localctx, 1); { - setState(118); + setState(120); variableDeclarationStatement(); } break; case IDENTIFIER: enterOuterAlt(_localctx, 2); { - setState(119); + setState(121); assignmentStatement(); } break; case T__14: enterOuterAlt(_localctx, 3); { - setState(120); + setState(122); ifStatement(); } break; case T__16: enterOuterAlt(_localctx, 4); { - setState(121); + setState(123); whileStatement(); } break; case T__17: enterOuterAlt(_localctx, 5); { - setState(122); + setState(124); returnStatement(); } break; case T__1: enterOuterAlt(_localctx, 6); { - setState(123); + setState(125); block(); } break; @@ -915,23 +915,23 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(126); + setState(128); type(); - setState(127); + setState(129); match(IDENTIFIER); - setState(130); + setState(132); _errHandler.sync(this); _la = _input.LA(1); if (_la==T__13) { { - setState(128); + setState(130); match(T__13); - setState(129); + setState(131); expression(0); } } - setState(132); + setState(134); match(T__3); } } @@ -948,7 +948,9 @@ public class SimpleJavaParser extends Parser { @SuppressWarnings("CheckReturnValue") public static class AssignmentStatementContext extends ParserRuleContext { - public TerminalNode IDENTIFIER() { return getToken(SimpleJavaParser.IDENTIFIER, 0); } + public VarContext var() { + return getRuleContext(VarContext.class,0); + } public ExpressionContext expression() { return getRuleContext(ExpressionContext.class,0); } @@ -977,13 +979,13 @@ public class SimpleJavaParser extends Parser { try { enterOuterAlt(_localctx, 1); { - setState(134); - match(IDENTIFIER); - setState(135); - match(T__13); setState(136); - expression(0); + var(); setState(137); + match(T__13); + setState(138); + expression(0); + setState(139); match(T__3); } } @@ -998,6 +1000,49 @@ public class SimpleJavaParser extends Parser { return _localctx; } + @SuppressWarnings("CheckReturnValue") + public static class VarContext extends ParserRuleContext { + public TerminalNode IDENTIFIER() { return getToken(SimpleJavaParser.IDENTIFIER, 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 SimpleJavaListener ) ((SimpleJavaListener)listener).enterVar(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof SimpleJavaListener ) ((SimpleJavaListener)listener).exitVar(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof SimpleJavaVisitor ) return ((SimpleJavaVisitor)visitor).visitVar(this); + else return visitor.visitChildren(this); + } + } + + public final VarContext var() throws RecognitionException { + VarContext _localctx = new VarContext(_ctx, getState()); + enterRule(_localctx, 26, RULE_var); + try { + enterOuterAlt(_localctx, 1); + { + setState(141); + match(IDENTIFIER); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + @SuppressWarnings("CheckReturnValue") public static class IfStatementContext extends ParserRuleContext { public ExpressionContext expression() { @@ -1030,28 +1075,28 @@ public class SimpleJavaParser extends Parser { public final IfStatementContext ifStatement() throws RecognitionException { IfStatementContext _localctx = new IfStatementContext(_ctx, getState()); - enterRule(_localctx, 26, RULE_ifStatement); + enterRule(_localctx, 28, RULE_ifStatement); try { enterOuterAlt(_localctx, 1); { - setState(139); - match(T__14); - setState(140); - match(T__5); - setState(141); - expression(0); - setState(142); - match(T__6); setState(143); - statement(); + match(T__14); + setState(144); + match(T__5); + setState(145); + expression(0); setState(146); + match(T__6); + setState(147); + statement(); + setState(150); _errHandler.sync(this); switch ( getInterpreter().adaptivePredict(_input,10,_ctx) ) { case 1: { - setState(144); + setState(148); match(T__15); - setState(145); + setState(149); statement(); } break; @@ -1098,19 +1143,19 @@ public class SimpleJavaParser extends Parser { public final WhileStatementContext whileStatement() throws RecognitionException { WhileStatementContext _localctx = new WhileStatementContext(_ctx, getState()); - enterRule(_localctx, 28, RULE_whileStatement); + enterRule(_localctx, 30, RULE_whileStatement); try { enterOuterAlt(_localctx, 1); { - setState(148); - match(T__16); - setState(149); - match(T__5); - setState(150); - expression(0); - setState(151); - match(T__6); setState(152); + match(T__16); + setState(153); + match(T__5); + setState(154); + expression(0); + setState(155); + match(T__6); + setState(156); statement(); } } @@ -1151,24 +1196,24 @@ public class SimpleJavaParser extends Parser { public final ReturnStatementContext returnStatement() throws RecognitionException { ReturnStatementContext _localctx = new ReturnStatementContext(_ctx, getState()); - enterRule(_localctx, 30, RULE_returnStatement); + enterRule(_localctx, 32, RULE_returnStatement); int _la; try { enterOuterAlt(_localctx, 1); { - setState(154); + setState(158); match(T__17); - setState(156); + setState(160); _errHandler.sync(this); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 270851375168L) != 0)) { { - setState(155); + setState(159); expression(0); } } - setState(158); + setState(162); match(T__3); } } @@ -1212,28 +1257,28 @@ public class SimpleJavaParser extends Parser { public final BlockContext block() throws RecognitionException { BlockContext _localctx = new BlockContext(_ctx, getState()); - enterRule(_localctx, 32, RULE_block); + enterRule(_localctx, 34, RULE_block); int _la; try { enterOuterAlt(_localctx, 1); { - setState(160); - match(T__1); setState(164); + match(T__1); + setState(168); _errHandler.sync(this); _la = _input.LA(1); while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 137439383044L) != 0)) { { { - setState(161); + setState(165); statement(); } } - setState(166); + setState(170); _errHandler.sync(this); _la = _input.LA(1); } - setState(167); + setState(171); match(T__2); } } @@ -1288,39 +1333,39 @@ public class SimpleJavaParser extends Parser { int _parentState = getState(); ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState); ExpressionContext _prevctx = _localctx; - int _startState = 34; - enterRecursionRule(_localctx, 34, RULE_expression, _p); + int _startState = 36; + enterRecursionRule(_localctx, 36, RULE_expression, _p); int _la; try { int _alt; enterOuterAlt(_localctx, 1); { - setState(180); + setState(184); _errHandler.sync(this); switch (_input.LA(1)) { case T__27: { - setState(170); + setState(174); match(T__27); - setState(171); + setState(175); expression(5); } break; case T__31: { - setState(172); + setState(176); match(T__31); - setState(173); + setState(177); expression(4); } break; case T__5: { - setState(174); + setState(178); match(T__5); - setState(175); + setState(179); expression(0); - setState(176); + setState(180); match(T__6); } break; @@ -1329,13 +1374,13 @@ public class SimpleJavaParser extends Parser { case T__34: case INTEGERLITERAL: { - setState(178); + setState(182); literal(); } break; case IDENTIFIER: { - setState(179); + setState(183); match(IDENTIFIER); } break; @@ -1343,7 +1388,7 @@ public class SimpleJavaParser extends Parser { throw new NoViableAltException(this); } _ctx.stop = _input.LT(-1); - setState(193); + setState(197); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,15,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { @@ -1351,16 +1396,16 @@ public class SimpleJavaParser extends Parser { if ( _parseListeners!=null ) triggerExitRuleEvent(); _prevctx = _localctx; { - setState(191); + setState(195); _errHandler.sync(this); switch ( getInterpreter().adaptivePredict(_input,14,_ctx) ) { case 1: { _localctx = new ExpressionContext(_parentctx, _parentState); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(182); + setState(186); if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)"); - setState(183); + setState(187); _la = _input.LA(1); if ( !(_la==T__18 || _la==T__19) ) { _errHandler.recoverInline(this); @@ -1370,7 +1415,7 @@ public class SimpleJavaParser extends Parser { _errHandler.reportMatch(this); consume(); } - setState(184); + setState(188); expression(9); } break; @@ -1378,9 +1423,9 @@ public class SimpleJavaParser extends Parser { { _localctx = new ExpressionContext(_parentctx, _parentState); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(185); + setState(189); if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)"); - setState(186); + setState(190); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 132120576L) != 0)) ) { _errHandler.recoverInline(this); @@ -1390,7 +1435,7 @@ public class SimpleJavaParser extends Parser { _errHandler.reportMatch(this); consume(); } - setState(187); + setState(191); expression(8); } break; @@ -1398,9 +1443,9 @@ public class SimpleJavaParser extends Parser { { _localctx = new ExpressionContext(_parentctx, _parentState); pushNewRecursionContext(_localctx, _startState, RULE_expression); - setState(188); + setState(192); if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); - setState(189); + setState(193); _la = _input.LA(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 4160749568L) != 0)) ) { _errHandler.recoverInline(this); @@ -1410,14 +1455,14 @@ public class SimpleJavaParser extends Parser { _errHandler.reportMatch(this); consume(); } - setState(190); + setState(194); expression(7); } break; } } } - setState(195); + setState(199); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,15,_ctx); } @@ -1464,15 +1509,15 @@ public class SimpleJavaParser extends Parser { public final LiteralContext literal() throws RecognitionException { LiteralContext _localctx = new LiteralContext(_ctx, getState()); - enterRule(_localctx, 36, RULE_literal); + enterRule(_localctx, 38, RULE_literal); try { - setState(199); + setState(203); _errHandler.sync(this); switch (_input.LA(1)) { case INTEGERLITERAL: enterOuterAlt(_localctx, 1); { - setState(196); + setState(200); match(INTEGERLITERAL); } break; @@ -1480,14 +1525,14 @@ public class SimpleJavaParser extends Parser { case T__33: enterOuterAlt(_localctx, 2); { - setState(197); + setState(201); booleanLiteral(); } break; case T__34: enterOuterAlt(_localctx, 3); { - setState(198); + setState(202); charLiteral(); } break; @@ -1529,12 +1574,12 @@ public class SimpleJavaParser extends Parser { public final BooleanLiteralContext booleanLiteral() throws RecognitionException { BooleanLiteralContext _localctx = new BooleanLiteralContext(_ctx, getState()); - enterRule(_localctx, 38, RULE_booleanLiteral); + enterRule(_localctx, 40, RULE_booleanLiteral); int _la; try { enterOuterAlt(_localctx, 1); { - setState(201); + setState(205); _la = _input.LA(1); if ( !(_la==T__32 || _la==T__33) ) { _errHandler.recoverInline(this); @@ -1580,15 +1625,15 @@ public class SimpleJavaParser extends Parser { public final CharLiteralContext charLiteral() throws RecognitionException { CharLiteralContext _localctx = new CharLiteralContext(_ctx, getState()); - enterRule(_localctx, 40, RULE_charLiteral); + enterRule(_localctx, 42, RULE_charLiteral); try { enterOuterAlt(_localctx, 1); { - setState(203); + setState(207); match(T__34); - setState(204); + setState(208); matchWildcard(); - setState(205); + setState(209); match(T__34); } } @@ -1605,7 +1650,7 @@ public class SimpleJavaParser extends Parser { public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { switch (ruleIndex) { - case 17: + case 18: return expression_sempred((ExpressionContext)_localctx, predIndex); } return true; @@ -1623,132 +1668,134 @@ public class SimpleJavaParser extends Parser { } public static final String _serializedATN = - "\u0004\u0001&\u00d0\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ + "\u0004\u0001&\u00d4\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\u0001\u0000\u0004\u0000"+ - ",\b\u0000\u000b\u0000\f\u0000-\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+ - "\u0001\u0001\u0001\u0005\u00015\b\u0001\n\u0001\f\u00018\t\u0001\u0001"+ - "\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002?\b"+ - "\u0002\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001"+ - "\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0003"+ - "\u0004L\b\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0005\u0004Q\b\u0004"+ - "\n\u0004\f\u0004T\t\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005"+ - "\u0001\u0005\u0001\u0005\u0003\u0005\\\b\u0005\u0001\u0005\u0001\u0005"+ - "\u0001\u0005\u0005\u0005a\b\u0005\n\u0005\f\u0005d\t\u0005\u0001\u0005"+ - "\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0005\u0006k\b\u0006"+ - "\n\u0006\f\u0006n\t\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0001\b"+ - "\u0001\b\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ - "\n\u0003\n}\b\n\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0003"+ - "\u000b\u0083\b\u000b\u0001\u000b\u0001\u000b\u0001\f\u0001\f\u0001\f\u0001"+ - "\f\u0001\f\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0003"+ - "\r\u0093\b\r\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e"+ - "\u0001\u000e\u0001\u000f\u0001\u000f\u0003\u000f\u009d\b\u000f\u0001\u000f"+ - "\u0001\u000f\u0001\u0010\u0001\u0010\u0005\u0010\u00a3\b\u0010\n\u0010"+ - "\f\u0010\u00a6\t\u0010\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011"+ - "\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011"+ - "\u0001\u0011\u0001\u0011\u0001\u0011\u0003\u0011\u00b5\b\u0011\u0001\u0011"+ - "\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011\u0001\u0011"+ - "\u0001\u0011\u0001\u0011\u0005\u0011\u00c0\b\u0011\n\u0011\f\u0011\u00c3"+ - "\t\u0011\u0001\u0012\u0001\u0012\u0001\u0012\u0003\u0012\u00c8\b\u0012"+ - "\u0001\u0013\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014"+ - "\u0001\u0014\u0000\u0001\"\u0015\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010"+ - "\u0012\u0014\u0016\u0018\u001a\u001c\u001e \"$&(\u0000\u0006\u0001\u0000"+ + "\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014\u0002\u0015\u0007\u0015"+ + "\u0001\u0000\u0004\u0000.\b\u0000\u000b\u0000\f\u0000/\u0001\u0001\u0001"+ + "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0005\u00017\b\u0001\n\u0001"+ + "\f\u0001:\t\u0001\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001"+ + "\u0002\u0003\u0002A\b\u0002\u0001\u0003\u0001\u0003\u0001\u0003\u0001"+ + "\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001"+ + "\u0004\u0001\u0004\u0003\u0004N\b\u0004\u0001\u0004\u0001\u0004\u0001"+ + "\u0004\u0005\u0004S\b\u0004\n\u0004\f\u0004V\t\u0004\u0001\u0004\u0001"+ + "\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0003\u0005^\b"+ + "\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0005\u0005c\b\u0005\n\u0005"+ + "\f\u0005f\t\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001"+ + "\u0006\u0005\u0006m\b\u0006\n\u0006\f\u0006p\t\u0006\u0001\u0007\u0001"+ + "\u0007\u0001\u0007\u0001\b\u0001\b\u0001\t\u0001\t\u0001\n\u0001\n\u0001"+ + "\n\u0001\n\u0001\n\u0001\n\u0003\n\u007f\b\n\u0001\u000b\u0001\u000b\u0001"+ + "\u000b\u0001\u000b\u0003\u000b\u0085\b\u000b\u0001\u000b\u0001\u000b\u0001"+ + "\f\u0001\f\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r\u0001\u000e\u0001\u000e"+ + "\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0003\u000e"+ + "\u0097\b\u000e\u0001\u000f\u0001\u000f\u0001\u000f\u0001\u000f\u0001\u000f"+ + "\u0001\u000f\u0001\u0010\u0001\u0010\u0003\u0010\u00a1\b\u0010\u0001\u0010"+ + "\u0001\u0010\u0001\u0011\u0001\u0011\u0005\u0011\u00a7\b\u0011\n\u0011"+ + "\f\u0011\u00aa\t\u0011\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012"+ + "\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012"+ + "\u0001\u0012\u0001\u0012\u0001\u0012\u0003\u0012\u00b9\b\u0012\u0001\u0012"+ + "\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012\u0001\u0012"+ + "\u0001\u0012\u0001\u0012\u0005\u0012\u00c4\b\u0012\n\u0012\f\u0012\u00c7"+ + "\t\u0012\u0001\u0013\u0001\u0013\u0001\u0013\u0003\u0013\u00cc\b\u0013"+ + "\u0001\u0014\u0001\u0014\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0015"+ + "\u0001\u0015\u0000\u0001$\u0016\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010"+ + "\u0012\u0014\u0016\u0018\u001a\u001c\u001e \"$&(*\u0000\u0006\u0001\u0000"+ "\t\u000b\u0001\u0000\f\r\u0001\u0000\u0013\u0014\u0001\u0000\u0015\u001a"+ - "\u0001\u0000\u001b\u001f\u0001\u0000!\"\u00d5\u0000+\u0001\u0000\u0000"+ - "\u0000\u0002/\u0001\u0000\u0000\u0000\u0004>\u0001\u0000\u0000\u0000\u0006"+ - "@\u0001\u0000\u0000\u0000\bE\u0001\u0000\u0000\u0000\nW\u0001\u0000\u0000"+ - "\u0000\fg\u0001\u0000\u0000\u0000\u000eo\u0001\u0000\u0000\u0000\u0010"+ - "r\u0001\u0000\u0000\u0000\u0012t\u0001\u0000\u0000\u0000\u0014|\u0001"+ - "\u0000\u0000\u0000\u0016~\u0001\u0000\u0000\u0000\u0018\u0086\u0001\u0000"+ - "\u0000\u0000\u001a\u008b\u0001\u0000\u0000\u0000\u001c\u0094\u0001\u0000"+ - "\u0000\u0000\u001e\u009a\u0001\u0000\u0000\u0000 \u00a0\u0001\u0000\u0000"+ - "\u0000\"\u00b4\u0001\u0000\u0000\u0000$\u00c7\u0001\u0000\u0000\u0000"+ - "&\u00c9\u0001\u0000\u0000\u0000(\u00cb\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/0\u0003\u0012\t\u000001\u0005\u0001\u0000\u000012\u0005%"+ - "\u0000\u000026\u0005\u0002\u0000\u000035\u0003\u0004\u0002\u000043\u0001"+ - "\u0000\u0000\u000058\u0001\u0000\u0000\u000064\u0001\u0000\u0000\u0000"+ - "67\u0001\u0000\u0000\u000079\u0001\u0000\u0000\u000086\u0001\u0000\u0000"+ - "\u00009:\u0005\u0003\u0000\u0000:\u0003\u0001\u0000\u0000\u0000;?\u0003"+ - "\u0006\u0003\u0000;\u0001"+ - "\u0000\u0000\u0000><\u0001\u0000\u0000\u0000>=\u0001\u0000\u0000\u0000"+ - "?\u0005\u0001\u0000\u0000\u0000@A\u0003\u0012\t\u0000AB\u0003\u0010\b"+ - "\u0000BC\u0005%\u0000\u0000CD\u0005\u0004\u0000\u0000D\u0007\u0001\u0000"+ - "\u0000\u0000EF\u0003\u0012\t\u0000FG\u0005\u0005\u0000\u0000GH\u0003\u0010"+ - "\b\u0000HI\u0005%\u0000\u0000IK\u0005\u0006\u0000\u0000JL\u0003\f\u0006"+ - "\u0000KJ\u0001\u0000\u0000\u0000KL\u0001\u0000\u0000\u0000LM\u0001\u0000"+ - "\u0000\u0000MN\u0005\u0007\u0000\u0000NR\u0005\u0002\u0000\u0000OQ\u0003"+ - "\u0014\n\u0000PO\u0001\u0000\u0000\u0000QT\u0001\u0000\u0000\u0000RP\u0001"+ - "\u0000\u0000\u0000RS\u0001\u0000\u0000\u0000SU\u0001\u0000\u0000\u0000"+ - "TR\u0001\u0000\u0000\u0000UV\u0005\u0003\u0000\u0000V\t\u0001\u0000\u0000"+ - "\u0000WX\u0003\u0012\t\u0000XY\u0005%\u0000\u0000Y[\u0005\u0006\u0000"+ - "\u0000Z\\\u0003\f\u0006\u0000[Z\u0001\u0000\u0000\u0000[\\\u0001\u0000"+ - "\u0000\u0000\\]\u0001\u0000\u0000\u0000]^\u0005\u0007\u0000\u0000^b\u0005"+ - "\u0002\u0000\u0000_a\u0003\u0014\n\u0000`_\u0001\u0000\u0000\u0000ad\u0001"+ - "\u0000\u0000\u0000b`\u0001\u0000\u0000\u0000bc\u0001\u0000\u0000\u0000"+ - "ce\u0001\u0000\u0000\u0000db\u0001\u0000\u0000\u0000ef\u0005\u0003\u0000"+ - "\u0000f\u000b\u0001\u0000\u0000\u0000gl\u0003\u000e\u0007\u0000hi\u0005"+ - "\b\u0000\u0000ik\u0003\u000e\u0007\u0000jh\u0001\u0000\u0000\u0000kn\u0001"+ - "\u0000\u0000\u0000lj\u0001\u0000\u0000\u0000lm\u0001\u0000\u0000\u0000"+ - "m\r\u0001\u0000\u0000\u0000nl\u0001\u0000\u0000\u0000op\u0003\u0010\b"+ - "\u0000pq\u0005%\u0000\u0000q\u000f\u0001\u0000\u0000\u0000rs\u0007\u0000"+ - "\u0000\u0000s\u0011\u0001\u0000\u0000\u0000tu\u0007\u0001\u0000\u0000"+ - "u\u0013\u0001\u0000\u0000\u0000v}\u0003\u0016\u000b\u0000w}\u0003\u0018"+ - "\f\u0000x}\u0003\u001a\r\u0000y}\u0003\u001c\u000e\u0000z}\u0003\u001e"+ - "\u000f\u0000{}\u0003 \u0010\u0000|v\u0001\u0000\u0000\u0000|w\u0001\u0000"+ - "\u0000\u0000|x\u0001\u0000\u0000\u0000|y\u0001\u0000\u0000\u0000|z\u0001"+ - "\u0000\u0000\u0000|{\u0001\u0000\u0000\u0000}\u0015\u0001\u0000\u0000"+ - "\u0000~\u007f\u0003\u0010\b\u0000\u007f\u0082\u0005%\u0000\u0000\u0080"+ - "\u0081\u0005\u000e\u0000\u0000\u0081\u0083\u0003\"\u0011\u0000\u0082\u0080"+ - "\u0001\u0000\u0000\u0000\u0082\u0083\u0001\u0000\u0000\u0000\u0083\u0084"+ - "\u0001\u0000\u0000\u0000\u0084\u0085\u0005\u0004\u0000\u0000\u0085\u0017"+ - "\u0001\u0000\u0000\u0000\u0086\u0087\u0005%\u0000\u0000\u0087\u0088\u0005"+ - "\u000e\u0000\u0000\u0088\u0089\u0003\"\u0011\u0000\u0089\u008a\u0005\u0004"+ - "\u0000\u0000\u008a\u0019\u0001\u0000\u0000\u0000\u008b\u008c\u0005\u000f"+ - "\u0000\u0000\u008c\u008d\u0005\u0006\u0000\u0000\u008d\u008e\u0003\"\u0011"+ - "\u0000\u008e\u008f\u0005\u0007\u0000\u0000\u008f\u0092\u0003\u0014\n\u0000"+ - "\u0090\u0091\u0005\u0010\u0000\u0000\u0091\u0093\u0003\u0014\n\u0000\u0092"+ - "\u0090\u0001\u0000\u0000\u0000\u0092\u0093\u0001\u0000\u0000\u0000\u0093"+ - "\u001b\u0001\u0000\u0000\u0000\u0094\u0095\u0005\u0011\u0000\u0000\u0095"+ - "\u0096\u0005\u0006\u0000\u0000\u0096\u0097\u0003\"\u0011\u0000\u0097\u0098"+ - "\u0005\u0007\u0000\u0000\u0098\u0099\u0003\u0014\n\u0000\u0099\u001d\u0001"+ - "\u0000\u0000\u0000\u009a\u009c\u0005\u0012\u0000\u0000\u009b\u009d\u0003"+ - "\"\u0011\u0000\u009c\u009b\u0001\u0000\u0000\u0000\u009c\u009d\u0001\u0000"+ - "\u0000\u0000\u009d\u009e\u0001\u0000\u0000\u0000\u009e\u009f\u0005\u0004"+ - "\u0000\u0000\u009f\u001f\u0001\u0000\u0000\u0000\u00a0\u00a4\u0005\u0002"+ - "\u0000\u0000\u00a1\u00a3\u0003\u0014\n\u0000\u00a2\u00a1\u0001\u0000\u0000"+ - "\u0000\u00a3\u00a6\u0001\u0000\u0000\u0000\u00a4\u00a2\u0001\u0000\u0000"+ - "\u0000\u00a4\u00a5\u0001\u0000\u0000\u0000\u00a5\u00a7\u0001\u0000\u0000"+ - "\u0000\u00a6\u00a4\u0001\u0000\u0000\u0000\u00a7\u00a8\u0005\u0003\u0000"+ - "\u0000\u00a8!\u0001\u0000\u0000\u0000\u00a9\u00aa\u0006\u0011\uffff\uffff"+ - "\u0000\u00aa\u00ab\u0005\u001c\u0000\u0000\u00ab\u00b5\u0003\"\u0011\u0005"+ - "\u00ac\u00ad\u0005 \u0000\u0000\u00ad\u00b5\u0003\"\u0011\u0004\u00ae"+ - "\u00af\u0005\u0006\u0000\u0000\u00af\u00b0\u0003\"\u0011\u0000\u00b0\u00b1"+ - "\u0005\u0007\u0000\u0000\u00b1\u00b5\u0001\u0000\u0000\u0000\u00b2\u00b5"+ - "\u0003$\u0012\u0000\u00b3\u00b5\u0005%\u0000\u0000\u00b4\u00a9\u0001\u0000"+ - "\u0000\u0000\u00b4\u00ac\u0001\u0000\u0000\u0000\u00b4\u00ae\u0001\u0000"+ - "\u0000\u0000\u00b4\u00b2\u0001\u0000\u0000\u0000\u00b4\u00b3\u0001\u0000"+ - "\u0000\u0000\u00b5\u00c1\u0001\u0000\u0000\u0000\u00b6\u00b7\n\b\u0000"+ - "\u0000\u00b7\u00b8\u0007\u0002\u0000\u0000\u00b8\u00c0\u0003\"\u0011\t"+ - "\u00b9\u00ba\n\u0007\u0000\u0000\u00ba\u00bb\u0007\u0003\u0000\u0000\u00bb"+ - "\u00c0\u0003\"\u0011\b\u00bc\u00bd\n\u0006\u0000\u0000\u00bd\u00be\u0007"+ - "\u0004\u0000\u0000\u00be\u00c0\u0003\"\u0011\u0007\u00bf\u00b6\u0001\u0000"+ - "\u0000\u0000\u00bf\u00b9\u0001\u0000\u0000\u0000\u00bf\u00bc\u0001\u0000"+ - "\u0000\u0000\u00c0\u00c3\u0001\u0000\u0000\u0000\u00c1\u00bf\u0001\u0000"+ - "\u0000\u0000\u00c1\u00c2\u0001\u0000\u0000\u0000\u00c2#\u0001\u0000\u0000"+ - "\u0000\u00c3\u00c1\u0001\u0000\u0000\u0000\u00c4\u00c8\u0005$\u0000\u0000"+ - "\u00c5\u00c8\u0003&\u0013\u0000\u00c6\u00c8\u0003(\u0014\u0000\u00c7\u00c4"+ - "\u0001\u0000\u0000\u0000\u00c7\u00c5\u0001\u0000\u0000\u0000\u00c7\u00c6"+ - "\u0001\u0000\u0000\u0000\u00c8%\u0001\u0000\u0000\u0000\u00c9\u00ca\u0007"+ - "\u0005\u0000\u0000\u00ca\'\u0001\u0000\u0000\u0000\u00cb\u00cc\u0005#"+ - "\u0000\u0000\u00cc\u00cd\t\u0000\u0000\u0000\u00cd\u00ce\u0005#\u0000"+ - "\u0000\u00ce)\u0001\u0000\u0000\u0000\u0011-6>KR[bl|\u0082\u0092\u009c"+ - "\u00a4\u00b4\u00bf\u00c1\u00c7"; + "\u0001\u0000\u001b\u001f\u0001\u0000!\"\u00d8\u0000-\u0001\u0000\u0000"+ + "\u0000\u00021\u0001\u0000\u0000\u0000\u0004@\u0001\u0000\u0000\u0000\u0006"+ + "B\u0001\u0000\u0000\u0000\bG\u0001\u0000\u0000\u0000\nY\u0001\u0000\u0000"+ + "\u0000\fi\u0001\u0000\u0000\u0000\u000eq\u0001\u0000\u0000\u0000\u0010"+ + "t\u0001\u0000\u0000\u0000\u0012v\u0001\u0000\u0000\u0000\u0014~\u0001"+ + "\u0000\u0000\u0000\u0016\u0080\u0001\u0000\u0000\u0000\u0018\u0088\u0001"+ + "\u0000\u0000\u0000\u001a\u008d\u0001\u0000\u0000\u0000\u001c\u008f\u0001"+ + "\u0000\u0000\u0000\u001e\u0098\u0001\u0000\u0000\u0000 \u009e\u0001\u0000"+ + "\u0000\u0000\"\u00a4\u0001\u0000\u0000\u0000$\u00b8\u0001\u0000\u0000"+ + "\u0000&\u00cb\u0001\u0000\u0000\u0000(\u00cd\u0001\u0000\u0000\u0000*"+ + "\u00cf\u0001\u0000\u0000\u0000,.\u0003\u0002\u0001\u0000-,\u0001\u0000"+ + "\u0000\u0000./\u0001\u0000\u0000\u0000/-\u0001\u0000\u0000\u0000/0\u0001"+ + "\u0000\u0000\u00000\u0001\u0001\u0000\u0000\u000012\u0003\u0012\t\u0000"+ + "23\u0005\u0001\u0000\u000034\u0005%\u0000\u000048\u0005\u0002\u0000\u0000"+ + "57\u0003\u0004\u0002\u000065\u0001\u0000\u0000\u00007:\u0001\u0000\u0000"+ + "\u000086\u0001\u0000\u0000\u000089\u0001\u0000\u0000\u00009;\u0001\u0000"+ + "\u0000\u0000:8\u0001\u0000\u0000\u0000;<\u0005\u0003\u0000\u0000<\u0003"+ + "\u0001\u0000\u0000\u0000=A\u0003\u0006\u0003\u0000>A\u0003\b\u0004\u0000"+ + "?A\u0003\n\u0005\u0000@=\u0001\u0000\u0000\u0000@>\u0001\u0000\u0000\u0000"+ + "@?\u0001\u0000\u0000\u0000A\u0005\u0001\u0000\u0000\u0000BC\u0003\u0012"+ + "\t\u0000CD\u0003\u0010\b\u0000DE\u0005%\u0000\u0000EF\u0005\u0004\u0000"+ + "\u0000F\u0007\u0001\u0000\u0000\u0000GH\u0003\u0012\t\u0000HI\u0005\u0005"+ + "\u0000\u0000IJ\u0003\u0010\b\u0000JK\u0005%\u0000\u0000KM\u0005\u0006"+ + "\u0000\u0000LN\u0003\f\u0006\u0000ML\u0001\u0000\u0000\u0000MN\u0001\u0000"+ + "\u0000\u0000NO\u0001\u0000\u0000\u0000OP\u0005\u0007\u0000\u0000PT\u0005"+ + "\u0002\u0000\u0000QS\u0003\u0014\n\u0000RQ\u0001\u0000\u0000\u0000SV\u0001"+ + "\u0000\u0000\u0000TR\u0001\u0000\u0000\u0000TU\u0001\u0000\u0000\u0000"+ + "UW\u0001\u0000\u0000\u0000VT\u0001\u0000\u0000\u0000WX\u0005\u0003\u0000"+ + "\u0000X\t\u0001\u0000\u0000\u0000YZ\u0003\u0012\t\u0000Z[\u0005%\u0000"+ + "\u0000[]\u0005\u0006\u0000\u0000\\^\u0003\f\u0006\u0000]\\\u0001\u0000"+ + "\u0000\u0000]^\u0001\u0000\u0000\u0000^_\u0001\u0000\u0000\u0000_`\u0005"+ + "\u0007\u0000\u0000`d\u0005\u0002\u0000\u0000ac\u0003\u0014\n\u0000ba\u0001"+ + "\u0000\u0000\u0000cf\u0001\u0000\u0000\u0000db\u0001\u0000\u0000\u0000"+ + "de\u0001\u0000\u0000\u0000eg\u0001\u0000\u0000\u0000fd\u0001\u0000\u0000"+ + "\u0000gh\u0005\u0003\u0000\u0000h\u000b\u0001\u0000\u0000\u0000in\u0003"+ + "\u000e\u0007\u0000jk\u0005\b\u0000\u0000km\u0003\u000e\u0007\u0000lj\u0001"+ + "\u0000\u0000\u0000mp\u0001\u0000\u0000\u0000nl\u0001\u0000\u0000\u0000"+ + "no\u0001\u0000\u0000\u0000o\r\u0001\u0000\u0000\u0000pn\u0001\u0000\u0000"+ + "\u0000qr\u0003\u0010\b\u0000rs\u0005%\u0000\u0000s\u000f\u0001\u0000\u0000"+ + "\u0000tu\u0007\u0000\u0000\u0000u\u0011\u0001\u0000\u0000\u0000vw\u0007"+ + "\u0001\u0000\u0000w\u0013\u0001\u0000\u0000\u0000x\u007f\u0003\u0016\u000b"+ + "\u0000y\u007f\u0003\u0018\f\u0000z\u007f\u0003\u001c\u000e\u0000{\u007f"+ + "\u0003\u001e\u000f\u0000|\u007f\u0003 \u0010\u0000}\u007f\u0003\"\u0011"+ + "\u0000~x\u0001\u0000\u0000\u0000~y\u0001\u0000\u0000\u0000~z\u0001\u0000"+ + "\u0000\u0000~{\u0001\u0000\u0000\u0000~|\u0001\u0000\u0000\u0000~}\u0001"+ + "\u0000\u0000\u0000\u007f\u0015\u0001\u0000\u0000\u0000\u0080\u0081\u0003"+ + "\u0010\b\u0000\u0081\u0084\u0005%\u0000\u0000\u0082\u0083\u0005\u000e"+ + "\u0000\u0000\u0083\u0085\u0003$\u0012\u0000\u0084\u0082\u0001\u0000\u0000"+ + "\u0000\u0084\u0085\u0001\u0000\u0000\u0000\u0085\u0086\u0001\u0000\u0000"+ + "\u0000\u0086\u0087\u0005\u0004\u0000\u0000\u0087\u0017\u0001\u0000\u0000"+ + "\u0000\u0088\u0089\u0003\u001a\r\u0000\u0089\u008a\u0005\u000e\u0000\u0000"+ + "\u008a\u008b\u0003$\u0012\u0000\u008b\u008c\u0005\u0004\u0000\u0000\u008c"+ + "\u0019\u0001\u0000\u0000\u0000\u008d\u008e\u0005%\u0000\u0000\u008e\u001b"+ + "\u0001\u0000\u0000\u0000\u008f\u0090\u0005\u000f\u0000\u0000\u0090\u0091"+ + "\u0005\u0006\u0000\u0000\u0091\u0092\u0003$\u0012\u0000\u0092\u0093\u0005"+ + "\u0007\u0000\u0000\u0093\u0096\u0003\u0014\n\u0000\u0094\u0095\u0005\u0010"+ + "\u0000\u0000\u0095\u0097\u0003\u0014\n\u0000\u0096\u0094\u0001\u0000\u0000"+ + "\u0000\u0096\u0097\u0001\u0000\u0000\u0000\u0097\u001d\u0001\u0000\u0000"+ + "\u0000\u0098\u0099\u0005\u0011\u0000\u0000\u0099\u009a\u0005\u0006\u0000"+ + "\u0000\u009a\u009b\u0003$\u0012\u0000\u009b\u009c\u0005\u0007\u0000\u0000"+ + "\u009c\u009d\u0003\u0014\n\u0000\u009d\u001f\u0001\u0000\u0000\u0000\u009e"+ + "\u00a0\u0005\u0012\u0000\u0000\u009f\u00a1\u0003$\u0012\u0000\u00a0\u009f"+ + "\u0001\u0000\u0000\u0000\u00a0\u00a1\u0001\u0000\u0000\u0000\u00a1\u00a2"+ + "\u0001\u0000\u0000\u0000\u00a2\u00a3\u0005\u0004\u0000\u0000\u00a3!\u0001"+ + "\u0000\u0000\u0000\u00a4\u00a8\u0005\u0002\u0000\u0000\u00a5\u00a7\u0003"+ + "\u0014\n\u0000\u00a6\u00a5\u0001\u0000\u0000\u0000\u00a7\u00aa\u0001\u0000"+ + "\u0000\u0000\u00a8\u00a6\u0001\u0000\u0000\u0000\u00a8\u00a9\u0001\u0000"+ + "\u0000\u0000\u00a9\u00ab\u0001\u0000\u0000\u0000\u00aa\u00a8\u0001\u0000"+ + "\u0000\u0000\u00ab\u00ac\u0005\u0003\u0000\u0000\u00ac#\u0001\u0000\u0000"+ + "\u0000\u00ad\u00ae\u0006\u0012\uffff\uffff\u0000\u00ae\u00af\u0005\u001c"+ + "\u0000\u0000\u00af\u00b9\u0003$\u0012\u0005\u00b0\u00b1\u0005 \u0000\u0000"+ + "\u00b1\u00b9\u0003$\u0012\u0004\u00b2\u00b3\u0005\u0006\u0000\u0000\u00b3"+ + "\u00b4\u0003$\u0012\u0000\u00b4\u00b5\u0005\u0007\u0000\u0000\u00b5\u00b9"+ + "\u0001\u0000\u0000\u0000\u00b6\u00b9\u0003&\u0013\u0000\u00b7\u00b9\u0005"+ + "%\u0000\u0000\u00b8\u00ad\u0001\u0000\u0000\u0000\u00b8\u00b0\u0001\u0000"+ + "\u0000\u0000\u00b8\u00b2\u0001\u0000\u0000\u0000\u00b8\u00b6\u0001\u0000"+ + "\u0000\u0000\u00b8\u00b7\u0001\u0000\u0000\u0000\u00b9\u00c5\u0001\u0000"+ + "\u0000\u0000\u00ba\u00bb\n\b\u0000\u0000\u00bb\u00bc\u0007\u0002\u0000"+ + "\u0000\u00bc\u00c4\u0003$\u0012\t\u00bd\u00be\n\u0007\u0000\u0000\u00be"+ + "\u00bf\u0007\u0003\u0000\u0000\u00bf\u00c4\u0003$\u0012\b\u00c0\u00c1"+ + "\n\u0006\u0000\u0000\u00c1\u00c2\u0007\u0004\u0000\u0000\u00c2\u00c4\u0003"+ + "$\u0012\u0007\u00c3\u00ba\u0001\u0000\u0000\u0000\u00c3\u00bd\u0001\u0000"+ + "\u0000\u0000\u00c3\u00c0\u0001\u0000\u0000\u0000\u00c4\u00c7\u0001\u0000"+ + "\u0000\u0000\u00c5\u00c3\u0001\u0000\u0000\u0000\u00c5\u00c6\u0001\u0000"+ + "\u0000\u0000\u00c6%\u0001\u0000\u0000\u0000\u00c7\u00c5\u0001\u0000\u0000"+ + "\u0000\u00c8\u00cc\u0005$\u0000\u0000\u00c9\u00cc\u0003(\u0014\u0000\u00ca"+ + "\u00cc\u0003*\u0015\u0000\u00cb\u00c8\u0001\u0000\u0000\u0000\u00cb\u00c9"+ + "\u0001\u0000\u0000\u0000\u00cb\u00ca\u0001\u0000\u0000\u0000\u00cc\'\u0001"+ + "\u0000\u0000\u0000\u00cd\u00ce\u0007\u0005\u0000\u0000\u00ce)\u0001\u0000"+ + "\u0000\u0000\u00cf\u00d0\u0005#\u0000\u0000\u00d0\u00d1\t\u0000\u0000"+ + "\u0000\u00d1\u00d2\u0005#\u0000\u0000\u00d2+\u0001\u0000\u0000\u0000\u0011"+ + "/8@MT]dn~\u0084\u0096\u00a0\u00a8\u00b8\u00c3\u00c5\u00cb"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/src/main/java/parser/generated/SimpleJavaVisitor.java b/src/main/java/parser/generated/SimpleJavaVisitor.java index 1d10783..dd4ca0f 100644 --- a/src/main/java/parser/generated/SimpleJavaVisitor.java +++ b/src/main/java/parser/generated/SimpleJavaVisitor.java @@ -1,4 +1,4 @@ -// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 +// Generated from C:/Users/Johannes/Documents/Github/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1 package parser.generated; import org.antlr.v4.runtime.tree.ParseTreeVisitor; @@ -88,6 +88,12 @@ public interface SimpleJavaVisitor extends ParseTreeVisitor { * @return the visitor result */ T visitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx); + /** + * Visit a parse tree produced by {@link SimpleJavaParser#var}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitVar(SimpleJavaParser.VarContext ctx); /** * Visit a parse tree produced by {@link SimpleJavaParser#ifStatement}. * @param ctx the parse tree diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 11de018..07d0ca2 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -25,7 +25,7 @@ public class SemanticAnalyzer implements SemanticVisitor { if (result.isValid()) { return node; } else { - throw new RuntimeException("errorString ERROR"); + throw new RuntimeException("Not Valid"); } } @@ -55,14 +55,14 @@ public class SemanticAnalyzer implements SemanticVisitor { return null; } - @Override - public TypeCheckResult typeCheck(IdentifierNode identifierNode) { - return null; - } - @Override public TypeCheckResult typeCheck(MethodNode methodNode) { List statements = methodNode.statements; + for (StatementNode statement : statements) { + if(statement instanceof AssignmentStatementNode assignmentStatementNode) { + assignmentStatementNode.accept(this); + } + } return null; } @@ -76,4 +76,17 @@ public class SemanticAnalyzer implements SemanticVisitor { return null; } + @Override + public TypeCheckResult typeCheck(AssignmentStatementNode assignmentStatementNode) { + if(assignmentStatementNode.expression instanceof LiteralNode literalNode) { + VarNode varNode = assignmentStatementNode.varNode; + if(varNode.getType().equals(literalNode.getType())) { + System.out.println("Type is same"); + } else { + System.out.println("Type Mismatch"); + } + } + return null; + } + } \ No newline at end of file diff --git a/src/main/java/semantic/SemanticVisitor.java b/src/main/java/semantic/SemanticVisitor.java index 445db69..2fbaf41 100644 --- a/src/main/java/semantic/SemanticVisitor.java +++ b/src/main/java/semantic/SemanticVisitor.java @@ -1,12 +1,11 @@ package semantic; -import ast.ASTNode; import ast.ClassNode; -import ast.IdentifierNode; import ast.ProgramNode; import ast.member.FieldNode; import ast.member.MethodNode; +import ast.statement.AssignmentStatementNode; import typechecker.TypeCheckResult; public interface SemanticVisitor { @@ -16,13 +15,11 @@ public interface SemanticVisitor { TypeCheckResult typeCheck(ClassNode toCheck); - TypeCheckResult typeCheck(IdentifierNode toCheck); - TypeCheckResult typeCheck(MethodNode toCheck); TypeCheckResult typeCheck(FieldNode toCheck); -// -// TypeCheckResult typeCheck(Assign toCheck); + + TypeCheckResult typeCheck(AssignmentStatementNode toCheck); // // TypeCheckResult typeCheck(MethodParameter toCheck); //