private bool AddOnEquation(char operation, KeyType type) { Debug.Log("AddOnEquation():" + " bufferStr = " + bufferStr + ", bufferType = " + bufferType.ToString()); Debug.Log("AddOnEquation():" + " operation = " + operation + ", type = " + type.ToString()); if (bufferType == KeyType.NumberKey && (type == KeyType.NumberKey || type == KeyType.NumberPointKey)) { if (bufferStr == num_zero.ToString()) { return(false); } else { char point = CalculatorData.GetKeyValueByName(KeyName.Number_point); if (bufferStr.Contains(point.ToString()) && type == KeyType.NumberPointKey) { return(false); } bufferStr += operation; return(true); } } bufferStr = operation.ToString(); bufferType = type; return(true); }
private string AddContent(string content, KeyName name, KeyType type) { if (defaultNum == errorInfo) { return(content); } char s = CalculatorData.GetKeyValueByName(name); if (content == defaultNum) { if (AddOnDefalut(s, type)) { content += s; } else { content = s.ToString(); } } else { if (AddOnEquation(s, type)) { content += s; } } return(content); }
private void InputOperatorStack_BacketRightKey() { while (operatorsStack.Peek() != CalculatorData.GetKeyValueByName(KeyName.Bracket_Left)) { Calculate(); } operatorsStack.Pop(); }
private void InputOperatorStack_Operator(KeyName newName) { char newOperator = CalculatorData.GetKeyValueByName(newName); int newLevel = OperatorFactory.OperatorPriority(newOperator); while (operatorsStack.Count != 0 && operatorsStack.Peek() != CalculatorData.GetKeyValueByName(KeyName.Bracket_Left)) { var oldOperator = operatorsStack.Peek(); var oldLevel = OperatorFactory.OperatorPriority(oldOperator); if (newLevel <= oldLevel) { Calculate(); } else { operatorsStack.Push(newOperator); return; } } operatorsStack.Push(newOperator); }
/// <summary> /// 计算器第一次运行时初始化方法 /// </summary> public InputRegular() { num_zero = CalculatorData.GetKeyValueByName(KeyName.Number_0); defaultNum = num_zero.ToString(); errorInfo = CalculatorData.GetErrorInfo(); }
private void InputOperatorStack_BacketLeftKey(KeyName newName) { var newOperator = CalculatorData.GetKeyValueByName(newName); operatorsStack.Push(newOperator); }