[antlr-interest] Semantic predicates in v4 lexer rules

Sam Harwell sam at tunnelvisionlabs.com
Mon Jan 23 13:33:53 PST 2012


I forgot to add, gated semantic predicates (ones followed by =>) no longer
exist in v4 because it will always look far enough ahead to make its
decision. Semantic predicates are now just {...}?", and syntactic predicates
are removed.

--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com


-----Original Message-----
From: A Z [mailto:asicaddress at gmail.com] 
Sent: Monday, January 23, 2012 3:21 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Semantic predicates in v4 lexer rules

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-addre
> > ss
>
>
> 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