[antlr-interest] Error handling using parallel instances of a C-target parser

Johannes Goller jogojapan at gmail.com
Sun May 9 23:04:45 PDT 2010


Hello,

I am working with a C-target parser, and I have multiple instances of the
parser running in parallel.

Now I would like to stop the parser from printing error messages to stderr.
Instead, I would like each instance of the parser to collect
the error messages in a list of strings, so that the caller can access the
complete list of error messages after the parser finished
and decide what to do about them.

>From an example I found here:
http://groups.google.com/group/il-antlr-interest/browse_thread/thread/80ec25032e9af7a8?pli=1
I understand how members of the parser instance can be defined using
@parser::context and @parser::apifuncs, and that works
very well. So, let's say I defined a member

   error_list_t   *error_list

which points to some kind of dynamic list structure, and assume there is a
global function

  add_to_error_list(error_list_t *, const char* msg)

which can be used to add a new message to the list.

Now I wonder how can the error handling methods of ANTLR be modified to add
error messages to the list rather than printing them to stderr.

Looking at various sources on the internet, it seems there is a function
emitErrorMessage() which is called whenever an error occurs.
Taking that as a starting point, I have the following questions:

(1) Is that the right function to override? Or is there a better one?
(2) How exactly do I have to specifiy the override in the ANTLR grammar?
(3) How can I access the current instance of the parser from inside the
error handling function?
Remember that error_list must be a member of the parser, rather than a
global object, because I have several parsers operating in parallel.

Many thanks for any help.

johannes.


More information about the antlr-interest mailing list