Compare commits

...

2 Commits

Author SHA1 Message Date
MaarxS
f69e5df5e7 finish ExpressionGenerator 2024-03-22 16:34:50 +01:00
MaarxS
04978dafe3 finish ExpressionGenerator 2024-03-20 14:32:26 +01:00

View File

@ -2,6 +2,8 @@ package de.dhbw.horb;
import de.dhbw.horb.ast.*;
import java.util.List;
public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitBinaryOperation(DecafParser.BinaryOperationContext ctx) {
@ -10,7 +12,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) {
throw new RuntimeException("TODO");
return generateFunctionCall(ctx.funcCall());
}
@Override
@ -30,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()));