/// <summary>
        /// Tries to perform the operation from finding the operator in the mapping.
        /// </summary>
        public static Boolean TryPerformOverFind(Value left, Value right, BinaryOperatorMappingList mapping, out Value value)
        {
            var least = default(Func <Value, Value, Value>);

            for (var i = 0; i != mapping.Count; i++)
            {
                var hit = mapping[i].IsMapping(left, right);

                if (hit == MapHit.Direct)
                {
                    value = mapping[i].Map(left, right);
                    return(true);
                }
                else if (hit == MapHit.Indirect)
                {
                    least = mapping[i].Map;
                }
            }

            if (least != null)
            {
                value = least(left, right);
                return(true);
            }

            value = null;
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Tries to perform the operation from finding the operator in the mapping.
        /// </summary>
        public static Boolean TryPerformOverFind(Value left, Value right, BinaryOperatorMappingList mapping, out Value value)
        {
            var least = default(Func<Value, Value, Value>);

            for (var i = 0; i != mapping.Count; i++)
            {
                var hit = mapping[i].IsMapping(left, right);

                if (hit == MapHit.Direct)
                {
                    value = mapping[i].Map(left, right);
                    return true;
                }
                else if (hit == MapHit.Indirect)
                {
                    least = mapping[i].Map;
                }
            }

            if (least != null)
            {
                value = least(left, right);
                return true;
            }

            value = null;
            return false;
        }
Exemple #3
0
 /// <summary>
 /// Provides registration of operator's Mappings list
 /// </summary>
 /// <param name="symbol">The symbol of the operator, e.g., +.</param>
 /// <param name="list">The BinaryMapping list of the operator</param>
 public static void BinaryOperator(String symbol, BinaryOperatorMappingList list)
 {
     var mapping = default(BinaryOperatorMappingList);
     if (!BinaryMappings.TryGetValue(symbol, out mapping))
     {
         BinaryMappings.Add(symbol, list);
     }
 }
        /// <summary>
        /// Provides registration of operator's Mappings list
        /// </summary>
        /// <param name="symbol">The symbol of the operator, e.g., +.</param>
        /// <param name="list">The BinaryMapping list of the operator</param>
        public static void BinaryOperator(String symbol, BinaryOperatorMappingList list)
        {
            var mapping = default(BinaryOperatorMappingList);

            if (!BinaryMappings.TryGetValue(symbol, out mapping))
            {
                BinaryMappings.Add(symbol, list);
            }
        }
        /// <summary>
        /// Performs the operation from finding the operator in the mapping.
        /// </summary>
        public Value PerformOverFind(Value left, Value right, BinaryOperatorMappingList mapping)
        {
            var ret = default(Value);

            if (!TryPerformOverFind(left, right, mapping, out ret))
            {
                throw new YAMPOperationInvalidException(Op, left, right);
            }

            return(ret);
        }
Exemple #6
0
        /// <summary>
        /// Performs the operation from finding the operator in the mapping.
        /// </summary>
        public Value PerformOverFind(Value left, Value right, BinaryOperatorMappingList mapping)
        {
            var ret = default(Value);

            if (!TryPerformOverFind(left, right, mapping, out ret))
                throw new YAMPOperationInvalidException(Op, left, right);

            return ret;
        }