add newDecl to ASTGenerator
This commit is contained in:
parent
66428159c1
commit
9d9dcfb9b6
@ -10,6 +10,7 @@ import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.*;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
import gen.DecafBaseVisitor;
|
||||
import gen.DecafParser;
|
||||
|
||||
@ -184,15 +185,18 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
return new AssignStatementExpression(ctx.Assign().getText(),(IExpression) left, (IExpression) right);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
@Override
|
||||
public Node visitMethodCall(DecafParser.MethodCallContext ctx) {
|
||||
return super.visitMethodCall(ctx);
|
||||
}
|
||||
|
||||
//add the expression list later to the constructor
|
||||
@Override
|
||||
public Node visitNewDecl(DecafParser.NewDeclContext ctx) {
|
||||
return super.visitNewDecl(ctx);
|
||||
String name = ctx.Identifier().getText();
|
||||
List<IExpression> expressions = generateExpressions(ctx.argumentList());
|
||||
return new NewStatementExpression(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -296,14 +300,11 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
return super.visitInstVar(ctx);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Node visitArgumentList(DecafParser.ArgumentListContext ctx) {
|
||||
// if (ctx.expression().size() == 1) {
|
||||
// return visitExpression(ctx.expression(0));
|
||||
// } else if (ctx.expression().size() >= 2) {
|
||||
// for(DecafParser.ExpressionContext expressionContext: ctx.expression()) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
public List<IExpression> generateExpressions(DecafParser.ArgumentListContext ctx) {
|
||||
List<IExpression> expressions = new ArrayList<>();
|
||||
for (DecafParser.ExpressionContext expressionContext : ctx.expression()) {
|
||||
expressions.add((IExpression) visitExpression(expressionContext));
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user