[antlr-interest] Excluding keywords

Indhu Bharathi indhu.b at s7software.com
Wed Jun 10 20:59:12 PDT 2009


As stated in the link you provided, there is nothing you have to do to get
this functionality. But 'identifier' should be a lexer rule. I guess your
grammar should be something like this:

 

APPLY                   :               'apply';

BROWSE              :               'browse'

.

 

ID            :               ('A'..'Z' | 'a'..'z') ('A'..'Z' | 'a'..'z' |
'0'..'9' | '_')*;

                

Now, if you write a rule like

 

r              :               ID;

 

only ID that is not a keyword will match this.

 

Am I oversimplifying the problem. Did I miss something?

 

Cheers, Indhu

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Avid Trober
Sent: Thursday, June 11, 2009 9:10 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Excluding keywords

 

I saw something close to my problem on the wiki,
http://www.antlr.org/pipermail/antlr-interest/2006-June/016563.html

 

But, I've got an "extra rule", filter.  Must I resort to an action, or is
there a way to do this purely in the grammar file?

 

 

filter : // identifier, but *not* a keyword

              ;

    

 

keyword :  APPLY

              | BROWSE 

              | CLOSE

              | OPEN

        ;

 

identifier : ('A'..'Z' | 'a'..'z') ('A'..'Z' | 'a'..'z' | '0'..'9' | '_')*

             ;

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090611/1b91c059/attachment.html 


More information about the antlr-interest mailing list