diff --git a/src/main/java/CompilerInput.txt b/src/main/java/CompilerInput.txt index 0a31d5c..a7d717c 100644 --- a/src/main/java/CompilerInput.txt +++ b/src/main/java/CompilerInput.txt @@ -2,6 +2,12 @@ public class Example { public int test; + public static int test(char b){ + + test = 3; + + } + } public class Test { diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e15eafa..bcb48c5 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -9,9 +9,6 @@ import parser.ASTBuilder; import parser.generated.SimpleJavaLexer; import parser.generated.SimpleJavaParser; import semantic.SemanticAnalyzer; -import ast.ClassNode; -import ast.ProgramNode; -import bytecode.ByteCodeGenerator; import java.io.IOException; import java.nio.file.Paths; diff --git a/src/main/java/ast/AssignmentNode.java b/src/main/java/ast/AssignmentNode.java new file mode 100644 index 0000000..38e7fb9 --- /dev/null +++ b/src/main/java/ast/AssignmentNode.java @@ -0,0 +1,14 @@ +package ast; + +public class AssignmentNode extends StatementNode { + + public Identifier identifier; + + public ExpressionNode expression; + + public AssignmentNode(String identifier, ExpressionNode expression) { + this.identifier = new Identifier(identifier); + this.expression = expression; + } + +} diff --git a/src/main/java/ast/ExpressionNode.java b/src/main/java/ast/ExpressionNode.java index 891d87c..9e6f2a8 100644 --- a/src/main/java/ast/ExpressionNode.java +++ b/src/main/java/ast/ExpressionNode.java @@ -1,4 +1,11 @@ package ast; -public class ExpressionNode { +public class ExpressionNode extends ASTNode { + + int Value; + + public ExpressionNode(int value) { + this.Value = value; + } + } diff --git a/src/main/java/classFileOutput/Example.class b/src/main/java/classFileOutput/Example.class index 7490cc1..c4a896a 100644 Binary files a/src/main/java/classFileOutput/Example.class and b/src/main/java/classFileOutput/Example.class differ diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index f57181d..e90ba95 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -6,6 +6,7 @@ import parser.generated.SimpleJavaParser; import java.util.ArrayList; import java.util.List; +import parser.generated.SimpleJavaParser.LiteralContext; public class ASTBuilder extends SimpleJavaBaseVisitor { @Override @@ -107,4 +108,26 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { return null; } + @Override + public ASTNode visitAssignmentStatement(SimpleJavaParser.AssignmentStatementContext ctx) { + ExpressionNode expressionNode = (ExpressionNode) visit(ctx.expression()); + return new AssignmentNode(ctx.IDENTIFIER().getText(), expressionNode); + } + + @Override + public ASTNode visitExpression(SimpleJavaParser.ExpressionContext ctx) { + if(ctx.literal() != null){ + return visitLiteral(ctx.literal()); + } + return null; + } + + @Override + public ASTNode visitLiteral(SimpleJavaParser.LiteralContext ctx) { + if(ctx.INTEGERLITERAL() != null){ + return new ExpressionNode(Integer.parseInt(ctx.INTEGERLITERAL().getSymbol().getText())); + } + return null; + } + }