[antlr-interest] C Target: Reverse look up of tokens for error reporting
Peterson, Joe
joe.peterson at intel.com
Tue Nov 3 14:55:54 PST 2009
Hello all,
I am trying to generate more useful error messages when I get a file that doesn't match the grammar. One of the complaints is that because I named my tokens, the error messages look like this:
syntax error detected in file missing_semicolon.test at line number 6, position 5; expecting SEMICOLON
To me, this seems obvious, but my customers don't like the token names, they'd rather see:
syntax error detected in file fail_missing_colon.ext at line number 6, position 2; expecting ';'
I prefer to have the names, though. Is there an easy way for me to reverse the look up so the error can replace SEMICOLON with ';' (as well as all my other tokens, of course)?
I can get the NAME of the token with:
recognizer->state->tokenNames[recognizer->state->exception->expecting]
I can't seem to see how to get the text of that token, though.
Thanks,
-JEEP
Joe Peterson
More information about the antlr-interest
mailing list