mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:08:04 +00:00
Parser bugfix
This commit is contained in:
parent
35d7733c62
commit
fb8bfb719a
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user