[antlr-interest] implemented your suggestion for AST factory
Terence Parr
parrt at jguru.com
Sat Dec 14 12:51:46 PST 2002
Loring,
Re: hetero tree mapping (Java mode)...
I have altered the Java code generator so that it generates a call to a
new ASTFactory(Hashtable) ctor. The generated parser has this:
protected void buildTokenTypeASTClassMap() {
tokenTypeToASTClassMap = new Hashtable();
tokenTypeToASTClassMap.put(new Integer(ID),
IDNode.class);
...
};
then does this in the parser ctor:
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
The TreeParser stuff I left alone as you can get the AST factory out of
the parser and set in the TreeParser manually upon its creation if you
are doing tree transforms. I don't want
duplicate-possibly-slightly-different copies of the mapping running
around.
All seems backward compatible. The Hashtable mapping is there for your
homegrown ASTFactory if you want it via Parser method:
/** If the user specifies a tokens{} section with heterogeneous
* AST node types, then ANTLR generates code to fill
* this mapping.
*/
public Hashtable getTokenTypeToASTClassMap() {
return tokenTypeToASTClassMap;
}
Oh, I fixed that problem where I was initializing a node during dup
from the text not the ast.
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