[antlr-interest] Operator tree construction in rewrite syntax

Gavin Lambert antlr at mirality.co.nz
Mon Apr 14 14:19:16 PDT 2008


At 08:46 15/04/2008, Thomas Brandon wrote:
 >I think you can do something like (syntax not checked):
 >sum: s1=something -> $s1 (Plus s2=something -> ^(Plus $sum $s2)
 >)*;
 >I'm not sure if you need the first rewrite or whether it will
 >already have it when you use $sum (the previously constructed
 >tree for the rule).

You do need the first rewrite, and it needs to be in parentheses 
or ANTLR will complain.  So:

sum
   : (s1=something -> $s1)
     (Plus s2=something -> ^(Plus $sum $s2))*
   ;



More information about the antlr-interest mailing list