finish ExpressionGenerator

This commit is contained in:
MaarxS 2024-03-22 16:34:50 +01:00
parent 04978dafe3
commit f69e5df5e7

View File

@ -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<Expression> {
@Override
@ -13,10 +12,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) {
String name = ctx.funcCall().id().getText();
List<DecafParser.ExprContext> expressions = ctx.funcCall().args().expr();
List<Expression> 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<Expression> {
return generateLocation(ctx.loc());
}
public static FunctionCall generateFunctionCall(DecafParser.FuncCallContext ctx) {
String name = ctx.id().getText();
List<DecafParser.ExprContext> expressions = ctx.args().expr();
List<Expression> 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()));