[antlr-interest] Problems with semantic predicates

Haralambi Haralambiev hharalambiev at gmail.com
Fri Apr 18 00:18:51 PDT 2008


Hello Jim and Gavin,

Thanks for the suggestions.

However, with the syntax suggested by Gavin, the problem still persists -
the synpred2_fragment method still contains the "if (!flag)" statement. By
the way - is there somewhere I could read regarding why is this check added
into this method?

And, Jim, your syntax fails to generate anything with the following
statement: "expecting SEMI, found '->'" - this is right before the "->
Token1" statement.

By the way, why do you refer the flag in the predicate with "$flag"? This
renders an error on my side ("attribute is not a token, parameter, or return
value: flag"), but with "{flag}?" it doesn't fail.

Thanks again for your feedback. I hope we could resolve the problem soon.

Hari

On 4/18/08, Jim Idle <jimi at temporal-wave.com> wrote:
>
>
>
> > -----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
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080418/c13480cc/attachment.html 


More information about the antlr-interest mailing list