Exemplo n.º 1
0
        public static Exception Show(SymExType type, SyntaxisNode node)
        {
            switch (type)
            {
            case SymExType.IncorrectNode:
                return(new Exception("Unexpected node type: " + node.GetType() + "!"));

            case SymExType.SimpleIdentify:
                return(new Exception("This identify is already in use: " + node.token.ToString()));

            case SymExType.NonexistentIdentify:
                return(new Exception("This identify is not exist: " + node.token.ToString()));

            default:
                return(new Exception("Exception of checking a node: " + node.ToString() + "; Position: " + node.token.ToString()));
            }
        }
Exemplo n.º 2
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.º 3
0
        private void SwitchBlockCheck(SyntaxisNode node, int level)
        {
            if (node.GetType() != typeof(SwitchBlockNode))
            {
                throw SymException.Show(SymExType.IncorrectNode, node);
            }

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

            foreach (SyntaxisNode item in node.children)
            {
                if (item.token.value.Equals(KeyWords.KW.kwCase))
                {
                    CheckNoneExistentNode(item.children[0], level); //переменная

                    ProgrammBlockNodeCheck(new ProgrammBlockNode()
                    {
                        children = new List <SyntaxisNode>()
                        {
                            item.children[1]
                        }
                    },
                                           level, false);
                }
                else
                {
                    ProgrammBlockNodeCheck(new ProgrammBlockNode()
                    {
                        children = new List <SyntaxisNode>()
                        {
                            item.children[0]
                        }
                    },
                                           level, false);
                }
            }

            levelIdentifiers.RemoveAt(level - 1);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Будут проверять на ошибку обращения к несуществующему параметру и т.д.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="level"></param>
 private void CheckNoneExistentNode(SyntaxisNode node, int level)
 {
 }
Exemplo n.º 5
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.º 6
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);
        }
Exemplo n.º 7
0
 public void Check(SyntaxisNode node)
 {
     GlobalNodeCheck(node);
 }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
 public Identify(SyntaxisNode node, typeOfIdentify type = typeOfIdentify.Parameter, typeOfAccess access = typeOfAccess.Global)
 {
     name        = node.token.GetText();
     this.type   = type;
     this.access = access;
 }
Exemplo n.º 10
0
        public static bool TryThis(AnalyzerModule.Analyzer analyzer, NonParam _delegate, out SyntaxisNode output, out int depth, out string error)
        {
            int startPos = analyzer.stepBackCount;

            try
            {
                output = _delegate.Invoke();
                depth  = analyzer.stepBackCount;
                error  = "";
                return(true);
            }
            catch (Exception ex)
            {
                depth  = analyzer.stepBackCount;
                error  = ex.Message;
                output = null;
                while (analyzer.stepBackCount > startPos)
                {
                    analyzer.StepBack();
                }
                return(false);
            }
        }