[antlr-interest] Tree walker exception handling

Loring Craymer lgcraymer at yahoo.com
Fri May 25 13:21:07 PDT 2007


Take a look at Ter's ErrorManager.java in the tool
directory.  It has a lot of extraneous stuff (as far
as your application is concerned), but is not a bad
model for error accumulation and reporting.  Throwing
exceptions for semantic errors is not user-friendly: 
you really want to report back as many semantic
problems as the user can handle, not just the first
one.

--Loring

--- Cameron Esfahani <dirty at apple.com> wrote:

> 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
> 
> 
> 



       
____________________________________________________________________________________Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz


More information about the antlr-interest mailing list