public void Visit(BinaryDiv 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 BinaryDiv(leftNode, rightNode); return(true); } else { node = null; return(false); } }
public void Visit(BinaryDiv 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(BinaryDiv node) { OperationPriorities priority = prevPriorities.Pop(); if ((int)priority > 6) { sb.Append("("); prevPriorities.Push(OperationPriorities.Div); node.LeftChild.Accept(this); sb.Append("/"); prevPriorities.Push(OperationPriorities.Div); node.RightChild.Accept(this); sb.Append(")"); } else { prevPriorities.Push(OperationPriorities.Div); node.LeftChild.Accept(this); sb.Append("/"); prevPriorities.Push(OperationPriorities.Div); node.RightChild.Accept(this); } }