public static void ParseOperand(Esymbol symbol,ref string expression,ref int pos,ref int begin,ref int end) { if (GetOprandType(symbol) == OprandType.Left) { if (CommonTool.GetSymbol(expression[pos + 1]) == Esymbol.LeftBracket) { //replace directly expression = expression.Remove(pos, 1); expression = expression.Insert(pos, _DicoperandFunc[symbol]); pos--; } else { expression = expression.Remove(pos, 1); expression = expression.Insert(pos, _DicoperandFunc[symbol]+"("); int pos2 = pos; pos2 = pos2 + _DicoperandFunc[symbol].Length + "(".Length; for (;pos2<expression.Length && !CommonTool.IsCaculateSymbol(expression[pos2]); pos2++) { } expression = expression.Insert(pos2, ")"); pos--; } } else { //右操作! } }
////数字节点只能是叶子。 //public GeneralNode(double number_p) //{ // number = number_p; // left = right = null; // isNumber = true; // symbol = Esymbol.Nothing; // priority = Epriority.Nothing; //} //操作符节点初始化 public void SetUpNode(params object[] paras)//Esymbol symbol_p, INode left_p, INode right_p) { if (paras != null && paras.Length == 4) { if (paras[0] != null) { number = (double)paras[0]; isNumber = true; } else { isNumber = false; } left = (INode)paras[1]; right = (INode)paras[2]; if (paras[3] != null) { symbol = (Esymbol)paras[3]; } else { symbol = Esymbol.Nothing; } priority = this.SymbolInPriority(symbol); } else throw new Exception("Node初始化参数数量对!"); }
public static void ParseOperand(Esymbol symbol, ref string expression, ref int pos, ref int begin, ref int end) { if (GetOprandType(symbol) == OprandType.Left) { if (CommonTool.GetSymbol(expression[pos + 1]) == Esymbol.LeftBracket) { //replace directly expression = expression.Remove(pos, 1); expression = expression.Insert(pos, _DicoperandFunc[symbol]); pos--; } else { expression = expression.Remove(pos, 1); expression = expression.Insert(pos, _DicoperandFunc[symbol] + "("); int pos2 = pos; pos2 = pos2 + _DicoperandFunc[symbol].Length + "(".Length; for (; pos2 < expression.Length && !CommonTool.IsCaculateSymbol(expression[pos2]); pos2++) { } expression = expression.Insert(pos2, ")"); pos--; } } else { //右操作! } }
public static OprandType GetOprandType(Esymbol symbol) { if (isOperand(symbol)) { if (symbol == Esymbol.Fan || symbol==Esymbol.JieChen) return OprandType.Left; else return OprandType.Right; } return OprandType.Nothing; }
public static bool IsCaculateSymbol(char c) { Esymbol s = GetSymbol(c); if (s == Esymbol.Division || s == Esymbol.Muliply || s == Esymbol.Plus || s == Esymbol.Subtraction || s == Esymbol.Power) { return(true); } return(false); }
public static OprandType GetOprandType(Esymbol symbol) { if (isOperand(symbol)) { if (symbol == Esymbol.Fan || symbol == Esymbol.JieChen) { return(OprandType.Left); } else { return(OprandType.Right); } } return(OprandType.Nothing); }
public static bool isOperand(Esymbol symbol) { return _DicoperandFunc.ContainsKey(symbol); }
public static bool isOperand(Esymbol symbol) { return(_DicoperandFunc.ContainsKey(symbol)); }