On Thu, Apr 1, 2010 at 1:21 PM, Christian Mayer <
[email protected]> wrote:
> I am wondering how to transform the rewrite rule
>
> Expr : mul_expr ( ( PLUS | MINUS )^ mul_expr )*;
>
> Into the explicit form with the arrow
>
> Expr : a=mul_expr ( op=( PLUS | MINUS ) b=mul_expr )* -> ? ;
>
> For later use in an AST tree parser.
>
> What is the proper way to do this? I checked ² The definitive ANTL
> reference²/online documentation but could not find anything about the
> syntax.
>
I did not test it, but I believe this would work:
Expr
: (a=mul_expr -> $a )
(op=(PLUS | MINUS) b=mul_expr -> ^($op $a $b) )*
;
Also see Chapter 7, section "Constructing AST's with rewrite rules"
paragraph "Rewrite Rules in Subrules" from "The definitive ANTLR reference".
Kind regards,
Bart.
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.