[antlr-interest] Rewrite rules, again!
Terence Parr
parrt at cs.usfca.edu
Thu Mar 13 17:01:02 PDT 2008
You need to alter the parse to associated things right to left.
(...)* associates left to right.
Something like:
assign : expr '=' x ;
x : assign
| expr
;
note that this is how grammars to ^ exponent operators...look for a
rule that does that.
Ter
On Mar 13, 2008, at 3:32 PM, Shaun Bogan wrote:
> 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.
>
> Any help is greatly appreciated,
> Shaun M Bogan
More information about the antlr-interest
mailing list