[antlr-interest] Re: AST factory / heterogeneous tree enhancement

micheal_jor open.zone at virgin.net
Tue Oct 22 08:44:25 PDT 2002


> That works now (2.7.1), except for tokens created by #[ ... ]

OK. Just ignore the warnings right?  ;-)

> > > 2. dup methods of ASTFactory don't respect the type of the 
nodes; 

<SNIP>

> > The dup() methods ultimately call the factory's create() method. 
> Once 
> > the factory is able to create the right nodes based on it's type, 
> the 
> > dup() methods should just work. At least that was the experience 
> with 
> > C#.
> 
> No, I had to fix that for adding tree construction syntax, and Ter 
is 
> adopting my fix.  dupXX() should duplicate the AST node(s) exactly, 
> not be created according to token type.  That fits with the
> capability 
> of specifying class when creating a token.

Duh!. I overlooked the implications of the "local override" features 
despite waxing lyrical about them (and Kunle reminding me about 
this). Yep, we need to CreateInstance() based on the type of the 
actual node objects.

> Hmm--Ter, there needs to be a policy for AST node typing during 
tree 
> transformations.  Should tree walkers have their own type tables, 
and 
> default to duplicating nodes unless there is a type/class mapping?  
> Then AST node information is preserved unless the AST type is 
> overridden.

<whisper>
I still haven't got to grips with tree walkers yet :-(
</whisper>

> > > 3. hetero tree construction does not call the factory.  E.g.,
> > > 
> > >      anIntRule : INT<AST=INTNode> ;
> > > 
> > >      generates
> > > 
> > >      INTNode v = new INTNode(LT(1));
> > > 
> > >      but we need to instead generate:
> > > 
> > >      AST v = (AST)astFactory.create(LT(1),"INTNode");
> > > 
> > >      where the create(...) method is new and specifies the type 
to
> > >      create.  This will use newInstance() instead of "new" by 
> > >      default.
> > > 
> > 
> > This contradicts the "Heterogeneous AST" section of the reference 
> > manual which states that "ANTLR uses the factory to create nodes
> for 
> > which it does not know the specific type". 
> > 
> > My opinion is that ANTLR should always use the ASTFactory except
> for 
> > (1) the new extended AST construction syntax and (2) the 
> per-tokenRef 
> 
> Actually, Ter cleverly turns #[ XXX ] into factory.create( XXX ).

I saw that. I guess explicitly teling the factory what to create is 
probably better than bypassing the factory all together. It certainly 
leads to more consistent create() syntax and one less "hack" to worry 
about.


Cheers,

Micheal


 

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



More information about the antlr-interest mailing list