[antlr-interest] When does AST construction go through factory?

Daniel Gackle gackle at shaw.ca
Thu Jan 16 22:18:19 PST 2003


Apologies if this has been discussed before.  I know there was a thread on
this a couple of months ago, but I can't find answers to my questions in the
archives.  I'm seeing different behavior with heterogeneous AST creation.
Sometimes the AST factory gets called and sometimes it doesn't.  For
example, suppose IDENT is a lexer token whereas TYPE is an imaginary token
used in an action statement like ## = #(#[TYPE,"TYPE"], ##).  I map each of
them to a specific AST type:

tokens {
	IDENT<AST=MyIdentifierNode>;
	TYPE<AST=MyTypeNode>;
}

What I'm seeing is that in one case the AST is created via the AST factory:

astFactory.create(TYPE,"TYPE")

while in the other it is not:

tmp277_AST = new MyIdentifierNode(LT(1));

This seems to be foiling my attempts to intercept the creation of each AST
node by means of a customized AST factory.  My questions are:

(1) When exactly does the AST factory get used, and when does new get used
instead? (Does it have to do with lexer tokens vs. imaginary tokens, or is
there some other criterion?)
(2) Is this the desired behavior?  If so, why?
(3) Any suggestions on a workaround that would allow me to "get at" the AST
construction of those non-factory nodes?

Many thanks,
Daniel


 

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



More information about the antlr-interest mailing list