What am I doing to get a cycle in my tree?

Monty Zukowski

Remember that tree construction doesn't deal only with nodes, but with siblings as well.

I was trying to turn #(PLUSEQ pi:idRef pe:expr) into #(ASSIGNMENT pi #(PLUS pi pe)) (Like a+=b --> a = a + b)

     : #(ASSIGNMENT idRef expr)
     |! #(PLUSEQ pi:idRef pe:expr)  {
	 newExpr = #(#[PLUS, "+"], pi, pe);
	 #assignment = #(#[ASSIGNMENT,"ASSIGNMENT"], pi, newExpr); 

The problem is that pi is a node with siblings, and you can't use it in two places. pi points to newExpr which points to PLUS which points to pi...

The solution is to copy pi like so:

	 newExpr = #(#[PLUS, "+"], #[pi.getType(), pi.getText()], pe);
	 #assignment = #(#[ASSIGNMENT,"ASSIGNMENT"], pi, newExpr); 

Thanks again to Johan Rosman for help on this one!

0 Comments  (click to add your comment)
Comment and Contribute






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



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.