[antlr-interest] Tricky rewrite (for me anyway)

craig at palantir.co.za craig at palantir.co.za
Thu Jul 31 00:12:23 PDT 2008


Hi Varun,

Glad to hear I am not alone!

I have not been able to get it right yet. I think its a simple problem, so
someone will give us a hand soon I am sure.

Cheers
Craig.

>> Hi Craig,

>> Have you found the answer to this yet? I'm having the exactly same problem!

>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org
>> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of craig at palantir.co.za
>> Sent: Wednesday, 30 July 2008 23:59
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] Tricky rewrite (for me anyway)

>> Hi all,

>> I am struggling with a tricky little rewrite rule.
>> I have managed to get this to work using a deep tree.
>> By that I mean:
>>         rule (('and'|'or')^ rule)* ;

>> I changed it recently to a simple list as follows.
>> The nodes are now siblings, which is what I want.

>> rules:	rule (('and'|'or') rule)*
>>                 ;
>> I need to figure out how to rewrite the above rule to put the 'and' or 'or'
in front so that the tree can match properly.

>> The tree then matches as follows:
>> Unfortunately due to the nature of the matching, I only get the last match in
the tree, not the 'or' or 'and'. I have looked at the tree and this structure
should work. I figure I need to put the 'and' or 'or' in front.
>> path : ^(ROOT xname* 'and')
>>      | ^(ROOT xname* 'or')
>>      | ^(ROOT xname*)
>>      ;

>> I need to make a tree like this.
>> path : ^(ROOT 'and' xname*)
>>         | ^(ROOT 'or' xname*)
>>         | ^(ROOT xname*)
>>         ;

>> because then the tree will work. How do I rewrite the tree to make it work?


>> ----------------------------------------------------------------
>> This message was sent using IMP, the Internet Messaging Program.






----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the antlr-interest mailing list