diff --git a/src/main/java/astGenerator/ASTGenerator.java b/src/main/java/astGenerator/ASTGenerator.java index 8ae4d20..2d8a6d0 100644 --- a/src/main/java/astGenerator/ASTGenerator.java +++ b/src/main/java/astGenerator/ASTGenerator.java @@ -39,7 +39,7 @@ public class ASTGenerator extends DecafBaseVisitor { hasMain = false; } for (DecafParser.LocalVarDeclContext fieldDecl: ctx.localVarDecl()) { - fieldDecls.add((FieldDecl) visit(fieldDecl)); + fieldDecls.add((FieldDecl) generateFieldDecl(fieldDecl)); } for (DecafParser.ConstuctorDeclContext constDecl: ctx.constuctorDecl()) { MethodDecl constructor = ((MethodDecl) visit(constDecl)); @@ -54,9 +54,13 @@ public class ASTGenerator extends DecafBaseVisitor { return new RefType(name,fieldDecls, methodDecls, hasMain); } + public Node generateFieldDecl(DecafParser.LocalVarDeclContext ctx) { + return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText()); + } + @Override public Node visitLocalVarDecl(DecafParser.LocalVarDeclContext ctx) { - return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText()); + return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText()); } @Override @@ -108,6 +112,8 @@ public class ASTGenerator extends DecafBaseVisitor { return visitStmtExpr(ctx.stmtExpr()); } else if (ctx.emptyStatement() != null) { return visitEmptyStatement(ctx.emptyStatement()); + } else if (ctx.localVarDecl() != null) { + return visitLocalVarDecl(ctx.localVarDecl()); } return null; }