[antlr-interest] trouble with ids and keywords

Gavin Lambert antlr at mirality.co.nz
Sat Feb 7 12:06:38 PST 2009


At 02:16 8/02/2009, Bob Marinier wrote:
 >The problem is that IDs in my system don't allow dashes, but 
some
 >keywords have dashes in them. So keywords with dashes don't get
 >recognized in the parser. But it seems to work if I put all of
 >the keywords with dashes in the lexer, and the ones without
 >dashes in the parser. Having the keywords list spread out over
 >two locations makes me cringe a bit, but maybe this is the
 >cleanest solution?

It might be.  Another option would be to accept the dashes in the 
lexer regardless and raise an error in the parser if they're used 
inappropriately (since it's better to have the parser raise errors 
than for the lexer to do so).  The downside of that, though, is 
that it becomes harder to recognise "a-b" (no spaces) as "a minus 
b".



More information about the antlr-interest mailing list