# 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
: #(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!

Comment and Contribute

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