If you download the source code to the Java FX compiler you will have a
complete example to work from, assuming a Java target. Start by creating a
superclass for the parser and overriding various error reporting points.
The JavaFX compiler will show you how to do that.

Jim

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Stephen McGruer
> Sent: Friday, February 04, 2011 4:14 PM
> To: [email protected]
> Subject: [antlr-interest] Correct way to handle custom errors?
>
> I was wondering what the "correct" way to handle custom errors in ANTLR
> 3 was. I'm implementing a parser/lexer for a small subset of C, and
> want to give better error messages than the general mismatched tokens
> error.
>
>  From this post -
> http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery I
> implemented my own error reporting class which grabs the recognition
> exception from the Parser. However, I'm then unsure about the best
> approach is to start recognising errors - from things as basic as
> replacing the name of my variable name rule (ID) with a more user-
> friendly term such as "identifier", to more complex things such as
> giving nice error messages when the user attempts to set a variable to
> a value that isn't an integer or character (the only two allowable
> types in my subset). The recognition exception doesn't seem to be too
> useful - getMessage() seems to return null.
> I assume that the getErrorHeader and getErrorMessage methods do
> something different to get information. The only way I can think of
> checking for errors at the moment is manually scraping the strings
> returned by these methods, which seems... clumsy.
>
> So, is there a sort of "normal" or "usual" method to approaching
> parser/lexer error message handling when doing programming language
> parsing?
>
> I hope the above contained enough information, and made sense.
>
> Thanks,
> Stephen
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

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

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

Reply via email to