public override void setChild(int index, Token token) { switch (index) { case 0: variable = token as Variable; break; case 1: expression = token; break; default: throw new Exception("Invalid child index: " + index); } token.indexInParent = index; token.parent = this; }
public TokenTree simplify() { bool somethingDone; do { somethingDone = false; List<Token> tokens = ReverseBFS(); foreach (Token t in tokens) { if (t is Operator) { Token left = t.getChild(0); Token right = t.getChild(1); if(left is Variable && right is Variable) { if(left.name == right.name) { if(t.name == "AND" || t.name == "OR" || t.name == "IMPLIES") { somethingDone = true; Token n = new Variable(name: left.name); if (t.parent == null) { root = n; } else { t.parent.setChild(t.indexInParent, n); } } } } } } } while (somethingDone); return this; }