Parser bugfix

This commit is contained in:
laurenz 2024-05-20 14:18:32 +02:00
parent 35d7733c62
commit fb8bfb719a
2 changed files with 12 additions and 8 deletions

View File

@ -113,9 +113,11 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
Type type = ASTGenerator.getType(ctx.type());
List<Expression> args = new ArrayList<>();
if (ctx.args() != null) {
for (var expr : ctx.args().expr()) {
Expression astExpr = expr.accept(this);
args.add(astExpr);
if (ctx.args() != null) {
for (var expr : ctx.args().expr()) {
Expression astExpr = expr.accept(this);
args.add(astExpr);
}
}
}
return new New(type, args);

View File

@ -41,10 +41,10 @@ public class StatementGenerator extends DecafBaseVisitor<List<Statement>> {
Assignment update = generateAssign(ctx.assign().get(ctx.assign().size() - 1));
Block block = new BlockGenerator().visit(ctx.block());
if (ctx.assign().size() == 1) {
Declaration declaration = new Declaration(ctx.localVarWithInitialization().id().IDENTIFIER().getText(),ASTGenerator.getType(ctx.localVarWithInitialization().type()));
Declaration declaration = new Declaration(ctx.localVarWithInitialization().id().IDENTIFIER().getText(), ASTGenerator.getType(ctx.localVarWithInitialization().type()));
Expression initialization = new ExpressionGenerator().visit(ctx.localVarWithInitialization().expr());
Assignment init = new Assignment(new FieldVarAccess(false, null, declaration.name()), initialization);
return List.of(declaration,new For(init,expr,update,block));
return List.of(declaration, new For(init, expr, update, block));
}
Assignment assign = generateAssign(ctx.assign(0));
return List.of(new For(assign, expr, update, block));
@ -123,9 +123,11 @@ public class StatementGenerator extends DecafBaseVisitor<List<Statement>> {
public List<Statement> visitNew(DecafParser.NewContext ctx) {
Type type = ASTGenerator.getType(ctx.type());
List<Expression> args = new ArrayList<>();
for (var expr : ctx.args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr);
if (ctx.args() != null) {
for (var expr : ctx.args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr);
}
}
return List.of(new New(type, args));
}