[antlr-interest] Semantic predicates in v4 lexer rules

Kyle Ferrio kferrio at gmail.com
Mon Jan 23 14:40:53 PST 2012


Thinking in syntactic predicates is one habit which will -not- be hard to
break.  :)

Kyle
 On Jan 23, 2012 2:43 PM, "Terence Parr" <parrt at cs.usfca.edu> wrote:

>  there is no need for syntactic predicates in either the parser or the
> lexer anymore. just specify the grammar you need, and honey badger will do
> its magic.
> Ter
> On Jan 23, 2012, at 1:21 PM, A Z wrote:
>
> > Thanks for the response. It's also giving me errors for all syntactic
> > predicates so I assume it's for the same reason.
> >
> >
> > On Tue, Jan 24, 2012 at 1:13 AM, Sam Harwell <sam at tunnelvisionlabs.com
> >wrote:
> >
> >> Even after this is resolved, semantic predicates are almost surely not
> the
> >> correct way to handle this. Instead, you should use an action like the
> >> following at the end of the rule to reset the keyword to an identifier
> if
> >> keywords are disabled. Semantic predicates in a v4 lexer have a major
> >> performance cost.
> >>
> >> K_IF : 'if' {if (!keywords) $type=ID;};
> >>
> >> --
> >> Sam Harwell
> >> Owner, Lead Developer
> >> http://tunnelvisionlabs.com
> >>
> >>
> >> -----Original Message-----
> >> From: Terence Parr [mailto:parrt at cs.usfca.edu]
> >> Sent: Monday, January 23, 2012 12:40 PM
> >> To: A Z
> >> Cc: antlr-interest at antlr.org
> >> Subject: Re: [antlr-interest] Semantic predicates in v4 lexer rules
> >>
> >> ooops. I removed actions from anywhere except the right-hand side but
> >> forgot
> >> to leave in predicates.
> >>
> >> adding to the list.
> >> Ter
> >> On Jan 23, 2012, at 10:31 AM, A Z wrote:
> >>
> >>> Can we still use sementic predicates in lexer rules using v4? The
> >>> following code works in 3.4 but 4.0ea complains with
> >>>
> >>> error(15): TestLexer.g:484:29: '{keywords == true}?' came as a
> >>> complete surprise to me while looking for lexer rule element
> >>>
> >>>
> >>> K_IF                       : {keywords == true}? => 'if';
> >>> K_INT                      : {keywords == true}? => 'int';
> >>>
> >>>
> >>> The language I'm using allows changing the keyword set via
> >>> preprocessor directives so all the keywords need to test a variable at
> >>> runtime. Is there another way to do this in v4?
> >>>
> >>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >>> Unsubscribe:
> >>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >>
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >>
> >>
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list