private void AddTreeNode(TreeNode parent, STNode node) { var newNode = parent.Nodes.Add(node.Type.ToString() + ": " + node.ToString()); newNode.Tag = node; if (node.Children != null) { foreach (var child in node.Children) { AddTreeNode(newNode, child); } } }
private void ConstructSyntaxTree() { syntaxTree.Nodes.Clear(); txtErrorMessage.Text = string.Empty; txtGeneratedFormula.Text = string.Empty; try { currentSyntaxTree = Parser.Parse(this.Workbook as Workbook, this.Cell, txtInput.Text); if (currentSyntaxTree != null) { syntaxTree.Nodes.Add(currentSyntaxTree.Type.ToString() + ": " + currentSyntaxTree.ToString()).Tag = currentSyntaxTree; if (currentSyntaxTree.Children != null) { foreach (var node in currentSyntaxTree.Children) { AddTreeNode(syntaxTree.Nodes[0], node); } } syntaxTree.ExpandAll(); } GenerateFormula(); } catch (FormulaParseException ex) { StringBuilder sb = new StringBuilder(); //sb.AppendLine(txtInput.Text); sb.Append(new string(' ', ex.Index)); sb.AppendLine("^"); sb.Append(ex.Message); txtErrorMessage.Text = sb.ToString(); currentSyntaxTree = null; } }