|
|
|
@@ -14,6 +14,7 @@ import ast.members.*;
|
|
|
|
|
import ast.parameters.ParameterNode;
|
|
|
|
|
import ast.statementexpressions.AssignNode;
|
|
|
|
|
import ast.statementexpressions.AssignableNode;
|
|
|
|
|
import ast.statementexpressions.IStatementExpressionNode;
|
|
|
|
|
import ast.statementexpressions.NewDeclarationNode;
|
|
|
|
|
import ast.statementexpressions.crementexpressions.CrementType;
|
|
|
|
|
import ast.statementexpressions.crementexpressions.DecrementNode;
|
|
|
|
@@ -79,7 +80,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|
|
|
|
if(ctx.AccessModifier() != null) {
|
|
|
|
|
constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
|
|
|
|
} else {
|
|
|
|
|
constructorNode = new ConstructorNode(null, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
|
|
|
|
constructorNode = new ConstructorNode("public", ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
|
|
|
|
}
|
|
|
|
|
if(ctx.parameterList() != null) {
|
|
|
|
|
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
|
|
|
@@ -182,7 +183,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) {
|
|
|
|
|
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
|
|
|
|
|
if(ctx.Assign() != null) {
|
|
|
|
|
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
|
|
|
|
|
} else {
|
|
|
|
|
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@@ -214,46 +220,60 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) {
|
|
|
|
|
|
|
|
|
|
List<IStatementNode> statements = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
//init
|
|
|
|
|
// Initialisierung
|
|
|
|
|
int i = 0;
|
|
|
|
|
if(ctx.localVariableDeclaration() != null) {
|
|
|
|
|
if (ctx.localVariableDeclaration() != null) {
|
|
|
|
|
statements.add((IStatementNode) visit(ctx.localVariableDeclaration()));
|
|
|
|
|
} else if(ctx.statementExpression(i) != null){
|
|
|
|
|
} else if (ctx.statementExpression(i) != null) {
|
|
|
|
|
statements.add((IStatementNode) visit(ctx.statementExpression(i)));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//condition
|
|
|
|
|
// Bedingung
|
|
|
|
|
IExpressionNode condition = (IExpressionNode) visit(ctx.expression());
|
|
|
|
|
|
|
|
|
|
//ink
|
|
|
|
|
IStatementNode crement = null;
|
|
|
|
|
if(ctx.statementExpression(i) != null){
|
|
|
|
|
crement = (IStatementNode) visit(ctx.statementExpression(i));
|
|
|
|
|
// Inkrement
|
|
|
|
|
IStatementExpressionNode crement = null;
|
|
|
|
|
boolean isPrefix = false;
|
|
|
|
|
if (ctx.statementExpression(i) != null) {
|
|
|
|
|
crement = (IStatementExpressionNode) visit(ctx.statementExpression(i));
|
|
|
|
|
|
|
|
|
|
if (crement instanceof IncrementNode) {
|
|
|
|
|
isPrefix = ((IncrementNode) crement).crementType == CrementType.PREFIX;
|
|
|
|
|
} else if (crement instanceof DecrementNode) {
|
|
|
|
|
isPrefix = ((DecrementNode) crement).crementType == CrementType.PREFIX;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlockNode forBlock = new BlockNode();
|
|
|
|
|
BlockNode forBlock = (BlockNode) visit(ctx.blockStatement());
|
|
|
|
|
|
|
|
|
|
BlockNode forStatements = (BlockNode) visit(ctx.blockStatement());
|
|
|
|
|
if(forStatements != null) {
|
|
|
|
|
forBlock.addStatement((IStatementNode) forStatements);
|
|
|
|
|
// While-Schleife
|
|
|
|
|
BlockNode whileBody = new BlockNode();
|
|
|
|
|
|
|
|
|
|
// Prä-Inkrement: Das Inkrement kommt vor dem Block
|
|
|
|
|
if (crement != null && isPrefix) {
|
|
|
|
|
whileBody.addStatement((IStatementNode) crement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(crement != null){
|
|
|
|
|
BlockNode forCrement = new BlockNode();
|
|
|
|
|
forCrement.addStatement((crement));
|
|
|
|
|
forBlock.addStatement(forCrement);
|
|
|
|
|
// Block Statements der For-Schleife in den While-Block kopieren
|
|
|
|
|
for (IStatementNode statement : forBlock.statements) {
|
|
|
|
|
whileBody.addStatement(statement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WhileNode While = new WhileNode(condition, forBlock);
|
|
|
|
|
// Post-Inkrement: Das Inkrement kommt nach dem Block
|
|
|
|
|
if (crement != null && !isPrefix) {
|
|
|
|
|
whileBody.addStatement((IStatementNode) crement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statements.add(While);
|
|
|
|
|
// Bedingung der While-Schleife
|
|
|
|
|
WhileNode whileNode = new WhileNode(condition, whileBody);
|
|
|
|
|
|
|
|
|
|
statements.add(whileNode);
|
|
|
|
|
|
|
|
|
|
BlockNode resultBlock = new BlockNode();
|
|
|
|
|
for(IStatementNode statement : statements) {
|
|
|
|
|
for (IStatementNode statement : statements) {
|
|
|
|
|
resultBlock.addStatement((IStatementNode) statement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|