[antlr-interest] Excluding keywords

Avid Trober avidtrober at gmail.com
Sat Jun 13 17:00:47 PDT 2009


> Did I miss something?

yes, because  of me.  I failed to mention part of the problem: identifiers can be keywords as long as the keyword has an underbar or a shift-number character like asterisk, percent, dollar, etc. after it.  (I didn't design the script language, so I can't change that).

  ----- Original Message ----- 
  From: Indhu Bharathi 
  To: 'Avid Trober' ; antlr-interest at antlr.org 
  Sent: Wednesday, June 10, 2009 10:59 PM
  Subject: RE: [antlr-interest] Excluding keywords


  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/20090613/bb7ae5a9/attachment.html 


More information about the antlr-interest mailing list