Jim Idle wrote:
Adamic Tomislav wrote:
  
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?
  
    
I suspect that this is because of your grammar and nothing to do with 
the recognition error override. Fix your lexer/parser and you will get 
an error. For instance, do you have an EOF terminating the grammar rule 
you are calling? If not then ANTLR will just not recognize a token in 
error at certain points and stop. If you do have the EOF, then you must 
have some sequence that allows numbers, and either unrecognized tokens 
are coming through on a different channel or are being thrown out by the 
lexer and you are not ignoring 
That should have read "and you are ignoring lexer errors"- sorry.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to