> You can pass trees from one rule to another as a parameter(s),
> maybe that might help, something like (probably requires more
> work to obtain the tree you are after):
> 
> protected
> expression
>     : e=conditionalOrExpression conditionalExpression[$e.tree]
>     ;
> 
> protected
> conditionalExpression[CommonTree TheActualASTRoot]
>     : QMARK t=expression COMMA f=expression
>             -> ^(ITE ${TheActualASTRoot} $t $f)
>     |
>     ;
> 
> Regards, Mark

Thank you Mark, for your clever reply.

May I ask if there is any way to do somthing like this:

protected
expression
    :   e=conditionalOrExpression c=conditionalExpression[$e] -> $c
    ;

protected
conditionalExpression[conditionalOrExpression e]
    :   QMARK t=expression COMMA f=expression   -> ^(ITE $e $t $f)
    |                                           -> $e
    ;

It seems cleaner to me, since this way subrules are not going to "play
dirty" with the root of their parents.

Unfortunately, this notation causes a "reference to undefined label in
rewrite rule: $e" error. The point may be "e" is not of
conditionalOrExpression type or, well, I don't really know why. Something
like that works with non-AST generating combined parsers (with more
classical actions, then). But it seems not to work with rewrite actions.

Thank you again,

Giampaolo

PS: I forgot to thank everybody for this really great open-source piece.


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.

Reply via email to