[antlr-interest] TreeDL news: tutorial, new releases, mailing lists

Alexey Demakov demakov at ispras.ru
Thu Oct 28 04:29:45 PDT 2004


Hi Michail

>   I find this TreeDL system quite interesting.  It is closer to the way
> I think than the typical homogeneous ASTs in ANTLR.  However, I see a
> couple of issues when comparing it to things I've done:
> 
> 1) I notice that you do not utilize Generic collections (ala Java 1.5).
> Is this something you are considering adding?  It would be a nice touch.

I plan to implement translation to C# and Java 1.5 as fast as I can.

> 2) Your visitor pattern include "visitXYZ" methods.  I've found that for
> many structures an "enterXYZ" and "leaveXYZ" pattern is more suitable.
> In fact, one might argue that anything that has children would probably
> benefit from the "enter-leave" pattern (also found in SableCC if I'm not
> mistaken).  It doesn't matter for things like evaluation, but if you
> want to output HTML (for example), it is nice.

Automatic tree traversing is not provided because there is no way to suit all tasks.
As you can see in interpreter visitor (step 5) I call visit methods for children explicitly (through accept() of course).
However, code generation library allows to visit children referenced in patterns:

public void visitBinaryExpr( BinaryExpr node )
{
    txt( "${left} ${Sign:sign} ${right}" );
}

Results of visit method for left and right children will be substituted automatically.

May be it is good idea to have a library of tree walker generators for particular  cases.
Such functionality can be added very easy, but I'm not sure which ones really needed.
TreeDL tool can be extended by plugins, tree structure is open (it is described in TreeDL of course ;) )
Existing plugins can be used as examples - so may be tree walker will be contributed
before I'll find time to implement them :)

> 3) I could not tell from the documentation but it seems that (at least
> for children), you implement get methods.  Do you also implement set
> methods?  Finally, are attributes handled similarly?  I like the
> attributed tree idea, but I'd like some control over the get/set methods
> (to allow for things like cache invalidation, for example).

Translation scheme is described in TreeDL tool description http://treedl.sourceforge.net/treedl/treedl_tool_en.html
Yes, get/set methods are generated for all children and attributes.
set-methods also contain some checks to ensure correctness of tree. For example, for lists with one or more elements
list size is checked, != null is checked for all non-optional members of reference type.

As described in TreeDL language description http://treedl.sourceforge.net/treedl/treedl_en.html
you can insert additional code to get/set methods:

attribute <int> arrayIndex
get
{
    Logger.log( "getArrayIndex() returns " + arrayIndex );
}
set
{
    if( arrayIndex < 0 || arrayIndex >= array.length )
    {
        throw new IndexOutOfBoundsException( "arrayIndex = " + arrayIndex );
    }
};

Moreover, you can define your own way to store attribute value:

body
{
    int x;
    int y;
} 

attribute custom <Position> position
get
{
    position = new Position( x, y );
}
set
{
    x = position.getX();
    y = position.getY();
};

Also you can see at Calc.java generated from Calc.tdl
Calc.java http://treedl.sourceforge.net/examples/calc/treedl/com/unitesk/atp/examples/calc/Calc.tdl-xref/index.html
Calc.tdl http://treedl.sourceforge.net/examples/calc/xref/com/unitesk/atp/examples/calc/Calc.html
And TDL.java generated from TreeDL.tdl
TreeDL.tdl http://treedl.sourceforge.net/treedl/treedl/com/unitesk/atp/treedl/TreeDL.tdl-xref/index.html
TDL.java http://treedl.sourceforge.net/treedl/xref/com/unitesk/atp/treedl/TDL.html

> 4) I didn't see this explicitly stated in your calc example, but is the
> interface for the visitor generated automatically?  If so, that is a
> very nice touch.

Yes, visitor interface is generated automatically, it is at the end of Calc.java

> 5) It isn't clear what the purpose of the "Syntax Grammar" section is.
> How is this used?  It seems like the tree definition + ANTLR grammar is
> pretty complete.  I don't see what the .bnf file is needed for.

As I mentioned in one of previos messages, we have BNF tool that generates syntax tests
from .bnf file. But primary usage of this file is documentation - it is useful if language design
and parser implementation are done by different persons.

> 6) Your tree directive seems to be used to indicate what package the
> eventual definitions will be included in.  Why not use the word
> "package" instead of "tree".  To me, "tree" implies it has something to
> do with the data structures themselves rather than just their location
> in the package hierarchy.

TreeDL tries to be as language independent as possible. So "package" is not good from my point of view.
In fact it should be not "tree" but "tree desription" but it is much longer :(

> Items #1-4 represent differences between TreeDL and the way I have been
> approaching things.  I would be very interested in seeing how these
> particular aspects of TreeDL evolve because I prefer your high-level
> approach (so long as it includes the functionality I need).

It seems to me that TreeDL already have almost all you want (except tree walkers may be) :)

> Looks very interesting.  Please keep us posted.

Thanks Michael,
Glad to answer any questions.

Regards,
Alexey

> 
> --
> Mike
> 
> > -----Original Message-----
> > From: Alexey Demakov [mailto:demakov at ispras.ru]
> > Sent: Wednesday, October 27, 2004 10:54 AM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] TreeDL news: tutorial, new releases, mailing
> > lists
> > 
> > 
> > Hi all,
> > 
> > For those of you who is interested in TreeDL (announced some time ago
> in
> > this list),
> > I have good news :)
> > 
> > TreeDL (Tree Description Language) is a notation for description
> > of formal text internal representation (such as abstract syntax tree).
> > 
> > 1. Step-by-step tutorial on TreeDL is available: How to create tool
> that
> > process simple language for calculator.
> > http://treedl.sourceforge.net/examples/calc/
> > 
> > 2. Mail lists for users and developers are available:
> > http://sourceforge.net/mail/?group_id=120633
> > If you are interested in TreeDL, please, subscribe, I really need your
> > feedback.
> > All further TreeDL discussion will be in these lists.
> > 
> > 3. New releases can be downloaded from project page
> > http://sourceforge.net/projects/treedl/
> > treedl-1.0-rc2
> > atplib-3.0-rc2
> > maven-atp-plugin-rc2
> > maven-treedl-plugin-rc3
> > 
> > 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