> > Do you think is it fine this way or there is some workaround I can
> implement
> > to avoid the need of a side-effect function?
> >
> > Giampaolo
>
> Predicates should not have observable* side effects.
>
> 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
> PS * since disambiguating semantic predicates may be called tens or
> hundreds of times at the same input file position in complex
> predicated parsers by antlr generated code, for performance
> reasons it may be necessary for complex semantic predicates to
> calculate the
> result once at each input file position, and cache the result, to
> avoid re-computing it over and over again.
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.