[antlr-interest] [c target] raising exceptions for semantic errors
Aaron Leiby
aleiby.antlr at gmail.com
Thu Nov 4 23:15:59 PDT 2010
I must be searching for the wrong thing because I can't find any examples or
documentation on how to add custom errors in grammar actions.
For example, if you have a grammar with a symbol table, and want to report
errors when symbols are used before they are defined, what's the method for
doing that in the C target?
In Java I believe you just throw a RecognitionException, etc.
I see there's a macro for creating exceptions: CONSTRUCTEX
And I see a similar function for creating exceptions: antlr3ExceptionNew
Additionally, in the generated code there are labels for jumping to on
HASEXCEPTION(), so I'm guessing there is a mechanism for working with all of
that, but I have yet to find it in the documentation or in previous email
threads or on the web.
What I have found is numerous discussions regarding displayRecognitionError,
but I'm not interested in changing *how* the errors are reported (yet). I
just want to enforce semantic errors (stuff the grammar itself can't encode,
but will require checks like isSymbolDefined in grammar actions, etc.).
Thanks!
Aaron
More information about the antlr-interest
mailing list