[antlr-interest] Translators Should Use Tree Grammars

Alexey Demakov demakov at ispras.ru
Wed Nov 17 00:55:18 PST 2004


From: "Terence Parr" <parrt at cs.usfca.edu>
> On Nov 16, 2004, at 9:19 AM, Alexey Demakov wrote:
> > From: "Terence Parr" <parrt at cs.usfca.edu>
> >> Ok, whew!  8 furiously written pages on visitors, tree node classes,
> >> tree grammars, and action execution:
> >>
> >> http://www.antlr.org/article/1100569809276/use.tree.grammars.tml
> >>
> >> Hopefully, this is clearly written.  Regardless, it summarizes my
> >> position rather thoroughly. ;)  Please send me feedback if you think
> >> the article can be improved etc...
> >
> > Ok, I'll try to be advocate of hetero-trees. :)
> 
> Using tree grammars has nothing to do with hetero vs homo trees.  i can 

Agree. I consider to add option to generated implementation of AST node interface :)

> parse both.  Hetero trees are only useful for when you want to 
> manipulate them manually.

Yes, but there are other applications of tree description.

> >  When tree structure is well-designed,
> > you can not create tree that doesn't correspond to syntactically 
> > correct input program.
> 
> Yes, that is nice (assuming the type system is up to it...only OO 
> languages can get close).

Almost all functionality of modern OO languages (Java, C#) can be simulated
even in C :) It affects only amount of generated code.
I have experience of translation from RSL specification language
to C-like language - had to translate high-level abstract data types
and to implement garbage collection.

> You must write code in a visitor to go to the children.  We use 
> patterns (i.e., rule references) in antlr to do that.  Naturally we 
> could use actions to go to the children manually ala visitors ;)

But you can't use children names until they are referenced in rule?

> > No, I'm looking at single file with tree description. :)
> 
> That is true.  Do you ever look at the generated classes though?  You 
> talk about manually setting/getting/building etc...  If you never look 
> at the output, all is well and i'll change the article ;)

Yes, tree description is the only source I use. It's easy to mentally 
translate children names to get/set method names :)

> >> You cannot list the expression tree types; one must find all 
> >> subclasses of ExprNode.
> >
> > HTML documentation can be generated from TreeDL tree description
> > with cross-references between node type and all inherited node types.
> 
> Yes, but what you have is not a grammar unless it explicitly shows the 
> possible subtrees.  Why use implicit rather than explicit 
> specification.  

Yes, it's not grammar. But I have all usual OOP bonuses - tree description
can be extended.  :)

> You are so close to a grammar!  I think the summary is 
> that you generate types and I generate methods and I allow actions in 
> the grammar rather than visitors. ;)

Yes, I think tree grammars should be supported by TreeDL :)
But ways to process trees will not restricted to it :)

> > But I believe TreeDL is more readable (especially
> > for newbies) than ANTLR tree grammar (without actions, but with labels 
> > for subrules).
> 
> Perhaps as they are more familiar with fields than grammars.

I watch your ideas since PCCTS and have to say that they are great
but sometimes requires time to understand :)

> >> it is completely self-contained
> >
> > The same is true for TreeDL tree description.
> 
> Minus the fact that stmt node does not list the statements, I might 
> agree. ;)

Consider tree description as a whole :)

> > visit() methods are grouped by node, like methods. And children can be 
> > referenced using $childName
> > shorthand notation because I hate Java long getChildName() and like C# 
> > properties.
> 
> That is good and is equiv to grammars + actions, right? :)

Yep :)

> > May be now it is time to remember this tool and rethink what should be 

remember -> recall

> > a source
> > and what should be generated. I'm inspired by tree grammars :)
> 
> Hooray!  Soon we will agree completely minus what the generated code 
> looks like :)

I hope :) As I skip parts of message where we've reached consensus,
this message is much shorter :)

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