[antlr-interest] Need help with generating a "nested" tree

John B. Brodie jbb at acm.org
Sat Jan 29 20:30:23 PST 2011


On Sat, 2011-01-29 at 09:34 -0800, Alan D. Cabrera wrote:
> functioncall
>     : varOrExp nameAndArgs+ -> ^(FUNCALL varOrExp nameAndArgs+)
>     ;
> 
> generates
> 
> (FUNCALL 
> 	varOrExp
> 	nameAndArgs1
> 	nameAndArgs2
> 	nameAndArgs3
> )
> 
> What I need it to do is generate
> 
> (FUNCALL 
> 	(FUNCALL
> 		(FUNCALL
> 			varOrExp
> 			nameAndArgs1)
> 		nameAndArgs2)
> 	nameAndArgs3)
> )
> 
> 
> I would appreciate any pointers on how I would go about generating this nested structure.
> 

I have Curried a function application by passing the partial tree to
dependent rules. (Note: I strongly suspect that my solution is really
way more complicated than it needs to be, sorry about that...).

Something like:

functioncall
    : ( varOrExp nameAndArgs -> ^(FUNCALL varOrExp nameAndArgs) )
      ( curried_call[$functioncall.tree] -> curried_call )?
    ;

curried_call [ CommonTree t ] :
      (apply[t] -> apply) ( curried_call[$apply.tree] -> curried_call )?
   ;

apply [ CommonTree t ] : nameAndArgs -> ^(FUNCALL {$t} nameAndArgs) ;

Hope this helps....
   -jbb




More information about the antlr-interest mailing list