mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:28:03 +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());
|
Type type = ASTGenerator.getType(ctx.type());
|
||||||
List<Expression> args = new ArrayList<>();
|
List<Expression> args = new ArrayList<>();
|
||||||
if (ctx.args() != null) {
|
if (ctx.args() != null) {
|
||||||
for (var expr : ctx.args().expr()) {
|
if (ctx.args() != null) {
|
||||||
Expression astExpr = expr.accept(this);
|
for (var expr : ctx.args().expr()) {
|
||||||
args.add(astExpr);
|
Expression astExpr = expr.accept(this);
|
||||||
|
args.add(astExpr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new New(type, args);
|
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));
|
Assignment update = generateAssign(ctx.assign().get(ctx.assign().size() - 1));
|
||||||
Block block = new BlockGenerator().visit(ctx.block());
|
Block block = new BlockGenerator().visit(ctx.block());
|
||||||
if (ctx.assign().size() == 1) {
|
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());
|
Expression initialization = new ExpressionGenerator().visit(ctx.localVarWithInitialization().expr());
|
||||||
Assignment init = new Assignment(new FieldVarAccess(false, null, declaration.name()), initialization);
|
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));
|
Assignment assign = generateAssign(ctx.assign(0));
|
||||||
return List.of(new For(assign, expr, update, block));
|
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) {
|
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<>();
|
||||||
for (var expr : ctx.args().expr()) {
|
if (ctx.args() != null) {
|
||||||
Expression astExpr = expr.accept(new ExpressionGenerator());
|
for (var expr : ctx.args().expr()) {
|
||||||
args.add(astExpr);
|
Expression astExpr = expr.accept(new ExpressionGenerator());
|
||||||
|
args.add(astExpr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return List.of(new New(type, args));
|
return List.of(new New(type, args));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user