Please use anltr.markmail.org as you will find many answers there. But you need to respect the cardinality of your rewrite elements:
X? ->X? X* ->X* X+ ->X+ (a='+'|a='-') t2=fred -> ^($a $t2) And so on. Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Victor Giordano > Sent: Tuesday, August 10, 2010 1:31 PM > To: [email protected] > Subject: Re: [antlr-interest] Doubt About rewrite rulse > > Thanks Junkman!!! But it's still doesn't work... :(. > I have another example: > > rule: TOKEN1? TOKEN2 -> ^(TOKEN1 TOKEN2) Works when token1 actually > exists, but when no.. :( ugly things happen.. > > Well, thanks for advance again!!. > Cya. > > > > El 10/08/2010 05:00 p.m., Junkman escribió: > > Hi Victor, > > > > Victor Giordano wrote: > >> Hi, i am a newbie. Trying to figure out how to work with AST tree and > >> > >> ... > >> > >> butttttttt if i want to use rewrite rules... how do i thread the > >> repetion EBNF operator like * or +. > >> > >> expr : term (('+'|'-') term)* -> term ^(('+'|'-') term)* ; > >> > > > > try this: > > > > expr: ( term -> term ) > > ( ( '+' | '-' ) term -> ^( ( '+' | '-' ) $expr term ) )* ; > > > > > > Not sure if the terms need to be distinguished with labels. > > > > The Antlr reference book describes the use of rewrite rule inside > > subrule in more detail. > > > > J > > > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/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.
