public void Visit(BinarySub node) { sb.Append("("); node.LeftChild.Accept(this); sb.Append("-"); node.RightChild.Accept(this); sb.Append(")"); }
public bool TryParse(string formula, out FormulaNode node) { if (formula == "-") { node = new BinarySub(leftNode, rightNode); return(true); } else { node = null; return(false); } }
public void Visit(BinarySub node) { if (!cachedResult.HasValue) { node.LeftChild.Accept(this); node.RightChild.Accept(this); int valueTwo = results.Pop(); int valueOne = results.Pop(); checked { results.Push(valueOne - valueTwo); } } }
public void Visit(BinarySub node) { OperationPriorities priority = prevPriorities.Pop(); if ((int)priority > 1) { sb.Append("("); prevPriorities.Push(OperationPriorities.Sub); node.LeftChild.Accept(this); sb.Append("-"); prevPriorities.Push(OperationPriorities.Sub); node.RightChild.Accept(this); sb.Append(")"); } else { prevPriorities.Push(OperationPriorities.Sub); node.LeftChild.Accept(this); sb.Append("-"); prevPriorities.Push(OperationPriorities.Sub); node.RightChild.Accept(this); } }