[antlr-interest] Doubt About rewrite rulse
Junkman
j at junkwallah.org
Tue Aug 10 13:00:59 PDT 2010
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
More information about the antlr-interest
mailing list