[antlr-interest] Operator tree construction in rewrite syntax

Marko Simovic markobarko at gmail.com
Tue Apr 15 09:20:03 PDT 2008


wow...crazy syntax. maybe the wiki section on tree generation should be
updated to note that this syntax is equivalent to the other one?

also, while we're on the subject, what about a rewrite syntax of this
one:

unary: (UnaryOp^)? something;

Thanks a bunch to everyone!,
Marko

-----Original Message-----
From: Gavin Lambert <antlr at mirality.co.nz>
To: Thomas Brandon <tbrandonau at gmail.com>, Marko Simovic
<markobarko at gmail.com>
Cc: antlr-interest <antlr-interest at antlr.org>
Subject: Re: [antlr-interest] Operator tree construction in rewrite
syntax
Date: Tue, 15 Apr 2008 09:19:16 +1200


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))*
   ;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080415/2565c8c1/attachment.html 


More information about the antlr-interest mailing list