[antlr-interest] newbie question about nondeterminism between keywords and identifiers

David Holroyd dave at badgers-in-foil.co.uk
Fri Feb 2 00:59:48 PST 2007


On Thu, Feb 01, 2007 at 08:58:22AM -0800, David Guy wrote:
> I have a typical lexer IDENT rule:
> IDENT
> options {testLiterals=true;}
>    : ('_'|'a'..'z')('_'|'a'..'z'|'0'..'9')*
>   ;
> 
> The language has some built in types. For example (from lexer):
> TYPE_DATE   :"date";
> // declares type
> COLON        : ':';
> 
> In my parser, if I have a rule like:
> decl:
> IDENT COLON TYPE_DATE
> ;
> 
> I cannot parse "mydate : date" or "date_foo : date". The first example
> gets IDENT than unexpected TYPE_DATE and the second case gets unexpected
> TYPE_DATE. 

I'm not sure what's up, but,

- Is the IDENT lexer rule defined after all the keyword rules?  IIRC,
  order is important.

- Does 'date' really need to be a keyword (i.e. it's not allowed as an
  identifier, or will drive some other part of the grammar)?


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list