public static BaseNode Parse(List<Token> tokenList, ref int curIndex, Equation owner)
{
Debug.Assert(null != tokenList);
Debug.Assert(null != owner);
Debug.Assert(curIndex < tokenList.Count);
//first get a value, which will be a number, function, param, or equation node
BaseNode myNumNode = BaseNode.ParseValueNode(tokenList, ref curIndex, owner);
Debug.Assert(null != myNumNode);
//if there are any tokens left, get an operator
if (curIndex < tokenList.Count)
{
BaseNode myOperNode = BaseNode.ParseOperNode(tokenList, ref curIndex, owner);
if (null != myOperNode)
{
//add that node to the end of the list
myNumNode.AppendNextNode(myOperNode);
//If it was able to pull an operator out, there has to be a number after it.
if (curIndex >= tokenList.Count)
{
throw new FormatException("Can't end an equation with an operator.");
}
//Recurse into the parse function and sort out the rest of the tokens
BaseNode nextNode = BaseNode.Parse(tokenList, ref curIndex, owner);
Debug.Assert(null != nextNode);
//add that node to the end of the list
myOperNode.AppendNextNode(nextNode);
}
}
//return the head node that I found
return myNumNode;
}