diff --git a/src/main/java/astGenerator/ASTGenerator.java b/src/main/java/astGenerator/ASTGenerator.java index 183013d..b628494 100644 --- a/src/main/java/astGenerator/ASTGenerator.java +++ b/src/main/java/astGenerator/ASTGenerator.java @@ -5,6 +5,8 @@ import abstractSyntaxTree.Class.MethodDecl; import abstractSyntaxTree.Class.RefType; import abstractSyntaxTree.Expression.BinaryExpression; import abstractSyntaxTree.Expression.IExpression; +import abstractSyntaxTree.Expression.IntConstantExpression; +import abstractSyntaxTree.Expression.LocalVarIdentifier; import abstractSyntaxTree.Node; import abstractSyntaxTree.Parameter.Parameter; import abstractSyntaxTree.Parameter.ParameterList; @@ -132,12 +134,12 @@ public class ASTGenerator extends DecafBaseVisitor { @Override public Node visitIfElseStmt(DecafParser.IfElseStmtContext ctx) { if (ctx.elseStmt() != null) { - return visitIfStmt(ctx.ifStmt()); - } else { Node expression = visitExpression(ctx.ifStmt().expression()); Node ifStatement = visitStatement(ctx.ifStmt().statement()); Node elseStatement = visitStatement(ctx.elseStmt().statement()); return new IfElseStatement((IExpression) expression, (IStatement) ifStatement, (IStatement) elseStatement); + } else { + return visitIfStmt(ctx.ifStmt()); } } @@ -190,7 +192,7 @@ public class ASTGenerator extends DecafBaseVisitor { @Override public Node visitExpression(DecafParser.ExpressionContext ctx) { if (ctx.subExpression() != null) { - + return visitSubExpression(ctx.subExpression()); } else if (ctx.binaryExpr() != null) { return visitBinaryExpr(ctx.binaryExpr()); } @@ -238,7 +240,15 @@ public class ASTGenerator extends DecafBaseVisitor { //todo @Override public Node visitDotSubExpr(DecafParser.DotSubExprContext ctx) { - return super.visitDotSubExpr(ctx); +// if (ctx.IntValue() != null) { +// int value = Integer.parseInt(ctx.IntValue().getText()); +// return new IntConstantExpression(value); +// } + if(ctx.Identifier() != null) { + String identifier = ctx.Identifier().getText(); + return new LocalVarIdentifier(identifier); + } + return null; } @Override @@ -256,8 +266,20 @@ public class ASTGenerator extends DecafBaseVisitor { @Override public Node visitSubExpression(DecafParser.SubExpressionContext ctx) { - if (ctx.subExpression() != null) { - visitSubExpression(ctx.subExpression()); + if (ctx.assignableExpr() != null) { + return visitAssignableExpr(ctx.assignableExpr()); + } else if (ctx.stmtExpr() != null) { + return visitStmtExpr(ctx.stmtExpr()); + } else if (ctx.subExpression() != null) { + return visitSubExpression(ctx.subExpression()); + } + return null; + } + + @Override + public Node visitAssignableExpr(DecafParser.AssignableExprContext ctx) { + if (ctx.Identifier() != null) { + return new LocalVarIdentifier(ctx.Identifier().getText()); } return null; }