[antlr-interest] Semantic predicates in v4 lexer rules
Sam Harwell
sam at tunnelvisionlabs.com
Mon Jan 23 11:13:12 PST 2012
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
More information about the antlr-interest
mailing list