On Oct 25, 2008, at 12:40 PM, Gavin Lambert wrote:

> 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 :)
>

Yep, RTFM... http://www.antlr.org/wiki/display/ANTLR3/Tree 
+construction at the top...

> >> ^('.' ^('.' '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))*
>  ;

Ok, thank you very much, that did it.

The answer leads to the next question. I've tried to split the rule  
into an additional selector subrule, but without success.

expr
     :    primary selector*
     ;

selector
     :    '.' ID
     |    '[' expr ']'
     ;

I went one step further and added array access to the selector (to  
make the example a bit more realistic).

My head is starting to spin from all those tree rewrite rules. If I'm  
again missing the obvious, please just send me a link to the correct  
information. This time, I've at least searched the list archive and  
read the manual... Or even better, if somebody has a tree grammar for  
Java expressions (that builds the tree as laid out in my original  
post), could you please send it to me?

Simon


List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to