private FactoryResult TryGetFunction(string equationString, IEquationMember previousMember)
        {
            FactoryResult result = RegularExpressionParser(
                Function.RegularExpression,
                equationString,
                (x) => new Function(x));

            return(result);
        }
        /// <summary>
        /// If there is a match with the regExpression then a FactoryResult is returned
        /// </summary>
        /// <param name="regExpression">The string which represents the member the ie "+" or "sqrt"</param>
        /// <param name="equationString"></param>
        /// <param name="memberFactory">Given the matching string returns an IEquationMember</param>
        /// <returns>FactoryResult or null if no match found</returns>
        private FactoryResult RegularExpressionParser(string regExpression, string replaceExpression, string equationString,
                                                      Func <string, IEquationMember> memberFactory)
        {
            FactoryResult result = RegularExpressionParser(regExpression, equationString, (x) =>
            {
                x = Regex.Replace(x, replaceExpression, "");
                return(memberFactory(x));
            });

            return(result);
        }
        private FactoryResult TryToExtractANumber(string equationString, IEquationMember previousMember)
        {
            FactoryResult result = RegularExpressionParser(
                Number.RegularExpression,
                equationString,
                (x) => new Number(double.Parse(x)));

            if (result != null)
            {
                return(result);
            }

            return(RegularExpressionParser(
                       @"^\s*PI",
                       equationString,
                       (x) => new Number(Math.PI)));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="equationString"></param>
        /// <param name="previousOperator"></param>
        /// <param name="opt">null if BinaryOperator cannot be made</param>
        /// <returns>True if object can be created</returns>
        private FactoryResult TryGetBracket(string equationString)
        {
            FactoryResult result = RegularExpressionParser(
                Bracket.LeftBracket.RegularExpression,
                equationString,
                (x) => Bracket.LeftBracket);

            if (result != null)
            {
                return(result);
            }

            return(RegularExpressionParser(
                       Bracket.RightBracket.RegularExpression,
                       equationString,
                       (x) => Bracket.RightBracket));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="charArr">Changes only if a this method returns true</param>
 /// <param name="previousMember"></param>
 /// <param name="opt">null if BinaryOperator cannot be made</param>
 /// <returns>True if object can be created</returns>
 private FactoryResult TryGetBinaryOperator(string equationString, IEquationMember previousMember)
 {
     if (BinaryOperatorHasValidPreviousOperator(previousMember))
     {
         foreach (IOperatorMember obj in BinaryOperator.AllOperators)
         {
             FactoryResult result = RegularExpressionParser(
                 obj.RegularExpression,
                 equationString,
                 (x) => obj);
             if (result != null)
             {
                 return(result);
             }
         }
     }
     return(null);
 }
        internal FactoryResult CreateEquationMember(
            string equationString,
            IEquationMember previousMember,
            IList <string> parameterNames)
        {
            FactoryResult result          = null;
            string        refinedEquation = new Regex(@"\s").Replace(equationString, "");

            foreach (var fun in GetParsers(parameterNames))
            {
                result = fun(refinedEquation, previousMember);
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }