[antlr-interest] summary of trip to Montreal/SableCC land

Alexey Demakov demakov at ispras.ru
Mon Nov 15 09:07:55 PST 2004


From: "Terence Parr" <parrt at cs.usfca.edu>
> On Nov 15, 2004, at 7:09 AM, Alexey Demakov wrote:
> > From: "Terence Parr" <parrt at cs.usfca.edu>
> >> ... As for
> >> tree construction, he builds trees that are "type safe"; that is, they
> >> conform to a particular structure specified in a "tree grammar"
> >> section.
> >
> > 561 generated files in 'node' package for Java 1.1 and
> > 409 for Simple C - imho, trees generated by SableCC are not very handy.
> 
> Yep, I don't like the visitor mechanism as I discussed with Etienne 
> and, like jjtree for javacc, I don't like generating a class per node.  
> That is pretty gross.  

Manually developed Java tree has about 150 nodes. I think it is about equivalent
to tree grammar size for ANTLR. So, I don't like implementation, not the idea itself.
Bad implementation can kill any idea :)

> First, people are so in love with objects that 
> EVERYTHING must be a class.  It's amazing we got any work done before 
> oo, right? ;)

Personally, I think that in Java vs C battle automatic memory management  
is more important than objects :)

> Also, when doing translations, it is the tree structure 
> that is important.  

Agree. So, let's specify it! :)

> Occasionally, you need special info at particular 
> nodes, but this is really just a set of attributes (mitchell is saying 
> this should be a dynamic list like HashMap or something).  You do NOT 

Yes, there should be possible to specify additional attributes for particalar node,
and should be possible to have dynamic attributes because we don't know beforehand
what users of tree structure want. 

> need to make this a separate object type just to access an overridden 
> method like "action()" because it is the action location in the grammar 

The main reason to have separate class for each node is reliability.
With type checking you can be sure that every tree that can be constructed
corresponds to syntactically correct input program.
After all, tree can be constructed not only by parser, but from XML serialization or
from another tree after some transformation. In this case we will notice
corrupted tree only at run-time.

> that gives you the proper "event trigger".  It has context (where it 
> lives in a rule) and you can have actions communicate easily whereas 
> visitor actions are like "incommunicato islands".  This is why Etienne 

You have access to children and parent of node that is parameter of visitor action.
What else do you need? Do you mean that it is not easy to locate node
within parent's children? But I don't remember such situation in real life.
In any case, context information can be passed through fields of visitor.
It solves the problem.

> particularly liked my dynamically-scoped attributes thingy (although I 
> think I need to give Gary Funck credit; he asked for these back in my 
> SORCERER days a decade ago--i think he has trouble remembering if he 
> invented them).  Visitors find it VERY difficult to pass in context; 
> can't use parameters, right?  You'd have to make each action method 
> have the combined set of parameters you need to pass.

In fact, I don't think that visitor is the best solution.
Recall the meaning of visitor pattern - to have virtual methods for tree nodes
without modification of node classes. There is another solution for this problem
- AOP-like powerful generation technics that allow to generate what you need
from clear description.

Clear description is important - how to reveal tree structure to team developers?

> Anyway, I should really flesh all this out in an article--and describe 
> why you need tree grammars more to get people using them.  First, I 
> suppose I need to get a less buggy tree parser going ;)

Worth to read :)

Btw, I begin to understand that separate tree description is closer to ANTLR
tree parsers than I thought before...
But what if I need more that one pass over tree - should I repeat tree grammar
in each tree walker? I don't like to have same info more than in one place.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list