[antlr-interest] Non-reserved keyword as identifier question
trunkel at gmail.com
Fri Aug 31 09:03:46 PDT 2007
I'm working on a MS-SQL grammar and I've run into a problem with
keywords/identifiers that I'm hoping somebody in the ANTLR collective
can help me resolve.
MS-SQL maintains a list of reserved keywords than can't be used as
identifiers unless they're delimited. In the following grammar 'NAME'
is a keyword, but not a reserved keyword, so it can be used as an
identifier. If I try to parse a statement like 'SELECT Name FROM
Customers' it will fail because the lexer will return 'Name' as a
distinct token, not the Identifier token.
I could create an identifier parser rule which includes the Identifier
token as well as every keyword in the grammar, but I think that would
be a long list of keywords. Is there another way to handle this
language = C;
backtrack = true;
( sql_statement (';')? )+ ;
'ALTER' 'ROLE' Identifier 'WITH' 'NAME' '=' Identifier
'SELECT' Identifier 'FROM' Identifier
// LEXER rules
More information about the antlr-interest