public string ReplaceFinalOperator(Symbol newOp) { if (string.IsNullOrEmpty(_equation)) { return newOp.ToString(); } return _equation.TrimEnd(Operators.ToArray()) + newOp.ToString(); }
public static NegativeSign Produce(Symbol symbol) { // neg-sign = minus if (symbol is Minus) { return new NegativeSign(symbol); } return null; }
public static PrefixOperator Produce(Symbol symbol) { // prefix-operator = plus / minus if (symbol is Plus || symbol is Minus) { return new PrefixOperator(symbol); } return null; }
public static InfixOperator Produce(Symbol symbol) { // infix-operator = caret / asterisk / forward-slash / plus / minus if (symbol is Plus || symbol is Minus || symbol is Asterisk || symbol is ForwardSlash || symbol is Caret) { return new InfixOperator(symbol); } return null; }
private static void inspectRecursive(StringBuilder sb, Symbol symbol, int depth) { sb.AppendLine(string.Format("{0}{1}: {2}", "".PadRight(depth * 2), symbol.GetType().Name, symbol.ToString())); foreach (var childSymbol in symbol.ConstituentSymbols) { inspectRecursive(sb, childSymbol, depth + 1); } }
private void operator operatorButtonClicked(Symbol op) { if (ERROR_MESSAGE.Equals(_equationText)) { changeEquationText("0" + op.ToString()); return; } var eq = new Equation(_equationText); if (eq.HasFinalOperator()) { changeEquationText(eq.ReplaceFinalOperator(op)); } else { changeEquationText(_equationText + op.ToString()); } }