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

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

View File

@ -123,10 +123,12 @@ public class StatementGenerator extends DecafBaseVisitor<List<Statement>> {
public List<Statement> visitNew(DecafParser.NewContext ctx) { public List<Statement> visitNew(DecafParser.NewContext ctx) {
Type type = ASTGenerator.getType(ctx.type()); Type type = ASTGenerator.getType(ctx.type());
List<Expression> args = new ArrayList<>(); List<Expression> args = new ArrayList<>();
if (ctx.args() != null) {
for (var expr : ctx.args().expr()) { for (var expr : ctx.args().expr()) {
Expression astExpr = expr.accept(new ExpressionGenerator()); Expression astExpr = expr.accept(new ExpressionGenerator());
args.add(astExpr); args.add(astExpr);
} }
}
return List.of(new New(type, args)); return List.of(new New(type, args));
} }