Compare commits

..

No commits in common. "873d1b7a0a12ac3d5bf86f6635b4b76cc51791ff" and "b91174eeee60a7fd911717a2cafc7af209510d6d" have entirely different histories.

2 changed files with 5 additions and 90 deletions

View File

@ -17,12 +17,6 @@ public class BinaryExpression extends AbstractType implements IExpression{
public IExpression left;
public IExpression right;
public BinaryExpression(String operator, IExpression left, IExpression right) {
this.operator = operator;
this.left = left;
this.right = right;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckHelper helper = new TypeCheckHelper();

View File

@ -4,7 +4,6 @@ import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Expression.BinaryExpression;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Node;
import abstractSyntaxTree.Parameter.Parameter;
import abstractSyntaxTree.Parameter.ParameterList;
@ -115,8 +114,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
@Override
public Node visitReturnStmt(DecafParser.ReturnStmtContext ctx) {
Node expression = visitExpression(ctx.expression());
return new ReturnStatement((IExpression) expression);
return new ReturnStatement(new BinaryExpression());
}
@Override
@ -134,25 +132,22 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
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);
return new IfElseStatement(new BinaryExpression(), (IStatement) ifStatement, (IStatement) elseStatement);
}
}
@Override
public Node visitIfStmt(DecafParser.IfStmtContext ctx) {
Node expression = visitExpression(ctx.expression());
Node statement = visitStatement(ctx.statement());
return new IfStatement((IExpression) expression, (IStatement) statement);
return new IfStatement(new BinaryExpression(), (IStatement) statement);
}
@Override
public Node visitWhileStmt(DecafParser.WhileStmtContext ctx) {
Node expression = visitExpression(ctx.expression());
Node statement = visitStatement(ctx.statement());
return new WhileStatement((IExpression) expression, (IStatement) statement);
return new WhileStatement(new BinaryExpression(), (IStatement) statement);
}
@Override
@ -172,6 +167,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
return null;
}
@Override
public Node visitAssign(DecafParser.AssignContext ctx) {
return new AssignStatementExpression("", null, null);
@ -186,79 +182,4 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
public Node visitNewDecl(DecafParser.NewDeclContext ctx) {
return super.visitNewDecl(ctx);
}
@Override
public Node visitExpression(DecafParser.ExpressionContext ctx) {
if (ctx.subExpression() != null) {
} else if (ctx.binaryExpr() != null) {
return visitBinaryExpr(ctx.binaryExpr());
}
return null;
}
@Override
public Node visitBinaryExpr(DecafParser.BinaryExprContext ctx) {
if (ctx.calcExpr() != null) {
return visitCalcExpr(ctx.calcExpr());
} else if (ctx.nonCalcExpr() != null) {
return visitNonCalcExpr(ctx.nonCalcExpr());
} else if (ctx.value() != null) {
//todo
} else if (ctx.binaryExpr() != null) {
//todo
}
return null;
}
@Override
public Node visitCalcExpr(DecafParser.CalcExprContext ctx) {
if (ctx.calcExpr() != null) {
Node left = visitCalcExpr(ctx.calcExpr());
Node right = visitDotExpr(ctx.dotExpr());
return new BinaryExpression(ctx.LineOperator().getText(), (IExpression) left, (IExpression) right);
} else {
visitDotExpr(ctx.dotExpr());
}
return null;
}
@Override
public Node visitDotExpr(DecafParser.DotExprContext ctx) {
if (ctx.dotExpr() != null) {
Node left = visitDotExpr(ctx.dotExpr());
Node right = visitDotSubExpr(ctx.dotSubExpr());
return new BinaryExpression(ctx.DotOperator().getText(), (IExpression) left, (IExpression) right);
} else {
visitDotSubExpr(ctx.dotSubExpr());
}
return null;
}
//todo
@Override
public Node visitDotSubExpr(DecafParser.DotSubExprContext ctx) {
return super.visitDotSubExpr(ctx);
}
@Override
public Node visitNonCalcExpr(DecafParser.NonCalcExprContext ctx) {
String operator;
if(ctx.nonCalcOperator().LogicalOpertor() != null) {
operator = ctx.nonCalcOperator().LogicalOpertor().getText();
} else {
operator = ctx.nonCalcOperator().ComparisonOperator().getText();
}
Node left = visitSubExpression(ctx.subExpression());
Node right = visitExpression(ctx.expression());
return new BinaryExpression(operator, (IExpression) left, (IExpression) right);
}
@Override
public Node visitSubExpression(DecafParser.SubExpressionContext ctx) {
if (ctx.subExpression() != null) {
visitSubExpression(ctx.subExpression());
}
return null;
}
}