[antlr-interest] Parsing Identifiers

Terence Parr parrt at cs.usfca.edu
Tue Jun 13 15:57:09 PDT 2006


On Jun 13, 2006, at 3:38 PM, Pankaj Rao wrote:

> Hi All,
>
> I have encoutered this special case while writing my parser and I  
> am trying to figure out the cleanest way to handle this.
>
> What I am trying to do is be able to parse identifiers having  
> characters beyond alphabets and numbers , for example   "?name" or  
> "%name"
>
> My lexer rule for parsing identifiers is as follows:
>
> IDENT
>
>   :  ('a'..'z' | 'A'..'Z' | '_' | '$' ) ( ('a'..'z' | 'A'..'Z' |  
> '_' | '$' ) | ('0'..'9' ))*
>
>     ;
>  So I thought about modyfing my Identifier rule to look for '?'.
>
> IDENT
>
>   :  ('a'..'z' | 'A'..'Z' | '_' | '$'|'?' ) ( ('a'..'z' | 'A'..'Z'  
> | '_' | '$' | '?') | ('0'..'9' ))*
>
>     ;

My guess is that you also have a '?' rule, which is first and hence  
has priority :)

Ter


More information about the antlr-interest mailing list