Esempio n. 1
0
        public void Parse(string str, int[] pars)
        {
            str = ConvertStirng(str);

            string tmp = InsertParValues(str, pars, false);

            tmp = "(" + tmp + ")";
            QuestTCPVariant range = Calc(tmp);
            double          value = range.GetValue();

            value = (value < -2000000000) ? -2000000000 : value;
            value = (value > 2000000000) ? 2000000000 : value;

            try
            {
                answer = (int)Math.Round(value + +0.00000000001f);
            }
            catch
            {
                calc_error = true;
                error      = true;
                answer     = 0;
            }
            if ((answer < 0) && (value > 0))
            {
                calc_error = true;
                error      = true;
                answer     = 0;
            }
            if (calc_error)
            {
                error = true;
            }
        }
Esempio n. 2
0
        private void OpTo(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
        {
            result.Clear();
            long min = (lf.vtype == QuestTCPVType.vtExt) ? (long)Math.Round(lf.vf) : lf.vd.GetMinimun();
            long max = (rf.vtype == QuestTCPVType.vtExt) ? (long)Math.Round(rf.vf) : rf.vd.GetMaximun();

            result.vtype = QuestTCPVType.vtRange;
            result.vd.Add(min, max);
        }
Esempio n. 3
0
        private void OpDiv(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
        {
            result.Clear();
            double l = lf.GetValue();
            double r = rf.GetValue();

            if (r == 0)
            {
                result.vf = (l < 0) ? -2000000000 : 2000000000;
            }
            else
            {
                result.vf = l / r;
            }
        }
Esempio n. 4
0
 private void OpIn(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
 {
     result.Clear();
     if ((lf.vtype == QuestTCPVType.vtExt) && (rf.vtype == QuestTCPVType.vtExt))
     {
         result.vf = lf.vf == rf.vf ? 1 : 0;
     }
     else if ((lf.vtype == QuestTCPVType.vtRange) && (rf.vtype == QuestTCPVType.vtExt))
     {
         result.vf = lf.vd.Have(rf.vf) ? 1 : 0;
     }
     else if ((lf.vtype == QuestTCPVType.vtExt) && (rf.vtype == QuestTCPVType.vtRange))
     {
         result.vf = rf.vd.Have(lf.vf) ? 1 : 0;
     }
     else if ((lf.vtype == QuestTCPVType.vtRange) && (rf.vtype == QuestTCPVType.vtRange))
     {
         result.vf = rf.vd.Have(lf.GetValue()) ? 1 : 0;
     }
 }
Esempio n. 5
0
        private void OpMod(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
        {
            result.Clear();
            double l = lf.GetValue();
            double r = rf.GetValue();

            r = Math.Truncate(r);
            if (r == 0)
            {
                result.vf = (l < 0) ? -2000000000 : 2000000000;
            }
            else
            {
                r = (r < 0) ? -r: r;
                bool ldz = l < 0;
                l         = ldz ? -l : l;
                result.vf = Math.Truncate(l - r * Math.Truncate(l / r));
                result.vf = ldz ? -result.vf : result.vf;
            }
        }
Esempio n. 6
0
 private void OpOr(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
 {
     result.Clear();
     if ((lf.vtype == QuestTCPVType.vtExt) && (rf.vtype == QuestTCPVType.vtExt))
     {
         result.vf = (lf.vf != 0) || (rf.vf != 0) ? 1 : 0;
     }
     else if ((lf.vtype == QuestTCPVType.vtRange) && (rf.vtype == QuestTCPVType.vtRange))
     {
         result.CopyDataFrom(lf);
         result.vd.Add(rf.vd);
     }
     else if ((lf.vtype == QuestTCPVType.vtExt) && (rf.vtype == QuestTCPVType.vtRange))
     {
         result.CopyDataFrom(rf);
         result.vd.Add(lf.vf);
     }
     else if ((lf.vtype == QuestTCPVType.vtRange) && (rf.vtype == QuestTCPVType.vtExt))
     {
         result.CopyDataFrom(lf);
         result.vd.Add(rf.vf);
     }
 }
Esempio n. 7
0
 private void OpNotEq(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
 {
     result.Clear();
     result.vf = lf.GetValue() != rf.GetValue() ? 1 : 0;
 }
Esempio n. 8
0
 private void OpDivTrunc(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
 {
     OpDiv(lf, rf, ref result);
     result.vf = Math.Truncate(result.vf);
 }
Esempio n. 9
0
 private void OpMul(QuestTCPVariant lf, QuestTCPVariant rf, ref QuestTCPVariant result)
 {
     result.Clear();
     result.vf = lf.GetValue() * rf.GetValue();
 }
Esempio n. 10
0
        private QuestTCPVariant Calc(string str)
        {
            QuestTCPVariant result = new QuestTCPVariant();

            if (!calc_error)
            {
                if (!result.Assign(str))
                {
                    int lenexpr = str.Length;
                    if ((str[0] == '(') && (str[lenexpr - 1] == ')') && CheckParentheses(str, 1, lenexpr - 2))
                    {
                        string          tmp = str.Substring(1, lenexpr - 2);
                        QuestTCPVariant var = Calc(tmp);
                        result.CopyDataFrom(var);
                    }
                    else
                    {
                        int c = FindOperation(str, lenexpr - 1);
                        if (c == -1)
                        {
                            calc_error = true;
                            return(result);
                        }
                        string left  = str.Substring(0, c);
                        string right = str.Substring(c + 1, lenexpr - c - 1);

                        QuestTCPVariant rf = Calc(right);
                        if (calc_error)
                        {
                            return(result);
                        }

                        QuestTCPVariant lf = Calc(left);
                        if (calc_error)
                        {
                            return(result);
                        }

                        try
                        {
                            char ch = str[c];
                            if (ch == '+')
                            {
                                OpAdd(lf, rf, ref result);
                            }
                            if (ch == '-')
                            {
                                OpSub(lf, rf, ref result);
                            }
                            if (ch == '*')
                            {
                                OpMul(lf, rf, ref result);
                            }
                            if (ch == '/')
                            {
                                OpDiv(lf, rf, ref result);
                            }
                            if (ch == 'f')
                            {
                                OpDivTrunc(lf, rf, ref result);
                            }
                            if (ch == 'g')
                            {
                                OpMod(lf, rf, ref result);
                            }
                            if (ch == '$')
                            {
                                OpTo(lf, rf, ref result);
                            }
                            if (ch == '#')
                            {
                                OpIn(lf, rf, ref result);
                            }
                            if (ch == '>')
                            {
                                OpHi(lf, rf, ref result);
                            }
                            if (ch == '<')
                            {
                                OpLo(lf, rf, ref result);
                            }
                            if (ch == 'c')
                            {
                                OpHiEq(lf, rf, ref result);
                            }
                            if (ch == 'b')
                            {
                                OpLoEq(lf, rf, ref result);
                            }
                            if (ch == 'e')
                            {
                                OpNotEq(lf, rf, ref result);
                            }
                            if (ch == '=')
                            {
                                OpEq(lf, rf, ref result);
                            }
                            if (ch == '&')
                            {
                                OpAnd(lf, rf, ref result);
                            }
                            if (ch == '|')
                            {
                                OpOr(lf, rf, ref result);
                            }
                        }
                        catch (Exception e)
                        {
                            calc_error = true;
                            throw e;
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 11
0
 public void CopyDataFrom(QuestTCPVariant source)
 {
     vd.CopyDataFrom(source.vd);
     vf    = source.vf;
     vtype = source.vtype;
 }