private void AddDefinitionsInUpperStatementList(syntax_tree_node currentNode, IEnumerable <statement> statementsToAdd) { var definitionsAdded = false; var ascendants = currentNode.AscendantNodes(true).ToArray(); // Объявление переменной в ближайшем statement_list for (int i = 0; i < ascendants.Length; i++) { if (ascendants[i] is statement_list statements) { statements.InsertBefore( ascendants[i - 1] as statement, statementsToAdd); definitionsAdded = true; break; } } Debug.Assert(definitionsAdded, "Couldn't add definitions"); }