reduceop () /* reduce binary op */
{ TOKEN op, lhs, rhs;
rhs = popopnd(); /* rhs at top */
lhs = popopnd();
op = popop();
op->operands = lhs; /* first child */
lhs->link = rhs; /* next sibling */
rhs->link = NULL; /* null terminate */
pushopnd(op); } /* subtree now operand */
We use the first child - next sibling form of tree; this represents an arbitrary tree using only two pointers. The tree form of a binary operator and operands is:
op
/
/
operands /
/
/ link
lhs ----------> rhs
Down arrows are always operands; side arrows are always link. The pretty-printer will print this as:
(op lhs rhs)