Exemplo n.º 1
0
        private void LocalVariableDeclaratorNodeCheck(List <SyntaxisNode> list, int level)
        {
            foreach (SyntaxisNode item in list)
            {
                NodeIdentificator id = item.children[0] as NodeIdentificator;

                if (!SymMethod.CheckUnique(levelIdentifiers, id.token.GetText(), level))
                {
                    throw SymException.Show(SymExType.SimpleIdentify, id);
                }

                levelIdentifiers[level - 1].Add(new Identify(id, typeOfIdentify.Peremen));

                CheckNoneExistentNode(item.children[1], level);
            }
        }
Exemplo n.º 2
0
        private void ConstantDeclaratorNodeCheck(List <SyntaxisNode> list, int level, string className)
        {
            foreach (SyntaxisNode item in list)
            {
                NodeIdentificator id = item.children[0] as NodeIdentificator;

                if (!SymMethod.CheckUnique(levelIdentifiers, id.token.GetText(), level))
                {
                    throw SymException.Show(SymExType.SimpleIdentify, id);
                }

                if (id.token.GetText() == className)
                {
                    throw new System.Exception("Имя переменной не должно совпадать с именем класса: " + id.ToString());
                }

                levelIdentifiers[level - 1].Add(new Identify(id, typeOfIdentify.Peremen));

                CheckNoneExistentNode(item.children[1], level);
            }
        }
Exemplo n.º 3
0
        private void EnumNodeCheck(SyntaxisNode node, int level)
        {
            if (node.GetType() != typeof(EnumBodyNode))//EnumNode))
            {
                throw SymException.Show(SymExType.IncorrectNode, node);
            }

            levelIdentifiers.Insert(level - 1, new List <Identify>());

            foreach (SyntaxisNode item in node.children)
            {
                NodeIdentificator identify = item.children[0] as NodeIdentificator;

                if (!SymMethod.CheckUnique(levelIdentifiers, identify.token.GetText(), level))
                {
                    throw SymException.Show(SymExType.SimpleIdentify, identify);
                }

                levelIdentifiers[level - 1].Add(new Identify(identify, typeOfIdentify.Parameter));
            }
        }
Exemplo n.º 4
0
        public void GlobalNodeCheck(SyntaxisNode node)
        {
            if (node.GetType() != typeof(GlobalNode))
            {
                throw SymException.Show(SymExType.IncorrectNode, node);
            }

            //создаем первый уровень
            levelIdentifiers.Add(new List <Identify>());

            foreach (SyntaxisNode item in node.children)
            {
                //usingNode не учитываем
                if (item.GetType() == typeof(UsingNode))
                {
                    continue;
                }

                if (item.GetType() == typeof(NamespaceDeclarationNode))
                {
                    storage.Add(levelIdentifiers);
                    levelIdentifiers = new List <List <Identify> >();

                    NamespaceDeclarationNodeCheck(item, 1);

                    levelIdentifiers.Clear();
                    levelIdentifiers = storage[storage.Count - 1];
                    storage.RemoveAt(storage.Count - 1);
                    continue;
                }

                //ищем идентификатор
                NodeIdentificator identify = SymMethod.SearchForType(item.children, typeof(NodeIdentificator)) as NodeIdentificator;
                if (!SymMethod.CheckUnique(levelIdentifiers, identify.token.GetText(), 1))
                {
                    throw SymException.Show(SymExType.SimpleIdentify, identify);
                }

                if (item.GetType() == typeof(ClassNode))
                {
                    levelIdentifiers[0].Add(new Identify(identify, typeOfIdentify.Class));
                    storage.Add(levelIdentifiers);
                    levelIdentifiers = new List <List <Identify> >();

                    ClassNodeCheck(item, 1, identify.token.GetText());

                    levelIdentifiers.Clear();
                    levelIdentifiers = storage[storage.Count - 1];
                    storage.RemoveAt(storage.Count - 1);
                    continue;
                }

                if (item.GetType() == typeof(EnumNode))
                {
                    levelIdentifiers[0].Add(new Identify(identify, typeOfIdentify.Enum));
                    //сохраняем текущий набор идентификаторов для последующего применения
                    //т.к. в enum все должно начинаться с 1-го уровня.
                    storage.Add(levelIdentifiers);
                    levelIdentifiers = new List <List <Identify> >();

                    //EnumNodeCheck(item, 1);
                    EnumNodeCheck(item.children[item.children.Count - 1], 1);

                    //возвращаем все на место
                    levelIdentifiers.Clear();
                    levelIdentifiers = storage[storage.Count - 1];
                    storage.RemoveAt(storage.Count - 1);
                    continue;
                }

                if (item.GetType() == typeof(StructureNode))
                {
                    levelIdentifiers[0].Add(new Identify(identify, typeOfIdentify.Struct));

                    storage.Add(levelIdentifiers);
                    levelIdentifiers = new List <List <Identify> >();

                    StructureNodeCheck(item, 1, identify.token.GetText());

                    levelIdentifiers.Clear();
                    levelIdentifiers = storage[storage.Count - 1];
                    storage.RemoveAt(storage.Count - 1);
                }
            }

            levelIdentifiers.RemoveAt(0);
        }
Exemplo n.º 5
0
        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);
        }