[antlr-interest] Tree walker exception handling

Cameron Esfahani dirty at apple.com
Tue May 22 17:25:23 PDT 2007


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

"There are times in the life of a nation when the only place a decent  
man can find himself is in prison."



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070522/4846e2fa/attachment-0001.html 


More information about the antlr-interest mailing list