Example #1
0
        public opCode Parse(string str)
        {
            if (str == null)
            {
                str = string.Empty;
            }
            mTokenizer = new tokenizer(this, str);
            mTokenizer.NextToken();
            opCode res = ParseExpr(null /* TODO Change to default(_) if this is not a reference type */, ePriority.none);

            if (mTokenizer.type == eTokenType.end_of_formula)
            {
                if (res == null)
                {
                    res = new opCodeImmediate(EvalType.String, string.Empty);
                }
                return(res);
            }
            else
            {
                mTokenizer.RaiseUnexpectedToken();
            }

            return(res);
        }
Example #2
0
 protected internal void Convert(tokenizer tokenizer, ref opCode param1, EvalType EvalType)
 {
     if (param1.EvalType != EvalType)
     {
         if (param1.CanReturn(EvalType))
         {
             param1 = new opCodeConvert(tokenizer, param1, EvalType);
         }
         else
         {
             tokenizer.RaiseError("Cannot convert " + param1.Name + " into " + EvalType);
         }
     }
 }
Example #3
0
        protected internal static opCode GetNew(tokenizer tokenizer, object baseObject, System.Reflection.MemberInfo method, IList <iEvalTypedValue> @params)
        {
            opCode o;

            o = new opCodeCallMethod(baseObject, method, @params);

            if (o.EvalType != EvalType.Object && o.SystemType != Globals.GetSystemType(o.EvalType))
            {
                return(new opCodeConvert(tokenizer, o, o.EvalType));
            }
            else
            {
                return(o);
            }
        }
Example #4
0
        public opCodeConvert(tokenizer tokenizer, iEvalTypedValue param1, EvalType EvalType)
        {
            mParam1 = param1;
            mParam1.ValueChanged += mParam1_ValueChanged;
            switch (EvalType)
            {
            case EvalType.Boolean:
            {
                mValueDelegate = TBool;
                mEvalType      = EvalType.Boolean;
                break;
            }

            case EvalType.Date:
            {
                mValueDelegate = TDate;
                mEvalType      = EvalType.Date;
                break;
            }

            case EvalType.Number:
            {
                mValueDelegate = TNum;
                mEvalType      = EvalType.Number;
                break;
            }

            case EvalType.String:
            {
                mValueDelegate = TStr;
                mEvalType      = EvalType.String;
                break;
            }

            default:
            {
                tokenizer.RaiseError("Cannot convert " + param1.SystemType.Name + " to " + EvalType);
                break;
            }
            }
        }
Example #5
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());
            }
        }