Compare commits
2 Commits
2b90f84c1e
...
f69e5df5e7
Author | SHA1 | Date | |
---|---|---|---|
|
f69e5df5e7 | ||
|
04978dafe3 |
@ -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()));
|
||||
|
Loading…
Reference in New Issue
Block a user