/// <summary>
 /// CheckParms( Parser.Token, CValue) - This method makes certain the single argument is non-null.
 ///		Raises an exception if it is.
 /// </summary>
 /// <param name="oToken">Parser.Token object</param>
 /// <param name="arg1">CValue argument</param>
 private void CheckParms(Parser.Token oToken, CValue arg1)
 {
     if (arg1 == null)
     {
         throw new ApplicationException("Argument not supplied near " + oToken.ToString() + " operation.");
     }
 }
        /// <summary>
        /// SetFunction(string): Sets the current function to a passed string.
        /// </summary>
        /// <param name="sEquation">string representing the function being used</param>
        public void SetFunction(string sEquation)
        {
            m_currentToken = null;
            m_nextToken    = null;

            m_sEquation = sEquation;
            m_Function  = null;
            InitFunctions();
        }
        /// <summary>
        /// OpFactor(...): Reads the passed operator, identifies the associated implementation object
        ///		and requests an operation object to be used in evaluating the equation.
        /// </summary>
        /// <param name="oSourceOp">Parser.Token object representing the operator in question.</param>
        /// <param name="oValue1">The first value object to be operated on.</param>
        /// <param name="oValue2">The second value object to be operated on.</param>
        /// <returns>CValue object representing an operation.</returns>
        private CValue OpFactory(Parser.Token oSourceOp, CValue oValue1, CValue oValue2)
        {
            foreach (COperator oOp in m_aOps)
            {
                if (oOp.IsMatch(oSourceOp))
                {
                    return(oOp.Factory(oValue1, oValue2));
                }
            }

            throw new ApplicationException("Invalid operator in equation.");
        }
        /// <summary>
        /// AddSub(): Detects the operation to perform addition or substraction.
        /// </summary>
        /// <returns>CValue object representing an operation.</returns>
        private CValue AddSub()
        {
            CValue oValue = MultDiv();

            while (m_currentToken == "+" || m_currentToken == "-")
            {
                Parser.Token oOp = m_currentToken;
                PositionNextToken();

                CValue oNextVal = MultDiv();

                CheckParms(oOp, oValue, oNextVal);
                oValue = OpFactory(oOp, oValue, oNextVal);
            }

            return(oValue);
        }
        /// <summary>
        /// Power():  Detects the operation to raise one number to the power
        ///		of another (a^2).
        /// </summary>
        /// <returns>CValue object representing an operation.</returns>
        private CValue Power()
        {
            CValue oValue = Sign();

            while (m_currentToken == "^")
            {
                Parser.Token oOp = m_currentToken;

                PositionNextToken();

                CValue oNextVal = Sign();

                CheckParms(oOp, oValue, oNextVal);
                oValue = OpFactory(oOp, oValue, oNextVal);
            }

            return(oValue);
        }
        /// <summary>
        /// PositionNextToken():  Manipulates the current Token position forward in the chain of tokens
        ///		discovered by the parser.
        /// </summary>
        private void PositionNextToken()
        {
            if (m_currentToken == null)
            {
                if (!m_enumTokens.MoveNext())
                {
                    throw new ApplicationException("Invalid equation.");
                }

                m_nextToken = (Parser.Token)m_enumTokens.Current;
            }

            m_currentToken = m_nextToken;

            if (!m_enumTokens.MoveNext())
            {
                m_nextToken = new Parser.Token();
            }
            else
            {
                m_nextToken = (Parser.Token)m_enumTokens.Current;
            }
        }
        /// <summary>
        /// Relational():  Detects the operation to perform a relational operator (>, <, <=, etc.).
        /// </summary>
        /// <returns>CValue object representing an operation.</returns>
        private CValue Relational()
        {
            CValue oValue = AddSub();

            while (m_currentToken == "&&" ||
                   m_currentToken == "||" ||
                   m_currentToken == "==" ||
                   m_currentToken == "<" ||
                   m_currentToken == ">" ||
                   m_currentToken == "<=" ||
                   m_currentToken == ">=" ||
                   m_currentToken == "!=" ||
                   m_currentToken == "<>")
            {
                Parser.Token oOp = m_currentToken;
                PositionNextToken();
                CValue oNextVal = Relational();

                CheckParms(oOp, oValue, oNextVal);
                oValue = OpFactory(oOp, oValue, oNextVal);
            }

            return(oValue);
        }
        /// <summary>
        /// Sign():  This method detects the existence of sign operators before
        ///		a number or variable.
        /// </summary>
        /// <returns>CValue object representing an operation.</returns>
        private CValue Sign()
        {
            bool bNeg = false;

            Parser.Token oToken = null;
            if (m_currentToken == "+" || m_currentToken == "-")
            {
                oToken = m_currentToken;
                bNeg   = (m_currentToken == "-");
                PositionNextToken();
            }
            //CValue oFunc = Function();
            // sdh: should be function when ready.
            CValue oFunc = Paren();


            if (bNeg)
            {
                CheckParms(oToken, oFunc);
                oFunc = new CSignNeg(oFunc);
            }

            return(oFunc);
        }
        /// <summary>
        /// PositionNextToken():  Manipulates the current Token position forward in the chain of tokens
        ///		discovered by the parser.
        /// </summary>
        private void PositionNextToken()
        {
            if(  m_currentToken == null)
            {
                if( !m_enumTokens.MoveNext() )
                    throw new ApplicationException( "Invalid equation." );

                m_nextToken = (Parser.Token)m_enumTokens.Current;
            }

            m_currentToken = m_nextToken;

            if( !m_enumTokens.MoveNext() )
                m_nextToken = new Parser.Token();
            else
                m_nextToken = (Parser.Token)m_enumTokens.Current;
        }
        /// <summary>
        /// SetFunction(string): Sets the current function to a passed string.
        /// </summary>
        /// <param name="sEquation">string representing the function being used</param>
        public void SetFunction( string sEquation )
        {
            m_currentToken = null;
            m_nextToken = null;

            m_sEquation = sEquation;
            m_Function = null;
            InitFunctions();
        }
 public override bool IsMatch(Parser.Token tkn)
 {
     return(tkn.ToString() == "<=");
 }
 /// <summary>
 /// IsMatch(): accepts an operation token and identifies if the implemented
 ///		operator class is responsible for it.  This allows for multiple operators
 ///		to represent a given operation (i.e. != and <> both represent the "not-equal" case.
 /// </summary>
 /// <param name="tkn">Parser.Token containing the operator in question</param>
 /// <returns>bool returning true if the object is reponsible for implementing the operator at hand.</returns>
 public abstract bool IsMatch(Parser.Token tkn);