import java.util.*; class TreeBuilder { Stack s = new Stack(); TreeBuilder() { s.push(null); } public void addByNode(Node n) { s.push((Node) n.clone()); } public Node getTop() { return (Node) s.peek(); } public void addNodeByType(Object t) { Node n = new Node(t); Node temp = null; boolean second = false; int i = 0; try {i = ((Integer) t).intValue();} catch (ClassCastException e) {i = TParser.ERROR;} switch (i) { case TParser.PLUS: case TParser.MINUS: case TParser.MULT: case TParser.DIV: case TParser.POW: case TParser.MIN: case TParser.MAX: case TParser.DERIV: temp = (Node) s.pop(); second = true; case TParser.NEG: case TParser.ABS: case TParser.SQRT: case TParser.SIN: case TParser.COS: case TParser.TAN: case TParser.SEC: case TParser.CSC: case TParser.COT: case TParser.LN: case TParser.LOG: case TParser.EXP: case TParser.ASIN: case TParser.ACOS: case TParser.ATAN: case TParser.ASEC: case TParser.INT: case TParser.DBL: case TParser.FACT: n.addChild((Node) s.pop()); default: break; } if (second) n.addChild(temp); second = false; s.push(n); } }