[antlr-interest] parser backtrack issue

Ashish asengine at gmail.com
Sat Jan 19 14:01:23 PST 2008


Thanks for reminding about AST operators. I'd decided to use rewrite rules
but the operators seem to be much easier.

This alias rocks!

-Ashish


On Jan 19, 2008 4:58 AM, David Holroyd <dave at badgers-in-foil.co.uk> wrote:

> On Fri, Jan 18, 2008 at 06:44:17PM -0800, Ashish wrote:
> > 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.
>
> It's quite simple with tree structuring operators (assuming you don't
> have additional reasons to use a rewrite),
>
>  booleanExpressions
>      :  booleanExpression ( boolOp^ booleanExpression )*
>      ;
>
>  boolOp
>      :  BOOLEAN_OR  | BOOLEAN_AND
>      ;
>
> Expressing this with the rewrite syntax is a bit more fiddly,
>
>  booleanExpressions
>      :  (   booleanExpression
>             -> booleanExpression
>         )
>         (   boolOp booleanExpression
>             -> ^(booleanOp $booleanExpression booleanExpression)
>         )*
>      ;
>
> The (apparently redundant) booleanExpression->booleanExpression is
> required to set the initial value of the $booleanExpressions result
> tree.
>
>
> ta,
> dave
>
> --
> http://david.holroyd.me.uk/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080119/26668265/attachment.html 


More information about the antlr-interest mailing list