[antlr-interest] Rewrite rules, again!
Johannes Luber
jaluber at gmx.de
Thu Mar 13 15:54:49 PDT 2008
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