[antlr-interest] TreeWalker and AST Transformation

Jens Bräuer mailists at gmx.net
Fri Nov 10 01:05:07 PST 2006


Dear Loring, Dear Antlr-Intrest

thanks a lot for your answer. Seems as i made a mistake when writing the
mail.
In contrast to what i wrote, the problem is, that before transformation
a _StepletBody_ has multiple StreamStatements as children. Only the
first child (aka StreamStatement) survives a walk with the TreeWalker.
Antlr version is 2.7.7.

>> pr_StepletBody
>> 	:
>> 	#(StepletBody (pr_StreamStatement)*)
>> 	;
>>
>> pr_StreamStatement
>> 	{ StringBuffer s;}
>> 	:
>> 	#(StreamStatement
>> 		(
>> 			pr_SimpleStreamStatement
>> 			| pr_MultiStreamStatement
>> 			| pr_TimeStreamStatement
>> 			| pr_StreamStatmntWithDefault
>> 			| pr_StepletInvokation
>>
>> 		)
>> 	)
>> 	;

Any hints ?

Greetings, Jens


Loring Craymer wrote:
> Jens--
> 
> The problem is that you are only looking for a single
> child; change the child subgroup to a closure
> 
> pr_StreamStatement
>  	{ StringBuffer s;}
>  	:
>  	#(StreamStatement
>  		(
>  			pr_SimpleStreamStatement
>  			| pr_MultiStreamStatement
>  			| pr_TimeStreamStatement
>  			| pr_StreamStatmntWithDefault
>  			| pr_StepletInvokation
>  
>  		)+   // CHANGED from ) to )+
>  	)
>  	;
> 
> and everything should work.
> 
> --Loring
> 
> 
> --- Jens Braeuer <mailists at gmx.net> wrote:
> 
>> Dear TreeTransformation-Experts,
>>
>> i've got a problem transforming an AST using a
>> TreeWalker, which i was
>> unable to solve using google, antlr-doc and the
>> mailinglist archive. :-)
>>
>> I currently work on a small code generation project,
>> which involves
>> TreeWalkers to modify a AST (so buildAST is true).
>>
>> The problem is, that _before_ using the TreeParser a
>> StreamStatement has
>> _multiple_ children whereas after using the
>> TreeParser only the first
>> child survives. I used included ASTFrame to look at
>> the results.
>>
>> Any hints on how i have to modify the grammar so all
>> children are included
>> in the output-tree ?
>>
>>
>> TreeWalker grammar snipet:
>> -----
>> pr_StepletBody
>> 	:
>> 	#(StepletBody (pr_StreamStatement)*)
>> 	;
>>
>> pr_StreamStatement
>> 	{ StringBuffer s;}
>> 	:
>> 	#(StreamStatement
>> 		(
>> 			pr_SimpleStreamStatement
>> 			| pr_MultiStreamStatement
>> 			| pr_TimeStreamStatement
>> 			| pr_StreamStatmntWithDefault
>> 			| pr_StepletInvokation
>>
>> 		)
>> 	)
>> 	;
>> ---------
>>
>>
>> Greetings, Jens Braeuer
>>
>>
>>
>>
>>
> 
> 
> 
> 
>  
> ____________________________________________________________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs.
> http://music.yahoo.com/unlimited
> 


-- 
Mit Unix zu arbeiten, ist wie mit einem wuerdigen Gegner zu ringen. Mit
Windows zu arbeiten, ist wie ein kleines heulendes Kind anzugreifen,
dass eine geladene .38er in der Hand hat.




More information about the antlr-interest mailing list