[antlr-interest] Rewrite rules, again!

Shaun Bogan smbogan at gmail.com
Thu Mar 13 15:59:10 PDT 2008


Thanks for the help, unfortunately, that doesn't work, because it
quits parsing after the second = sign when it matches a = b = c;


On Thu, Mar 13, 2008 at 5:54 PM, Johannes Luber <jaluber at gmx.de> wrote:
> Shaun Bogan schrieb:
>
> > I got some great help creating the following for my grammar:
> >
> > assignops :
> > (boolops->boolops)(firstops b2=boolops -> ^(OPERATOR ^(firstops
> > ^(OPERAND $b2) ^(OPERAND $assignops))))*
> > ;
> >
> > To make the above clear, it is basically just:
> > assignops :
> >     boolops (firstops boolops)*
> >     ;
> > with rewrite rules.
> >
> > The problem is this creates an AST that groups items in the reverse of
> > how I need them.  For example:
> > a = b = c;
> > will create a tree that my tree walker (doing depth first) would evaluate as:
> > (a = b) = c;
> >
> > This is obviously wrong.  It should be a = (b = c);
> >
> > Essentially, my parse tree looks fine, but I can't figure out how (if
> > there is a way) to get my rewrite rule to write my AST like above.
>
> How about?
>
> assignops :
>  (boolops->boolops)(firstops b2=boolops -> ^(OPERATOR ^(firstops
>  ^(OPERAND $b2) ^(OPERAND $assignops))))?
>  ;
>
> Johannes
>


More information about the antlr-interest mailing list