protected Expression ParseCommon(Expression result) { while (!(AtEnd || Current == SyntaxToken.ParenClose || Current == SyntaxToken.Comma || GetOrderByDirection(Current).HasValue)) { var @operator = GetOperator(Current); if ([email protected]) { throw new ODataException(ErrorMessages.Parser_ExpectedOperator); } else if (!OperatorUtil.IsBinary(@operator.Value)) { throw new ODataException(ErrorMessages.Parser_ExpectedBinaryOperator); } MoveNext(); ExpectAny(); var right = ParseCommonItem(); // Apply operator precedence var binary = result as BinaryExpression; if (binary != null && binary.Operator < @operator.Value) { result = CreateBinary( @operator.Value, result, ParseCommon(right) ); } else if (binary != null) { result = Rebalance( binary, @operator.Value, ParseCommon(right) ); } else { result = CreateBinary( @operator.Value, result, right ); } } return(result); }
private Expression CreateBinary(Operator @operator, Expression left, Expression right) { if (OperatorUtil.IsLogical(@operator)) { return(new LogicalExpression(@operator, left, right)); } else if (OperatorUtil.IsCompare(@operator)) { return(new ComparisonExpression(@operator, left, right)); } else if (OperatorUtil.IsArithmetic(@operator)) { return(new ArithmeticExpression(@operator, left, right)); } else { throw new NotSupportedException(); } }