Added down to Expression
This commit is contained in:
parent
03645f7a84
commit
a86bede5a7
@ -2,6 +2,12 @@ public class Example {
|
||||
|
||||
public int test;
|
||||
|
||||
public static int test(char b){
|
||||
|
||||
test = 3;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Test {
|
||||
|
@ -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;
|
||||
|
14
src/main/java/ast/AssignmentNode.java
Normal file
14
src/main/java/ast/AssignmentNode.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
package ast;
|
||||
|
||||
public class ExpressionNode {
|
||||
public class ExpressionNode extends ASTNode {
|
||||
|
||||
int Value;
|
||||
|
||||
public ExpressionNode(int value) {
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
@ -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<ASTNode> {
|
||||
@Override
|
||||
@ -107,4 +108,26 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user