Move the SCOL for var_assigns and var_decl to the statement rule
This commit is contained in:
@@ -20,11 +20,14 @@ braced_block
|
|||||||
: OBRK statement+ CBRK
|
: OBRK statement+ CBRK
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
// Only the first child of a rule alternative will be visited!
|
||||||
|
// i.e. SCOL won't be visited, but thats unneccesary anyway
|
||||||
statement
|
statement
|
||||||
: print
|
: print
|
||||||
| if_statement
|
| if_statement
|
||||||
| variable_declaration
|
| variable_declaration SCOL
|
||||||
| variable_assignment
|
| variable_assignment SCOL
|
||||||
| return_statement
|
| return_statement
|
||||||
| whileLoop
|
| whileLoop
|
||||||
| doWhileLoop
|
| doWhileLoop
|
||||||
@@ -39,11 +42,11 @@ if_statement
|
|||||||
;
|
;
|
||||||
|
|
||||||
variable_declaration
|
variable_declaration
|
||||||
: LET IDENT (EQUAL expression)? SCOL
|
: LET IDENT (EQUAL expression)?
|
||||||
;
|
;
|
||||||
|
|
||||||
variable_assignment
|
variable_assignment
|
||||||
: IDENT EQUAL expression SCOL
|
: IDENT EQUAL expression
|
||||||
;
|
;
|
||||||
|
|
||||||
return_statement
|
return_statement
|
||||||
|
|||||||
@@ -23,12 +23,20 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
return new Program(funcs, expression);
|
return new Program(funcs, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Node visitStatement(KlangParser.StatementContext ctx) {
|
||||||
|
// The first child is the proper context we need to visit
|
||||||
|
// The second child is either null or just a SCOL!
|
||||||
|
return this.visit(ctx.getChild(0));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node visitBraced_block(KlangParser.Braced_blockContext ctx) {
|
public Node visitBraced_block(KlangParser.Braced_blockContext ctx) {
|
||||||
Statement[] statements = new Statement[ctx.statement().size()];
|
Statement[] statements = new Statement[ctx.statement().size()];
|
||||||
|
|
||||||
for (int i = 0; i < ctx.statement().size(); i++) {
|
for (int i = 0; i < ctx.statement().size(); i++) {
|
||||||
Node currentStatement = this.visit(ctx.statement(i));
|
var stmtCtx = ctx.statement(i);
|
||||||
|
Node currentStatement = this.visit(stmtCtx);
|
||||||
statements[i] = (Statement) currentStatement;
|
statements[i] = (Statement) currentStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user