[antlr-interest] Matching keywords in the lexer

Peggy Fieland madcapmaggie at yahoo.com
Thu Aug 10 08:10:40 PDT 2006


I did it in the parser.  For example, you might
specify:

ident: ID | INCLUDE;



--- "Zheng, Xiaoran" <xzheng at doubleclick.net> wrote:

>  I defined this in my lexer to distinguish between
> the keyword "include"
> with other identifiers.
> 
>      protected
>      ID options{testLiterals=true;/*I have other
> keywords defined in the
> parser*/}
>               :
>
('_'|'a'..'z'|'A'..'Z')('_'|'a'..'z'|'A'..'Z'|'0'..'9')*
>               ;
>      protected
>      INCLUDE  : ("include" STRING SEMI) {/*I will
> add the code to deal
> w/ this later*/}
>               ;
>      ID_OR_INCLUDE 
>               : (ID)=>ID  {$setType(ID);}
>               | INCLUDE                          
> 		  ;
> 
>  Is this correct? If so, it doesn't seem to work.
> What am I doing wrong?
> 
>  Any help would be greatly appreciated. Thanks.
> 
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf
> Of Zheng, Xiaoran
> Sent: Wednesday, August 09, 2006 4:46 PM
> To: Antlr Interest
> Subject: [antlr-interest] Matching keywords in the
> lexer
> 
>  
> Hi, I am still working on the problem of nested
> include files.
> 
> I am trying to match "keyword filename;", keyword
> clashes with the
> identifier rule. Is there anyway for me to resolve
> this in the lexer and
> do a "keyword filename;" match?
> 
> Thanks.
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf
> Of Zheng, Xiaoran
> Sent: Wednesday, August 09, 2006 4:32 PM
> To: Antlr Interest
> Subject: RE: [antlr-interest]
> java.util.NoSuchElementException
> 
>  
> The exception is thrown from "uponEOF" which I
> defined in the lexer.
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf
> Of Terence Parr
> Sent: Wednesday, August 09, 2006 4:29 PM
> To: Antlr Interest
> Subject: Re: [antlr-interest]
> java.util.NoSuchElementException
> 
> 
> On Aug 9, 2006, at 1:22 PM, Zheng, Xiaoran wrote:
> 
> > When I have a grammar defined as follows:
> >
> > A : B*C*
> > B : ...
> > C : ...
> >
> > why do I get an NoSuchElementException?
> 
> what version?  you missing a semicolon?  A complete
> grammar please.
> Ter
> 



More information about the antlr-interest mailing list