[antlr-interest] mild simplification and tree grammars

Mark Wright markwright at internode.on.net
Tue Apr 20 06:09:08 PDT 2010


On Tue, Apr 20, 2010 at 01:51:36PM +0200, Giampaolo Tomassoni wrote:

Oops, I see placed the { after the $ earlier, where it should
be outside the $paramater, like {$parameter}, as in:

protected
conditionalExpression[CommonTree TheActualASTRoot]
    :   QMARK t=expression COMMA f=expression
            -> ^(ITE {$TheActualASTRoot} $t $f)
    |
    ;

> ...
> 
> The specific question is: the above (piece of) tree grammar needs to compile
> with backtrack=true, which I don't like. I'm going to re-create a LLR
> grammar doing the same. I see it mimes a lot the parsing grammar I used to
> generate the source tree, but with a lot more cases in rules. This sounds
> fine to me, but then I'm still getting some problem:
> 
> 
> protected
> conditionalOrExpression
>     :	OR FALSE r=conditionalOrExpression	{shc=true;}	-> $r
>     |	OR TRUE conditionalOrExpression		{shc=true;}	-> TRUE
>     |	OR l=conditionalAndExpression r=conditionalOrRightSide[$l.tree] -> $r
>     |	conditionalAndExpression
>     ;
> 
> protected
> conditionalOrRightSide [CommonTree l]
>     :	FALSE			{shc=true;}	-> $l
>     |	TRUE			{shc=true;}	-> TRUE
>     |	r=conditionalOrExpression		-> OR $l $r
>     ;

So maybe it might work like:

protected
conditionalOrRightSide [CommonTree l]
    :	FALSE			{shc=true;}	-> $l
    |	TRUE			{shc=true;}	-> TRUE
    |	r=conditionalOrExpression		-> OR {$l} $r
    ;
 
> conditionalOrExpression2 rises the error "(137): reference to undefined
> label in rewrite rule: $l", which is the same I got in the parsing grammar
> and which was circumvented by adopting a different notation (thanks to
> John).
> 
> I have ANTLR 3.2. Is it a bug or am I the bug?
> 
> Regards,
> 
> 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