Exemplo n.º 1
0
 public static object ComputeOne(string str, string sO)
 {
     if (Arithmetic.CheckNumber(str))
     {
         return(Arithmetic.ComputeOneNumber(Convert.ToDouble(str), sO));
     }
     if (Arithmetic.CheckBoolean(str))
     {
         return(Arithmetic.ComputeOneBoolean(Convert.ToBoolean(str), sO));
     }
     if (Arithmetic.CheckString(str))
     {
         return(Arithmetic.ComputeOneString(str, sO));
     }
     return("ComputerOne [" + str + "][" + sO + "] Sorry!");
 }
Exemplo n.º 2
0
        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 (Arithmetic.OperatorMap.IsVar(text))
                    {
                        stack.Push(text);
                    }
                    else
                    {
                        if (Arithmetic.OperatorMap.CheckOperator(text))
                        {
                            if (!Arithmetic.CheckOneOperator(text))
                            {
                                string sR    = stack.Pop().ToString();
                                string text2 = stack.Pop().ToString();
                                string obj   = Arithmetic.ComputeTwo(text2, sR, text).ToString();
                                stack.Push(obj);
                            }
                            else
                            {
                                string text2 = stack.Pop().ToString();
                                string obj   = Arithmetic.ComputeOne(text2, text).ToString();
                                stack.Push(obj);
                            }
                        }
                    }
                }
                string text3 = stack.Pop().ToString();
                result = text3;
            }
            catch
            {
                Console.WriteLine("Result:表达式不符合运算规则!Sorry!");
                result = "Sorry!Error!";
            }
            return(result);
        }
Exemplo n.º 3
0
 public static object ComputeTwo(string sL, string sR, string sO)
 {
     if (Arithmetic.CheckNumber(sL))
     {
         if (Arithmetic.CheckNumber(sR))
         {
             return(Arithmetic.ComputeTwoNumber(Convert.ToDouble(sL), Convert.ToDouble(sR), sO));
         }
         if (Arithmetic.CheckString(sR))
         {
             return(Arithmetic.ComputeTwoString(sL, sR, sO));
         }
     }
     else
     {
         if (Arithmetic.CheckBoolean(sL))
         {
             if (Arithmetic.CheckBoolean(sR))
             {
                 return(Arithmetic.ComputeTwoBoolean(Convert.ToBoolean(sL), Convert.ToBoolean(sR), sO));
             }
             if (Arithmetic.CheckString(sR))
             {
                 return(Arithmetic.ComputeTwoString(sL, sR, sO));
             }
         }
         else
         {
             if (Arithmetic.CheckString(sL))
             {
                 return(Arithmetic.ComputeTwoString(sL, sR, sO));
             }
         }
     }
     return("ComputeTwo [" + sL + "][" + sO + "][" + sR + "] Sorry!");
 }
Exemplo n.º 4
0
 public static object ComputeExpression(string sExpression, string[] mapVar, string[] mapValue)
 {
     return(Arithmetic.ComputePostfix(Arithmetic.ConvertToPostfix(Arithmetic.ConvertExpression(Arithmetic.ConvertExpression(sExpression), mapVar, mapValue))));
 }
Exemplo n.º 5
0
 public static object ComputeExpression(string sExpression)
 {
     return(Arithmetic.ComputePostfix(Arithmetic.ConvertToPostfix(Arithmetic.ConvertExpression(sExpression))));
 }