[antlr-interest] mild simplification and tree grammars
Mark Wright
markwright at internode.on.net
Wed Apr 21 05:14:59 PDT 2010
On Wed, Apr 21, 2010 at 01:27:02PM +0200, Giampaolo Tomassoni wrote:
> > The solution seems simple: the actions should be called before the
> > tree rewrites, like:
> >
> > condExpr
> > : QMARK c=orExpression t=condExpr f=condExpr
> > {shc=true;}
> > -> {($c.tree.getType()==TRUE)}? $t
> > -> {($c.tree.getType()==FALSE)}? $f
> > ->
> > ;
> >
> > Regards, Mark
>
> Well, I attempted that, but then the shc var is set true even when there are
> no rewrites (the empty rewrite case in your example). This is probably
> because the disambiguating predicates are on the right side of the rewrite
> operator, while the {shc=true;} seems an action to me. So, it is of course
> to its left.
>
> I don't see a way to put an action to the right side of the rewrite
> operator, since a {...} notation would be interpreted like a tree reference,
> if I understand it right.
>
> Maybe all this means there is space for an enhancement in ANTLR? ;)
>
> Giampaolo
I guess then it is necessary to repeat the predicate test in the action
code then conditionally set shc, or to call a method from the action code with
whatever parameters are necessary for it to compute whether it should set shc or not.
Regards, Mark
More information about the antlr-interest
mailing list