[antlr-interest] Tree Operators vs. Tree Rewrite Rules

Gavin Lambert antlr at mirality.co.nz
Sat Oct 25 03:40:15 PDT 2008


At 22:57 25/10/2008, Simon wrote:
 >Is it so obvious? Or is it simply not possible to achieve
the same thing using rewrite rules?

It is possible, and it's not quite so obvious (though it has been 
mentioned a few times in the archives).  But messages sometimes 
slip through the cracks :)

 >> ^('.' ^('.' 'a' 'b') 'c')
[...]
 >> expr
 >> 	:	primary ('.'^ ID )*
 >> 	;
[...]
 >> However, I can't get the same tree using tree rewrite
 >> rules. Is it possible at all? If so, could somebody
 >> please show me how?

expr
   :  (primary -> primary)
      ('.' ID -> ^('.' $expr ID))*
   ;



More information about the antlr-interest mailing list