[antlr-interest] Error reporting with the C runtime: tokenNames

Ned Gill thomas.gill at csr.com
Tue May 19 01:23:21 PDT 2009


Hi list.

I'm writing a custom displayRecognitionError for my parser, based heavily  
on the default in antlr3baserecognizer.c.  For reporting the names of  
tokens, I'm using the tokenNames array passed in for messages such as "...  
Missing ']'".  However, for named tokens (e.g. those created in the tokens  
{ ... } stanza), tokenNames contains er.. the name of the token.  So for  
example, I'm using the names RPAREN for the token ')', and I see messages  
like "... Missing RPAREN."  Unfortunately these names aren't going to make  
any sense for users.

I understand why tokenNames is the way it is (named tokens could be more  
compilcated than a simple string).  However, is there a way that I can  
show the matching string for simple tokens rather than the name, (possibly  
limited to just those declared with "tokens {...}")?

I considered removing some or all of the simple named tokens, but this  
would be inconvenient as my grammar generates trees which re-use the same  
tokens.

I'm already maintaining my own version of C.stg for other reasons, so I  
could make changes to that if necessary.


Thanks,
Ned.



More information about the antlr-interest mailing list