[antlr-interest] Comments and questions on a recent project

mzukowski at yci.com mzukowski at yci.com
Mon Aug 26 08:19:28 PDT 2002


> Sorry, I wasn't clear about that.  The "class_definition" 
> rule is used in
> other places.  I suppose I could move the imaginary node 
> creation up one
> level.  The drawback would be that I would end up creating 
> DEFINITION nodes
> in several places rather than just one.  Is there a way to 
> add a child to an
> existing node?!?  I wasn't able to get this out of the tree 
> construction
> documentation.  In other words, isn't there an easy way to do 
> this in a
> language neutral way:
> 
> stored_definition
>   : (fn:"final")? cd:class_definition
>     { #cd->addChild(#fn); }
> 

Yes:

{#cd=#[#cd,#fn];}


> > Typically I build tables to handle this sort of thing.  Just 
> > about anything
> > that can be in an AST can be in a table with the node as a 
> > key and then a
> > value of whatever.
> 
> An excellent suggestion.  This way I can create a tables on 
> an application
> specific basis.  Thanks!
> 
> > I'll comment upon the rest, hopefully at lunchtime.
> > 
> > Monty
> 
> Here is one more question (although your "table" suggestion might work
> well).  How to establish "parent" relationships?  Is there 
> any facility for
> finding parent nodes?
> 

No, that is something you would want to handle in your AST.  Have a look at
the TNode class in the GCC tranlation framework
www.codetransform.com/gcc.html.  (Specifically
http://www.antlr.org/grammars/cgram/grammars/TNode.java if you just want the
one class.)

Basically it is an AST class with a notion of a parent (also it has its own
table for extra per node information--another way you could go for your
extra info).   Should be trivial to port to C++.  The key is that once
you've built the tree you have to call doubleLink() to set it up after the
tree is built.  That's easier than maintaining it as you build.

Monty

 

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



More information about the antlr-interest mailing list