[antlr-interest] C Runtime Error Handling Problems

Bot Tiger bottiger1 at gmail.com
Wed Jan 28 00:21:36 PST 2009


Hello ANTLR community,

I have been testing out the error reporting capabilities of the C runtime
and have run into some difficulties trying to get a Line Number.


Using the calculator example from the 5 minute intro to ANTLR, I have tried
to use the default error handler.
However, upon trying to detect an EOF token, it segfaults, so I have
attempted to override the default error handlers at

pParser->rec->reportError
pParser->rec->recover

pLexer->rec->reportError
pLexer->rec->recover


Entering an incomplete expression such as "1+2+" results in an error of
ANTLR3_EARLY_EXIT_EXCEPTION.

Unfortunately, in antlr3baserecognizer.c, all it does is:
ANTLR3_FPRINTF(stderr, " : missing elements...\n");

All my attempts to get a string offset from anywhere have failed.

Here are a list of my attempts and why it fails.

========================================
recognizer->state->exception->charPositionInLine
--- returns -1

theToken    = (pANTLR3_COMMON_TOKEN)(recognizer->state->exception->token);
ttext        = theToken->toString(theToken);
--- returns a gibberish string

theToken->getCharPositionInLine(theToken);
--- also returns -1

recognizer->state->tokenNames[exception->expecting]
--- exception->expecting is always 0, and the string returned is always
"<invalid>"


recognizer->state->tokenStartLine
--- always returns 0

recognizer->state->tokenStartCharPositionInLine
--- always returns 0

recognizer->state->tokenStartCharIndex
--- always returns 0


(pANTLR3_COMMON_TOKEN)exception->token->....
--- same problems as tokens above

recognizer->state->token->....
--- same problem as tokens above

(pANTLR3_COMMON_TOKEN)recognizer->getCurrentInputSymbol(recognizer,
parser->tstream->istream)
--- same problems as the tokens above



As you can see I've exhausted almost every combination I can think of, and I
am just wondering if none of the offset indexes are implemented.

Please send any information on how to get a string offset for either an
expected token location or the last scanned token.

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090128/dd161eb5/attachment.html 


More information about the antlr-interest mailing list