[antlr-interest] heterogeneous AST nodes and AST factory problem

Terence Parr parrt at jguru.com
Sun Nov 17 13:29:55 PST 2002


Uh oh...Houston we have a problem...

So, with the heterogeneous trees, you can say:

       tokens {
          PLUS<AST=PLUSNode>;
          ...
         }

and I'm supposed to notify the factory how to build PLUS tree nodes.  
No problem--I can do this in the generated parser's constructor with:

astFactory.setTokenTypeASTNodeType(PLUS, "PLUSNode");
...

where...

	/** Specify an "override" on the Java object created for a
	 *  specific token.
	 *  @since 2.7.2
	 */
	public void setTokenTypeASTNodeType(int tokenType, String className) 
{...}

The problem is, you can't set the AST factory until after the 
constructor executes:

JavaParser p = new JavaParser(lexer);
p.setASTFactory(...);

So, the default factory gets the setTokenTypeASTNodeType() and not your 
new factory.

Should I generate a new constructor for each parser that lets you 
specify the ast factory?  Ick!  But otherwise you are stuck with the 
dfault factory.

Thoughts?

Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list