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
On Sun, Apr 18, 2010 at 12:39:23PM +0200, Giampaolo Tomassoni wrote:
> Hello everybody,
>
> I'm facing a problem for which it seems I can't find a reply in the site
> docs and faqs.
>
> I would like to parse text based on a very simple grammar (arithmetic
> expressions with some boolean enhancement). Every example in the site seems
> to adopt a non-LLR notation, while I would instead prefer to use
> backtrack=false.
>
> In example, I have stuff like this:
>
>
> protected
> expression
> : (e=conditionalOrExpression -> $e) c=conditionalExpression
> ;
>
> protected
> conditionalExpression
> : QMARK t=expression COMMA f=expression -> ???
> |
> ;
>
>
> Where conditionalExpression should possibly substitute the AST element
> produced by "expression" with something like
>
> -> ^(ITE [TheActualASTRoot] $t $f)
>
> in case the first case is matched.
>
> The fact is that I can't find in the site docs how to replace the top of a
> parent rule, if at all possible.
>
> Am I completely headed toward the wrong direction?
>
> Giampaolo
>
>
> 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.