[antlr-interest] Need help with generating a "nested" tree
Alan D. Cabrera
list at toolazydogs.com
Sat Jan 29 23:57:09 PST 2011
On Jan 29, 2011, at 8:30 PM, John B. Brodie wrote:
> 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....
Thanks for looking into this for me. I fiddled around a bit and and this rule seems to do the trick.
functioncall
: (varOrExp nameAndArgs -> ^(FUNCALL varOrExp nameAndArgs)) (nameAndArgs -> ^(FUNCALL $functioncall nameAndArgs))*
;
Regards,
Alan
More information about the antlr-interest
mailing list