Пример #1
0
 public string ReplaceFinalOperator(Symbol newOp)
 {
     if (string.IsNullOrEmpty(_equation))
     {
         return newOp.ToString();
     }
     return _equation.TrimEnd(Operators.ToArray()) + newOp.ToString();
 }
Пример #2
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 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);
     }
 }
Пример #6
0
 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());
     }
 }