[antlr-interest] loose tree walker?

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Mon May 2 17:10:44 PDT 2005


It depends.  With 2.8, I would tend to generate the full tree grammar and 
process the elifs within that context.  With manual grammar generation, 
I've taken the "loose" approach to get something up fast.  The full grammar 
will be more maintainable over the long run if other features are to be 
added, but you can always fold the "loose" grammar into a full grammar later.

--Loring


At 01:49 PM 5/2/2005, Bryan Ewbank wrote:
>I'm seeking guidance and information. Let's say I'm doing a tree
>transformation to replace "elif" with "if" everywhere it occurs.
>
>I can either be very precise and walk the entire tree as it is
>supposed to be formed now:
>     prog : ( stmt )* ;
>     stmt : ( stmt_if | stmt_for | ... ) ;
>     stmt_if : #(IF expr stmt ( stmt_elif | stmt )? );
>     stmt_elif #(ELIF expr stmt ( stmt )? ) { ... convert elif to if ... } ;
>     // omitting expr and the rest of the grammar
>
>Or I can do a loose tree walker, like this:
>
>     traverseKids : ( traverseTree )* ;
>     traverseTree : ( (ELIF) => stmt_elif | #( . traverseKids ) );
>     stmt_elif : #(ELIF traverseKids ) { ... convert elif to if ... } ;
>
>The second has some appeal to me simply because it removes the rest of
>the tree and the dependencies on how that tree is shaped.
>
>what do others do?




More information about the antlr-interest mailing list