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

craig at palantir.co.za craig at palantir.co.za
Wed Jul 30 06:59:23 PDT 2008


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.




More information about the antlr-interest mailing list