Exemplo n.º 1
0
 /// <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.");
     }
 }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        /// <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.");
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <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;
            }
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        /// <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();
        }
Exemplo n.º 11
0
 public override bool IsMatch(Parser.Token tkn)
 {
     return(tkn.ToString() == "<=");
 }
Exemplo n.º 12
0
 /// <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);