[antlr-interest] Getting token source within tree walker?

Diehl, Matthew J matthew.j.diehl at intel.com
Wed Jul 18 20:22:15 PDT 2007


> I'm doing some input validation and error checking in my 
> parser.  I'd like to move it to my tree walker, but I'm 
> having some trouble: If I get an error, in addition to 
> printing out the line number, I need to print out the input 
> file name as well. 
> 
> From the parser, I can access the input stream associated 
> with a token, and get the file name from there.
> 

I just send in the file name into the tree (along with my reserved words
dictionary):

XXXWalker walker = new XXXWalker (nodes);
XXXWalker.design_top_return r2 =
walker.design_top(fileName,reservedWords);

and then access it by:
design_file[String fileName, Set rw]
scope {String fileName;}
@init {$design_file::fileName=fileName;}
  : stuff stuff
  ;

Matt


More information about the antlr-interest mailing list