[antlr-interest] Custom ast factory

Paul Johnson gt54-antlr at cyconix.com
Mon Oct 24 01:22:31 PDT 2005


Jim Crafton wrote:
> I am trying to get my custom ast factory to work as the creator of new
> AST nodes. However I don't see how to make this happen. I do the
> following in my constructor :
> 
> 
> CppASTNodeFactory() :
> ASTFactory("CppASTNodeFactory",CppASTNode::factory),
> nodeFactory(&CppASTNode::factory) {}
> 
>>From tracing the code, what this means is that the "factory" method
> for creating node is actually the  CppASTNode::factory, which is a
> static method. Is there a way to get the parser to call a member
> method on the ast factory that I can then override in my custom ast
> class?

I don't use the parser, but this should (?!) work:

1) subclass AST

2) include a factory method in your new class

3) Your factory method is now automatically registered by 
'initializeASTFactory', without the need to subclass ASTFactory

Paul



More information about the antlr-interest mailing list