[antlr-interest] backtrack=false and AST generation
Mark Wright
markwright at internode.on.net
Sun Apr 18 05:07:19 PDT 2010
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
>
More information about the antlr-interest
mailing list