[antlr-interest] Problems with semantic predicates
Jim Idle
jimi at temporal-wave.com
Thu Apr 17 16:07:06 PDT 2008
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Gavin Lambert
> Sent: Thursday, April 17, 2008 1:31 PM
> To: Haralambi Haralambiev; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Problems with semantic predicates
>
> At 04:02 18/04/2008, Haralambi Haralambiev wrote:
> >r2[boolean flag]
> >:{flag}? Token1 -> ^(NODE Token1)
> >|Token1
> >;
> [...]
> >In the example above - the method synpred2_fragment() contains a
> >statement if ( !(flag) ) but the variable flag cannot be resolved.
>
> As Johannes has already said, the problem is that the predicate is
> getting hoisted. However, I think there's another way to get it
> to work -- rewrite the rule so that it doesn't *need* to hoist the
> predicate:
Right idea mate, slightly wrong syntax ;-) :
r2[boolean flag]
: Token1
{$flag}? -> ^(NODE Token1)
-> Token1
;
>
> r2[boolean flag]
> : Token1
> ( {$flag}? => -> ^(NODE Token1)
> | -> Token1
> )
> ;
>
Jim
No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.0/1382 - Release Date: 4/16/2008 5:34 PM
More information about the antlr-interest
mailing list