[antlr-interest] Operator tree construction in rewrite syntax

Gavin Lambert antlr at mirality.co.nz
Tue Apr 15 12:41:54 PDT 2008


At 04:20 16/04/2008, Marko Simovic wrote:
>also, while we're on the subject, what about a rewrite syntax of 
>this one:
>
>unary: (UnaryOp^)? something;

That one's simpler, because there aren't any loops (so no need to 
generate multiple trees):

unary
   :  UnaryOp s1=something -> ^(UnaryOp $s1)
   |  s2=something -> $s2
   ;

The main thing you need to remember is that whenever you use -> 
you are setting the tree for the entire rule, and that if needed 
you can include a previously-generated tree for the rule within 
the new tree being constructed.



More information about the antlr-interest mailing list