[antlr-interest] Tree walker exception handling
Cameron Esfahani
dirty at apple.com
Fri May 25 13:07:27 PDT 2007
I know the questions are a bit open-ended, but does anyone have any
suggestions?
On May 22, 2007, at 5:25 PM, Cameron Esfahani wrote:
> I'm developing a language that supports assignment:
>
> foo = 125
> bar = foo + 1
>
> Obviously, I need to create a symbol table to hold all of the
> assignment operations, and then validate all symbols against that
> table.
>
> From what I can tell, I should be doing this in a tree walker
> pass. The problem I'm having is, what do I do when I find a
> logical versus syntactical error? For example, when the user
> erroneously supplies a symbol that doesn't exist?
>
> Right now, I'm just throwing a RecognitionException from within the
> relevant tree walker rule, and I have a @rulecatch which grabs this:
>
> @rulecatch {
> catch ( RecognitionException e ) {
> System.exit( 0 );
> }
> }
>
> I call System.exit() because I don't want the exception stack frame
> printing out. It would scare my users.
>
> In the handler, I want to print out some useful information, like
> the name and line number of the undefined symbol. Can I still get
> this lexer information from a tree walker?
>
> Is it appropriate to use the RecognitionException for these kind of
> logical errors? I'm almost wondering if I should create my own
> class of errors and then throw them as appropriate.
>
Cameron Esfahani
dirty at apple.com
"Americans are very skilled at creating a custom meaning from
something that's mass-produced."
Ann Powers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070525/9019d758/attachment.html
More information about the antlr-interest
mailing list