fix ifstmt in ASTGenerator
This commit is contained in:
parent
ab19751146
commit
8549799175
@ -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<Node> {
|
||||
@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<Node> {
|
||||
@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<Node> {
|
||||
//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<Node> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user