[antlr-interest] AST matching and N-ary tree nodes.

Monty Zukowski monty at codetransform.com
Thu Oct 7 07:36:59 PDT 2004


On Oct 7, 2004, at 7:21 AM, Bryan Ewbank wrote:

>
> Hi Folks,
>
> I've been building flattened trees for things like argument lists, but 
> am
> now encountering a question of how to process these nodes in a general 
> way,
> since AST matching is generous...
>
> 	// Used to use this
> 		arglist : arg ( COMMA^ arg )*
>
> 	// Now use this
> 		arglist : arg ( COMMA! arg )*
> 			{ #arglist = #( #[ARGLIST], #arglist)
>
> The problem is that I don't know how many kids the ARGLIST node can 
> have,
> and I don't see a way (v 2.7.4) to easily walk the children.
>

The tree rule would be identical to what you had before, substituting 
ARGLIST for COMMA.  Your tree used to be #(COMMA arg1 arg2 ...)  now it 
is #(ARGLIST arg1 arg2 ...).

arglist: #(ARGLIST (arg)*);

You won't know how many are in there until you walk them all.  If you 
wanted you could keep count in the parser and store that in the ARGLIST 
node if you make a custom tree node class to hold that info.

> Am I building this tree in a non-ANTLR style?  Do I need to go back to 
> using
> the "COMMA^" model?
>
> - Bryan Ewbank
> "The best tool for requirements analysis and design is a crayon"
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>



 
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