[antlr-interest] parser backtrack issue

Ashish asengine at gmail.com
Fri Jan 18 18:44:17 PST 2008


Hi,
I defined boolean expressions as
booleanExpressions
     :  booleanExpression ( BOOLEAN_OR  booleanExpression )*
     |  booleanExpression ( BOOLEAN_AND booleanExpression )*

but the antlr code generator complained so I added the backtrack option as
below
booleanExpressions
options {
 backtrack = true;
}
     :  booleanExpression ( BOOLEAN_OR  booleanExpression )*
     |  booleanExpression ( BOOLEAN_AND booleanExpression )*

But when run with the input
select a from b where c > d && x < y;

I get the following error
recoverFromMismatchedToken
BR.recoverFromMismatchedToken
line 1:28 mismatched input '&&' expecting SEMICOLON
I can get rid of the error if booleanExpressions is defined as
 booleanExpressions
     :  booleanExpression ( (BOOLEAN_OR  | BOOLEAN_AND) booleanExpression )*

however I am not sure how to go about writing the rewrite rule for AST
generation for this one line version.
Writing the rewrite rule for the 2 line version seems fairly obvious.

Thanks again,
Ashish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080118/c2c091c4/attachment-0001.html 


More information about the antlr-interest mailing list