ParseToken() protected method

Parse the specified tokenList and curIndex. overloaded by child types to do there own specific parsing.
protected ParseToken ( List tokenList, int &curIndex, Equation owner ) : void
tokenList List Token list.
curIndex int Current index.
owner Equation the equation that this node is part of. required to pull function delegates out of the dictionary
return void
Beispiel #1
0
        /// <summary>
        /// Given a list of tokens and the index, get an operator node based on whatever is at that index.
        /// </summary>
        /// <returns>The oper node, or null if it hit the end of the equation.</returns>
        /// <param name="tokenList">Token list.</param>
        /// <param name="curIndex">Current index.</param>
        /// <param name="owner">the equation that this node is part of.  required to pull function delegates out of the dictionary</param>
        static protected BaseNode ParseOperNode(List <Token> tokenList, ref int curIndex, Equation owner)
        {
            Debug.Assert(null != tokenList);
            Debug.Assert(null != owner);
            Debug.Assert(curIndex < tokenList.Count);

            //what kind of token do I have at that index?
            switch (tokenList[curIndex].TypeOfToken)
            {
            case TokenType.Operator:
            {
                //ok create an operator node
                OperatorNode operNode = new OperatorNode();

                //parse into that node
                operNode.ParseToken(tokenList, ref curIndex, owner);

                //return the thing
                return(operNode);
            }

            case TokenType.CloseParen:
            {
                //close paren, just eat it and return null.  It means this equation is finished parsing
                curIndex++;
                return(null);
            }

            default:
            {
                //should just be close paren nodes in here, which we should never get
                throw new FormatException("Expected a \"operator\" token, but got a " + tokenList[curIndex].TypeOfToken.ToString());
            }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Given a list of tokens and the index, get an operator node based on whatever is at that index.
        /// </summary>
        /// <returns>The oper node, or null if it hit the end of the equation.</returns>
        /// <param name="tokenList">Token list.</param>
        /// <param name="curIndex">Current index.</param>
        /// <param name="owner">the equation that this node is part of.  required to pull function delegates out of the dictionary</param>
        protected static BaseNode ParseOperNode(List<Token> tokenList, ref int curIndex, Equation owner)
        {
            Debug.Assert(null != tokenList);
            Debug.Assert(null != owner);
            Debug.Assert(curIndex < tokenList.Count);

            //what kind of token do I have at that index?
            switch (tokenList[curIndex].TypeOfToken)
            {
                case TokenType.Operator:
                {
                    //ok create an operator node
                    OperatorNode operNode = new OperatorNode();

                    //parse into that node
                    operNode.ParseToken(tokenList, ref curIndex, owner);

                    //return the thing
                    return operNode;
                }

                case TokenType.CloseParen:
                {
                    //close paren, just eat it and return null.  It means this equation is finished parsing
                    curIndex++;
                    return null;
                }

                default:
                {
                    //should just be close paren nodes in here, which we should never get
                    throw new FormatException("Expected a \"operator\" token, but got a " + tokenList[curIndex].TypeOfToken.ToString());
                }
            }
        }