fix parameterList in ast

This commit is contained in:
StefanZ3 2024-06-20 09:35:43 +02:00
parent 719e19e7f8
commit ebd4f7ca4e

View File

@ -66,7 +66,10 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
@Override
public Node visitConstuctorDecl(DecafParser.ConstuctorDeclContext ctx) {
String name = ctx.Identifier().getText();
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
ParameterList parameterList = new ParameterList(new ArrayList<>());
if (ctx.parameterList() != null) {
parameterList = (ParameterList) visit(ctx.parameterList());
}
BlockStatement block = (BlockStatement) visitBlock(ctx.block());
return new MethodDecl("", null, name, parameterList, block);
}
@ -76,8 +79,11 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
String type;
String name = ctx.Identifier().getText();
BlockStatement block = (BlockStatement) visitBlock(ctx.block());
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
if (ctx.Void() != null) {
ParameterList parameterList = new ParameterList(new ArrayList<>());
if (ctx.parameterList() != null) {
parameterList = (ParameterList) visit(ctx.parameterList());
}
if (ctx.Void() != null) {
type = "void";
} else {
type = ctx.type().getText();