Why are trees not built properly when I manually manipulate the return tree (with an action) for a rule?

Terence Parr

Generally the problem is that you cannot use manual tree construction actions within a rule that is doing automatic tree construction--you confuse the automatic mechanism. For example, to construct a tree for repeated method call input like f(a)(b) (return value from f(a) is a function), you cannot do this:

call:
	primary_expr
	(
		LPAREN! expr RPAREN!
		{ ## = #([CALL,"call"],##); }
	)*
	;
The assignment "##=..." messes up the automatic mechanism. You could do something like this:
call : primary_expr ( LPAREN^ expr RPAREN! )* ;
and then put in an action to modify LPAREN to a CALL node. If you really want to do the manual method, it's no problem, but you will need to change the above action to reference trees created by invocation of rules primary_expr and expr (and, of course, turn off auto construction for "call" by using a "!" on the declaration). Recall that "!" only affects the immediate rule. Trees are still created by calling other rules, they are just not automatically stitched into a tree for "call".
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact