how can I say to antlr if you see a 'BEGIN' then at this line you must see an 'END'?
here is my code ( i only need the BEGIN/END when i have multiple statements)
whileStatement
: 'WHILE' expression 'DO'
'BEGIN'?
statement
'END'?
;
and my statements
statement
: assignmentStatement
| ifStatement
| doLoopStatement
| whileStatement
| procedureCallStatement
;
No experience with ANTLR, but generally in BNF/context-free grammars you'd express this as
whileStatement
: 'WHILE' expr 'DO'
statementBlock
;
statementBlock
: statement
| 'BEGIN' statement* 'END'
;
or add statementBlock
as an alternative in the definition of statement
.
精彩评论