Most of the uses of Antlr I have seen show temporary use of ASTs.  I
mean temporary here in that usually the AST is built, used and discarded
in a single step.

I have a particular usage where I am generating SQL statements and
really I could pre-build large chunks of the resulting SQL AST up-front.
First I am wondering how kosher this is.  Considering its not a pattern
I see discussed very often I am a little cautious.  The reason I
contemplate this approach even is because it would seem much more
efficient (seem because i think i would end up needing to clone the
pre-built AST fragments to insulate the master fragment from contextual
state changes).

If the general approach itself is sound, I wonder if anyone has taken on
such an approach and had any heads-ups or pointers.

As an example of what I mean, imagine you need to build a SQL SELECT
LIST.  The usual approach I have seen is to build the AST on the fly
from the text representations of each select expression:

CommonTree selectList = new CommonTree( SELECT_LIST, "{select list}" );
int count = 0;
for ( String columnName : someListOfColumnNames ) {
    CommonTree column = new CommonTree( COLUMN, columnName );
    CommonTree alias = new CommonTree( ALIAS, "y" + count++ + "_" );
    CommonTree selectExpr = new CommonTree( SELECT_EXPRESSION, "{select
expression}" );
    selectExpr.addChild( column );
    selectExpr.addChild( alias );
    selectList.addChild( selectExpr );
}

More I am thinking a pattern like:
CommonTree selectList = new CommonTree( SELECT_LIST, "{select list}" );
int count = 0;
for ( CommonTree column : someListOfColumns ) {
    CommonTree alias = new CommonTree( ALIAS, "y" + count++ + "_" );
    CommonTree selectExpr = new CommonTree( SELECT_EXPRESSION, "{select
expression}" );
    selectExpr.addChild( column );
    selectExpr.addChild( alias );
    selectList.addChild( selectExpr );
}

Which is a trivial change here specifically.  More I am worried about
handling more complex (possible nested) tree structures in this manner.
Any thoughts/pointers would be appreciated.

-- 
Steve Ebersole <[email protected]>
http://hibernate.org


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to