[antlr-interest] C runtime and parser error reporting confusion

Adamic Tomislav tomislav.adamic at gmail.com
Mon Aug 10 15:09:04 PDT 2009


Hi everybody...

I'm trying to override displayRecognitionError in C runtime for my
parser grammar. In my combined parser and lexer grammar file I have
following:

@parser::apifuncs {
	RECOGNIZER->displayRecognitionError = myDisplayRecognitionError;
}

In my code I have the implementation of myDisplayRecognitionError
which currently doesn't do anything smart except that it notifies me
it has been run:

.h file:

#ifdef __cplusplus
extern "C" {
#endif

//...
void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,
pANTLR3_UINT8 * tokenNames);
//...

#ifdef __cplusplus
}
#endif

.c file (compiled as C++):

#include <stdexcept>
//...
void myDisplayRecognitionError (pANTLR3_BASE_RECOGNIZER recognizer,
pANTLR3_UINT8 * tokenNames) {
    // Just a notification for now...
    throw std::logic_error();
}
//...

Now, I have two test strings for my parser. Both should triger
myDisplayRecognitionError. First one "somethingsomething" actually
does. Second one being "something2something" passes without triggering
myDisplayRecognitionError and gets parsed as "2" beacause my grammar
recognizes numbers. This is not what I want, the second one should
trigger error also. Things marked here as "something" can be anything
that is not defined by my grammar. I've been searching through
mailinglist archives but I just can't figure it out... What am I doing
wrong?


More information about the antlr-interest mailing list