[antlr-interest] skipping tokens...

Gavin Lambert antlr at mirality.co.nz
Mon Dec 29 23:55:11 PST 2008


At 18:55 30/12/2008, pady wrote:
 >ifStatement
 >: ^('if' b=boolExpression statementBlock ^(ELSE statement) )
 >;
 >
 >if the boolExpression returns false, I would like to skip
 >execution of "statementBlock" but make the current token move
 >to the "else" part for matching. Can this be done using antlr
 >syntax ? Or should i have to do this through some java code
 >( ie passing the status to statementBlock and all its
 >children etc ).

That's certainly one way you could do it (and passing parameters 
into subrules is part of the standard ANTLR syntax), but provided 
that the statementBlock consists of exactly one subtree you can 
write something like this:

ifStatement
   :  ^('if' b=boolExpression
        ( { $b.value }? => statementBlock ^(ELSE .        )
        |                  .              ^(ELSE statement)
        )
      )
   ;



More information about the antlr-interest mailing list