[antlr-interest] about parse key words

David-Sarah Hopwood david-sarah at jacaranda.org
Fri Nov 6 12:21:49 PST 2009

Renee Luo wrote:
> Hi there,
> I have a problem with parse key words.  Like in PL/SQL "EXIT"  is key word.
> But some variable names also include this key word.

This is quite a common requirement. The approach I use is to declare a
keyword rule that has all keyword tokens as alternatives, and then make
the identifier rule explicitly allow either a keyword or a

  BEGIN   : 'BEGIN' ;
  keyword : DECLARE | BEGIN | ... ;

  NonKeywordIdentifier : IdentifierStart IdentifierContinue* ;

  identifier : NonKeywordIdentifier | keyword ;

Note that this may result in grammar ambiguities unless the language has
been very carefully designed to avoid them. Some of these ambiguities might
have to be resolved using predicates.

David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091106/baac4119/attachment.bin 

More information about the antlr-interest mailing list