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.Class.RefType;
|
||||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||||
import abstractSyntaxTree.Expression.IExpression;
|
import abstractSyntaxTree.Expression.IExpression;
|
||||||
|
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||||
|
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||||
import abstractSyntaxTree.Node;
|
import abstractSyntaxTree.Node;
|
||||||
import abstractSyntaxTree.Parameter.Parameter;
|
import abstractSyntaxTree.Parameter.Parameter;
|
||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
@ -132,12 +134,12 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
|||||||
@Override
|
@Override
|
||||||
public Node visitIfElseStmt(DecafParser.IfElseStmtContext ctx) {
|
public Node visitIfElseStmt(DecafParser.IfElseStmtContext ctx) {
|
||||||
if (ctx.elseStmt() != null) {
|
if (ctx.elseStmt() != null) {
|
||||||
return visitIfStmt(ctx.ifStmt());
|
|
||||||
} else {
|
|
||||||
Node expression = visitExpression(ctx.ifStmt().expression());
|
Node expression = visitExpression(ctx.ifStmt().expression());
|
||||||
Node ifStatement = visitStatement(ctx.ifStmt().statement());
|
Node ifStatement = visitStatement(ctx.ifStmt().statement());
|
||||||
Node elseStatement = visitStatement(ctx.elseStmt().statement());
|
Node elseStatement = visitStatement(ctx.elseStmt().statement());
|
||||||
return new IfElseStatement((IExpression) expression, (IStatement) ifStatement, (IStatement) elseStatement);
|
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
|
@Override
|
||||||
public Node visitExpression(DecafParser.ExpressionContext ctx) {
|
public Node visitExpression(DecafParser.ExpressionContext ctx) {
|
||||||
if (ctx.subExpression() != null) {
|
if (ctx.subExpression() != null) {
|
||||||
|
return visitSubExpression(ctx.subExpression());
|
||||||
} else if (ctx.binaryExpr() != null) {
|
} else if (ctx.binaryExpr() != null) {
|
||||||
return visitBinaryExpr(ctx.binaryExpr());
|
return visitBinaryExpr(ctx.binaryExpr());
|
||||||
}
|
}
|
||||||
@ -238,7 +240,15 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
|||||||
//todo
|
//todo
|
||||||
@Override
|
@Override
|
||||||
public Node visitDotSubExpr(DecafParser.DotSubExprContext ctx) {
|
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
|
@Override
|
||||||
@ -256,8 +266,20 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node visitSubExpression(DecafParser.SubExpressionContext ctx) {
|
public Node visitSubExpression(DecafParser.SubExpressionContext ctx) {
|
||||||
if (ctx.subExpression() != null) {
|
if (ctx.assignableExpr() != null) {
|
||||||
visitSubExpression(ctx.subExpression());
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user