Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
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);
        }