Example #1
0
 private static void CheckBinaryOperatorNodeType <TLeft, TRight>(BinaryOperatorBindingParserNode node, BindingTokenType operatorType)
     where TLeft : BindingParserNode
     where TRight : BindingParserNode
 {
     Assert.IsTrue(node.Operator == operatorType);
     Assert.IsTrue(node.FirstExpression is TLeft);
     Assert.IsTrue(node.SecondExpression is TRight);
 }
Example #2
0
 private static void CheckBinaryOperatorNodeType <TLeft, TRight>(BinaryOperatorBindingParserNode node, BindingTokenType operatorType)
     where TLeft : BindingParserNode
     where TRight : BindingParserNode
 {
     Assert.AreEqual(operatorType, node.Operator);
     Assert.IsInstanceOfType(node.FirstExpression, typeof(TLeft));
     Assert.IsInstanceOfType(node.SecondExpression, typeof(TRight));
 }
Example #3
0
        protected override Expression VisitBinaryOperator(BinaryOperatorBindingParserNode node)
        {
            var left  = HandleErrors(node.FirstExpression, Visit);
            var right = HandleErrors(node.SecondExpression, Visit);

            ThrowOnErrors();

            ExpressionType eop;

            switch (node.Operator)
            {
            case BindingTokenType.AddOperator:
                eop = ExpressionType.Add;
                break;

            case BindingTokenType.SubtractOperator:
                eop = ExpressionType.Subtract;
                break;

            case BindingTokenType.MultiplyOperator:
                eop = ExpressionType.Multiply;
                break;

            case BindingTokenType.DivideOperator:
                eop = ExpressionType.Divide;
                break;

            case BindingTokenType.ModulusOperator:
                eop = ExpressionType.Modulo;
                break;

            case BindingTokenType.EqualsEqualsOperator:
                eop = ExpressionType.Equal;
                break;

            case BindingTokenType.LessThanOperator:
                eop = ExpressionType.LessThan;
                break;

            case BindingTokenType.LessThanEqualsOperator:
                eop = ExpressionType.LessThanOrEqual;
                break;

            case BindingTokenType.GreaterThanOperator:
                eop = ExpressionType.GreaterThan;
                break;

            case BindingTokenType.GreaterThanEqualsOperator:
                eop = ExpressionType.GreaterThanOrEqual;
                break;

            case BindingTokenType.NotEqualsOperator:
                eop = ExpressionType.NotEqual;
                break;

            case BindingTokenType.NullCoalescingOperator:
                eop = ExpressionType.Coalesce;
                break;

            case BindingTokenType.AndOperator:
                eop = ExpressionType.And;
                break;

            case BindingTokenType.AndAlsoOperator:
                eop = ExpressionType.AndAlso;
                break;

            case BindingTokenType.OrOperator:
                eop = ExpressionType.Or;
                break;

            case BindingTokenType.OrElseOperator:
                eop = ExpressionType.OrElse;
                break;

            case BindingTokenType.AssignOperator:
                eop = ExpressionType.Assign;
                break;

            default:
                throw new NotSupportedException($"unary operator { node.Operator } is not supported");
            }

            return(ExpressionHelper.GetBinaryOperator(left, right, eop));
        }