コード例 #1
0
        private void Eval()
        {
            var op = OperationStack.Pop();

            if (Operations.ContainsKey(op))
            {
                object b = OperandStack.Pop();
                object a = OperandStack.Pop();
                OperandStack.Push(Operations[op](a, b));
            }

            if (FuncsSignatures.ContainsKey(op))
            {
                var list = new List <object>();
                for (int i = 0; i < FuncsSignatures[op]; i++)
                {
                    list.Add(OperandStack.Pop());
                }
                list.Reverse();
                OperandStack.Push(Funcs[op](list));
            }
        }
コード例 #2
0
 private void Work(string token)
 {
     if (FuncsSignatures.ContainsKey(token))
     {
         OperationStack.Push(token);
     }
     else if (token == "(" || token == "[")
     {
         OperationStack.Push(token);
     }
     else if (token == ",")
     {
     }
     else if (token == ")" || token == "]")
     {
         while (OperationStack.Peek() != "[" && OperationStack.Peek() != "(")
         {
             Eval();
         }
         Eval();
     }
     else if (Priorities.ContainsKey(token))
     {
         while (OperationStack.Count > 0 && GetPriority(OperationStack.Peek()) >= GetPriority(token))
         {
             Eval();
         }
         OperationStack.Push(token);
     }
     else if (owner.Variables.ContainsKey(token))
     {
         OperandStack.Push(owner.Variables[token].Value);
     }
     else
     {
         OperandStack.Push(Parser.ParseTypes(token));
     }
 }