コード例 #1
0
 protected virtual void EmitMathExpression(NPathMathExpression mathExpression)
 {
     Write("(");
     EmitExpression(mathExpression.LeftOperand);
     Write(" " + mathExpression.Operator + " ");
     EmitExpression(mathExpression.RightOperand);
     Write(")");
 }
コード例 #2
0
        private NPathMathExpression ParseMathOperator(IValue leftOperand)
        {
            NPathMathExpression math = new NPathMathExpression();

            math.LeftOperand = leftOperand;

            Token currentToken = tokenizer.GetCurrentToken();

            #region parse operator

            if (currentToken.IsType("add"))
            {
                math.Operator = "add";
            }
            if (currentToken.IsType("minus"))
            {
                math.Operator = "minus";
            }
            if (currentToken.IsType("mul"))
            {
                math.Operator = "mul";
            }
            if (currentToken.IsType("div"))
            {
                math.Operator = "div";
            }
            if (currentToken.IsType("xor"))
            {
                math.Operator = "xor";
            }
            if (currentToken.IsType("mod"))
            {
                math.Operator = "mod";
            }
//			if (currentToken.IsType("and"))
//				math.Operator = "and";
//			if (currentToken.IsType("or"))
//				math.Operator = "or";

            #endregion

            tokenizer.MoveNext();

            if (CurrentIsValue())
            {
                math.RightOperand = ParseExpression();
            }
            else
            {
                //unknown value?
                throw GetExpectedTokenException("Value");
            }

            return(math);
        }
コード例 #3
0
 protected virtual void EmitMathExpression(NPathMathExpression mathExpression)
 {
     Write("(");
     EmitExpression(mathExpression.LeftOperand);
     Write(" " + mathExpression.Operator + " ");
     EmitExpression(mathExpression.RightOperand);
     Write(")");
 }
コード例 #4
0
        protected virtual object EvalMathExpression(object item, NPathMathExpression mathExpression)
        {
            object leftValue  = EvalValue(item, mathExpression.LeftOperand);
            object rightValue = EvalValue(item, mathExpression.RightOperand);

            if (leftValue is double && rightValue is double)
            {
                double leftDouble  = (double)leftValue;
                double rightDouble = (double)rightValue;
                switch (mathExpression.Operator)
                {
                case "add":
                {
                    return(leftDouble + rightDouble);
                }

                case "minus":
                {
                    return(leftDouble - rightDouble);
                }

                case "mul":
                {
                    return(leftDouble * rightDouble);
                }

                case "div":
                {
                    return(leftDouble / rightDouble);
                }

                default:
                    throw new Exception("unknown expression");                             // do not localize
                }
            }
            else if (IsStringOrNull(leftValue) && IsStringOrNull(rightValue))
            {
                string leftString  = (string)leftValue;
                string rightString = (string)rightValue;

                switch (mathExpression.Operator)
                {
                case "add":
                {
                    //is this how it behaves in SQL ????
                    if (leftString == null && rightString == null)
                    {
                        return(null);
                    }
                    else if (leftString != null && rightString == null)
                    {
                        return(leftString);
                    }
                    else if (leftString == null && rightString != null)
                    {
                        return(rightString);
                    }
                    else
                    {
                        return(leftString + rightString);
                    }
                }

                default:
                    throw new Exception("unknown expression");                             // do not localize
                }
            }

            throw new Exception("unknown expression");             // do not localize
        }
コード例 #5
0
        protected virtual void EmitExpression(IValue expression)
        {
            if (expression is NPathNotExpression)
            {
                NPathNotExpression value = (NPathNotExpression)expression;
                EmitNot(value);
            }
            if (expression is NPathFunction)
            {
                NPathFunction value = (NPathFunction)expression;
                EmitFunction(value);
            }
            if (expression is NPathParameter)
            {
                NPathParameter value = (NPathParameter)expression;
                EmitParameter(value);
            }
            if (expression is NPathNullValue)
            {
                NPathNullValue value = (NPathNullValue)expression;
                EmitNullValue(value);
            }
            if (expression is NPathBetweenExpression)
            {
                NPathBetweenExpression value = (NPathBetweenExpression)expression;
                EmitBetween(value);
            }
            if (expression is NPathBooleanValue)
            {
                NPathBooleanValue value = (NPathBooleanValue)expression;
                EmitBooleanValue(value);
            }
            if (expression is NPathDecimalValue)
            {
                NPathDecimalValue value = (NPathDecimalValue)expression;
                EmitDecimalValue(value);
            }
            if (expression is NPathDateTimeValue)
            {
                NPathDateTimeValue value = (NPathDateTimeValue)expression;
                EmitDateTimeValue(value);
            }
            if (expression is NPathGuidValue)
            {
                NPathGuidValue value = (NPathGuidValue)expression;
                EmitGuidValue(value);
            }
            if (expression is NPathStringValue)
            {
                NPathStringValue value = (NPathStringValue)expression;
                EmitStringValue(value);
            }
            if (expression is NPathIdentifier)
            {
                NPathIdentifier propertyPath = (NPathIdentifier)expression;
                EmitPropertyPath(propertyPath);
            }
            if (expression is NPathPropertyFilter)
            {
                NPathPropertyFilter propertyFilter = (NPathPropertyFilter)expression;
                EmitPropertyFilter(propertyFilter);
            }
            if (expression is NPathParenthesisGroup)
            {
                NPathParenthesisGroup parenthesisGroup = (NPathParenthesisGroup)expression;
                EmitParenthesisGroup(parenthesisGroup);
            }
            if (expression is NPathMathExpression)
            {
                NPathMathExpression mathExpression = (NPathMathExpression)expression;
                EmitMathExpression(mathExpression);
            }
            if (expression is NPathCompareExpression)
            {
                NPathCompareExpression compareExpression = (NPathCompareExpression)expression;
                EmitCompareExpression(compareExpression);
            }

            if (expression is NPathBooleanExpression)
            {
                NPathBooleanExpression boolExpression = (NPathBooleanExpression)expression;
                EmitBooleanExpression(boolExpression);
            }
            if (expression is NPathInExpression)
            {
                NPathInExpression value = (NPathInExpression)expression;
                EmitIn(value);
            }
            if (expression is NPathSearchFunction)
            {
                NPathSearchFunction value = (NPathSearchFunction)expression;
                EmitSearchFunction(value);
            }
        }
コード例 #6
0
        protected virtual object EvalMathExpression(object item, NPathMathExpression mathExpression)
        {
            object leftValue = EvalValue(item, mathExpression.LeftOperand);
            object rightValue = EvalValue(item, mathExpression.RightOperand);

            if (leftValue is double && rightValue is double)
            {
                double leftDouble = (double) leftValue;
                double rightDouble = (double) rightValue;
                switch (mathExpression.Operator)
                {
                    case "add":
                        {
                            return leftDouble + rightDouble;
                        }
                    case "minus":
                        {
                            return leftDouble - rightDouble;
                        }
                    case "mul":
                        {
                            return leftDouble*rightDouble;
                        }
                    case "div":
                        {
                            return leftDouble/rightDouble;
                        }
                    default:
                        throw new Exception("unknown expression"); // do not localize
                }
            }
            else if (IsStringOrNull(leftValue) && IsStringOrNull(rightValue))
            {
                string leftString = (string) leftValue;
                string rightString = (string) rightValue;

                switch (mathExpression.Operator)
                {
                    case "add":
                        {
                            //is this how it behaves in SQL ????
                            if (leftString == null && rightString == null)
                            {
                                return null;
                            }
                            else if (leftString != null && rightString == null)
                            {
                                return leftString;
                            }
                            else if (leftString == null && rightString != null)
                            {
                                return rightString;
                            }
                            else
                            {
                                return leftString + rightString;
                            }
                        }
                    default:
                        throw new Exception("unknown expression"); // do not localize
                }
            }

            throw new Exception("unknown expression"); // do not localize
        }
コード例 #7
0
		private SqlExpression EvalMath(NPathMathExpression mathExpression)
		{
			SqlExpression leftExpression = EvalExpression(mathExpression.LeftOperand);
			SqlExpression rightExpression = EvalExpression(mathExpression.RightOperand);

			SqlMathOperatorType mathOperator ;
			switch(mathExpression.Operator)
			{
				case "add":
					mathOperator = SqlMathOperatorType.Add;
					break;

				case "minus":
					mathOperator = SqlMathOperatorType.Subtract;
					break;

				case "div":
					mathOperator = SqlMathOperatorType.Divide;
					break;

				case "mul":
					mathOperator = SqlMathOperatorType.Multiply;
					break;
				default:
					throw new IAmOpenSourcePleaseImplementMeException("Operator not implemented");
			}

			

			SqlMathExpression predicate = new SqlMathExpression(leftExpression,mathOperator,rightExpression);
			
			return predicate;
		}
コード例 #8
0
        private NPathMathExpression ParseMathOperator(IValue leftOperand)
        {
            NPathMathExpression math = new NPathMathExpression();
            math.LeftOperand = leftOperand;

            Token currentToken = tokenizer.GetCurrentToken();

            #region parse operator

            if (currentToken.IsType("add"))
                math.Operator = "add";
            if (currentToken.IsType("minus"))
                math.Operator = "minus";
            if (currentToken.IsType("mul"))
                math.Operator = "mul";
            if (currentToken.IsType("div"))
                math.Operator = "div";
            if (currentToken.IsType("xor"))
                math.Operator = "xor";
            if (currentToken.IsType("mod"))
                math.Operator = "mod";
            //			if (currentToken.IsType("and"))
            //				math.Operator = "and";
            //			if (currentToken.IsType("or"))
            //				math.Operator = "or";

            #endregion

            tokenizer.MoveNext();

            if (CurrentIsValue())
            {
                math.RightOperand = ParseExpression();
            }
            else
            {
                //unknown value?
                throw GetExpectedTokenException("Value");
            }

            return math;
        }