[antlr-interest] Problems with semantic predicates
Johannes Luber
jaluber at gmx.de
Thu Apr 17 10:15:41 PDT 2008
Haralambi Haralambiev schrieb:
> Hello Johannes,
>
> So, if I understand correctly, you suggest to have the following (using
> a scope):
>
> r2
> : {$r::flag}? Token1 -> ^(NODE Token1)
> | Token1
> ;
>
> If the above is a correct assumption, then how can I set the scope
> variable, as I could only think of the following way:
>
> r
> scope {
> boolean flag;
> }
> : Token1^ Token2!
> {$r::flag = true;}
> r2
> | Token1^
> {$r::flag = false;}
> r2
> ;
>
> This solution, however, will fail, as the action for setting the scope
> variable will not be executed until the backtracking is over. But I need
> this variable set, as it will be used as a predicate for the parsing.
> Thus, we have a catch-22 situation.
>
> A solution I could think of is not to have two alternatives for r2, but
> rather construct the CommonTree manually with java code and within to
> use the knowledge of the boolean flag. But I dislike this solution and
> am open to suggestions.
Try using {{$r::flag = true;}}.
Johannes
More information about the antlr-interest
mailing list