dcsimg
Tree construction of left-associative expressions.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   David_Jones
Posted On:   Thursday, January 24, 2002 01:54 PM

I want to parse expressions such that the resulting parse trees are of the form: #(BIN_OP left op right) For "a+b-1", I want to see: #(BIN_OP #(BIN_OP a PLUS b) MINUS 1) I have the following code: exp7 : exp8 ( binop7 exp8 { #exp7 = #([BIN_OP, "BIN_OP"], exp7); } )* ; However, after assigning to #exp7, subsequent children are added to the right of the last child, which is not what I want. I get instead: #(BIN_OP #(BIN_OP a PLUS b MINUS 1)) Since the documented behavior of assigning to #exp7 is not what I want, how    More>>

I want to parse expressions such that the resulting parse trees are of the form:


#(BIN_OP left op right)


For "a+b-1", I want to see:


#(BIN_OP #(BIN_OP a PLUS b) MINUS 1)


I have the following code:


			
				
exp7 :
exp8 ( binop7 exp8
{ #exp7 = #([BIN_OP, "BIN_OP"], exp7); } )*
;



However, after assigning to #exp7, subsequent children are added to the right of the last child, which is not what I want. I get instead:


#(BIN_OP #(BIN_OP a PLUS b MINUS 1))


Since the documented behavior of assigning to #exp7 is not what I want, how do I construct this tree, such that the snippet in ( )* works properly? (Note: if I don't have ( )* then I do get an imaginary parent. This is well documented with plenty of examples.)

   <<Less

Re: Tree construction of left-associative expressions.

Posted By:   Terence_Parr  
Posted On:   Saturday, February 2, 2002 10:04 AM

The use of #exp7 assignment within a rule that is doing automatic construction is a "no-no"; i.e., can't mix auto and manual construction. I would use ! on the rule and then continue constructing as you are. Recall that trees are still built for rules referenced from exp7--they are just not automatically stitched into a tree for exp7.
About | Sitemap | Contact