From f69e5df5e73b946993f0d8a19b6f4f7e346305e3 Mon Sep 17 00:00:00 2001 From: MaarxS Date: Fri, 22 Mar 2024 16:34:50 +0100 Subject: [PATCH] finish ExpressionGenerator --- .../java/de/dhbw/horb/ExpressionGenerator.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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()));