[antlr-interest] Error reporting when using keywork in wrong place

Paulo J. Matos paulo at matos-sorge.com
Fri Dec 9 09:19:07 PST 2011


Hello,

I have a C generated antlr3 parser and I have a token 'z'.
It's perhaps an unfortunate name but a lot of users try to use z as a 
variable name and hit a message like:
Error: near 'z' : syntax error.

This most likely will leave them baffled at what is going on if they 
don't realize that 'z' is a keyword.

I have redefined displayParserRecognitionError but the only thing I get 
when this happens is an exception of type ANTLR3_RECOGNITION_EXCEPTION 
which contains little information about context. Any hints on how to 
provide a slightly better error message?

Something like:
Error: trying to use keyword 'z' where something else is expected.

This would already be better. However, the problem is identifying 'z' as 
a keyword.

Cheers,
-- 
PMatos



More information about the antlr-interest mailing list