[antlr-interest] parser backtrack issue

Gavin Lambert antlr at mirality.co.nz
Fri Jan 18 18:59:18 PST 2008


At 15:44 19/01/2008, Ashish wrote:
>I defined boolean expressions as
>booleanExpressions
>      :  booleanExpression ( BOOLEAN_OR  booleanExpression )*
>      |  booleanExpression ( BOOLEAN_AND booleanExpression )*

That's only going to match a chain of ANDs or a chain or ORs.  It 
won't match a mixed sequence of ANDs and ORs, for example.  You 
probably want this:

booleanExpressions
   :  booleanExpression ((BOOLEAN_OR | BOOLEAN_AND) 
booleanExpression)*
   ;

Or this:

booleanExpressions
   :  booleanExpression
      ( BOOLEAN_OR booleanExpressions
      | BOOLEAN_AND booleanExpressions
      )?
   ;



More information about the antlr-interest mailing list