Esempio n. 1
0
 public string cm_TypeToStr()
 {
     if (cf_Type == eTokenType.Null)
     {
         return("$");
     }
     return(cf_Type.ToString());
 }
Esempio n. 2
0
        private IList <iEvalTypedValue> ParseParameters(ref bool brackets)
        {
            IList <iEvalTypedValue> parameters = new List <iEvalTypedValue>();
            opCode     valueleft;
            eTokenType lClosing = eTokenType.none;

            if (mTokenizer.type == eTokenType.open_parenthesis || (mTokenizer.type == eTokenType.open_bracket & mEvaluator.Syntax == eParserSyntax.cSharp))
            {
                switch (mTokenizer.type)
                {
                case eTokenType.open_bracket:
                {
                    lClosing = eTokenType.close_bracket;
                    brackets = true;
                    break;
                }

                case eTokenType.open_parenthesis:
                {
                    lClosing = eTokenType.close_parenthesis;
                    break;
                }
                }

                mTokenizer.NextToken(); // eat the parenthesis
                do
                {
                    if (mTokenizer.type == lClosing)
                    {
                        // good we eat the end parenthesis and continue ...
                        mTokenizer.NextToken();
                        break;
                    }

                    valueleft = ParseExpr(null /* TODO Change to default(_) if this is not a reference type */, ePriority.none);
                    parameters.Add(valueleft);
                    if (mTokenizer.type == lClosing)
                    {
                        // good we eat the end parenthesis and continue ...
                        mTokenizer.NextToken();
                        break;
                    }
                    else if (mTokenizer.type == eTokenType.comma)
                    {
                        mTokenizer.NextToken();
                    }
                    else
                    {
                        mTokenizer.RaiseUnexpectedToken(lClosing.ToString() + " not found");
                    }
                }while (true);
            }
            return(parameters);
        }
Esempio n. 3
0
 internal void RaiseUnexpectedToken(string msg = null)
 {
     if (msg.Length == 0)
     {
         msg = "";
     }
     else
     {
         msg += "; ";
     }
     RaiseError(msg + "Unexpected " + type.ToString().Replace('_', ' ') + " : " + value.ToString());
 }
Esempio n. 4
0
 internal void RaiseWrongOperator(eTokenType tt, object ValueLeft, object valueRight, string msg = null)
 {
     if (msg.Length > 0)
     {
         msg.Replace("[op]", tt.GetType().ToString());
         msg += ". ";
     }
     msg = "Cannot apply the operator " + tt.ToString();
     if (ValueLeft == null)
     {
         msg += " on nothing";
     }
     else
     {
         msg += " on a " + ValueLeft.GetType().ToString();
     }
     if (valueRight != null)
     {
         msg += " and a " + valueRight.GetType().ToString();
     }
     RaiseError(msg);
 }
Esempio n. 5
0
	public opCodeBinary(tokenizer tokenizer, opCode param1, eTokenType tt, opCode param2)
	{
		mParam1 = param1;
		mParam2 = param2;

		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, 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, param1, ref 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, mParam1, ref EvalType.Boolean);
				Convert(tokenizer, mParam2, ref 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());
		}
	}
Esempio n. 6
0
	internal void RaiseWrongOperator(eTokenType tt, object ValueLeft, object valueRight, string msg) 
	{ 
		if (Strings.Len(msg) > 0) { 
			msg.Replace("[op]", tt.GetType().ToString()); 
			msg // ERROR: Unknown assignment operator ConcatString ; 
		} 
		msg = "Cannot apply the operator " + tt.ToString(); 
		if (ValueLeft == null) { 
			msg // ERROR: Unknown assignment operator ConcatString ; 
		} 
		else { 
			msg // ERROR: Unknown assignment operator ConcatString ; 
		} 
		if ((valueRight != null)) { 
			msg // ERROR: Unknown assignment operator ConcatString ; 
		} 
		RaiseError(msg); 
	}
Esempio n. 7
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());
            }
        }