Пример #1
0
        public opCodeBinary(tokenizer tokenizer, opCode param1, eTokenType tt, opCode param2)
        {
            mParam1 = param1;
            mParam2 = param2;

            mParam1.ValueChanged += mParam1_ValueChanged;
            mParam2.ValueChanged += mParam2_ValueChanged;

            EvalType v1Type = mParam1.EvalType;
            EvalType v2Type = mParam2.EvalType;

            switch (tt)
            {
            case eTokenType.operator_plus:
            {
                if (v1Type == EvalType.Number & v2Type == EvalType.Number)
                {
                    mValueDelegate = NUM_PLUS_NUM;
                    mEvalType      = EvalType.Number;
                }
                else if (v1Type == EvalType.Number & v2Type == EvalType.Date)
                {
                    SwapParams(ref mParam1, ref mParam2);
                    mValueDelegate = DATE_PLUS_NUM;
                    mEvalType      = EvalType.Date;
                }
                else if (v1Type == EvalType.Date & v2Type == EvalType.Number)
                {
                    mValueDelegate = DATE_PLUS_NUM;
                    mEvalType      = EvalType.Date;
                }
                else if (mParam1.CanReturn(EvalType.String) & mParam2.CanReturn(EvalType.String))
                {
                    Convert(tokenizer, ref param1, EvalType.String);
                    mValueDelegate = STR_CONCAT_STR;
                    mEvalType      = EvalType.String;
                }

                break;
            }

            case eTokenType.operator_minus:
            {
                if (v1Type == EvalType.Number & v2Type == EvalType.Number)
                {
                    mValueDelegate = NUM_MINUS_NUM;
                    mEvalType      = EvalType.Number;
                }
                else if (v1Type == EvalType.Date & v2Type == EvalType.Number)
                {
                    mValueDelegate = DATE_MINUS_NUM;
                    mEvalType      = EvalType.Date;
                }
                else if (v1Type == EvalType.Date & v2Type == EvalType.Date)
                {
                    mValueDelegate = DATE_MINUS_DATE;
                    mEvalType      = EvalType.Number;
                }

                break;
            }

            case eTokenType.operator_mul:
            {
                if (v1Type == EvalType.Number & v2Type == EvalType.Number)
                {
                    mValueDelegate = NUM_MUL_NUM;
                    mEvalType      = EvalType.Number;
                }

                break;
            }

            case eTokenType.operator_div:
            {
                if (v1Type == EvalType.Number & v2Type == EvalType.Number)
                {
                    mValueDelegate = NUM_DIV_NUM;
                    mEvalType      = EvalType.Number;
                }

                break;
            }

            case eTokenType.operator_percent:
            {
                if (v1Type == EvalType.Number & v2Type == EvalType.Number)
                {
                    mValueDelegate = NUM_PERCENT_NUM;
                    mEvalType      = EvalType.Number;
                }

                break;
            }

            case eTokenType.operator_and:
            case eTokenType.operator_or:
            {
                Convert(tokenizer, ref mParam1, EvalType.Boolean);
                Convert(tokenizer, ref mParam2, EvalType.Boolean);
                switch (tt)
                {
                case eTokenType.operator_or:
                {
                    mValueDelegate = BOOL_OR_BOOL;
                    mEvalType      = EvalType.Boolean;
                    break;
                }

                case eTokenType.operator_and:
                {
                    mValueDelegate = BOOL_AND_BOOL;
                    mEvalType      = EvalType.Boolean;
                    break;
                }
                }

                break;
            }
            }

            if (mValueDelegate == null)
            {
                tokenizer.RaiseError("Cannot apply the operator " + tt.ToString().Replace("operator_", "") + " on " + v1Type.ToString() + " and " + v2Type.ToString());
            }
        }
Пример #2
0
 public bool Equals(EvalType right)
 {
     return Value == right.ToString();
 }