Added Interface
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
i22035 2024-06-20 18:44:42 +02:00
parent d3e9fa9b43
commit 50a52a1e87
36 changed files with 131 additions and 175 deletions

View File

@ -1,7 +1,7 @@
import oldAst.ASTNode;
import ast.ASTNode;
import org.antlr.v4.runtime.*;
import oldAst.ProgramNode;
import bytecode.ByteCodeGenerator;
import ast.ProgramNode;
//import bytecode.ByteCodeGenerator;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.tree.ParseTree;
@ -9,7 +9,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import semantic.SemanticAnalyzer;
//import semantic.SemanticAnalyzer;
import java.io.IOException;
import java.nio.file.Paths;
@ -60,7 +60,7 @@ public class Main {
/* ------------------------- AST builder -> AST ------------------------- */
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
System.out.println(abstractSyntaxTree);
// Printing the AST
// System.out.println("-------------------- AST builder -> AST --------------------");
// // System.out.println("AST: " + ast.toString());
@ -70,8 +70,8 @@ public class Main {
/*
* ------------------------- Semantic Analyzer -> Tast -------------------------
*/
SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ProgramNode typedAst = (ProgramNode) semanticAnalyzer.generateTast(abstractSyntaxTree);
//SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
//ProgramNode typedAst = (ProgramNode) semanticAnalyzer.generateTast(abstractSyntaxTree);
// Printing the Tast
System.out.println("Tast generated");
@ -80,9 +80,9 @@ public class Main {
* ------------------------- Bytecode Generator -> Bytecode
* -------------------------
*/
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
//ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
//byteCodeGenerator.generateByteCode(abstractSyntaxTree);
byteCodeGenerator.visit(typedAst);
//byteCodeGenerator.visit(typedAst);
System.out.println("Bytecode generated");
}

View File

@ -1,19 +1,14 @@
package ast;
import ast.type.AccessModifierNode;
import ast.type.EnumAccessModifierNode;
import bytecode.visitor.ClassVisitor;
import ast.member.ConstructorNode;
import ast.member.MemberNode;
import ast.member.MethodNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class ClassNode implements ASTNode, Visitable {
public class ClassNode implements ASTNode {
public AccessModifierNode accessType;
public String identifier;
public List<MemberNode> members = new ArrayList<>();
@ -50,14 +45,4 @@ public class ClassNode implements ASTNode, Visitable {
}
return methods;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
}

View File

@ -1,27 +1,13 @@
package ast;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class ProgramNode implements ASTNode, Visitable {
public class ProgramNode implements ASTNode {
public List<ClassNode> classes = new ArrayList<>();
public void addClass(ClassNode classNode) {
classes.add(classNode);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ProgramVisitor programVisitor) {
programVisitor.visit(this);
}
}

View File

@ -1,17 +1,17 @@
package ast.block;
import ast.ASTNode;
import ast.statement.StatementNode;
import ast.statement.IStatementNode;
import java.util.ArrayList;
import java.util.List;
public class BlockNode implements ASTNode {
public List<StatementNode> statements = new ArrayList<>();
public List<IStatementNode> statements = new ArrayList<>();
public BlockNode() {}
public void addStatement(StatementNode statement) {
public void addStatement(IStatementNode statement) {
statements.add(statement);
}
}

View File

@ -1,4 +0,0 @@
package ast.expression;
public class ExpressionNode {
}

View File

@ -0,0 +1,5 @@
package ast.expression;
import ast.ASTNode;
public interface IExpressionNode extends ASTNode {}

View File

@ -1,4 +0,0 @@
package ast.expression.binaryexpression;
public class BinaryExpression {
}

View File

@ -0,0 +1,7 @@
package ast.expression.binaryexpression;
import ast.expression.IExpressionNode;
import java.beans.Expression;
public class BinaryExpressionNode implements IExpressionNode {}

View File

@ -2,7 +2,7 @@ package ast.expression.binaryexpression;
import ast.ASTNode;
public class CalculationExpressionNode implements ASTNode {
public class CalculationExpressionNode extends BinaryExpressionNode {
public CalculationExpressionNode calculationExpression;
public String operator;
public DotExpressionNode dotExpression;

View File

@ -2,7 +2,7 @@ package ast.expression.binaryexpression;
import ast.ASTNode;
public class DotExpressionNode implements ASTNode {
public class DotExpressionNode extends BinaryExpressionNode {
public DotExpressionNode dotExpression;
public String operator;
public DotSubstractionExpressionNode dotSubstractionExpression;

View File

@ -5,7 +5,7 @@ import ast.expression.unaryexpression.MemberAccessNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import ast.type.ValueNode;
public class DotSubstractionExpressionNode implements ASTNode {
public class DotSubstractionExpressionNode extends BinaryExpressionNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;

View File

@ -1,15 +1,15 @@
package ast.expression.binaryexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import ast.expression.unaryexpression.UnaryExpressionNode;
public class NonCalculationExpressionNode implements ASTNode {
public class NonCalculationExpressionNode extends BinaryExpressionNode {
public UnaryExpressionNode unaryExpression;
public String operator;
public ExpressionNode expression;
public IExpressionNode expression;
public NonCalculationExpressionNode(UnaryExpressionNode unaryExpression, String operator, ExpressionNode expression) {
public NonCalculationExpressionNode(UnaryExpressionNode unaryExpression, String operator, IExpressionNode expression) {
this.unaryExpression = unaryExpression;
this.operator = operator;
this.expression = expression;

View File

@ -1,12 +1,12 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
public class NotExpressionNode implements ASTNode {
public ExpressionNode expression;
public IExpressionNode expression;
public NotExpressionNode(ExpressionNode expression) {
public NotExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@ -1,20 +1,19 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.statement.StatementNode;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
import ast.type.ValueNode;
import java.util.Objects;
public class UnaryExpressionNode implements ASTNode {
public class UnaryExpressionNode implements IExpressionNode {
public String thisExp;
public String identifier;
public MemberAccessNode memberAccess;
public ValueNode value;
public NotExpressionNode notExpression;
public StatementNode statement;
public ExpressionNode expression;
public IStatementNode statement;
public IExpressionNode expression;
public UnaryExpressionNode(String value) {
if(Objects.equals(value, "this")) {
@ -36,11 +35,11 @@ public class UnaryExpressionNode implements ASTNode {
this.notExpression = notExpression;
}
public UnaryExpressionNode(StatementNode statement) {
public UnaryExpressionNode(IStatementNode statement) {
this.statement = statement;
}
public UnaryExpressionNode(ExpressionNode expression) {
public UnaryExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@ -3,8 +3,6 @@ package ast.member;
import ast.block.BlockNode;
import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode;
import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
@ -20,8 +18,8 @@ public class ConstructorNode extends MethodNode {
this.identifier = identifier;
}
public ConstructorNode(AccessModifierNode accessType, String identifier, BlockNode body) {
this.accessType = accessType;
public ConstructorNode(String accessType, String identifier, BlockNode body) {
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
this.body = body;
}
@ -30,10 +28,4 @@ public class ConstructorNode extends MethodNode {
parameters.add(parameterNode);
}
/*
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
*/
}

View File

@ -2,12 +2,8 @@ package ast.member;
import ast.type.AccessModifierNode;
import ast.type.TypeNode;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class FieldNode implements MemberNode, Visitable {
public class FieldNode implements MemberNode {
public AccessModifierNode accessTypeNode;
public TypeNode type;
public String identifier;
@ -17,14 +13,4 @@ public class FieldNode implements MemberNode, Visitable {
this.type = type;
this.identifier = name;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
}

View File

@ -4,10 +4,6 @@ import ast.block.BlockNode;
import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode;
import ast.type.TypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
@ -17,7 +13,7 @@ public class MethodNode implements MemberNode {
public TypeNode type;
public Boolean voidType;
public String identifier;
public List<ParameterNode> parameters;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public MethodNode() {}
@ -26,9 +22,9 @@ public class MethodNode implements MemberNode {
this.block = block;
}
public MethodNode(AccessModifierNode accessModifier, TypeNode type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = accessModifier;
this.type = type;
public MethodNode(String accessModifier, String type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = new AccessModifierNode(accessModifier);
this.type = new TypeNode(type);
this.voidType = voidType;
this.identifier = identifier;
this.block = block;

View File

@ -1,21 +1,21 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
public class ForStatementNode implements ASTNode {
public ExpressionNode statementExpressionInit;
public StatementNode localVariableDeclarationInit;
public ExpressionNode expression;
public ExpressionNode statementExpression;
public class ForStatementNode implements IStatementNode {
public IExpressionNode statementExpressionInit;
public IStatementNode localVariableDeclarationInit;
public IExpressionNode expression;
public IExpressionNode statementExpression;
public ForStatementNode(ExpressionNode statementExpressionInit, ExpressionNode expression, ExpressionNode statementExpression) {
public ForStatementNode(IExpressionNode statementExpressionInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.statementExpressionInit = statementExpressionInit;
this.expression = expression;
this.statementExpression = statementExpression;
}
public ForStatementNode(StatementNode localVariableDeclarationInit, ExpressionNode expression, ExpressionNode statementExpression) {
public ForStatementNode(IStatementNode localVariableDeclarationInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.localVariableDeclarationInit = localVariableDeclarationInit;
this.expression = expression;
this.statementExpression = statementExpression;

View File

@ -0,0 +1,6 @@
package ast.statement;
import ast.ASTNode;
public interface IStatementNode extends ASTNode {
}

View File

@ -1,16 +1,16 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import ast.type.TypeNode;
public class LocalVariableDeclarationNode implements ASTNode {
public class LocalVariableDeclarationNode implements IStatementNode {
public TypeNode type;
public String identifier;
public String assign;
public ExpressionNode expression;
public IExpressionNode expression;
public LocalVariableDeclarationNode(TypeNode type, String identifier, String assign, ExpressionNode expression) {
public LocalVariableDeclarationNode(TypeNode type, String identifier, String assign, IExpressionNode expression) {
this.type = type;
this.identifier = identifier;
this.assign = assign;

View File

@ -1,16 +1,12 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.type.TypeNode;
import ast.expression.IExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class ReturnStatementNode implements IStatementNode {
public IExpressionNode expression;
public class ReturnStatementNode implements ASTNode {
public ExpressionNode expression;
public ReturnStatementNode(ExpressionNode expression) {
public ReturnStatementNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@ -1,4 +0,0 @@
package ast.statement;
public class StatementNode {
}

View File

@ -2,13 +2,13 @@ package ast.statement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
public class WhileStatementNode implements ASTNode {
public ExpressionNode expression;
public class WhileStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public WhileStatementNode(ExpressionNode expression, BlockNode block) {
public WhileStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}

View File

@ -2,8 +2,9 @@ package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.statement.IStatementNode;
public class ElseStatementNode implements ASTNode {
public class ElseStatementNode implements IStatementNode {
public BlockNode block;
public ElseStatementNode(BlockNode block) {

View File

@ -1,11 +1,12 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.statement.IStatementNode;
import java.util.ArrayList;
import java.util.List;
public class IfElseStatementNode implements ASTNode {
public class IfElseStatementNode implements IStatementNode {
public IfStatementNode ifStatement;
public List<ElseStatementNode> elseStatements = new ArrayList<>();

View File

@ -2,13 +2,14 @@ package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
public class IfStatementNode implements ASTNode {
public ExpressionNode expression;
public class IfStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public IfStatementNode(ExpressionNode expression, BlockNode block) {
public IfStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}

View File

@ -1,13 +1,13 @@
package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
public class AssignStatementExpressionNode implements ASTNode {
public class AssignStatementExpressionNode implements IStatementExpressionNode {
public AssignableExpressionNode assignable;
public ExpressionNode expression;
public IExpressionNode expression;
public AssignStatementExpressionNode(AssignableExpressionNode assignable, ExpressionNode expression) {
public AssignStatementExpressionNode(AssignableExpressionNode assignable, IExpressionNode expression) {
this.assignable = assignable;
this.expression = expression;
}

View File

@ -3,7 +3,7 @@ package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.unaryexpression.MemberAccessNode;
public class AssignableExpressionNode implements ASTNode {
public class AssignableExpressionNode implements IStatementExpressionNode {
public String identifier;
public MemberAccessNode memberAccess;

View File

@ -0,0 +1,5 @@
package ast.statement.statementexpression;
import ast.statement.IStatementNode;
public interface IStatementExpressionNode extends IStatementNode {}

View File

@ -1,20 +1,20 @@
package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class NewDeclarationStatementExpressionNode implements ASTNode {
public class NewDeclarationStatementExpressionNode implements IStatementExpressionNode {
public String identifier;
public List<ExpressionNode> expressions = new ArrayList<>();
public List<IExpressionNode> expressions = new ArrayList<>();
public NewDeclarationStatementExpressionNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(ExpressionNode expression) {
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
}

View File

@ -2,8 +2,9 @@ package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
public class DecrementExpressionNode implements ASTNode {
public class DecrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;

View File

@ -2,8 +2,9 @@ package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
public class IncrementExpressionNode implements ASTNode {
public class IncrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;

View File

@ -1,20 +1,20 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class ChainedMethodNode implements ASTNode {
public String identifier;
public List<ExpressionNode> expressions = new ArrayList<>();
public List<IExpressionNode> expressions = new ArrayList<>();
public ChainedMethodNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(ExpressionNode expression) {
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
}

View File

@ -1,16 +1,17 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.ExpressionNode;
import ast.expression.IExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class MethodCallStatementExpressionNode implements ASTNode {
public class MethodCallStatementExpressionNode implements IStatementExpressionNode {
public TargetNode target;
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
public String identifier;
public List<ExpressionNode> expressions = new ArrayList<>();
public List<IExpressionNode> expressions = new ArrayList<>();
public MethodCallStatementExpressionNode(TargetNode target, String identifier) {
this.target = target;
@ -21,7 +22,7 @@ public class MethodCallStatementExpressionNode implements ASTNode {
chainedMethods.add(chainedMethode);
}
public void addExpression(ExpressionNode expression) {
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}

View File

@ -53,7 +53,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode = new ConstructorNode((AccessModifierNode) visit(ctx.AccessModifier()), ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter));
}
@ -66,13 +66,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return new MethodNode((BlockNode) visit(ctx.block()));
} else {
if(ctx.type() != null) {
MethodNode methodNode = new MethodNode((AccessModifierNode) visit(ctx.AccessModifier()), (TypeNode) visit(ctx.type()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), ctx.type().getText(), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
return methodNode;
} else {
MethodNode methodNode = new MethodNode((AccessModifierNode) visit(ctx.AccessModifier()), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
@ -108,34 +108,34 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitReturnStatement(SimpleJavaParser.ReturnStatementContext ctx) {
return new ReturnStatementNode((ExpressionNode) visit(ctx.expression()));
return new ReturnStatementNode((IExpressionNode) visit(ctx.expression()));
}
@Override
public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) {
return new LocalVariableDeclarationNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (ExpressionNode) visit(ctx.expression()));
return new LocalVariableDeclarationNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
}
@Override
public ASTNode visitBlock(SimpleJavaParser.BlockContext ctx) {
BlockNode blockNode = new BlockNode();
for(SimpleJavaParser.StatementContext statement : ctx.statement()) {
blockNode.addStatement((StatementNode) visit(statement));
blockNode.addStatement((IStatementNode) visit(statement));
}
return blockNode;
}
@Override
public ASTNode visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) {
return new WhileStatementNode((ExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
return new WhileStatementNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
}
@Override
public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) {
if(ctx.statementExpression(0) != null) {
return new ForStatementNode((ExpressionNode) visit(ctx.statementExpression(0)), (ExpressionNode) visit(ctx.expression()), (ExpressionNode) visit(ctx.statementExpression(1)));
return new ForStatementNode((IExpressionNode) visit(ctx.statementExpression(0)), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
} else if(ctx.localVariableDeclaration() != null) {
return new ForStatementNode((StatementNode) visit(ctx.localVariableDeclaration()), (ExpressionNode) visit(ctx.expression()), (ExpressionNode) visit(ctx.statementExpression(1)));
return new ForStatementNode((IStatementNode) visit(ctx.localVariableDeclaration()), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
}
return null;
}
@ -151,7 +151,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitIfStatement(SimpleJavaParser.IfStatementContext ctx) {
return new IfStatementNode((ExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
return new IfStatementNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
}
@Override
@ -175,14 +175,14 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitAssign(SimpleJavaParser.AssignContext ctx) {
return new AssignStatementExpressionNode((AssignableExpressionNode) visit(ctx.assignableExpression()), (ExpressionNode) visit(ctx.expression()));
return new AssignStatementExpressionNode((AssignableExpressionNode) visit(ctx.assignableExpression()), (IExpressionNode) visit(ctx.expression()));
}
@Override
public ASTNode visitNewDeclaration(SimpleJavaParser.NewDeclarationContext ctx) {
NewDeclarationStatementExpressionNode newDeclarationStatementExpressionNode = new NewDeclarationStatementExpressionNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
newDeclarationStatementExpressionNode.addExpression((ExpressionNode) visit(expression));
newDeclarationStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
}
return newDeclarationStatementExpressionNode;
}
@ -194,7 +194,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod));
}
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
methodCallStatementExpressionNode.addExpression((ExpressionNode) visit(expression));
methodCallStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
}
return methodCallStatementExpressionNode;
}
@ -217,7 +217,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
public ASTNode visitChainedMethod(SimpleJavaParser.ChainedMethodContext ctx) {
ChainedMethodNode chainedMethodNode = new ChainedMethodNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
chainedMethodNode.addExpression((ExpressionNode) visit(expression));
chainedMethodNode.addExpression((IExpressionNode) visit(expression));
}
return chainedMethodNode;
}
@ -295,9 +295,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
} else if(ctx.notExpression() != null) {
return new UnaryExpressionNode((NotExpressionNode) visitNotExpression(ctx.notExpression()));
} else if(ctx.statementExpression() != null) {
return new UnaryExpressionNode((StatementNode) visitStatementExpression(ctx.statementExpression()));
return new UnaryExpressionNode((IStatementNode) visitStatementExpression(ctx.statementExpression()));
} else if(ctx.expression() != null) {
return new UnaryExpressionNode((ExpressionNode) visitExpression(ctx.expression()));
return new UnaryExpressionNode((IExpressionNode) visitExpression(ctx.expression()));
}
return null;
}
@ -332,7 +332,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitNotExpression(SimpleJavaParser.NotExpressionContext ctx) {
return new NotExpressionNode((ExpressionNode) visitExpression(ctx.expression()));
return new NotExpressionNode((IExpressionNode) visitExpression(ctx.expression()));
}
@ -382,7 +382,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitNonCalculationExpression(SimpleJavaParser.NonCalculationExpressionContext ctx) {
return new NonCalculationExpressionNode((UnaryExpressionNode) visit(ctx.unaryExpression()), ctx.nonCalculationOperator().getText(), (ExpressionNode) visit(ctx.expression()));
return new NonCalculationExpressionNode((UnaryExpressionNode) visit(ctx.unaryExpression()), ctx.nonCalculationOperator().getText(), (IExpressionNode) visit(ctx.expression()));
}
@Override

View File

@ -11,8 +11,7 @@ public class Example {
public class Test {
public static int testMethod(char x, int a){
x = x + a;
return x;
}
}