diff --git a/src/main/java/de/dhbw/horb/ExpressionGenerator.java b/src/main/java/de/dhbw/horb/ExpressionGenerator.java index 30b33e7..63f7730 100644 --- a/src/main/java/de/dhbw/horb/ExpressionGenerator.java +++ b/src/main/java/de/dhbw/horb/ExpressionGenerator.java @@ -3,7 +3,6 @@ package de.dhbw.horb; import de.dhbw.horb.ast.*; import java.util.List; -import java.util.stream.Collectors; public class ExpressionGenerator extends DecafBaseVisitor { @Override @@ -13,10 +12,7 @@ public class ExpressionGenerator extends DecafBaseVisitor { @Override public Expression visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) { - String name = ctx.funcCall().id().getText(); - List expressions = ctx.funcCall().args().expr(); - List args = expressions.stream().map(this::visit).toList(); - return new FunctionCall(name, args); + return generateFunctionCall(ctx.funcCall()); } @Override @@ -36,6 +32,14 @@ public class ExpressionGenerator extends DecafBaseVisitor { return generateLocation(ctx.loc()); } + public static FunctionCall generateFunctionCall(DecafParser.FuncCallContext ctx) { + String name = ctx.id().getText(); + List expressions = ctx.args().expr(); + List args = expressions.stream() + .map(exp -> new ExpressionGenerator().visit(exp)).toList(); + return new FunctionCall(name, args); + } + public static Expression generateConstant(DecafParser.LiteralContext ctx){ if(ctx.number() != null) return new IntConstant(Integer.valueOf(ctx.number().getText()));