private void StructureNodeCheck(SyntaxisNode node, int level, string structName) { List <SyntaxisNode> notFoundReserve = notFoundPerem; notFoundPerem = new List <SyntaxisNode>(); if (node.GetType() != typeof(StructureNode)) { throw SymException.Show(SymExType.IncorrectNode, node); } levelIdentifiers.Insert(level - 1, new List <Identify>()); StructureBodyNode _classBody = SymMethod.SearchForType(node.children, typeof(StructureBodyNode)) as StructureBodyNode; foreach (SyntaxisNode item in _classBody.children) { if (item.GetType() == typeof(ConstantDeclarationNode)) { int Pos = SymMethod.SearchPos(item.children, typeof(ConstantDeclaratorNode)); List <SyntaxisNode> list = SymMethod.Copy(item.children, Pos); ConstantDeclaratorNodeCheck(list, level, structName); continue; } if (item.GetType() == typeof(FieldDeclarationNode)) { int Pos = SymMethod.SearchPos(item.children, typeof(VariableDeclaratorNode)); List <SyntaxisNode> list = SymMethod.Copy(item.children, Pos); ConstantDeclaratorNodeCheck(list, level, structName);//FieldDeclarationNodeCheck(list, level, className); continue; } if (item.GetType() == typeof(ConstructorDeclarationNode)) { NodeIdentificator identify = SymMethod.SearchForType(item.children, typeof(NodeIdentificator)) as NodeIdentificator; if (identify.token.GetText() != structName) { throw new System.Exception("Неправильное имя конструктора: " + identify.ToString()); } //ProgrammBlockNode pbNode var pb = SymMethod.SearchForType(item.children, typeof(ProgrammBlockNode)); if (pb != null) { ProgrammBlockNodeCheck(pb, level + 1); } } if (item.GetType() == typeof(MethodDeclarationNode)) { NodeIdentificator identify = SymMethod.SearchForType(item.children, typeof(NodeIdentificator)) as NodeIdentificator; if (identify.token.GetText() == structName) { throw new System.Exception("Имя метода не должно совпадать с именем класса: " + identify.ToString()); } //ProgrammBlockNode pbNode var pb = SymMethod.SearchForType(item.children, typeof(ProgrammBlockNode)); if (pb != null) { ProgrammBlockNodeCheck(pb, level + 1); } } } //проверка на ненайденные identify. Обязательно в конце класса или структуры foreach (SyntaxisNode item in notFoundPerem) { if (SymMethod.CheckUnique(levelIdentifiers, item.token.GetText(), level)) { throw SymException.Show(SymExType.NonexistentIdentify, item); } } //удаление данных notFoundPerem = notFoundReserve; levelIdentifiers.RemoveAt(level - 1); }
private void ProgrammBlockNodeCheck(SyntaxisNode programmBlock, int level, bool createNewLevel = true) { if (programmBlock.GetType() != typeof(ProgrammBlockNode)) { throw SymException.Show(SymExType.IncorrectNode, programmBlock); } if (createNewLevel) { levelIdentifiers.Insert(level - 1, new List <Identify>()); } foreach (SyntaxisNode item in programmBlock.children) { if (item.GetType() == typeof(DeclarationStatementNode)) { int pos = SymMethod.SearchPos(item.children, typeof(LocalVariableDeclaratorNode)); List <SyntaxisNode> list = SymMethod.Copy(item.children, pos); LocalVariableDeclaratorNodeCheck(list, level); continue; } if (item.GetType() == typeof(ProgrammBlockNode)) { ProgrammBlockNodeCheck(item, level + 1); continue; } if (item.GetType() == typeof(AssignmentNode)) { CheckNoneExistentNode(item.children[0], level); //identify CheckNoneExistentNode(item.children[1], level); //assigment part continue; } if (item.GetType() == typeof(IfStatementNode)) { CheckNoneExistentNode(item.children[0], level); //условие for (int i2 = 1; i2 < item.children.Count; i2++) { if (item.children[i2].GetType() != typeof(ProgrammBlockNode)) { ProgrammBlockNodeCheck( new ProgrammBlockNode() { children = new List <SyntaxisNode>() { item.children[i2] } }, level + 1); } else { ProgrammBlockNodeCheck(item.children[i2], level + 1); } } continue; } if (item.GetType() == typeof(SwitchStatementNode)) { CheckNoneExistentNode(item.children[0], level); //переменная SwitchBlockCheck(item.children[1], level + 1); } if (item.GetType() == typeof(WhileStatementNode)) { CheckNoneExistentNode(item.children[0], level); ProgrammBlockNodeCheck(item.children[1], level + 1); } if (item.GetType() == typeof(DoStatementNode)) { ProgrammBlockNodeCheck(item.children[0], level + 1); CheckNoneExistentNode(item.children[1], level); } //if (item.GetType() == typeof(ForStatementNode)) //{ // int pos = 0; // if (item.children[pos].GetType() != typeof(EmptyStatementNode)) // { // ForInitializerCheck(item.children[pos], level); // pos++; // } // pos++; // if (item.children[pos].GetType() != typeof(EmptyStatementNode)) // { // For_Condition(item.children[pos], level); // pos++; // } // pos++; // if (item.children[pos].GetType() == typeof(Statement_Expression_List)) // { // StatementExpressionListCheck(item.children[pos], level); // pos++; // } // if(item.children[pos].GetType() != typeof(ProgrammBlockNode)) // ProgrammBlockNodeCheck(new ProgrammBlockNode() // { // children = new List<SyntaxisNode>() // { item.children[pos] } // }, // level + 1); // else // ProgrammBlockNodeCheck(item.children[pos], level + 1); //} //добавь continie для continue и break //для return //все остальное смотреть через CheckNoneExistentNode } if (createNewLevel) { levelIdentifiers.RemoveAt(level - 1); } }