[antlr-interest] tree parsing error messages

Terence Parr parrt at cs.usfca.edu
Tue Jan 4 13:42:30 PST 2005


On Jan 4, 2005, at 12:43 PM, Joshua Davis wrote:

> I noticed that synthetic tokens don't produce nice line numbers, if 
> it's
> a simple change that sounds like a good idea.

Hi.  I spoke too soon.  The default implementation of BaseAST and even 
CommonAST are too stupid in current ANTLR.  For example, no setLine() 
method on AST and I don't want to break backward compatibility to add 
it to the interface.  Argh!!!!

In my trees, I carry the token object around as a payload.  Then my 
getLine() override is simply:

     public int getLine() {
		int line=0;
         if ( token!=null ) {
             line = token.getLine();
         }
		if ( line==0 ) {
			AST child = getFirstChild();
			if ( child!=null ) {
				line = child.getLine();
			}
		}
         return line;
     }

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





More information about the antlr-interest mailing list