private static void RegisterModules() { foreach (var moduleRegistrar in ModuleRegistrarFactory.GetHandlers()) { foreach (var o in moduleRegistrar.Register()) { OperatorMap.RegisterOperator(o); } } }
/// <summary> /// 找出第一个闭括号 /// </summary> /// <param name="alExpression"></param> /// <returns></returns> public static int Find_First_RightBracket(ArrayList alExpression) { for (int i = 0; i < alExpression.Count; i++) { if (OperatorMap.CheckRightBracket(alExpression[i].ToString())) { return(i); } } return(0); }
public Plugins(Plugins original) { foreach (var kv in original.OperatorMap) { OperatorMap.Add(kv.Key, kv.Value); } foreach (var kv in original.RunMap) { RunMap.Add(kv.Key, kv.Value); } }
public static int Find_Near_LeftBracket(ArrayList alExpression, int iRightBracket) { for (int i = iRightBracket - 2; i >= 0; i--) { if (OperatorMap.CheckLeftBracket(alExpression[i].ToString())) { return(i); } } return(0); }
public static OperatorMap.Map GetMap(string Operator) { if (OperatorMap.CheckOperator(Operator)) { OperatorMap.Map[] array = OperatorMap.map(); for (int i = 0; i < array.Length; i++) { OperatorMap.Map result = array[i]; if (result.Operator == Operator) { return(result); } } } return(new OperatorMap.Map(99, Operator)); }
/// <summary> /// 计算后缀表达式 /// </summary> /// <param name="alexpression"></param> /// <returns></returns> public static object ComputePostfix(ArrayList alexpression) { try { //·建立一个栈S Stack s = new Stack(); int count = alexpression.Count; int i = 0; while (i < count) { //·从左到右读后缀表达式,读到数字就将它转换为数值压入栈S中, string word = alexpression[i++].ToString(); if (OperatorMap.IsVar(word)) { s.Push(word); // System.Console.WriteLine("Push:{0}",word); } else//读到运算符则从栈中依次弹出两个数分别到Y和X, if (OperatorMap.CheckOperator(word)) { string y, x, sResult; if (!CheckOneOperator(word)) { y = s.Pop().ToString(); x = s.Pop().ToString(); //然后以“X 运算符 Y”的形式计算机出结果,再压加栈S中 sResult = ComputeTwo(x, y, word).ToString(); s.Push(sResult); } else { x = s.Pop().ToString(); sResult = ComputeOne(x, word).ToString(); s.Push(sResult); } } } string spop = s.Pop().ToString(); // System.Console.WriteLine("Result:{0}",spop); return(spop); } catch { System.Console.WriteLine("Result:表达式不符合运算规则!Sorry!"); return("Sorry!Error!"); } }
public static object ComputePostfix(ArrayList alexpression) { object result; try { Stack stack = new Stack(); int count = alexpression.Count; int i = 0; while (i < count) { string text = alexpression[i++].ToString(); if (OperatorMap.IsVar(text)) { stack.Push(text); } else { if (OperatorMap.CheckOperator(text)) { if (!CheckOneOperator(text)) { string sR = stack.Pop().ToString(); string text2 = stack.Pop().ToString(); string obj = ComputeTwo(text2, sR, text).ToString(); stack.Push(obj); } else { string text2 = stack.Pop().ToString(); string obj = ComputeOne(text2, text).ToString(); stack.Push(obj); } } } } string text3 = stack.Pop().ToString(); result = text3; } catch { Console.WriteLine("Result:表达式不符合运算规则!Sorry!"); result = "Sorry!Error!"; } return(result); }
/// <summary> /// 中缀表达式转换为后缀表达式 /// </summary> /// <param name="alexpression"></param> /// <returns></returns> public static ArrayList ConvertToPostfix(ArrayList alexpression) { ArrayList alOutput = new ArrayList(); Stack sOperator = new Stack(); string word = null; int count = alexpression.Count; int i = 0; while (i < count) { word = alexpression[i++].ToString(); //·读到左括号时总是将它压入栈中 if (OperatorMap.CheckLeftBracket(word)) { sOperator.Push(word); } else //·读到右括号时,将*近栈顶的第一个左括号上面的运算符全部依次弹出,送至输出队列后,再丢弃左括号。 if (OperatorMap.CheckRightBracket(word)) { while (true) { if (sOperator.Count == 0) { break; } string sTop = sOperator.Peek().ToString(); if (sTop == "(") { sOperator.Pop(); break; } else { alOutput.Add(sOperator.Pop()); } } } else //·当读到数字直接送至输出队列中 if (OperatorMap.IsVar(word)) { alOutput.Add(word); } else //·当读到运算符t时, // a.将栈中所有优先级高于或等于t的运算符弹出,送到输出队列中; // b.t进栈 if (OperatorMap.CheckOperator(word)) { while (sOperator.Count > 0) { string sPop = sOperator.Peek().ToString(); if (sPop == "(") { break; } if (OperatorMap.GetMaxprior(word, sPop) >= 0) { // sPop = sOperator.Pop().ToString(); alOutput.Add(sOperator.Pop().ToString()); } else { break; } // System.Console.WriteLine("XH{0}",sPop); } sOperator.Push(word); } // System.Console.WriteLine("{0}",word.ToString()); } //中缀表达式全部读完后,若栈中仍有运算符,将其送到输出队列中 while (sOperator.Count > 0) { string s = sOperator.Pop().ToString(); alOutput.Add(s); // System.Console.WriteLine("{0}:{1}",sOperator.Count,s.ToString()); } return(alOutput); }
/// <summary> /// Resolves an operator call, throwing an exception if no resolution is possible. /// </summary> /// <param name="operatorName">The name of the operator being called.</param> /// <param name="signature">The signature of the arguments to the call.</param> /// <returns>The operator matching the given name and signature if one exists, otherwise an exception is thrown.</returns> public Operator ResolveCall(string operatorName, Signature signature) { return(OperatorMap.ResolveCall(operatorName, signature)); }
public static ArrayList ConvertToPostfix(ArrayList alexpression) { ArrayList arrayList = new ArrayList(); Stack stack = new Stack(); int count = alexpression.Count; int i = 0; while (i < count) { string text = alexpression[i++].ToString(); if (OperatorMap.CheckLeftBracket(text)) { stack.Push(text); } else { if (OperatorMap.CheckRightBracket(text)) { while (stack.Count != 0) { string a = stack.Peek().ToString(); if (a == "(") { stack.Pop(); break; } arrayList.Add(stack.Pop()); } } else { if (OperatorMap.IsVar(text)) { arrayList.Add(text); } else { if (OperatorMap.CheckOperator(text)) { while (stack.Count > 0) { string text2 = stack.Peek().ToString(); if (text2 == "(" || OperatorMap.GetMaxprior(text, text2) < 0) { break; } arrayList.Add(stack.Pop().ToString()); } stack.Push(text); } } } } } while (stack.Count > 0) { string value = stack.Pop().ToString(); arrayList.Add(value); } return(arrayList); }
public static int GetMaxprior(string Loperator, string Roperator) { return(OperatorMap.GetMap(Loperator).Priority - OperatorMap.GetMap(Roperator).Priority); }
public static int Getprior(string Operator) { return(OperatorMap.GetMap(Operator).Priority); }
private void DropSessionObjects() { if (HasSessionObjects()) { List <String> objectNames = new List <String>(); for (int index = 0; index < _sessionObjects.Count; index++) { objectNames.Add(((Schema.SessionObject)_sessionObjects[index]).GlobalName); } for (int index = 0; index < _sessionOperators.Count; index++) { _server._systemProcess.CatalogDeviceSession.ResolveOperatorName(((Schema.SessionObject)_sessionOperators[index]).GlobalName); OperatorMap operatorMap = _server.Catalog.OperatorMaps[((Schema.SessionObject)_sessionOperators[index]).GlobalName]; foreach (OperatorSignature signature in operatorMap.Signatures.Signatures.Values) { objectNames.Add(signature.Operator.Name); } } string[] objectNameArray = new string[objectNames.Count]; for (int index = 0; index < objectNames.Count; index++) { objectNameArray[index] = objectNames[index]; } Block block = (Block)_server.Catalog.EmitDropStatement(_server._systemProcess.CatalogDeviceSession, objectNameArray, String.Empty); _server._systemProcess.BeginCall(); try { ServerStatementPlan plan = new ServerStatementPlan(_server._systemProcess); try { // Push a timestamp safe context to prevent the drops from flushing cache-points plan.Plan.EnterTimeStampSafeContext(); try { for (int index = 0; index < block.Statements.Count; index++) { plan.Program.Code = Compiler.Compile(plan.Plan, block.Statements[index]); plan.Program.Execute(null); } } finally { plan.Plan.ExitTimeStampSafeContext(); } } finally { plan.Dispose(); } } catch (Exception E) { throw WrapException(E); } finally { _server._systemProcess.EndCall(); } //FServer.RunScript(new D4TextEmitter().Emit(FServer.Catalog.EmitDropStatement(FServer.FSystemProcess, LObjectNameArray, String.Empty)), FCurrentLibrary.Name); } }