This is a single node of the equation. All the other node types inherit from this one.
Exemplo n.º 1
0
        /// <summary>
        /// Parse the specified equationText.
        /// </summary>
        /// <param name="equationText">Equation text.</param>
        public void Parse(string equationText)
        {
            //grab the equation text
            TextEquation = equationText;

            //straight up tokenize the equation: operators, numbers, parens, functions, params
            List<Token> tokenList = Tokenize(equationText);

            //sort out those tokens into a linked list of equation nodes
            int index = 0;
            BaseNode listRootNode = BaseNode.Parse(tokenList, ref index, this);

            //take that linked list and bend it into a binary tree.  Grab the root node
            RootNode = listRootNode.Treeify();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Make this node into a head node.
 /// </summary>
 protected void MakeHead()
 {
     //note that if there is a prev node, it has to take care of it's own pointers!
     Prev = null;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Parse the specified tokenList and curIndex.
        /// overloaded by child types to do there own specific parsing.
        /// </summary>
        /// <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 override void ParseToken(List<Token> tokenList, ref int curIndex, Equation owner)
        {
            Debug.Assert(null != tokenList);
            Debug.Assert(null != owner);
            Debug.Assert(curIndex < tokenList.Count);

            //parse the equation into our subnode
            SubEquation = BaseNode.Parse(tokenList, ref curIndex, owner);

            //if some smart ass types in () the parse method wouldve returned null.
            //it should evaluate to 0 in that case, so create a number node and set the value.
            if (null == SubEquation)
            {
                NumberNode fakeNode = new NumberNode();
                fakeNode.NumberValue = 0.0f;
                SubEquation = fakeNode;
            }
            Debug.Assert(null != SubEquation);

            //treeify the subequation so we can solve it
            SubEquation = SubEquation.Treeify();
            Debug.Assert(null != SubEquation);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Appends the next node.
 /// </summary>
 /// <param name="nextNode">Next node.</param>
 public void AppendNextNode(BaseNode nextNode)
 {
     Debug.Assert(null != nextNode);
     nextNode.Prev = this;
     this.Next = nextNode;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Appends the next node.
 /// </summary>
 /// <param name="nextNode">Next node.</param>
 public void AppendNextNode(BaseNode nextNode)
 {
     Debug.Assert(null != nextNode);
     nextNode.Prev = this;
     this.Next     = nextNode;
 }