private void ComputeTree() { ToList(); if (!processingFailed) { treeOperation = ComputeSubTree(listeTokens); } }
public override bool ToSubTree(LinkedList <AnodeAst> list, LinkedListNode <AnodeAst> currentNode) { if (hasError) { return(true); } LinkedListNode <AnodeAst> numberNode; if (sideNumbers[content] == sidesNumberEnum.LEFT) { numberNode = currentNode.Previous; } else { numberNode = currentNode.Next; } if (numberNode == null) { logger.Info("String opération not correct"); hasError = true; } else { // création de l'arbre ChildNode = numberNode.Value; // Delete childNode from the list hasError |= !list.Remove(ChildNode); } // dé-marquage du noeud : il doit maintenant être considéré comme un sous-arbre. IsTree = true; logger.Info(string.Format("Function to sub tree {0}, node = {1}", content, ChildNode.EvalNode())); return(hasError); }
private bool ComputeParentheses(LinkedList <AnodeAst> list) { if (processingFailed) { return(false); } LinkedListNode <AnodeAst> openingParenthesis = FindNode(list, e => e.Value.IsParentheseOuvrante()); LinkedListNode <AnodeAst> closingParenthesis = null; LinkedListNode <AnodeAst> currentNode = openingParenthesis; int parenthesisCount = 0; bool foundParenthesis = false; // Find the opening and closing parenthesis : // Find a subset : From (3+(2+5))+(1+2) : extract first (3+(2+5)) and then (1+2) while (currentNode != null) { if (currentNode.Value.IsParentheseOuvrante()) { // +1 pour parenthese ouvrante ++parenthesisCount; } else if (currentNode.Value.IsParentheseFermante()) { // -1 pour parenthese fermante --parenthesisCount; if (parenthesisCount == 0) { closingParenthesis = currentNode; currentNode = list.Last; // get out of the loop } } currentNode = currentNode.Next; } // If we found parenthesis if (closingParenthesis != null) { foundParenthesis = true; var subList = new LinkedList <AnodeAst>(); // Isolate the operations inside the parenthesis currentNode = openingParenthesis.Next; while (currentNode != closingParenthesis) { subList.AddLast(currentNode.Value); currentNode = currentNode.Next; } // Compute operation AnodeAst resultNode = ComputeSubTree(subList); // add resultNode in list list.AddBefore(openingParenthesis, resultNode); // Delete nodes in list currentNode = openingParenthesis.Next; while (currentNode != closingParenthesis) { list.Remove(openingParenthesis); openingParenthesis = currentNode; currentNode = currentNode.Next; } list.Remove(openingParenthesis); list.Remove(currentNode); } return(foundParenthesis); }