Пример #1
0
        public int SetAstRoot(string procName, TNODE node)
        {
            var procedure = GetProc(procName);

            if (procedure == null)
            {
                return(-1);
            }
            else
            {
                procedure.AstRoot = node;
                return(procedure.Index);
            }
        }
Пример #2
0
        public int SetAstRoot(int codeLine, TNODE node)
        {
            var procedure = GetStmt(codeLine);

            if (procedure == null)
            {
                return(-1);
            }
            else
            {
                procedure.AstRoot = node;
                return(0);
            }
        }
Пример #3
0
        private static List <int> GetConstantIndexes(Dictionary <string, List <string> > attributes)
        {
            List <int>    indexes   = new List <int>();
            List <string> constantV = new List <string>();

            if (attributes.ContainsKey("value"))
            {
                constantV = attributes["value"];
            }
            if (constantV.Count > 1)
            {
                return(indexes);
            }

            if (constantV.Count == 1)
            {
                if (!int.TryParse(constantV[0], out _))
                {
                    return(indexes);
                }
            }

            foreach (Statement stmt in StmtTable.StmtTable.Instance.Statements)
            {
                TNODE      node   = stmt.AstRoot;
                List <int> consts = AST.AST.Instance.GetConstants(node);
                if (constantV.Count == 1)
                {
                    if (consts.Contains(Int32.Parse(constantV[0])))
                    {
                        indexes.Add(Int32.Parse(constantV[0]));
                    }
                }
                else
                {
                    indexes.AddRange(consts);
                }
            }

            return(indexes.Distinct().ToList());
        }
Пример #4
0
        public List <Procedure> GetCalls(List <Procedure> procedures, TNODE stmtNode)
        {
            List <string> procNames = AST.AST.Instance
                                      .GetLinkedNodes(stmtNode, LinkTypeEnum.Child)
                                      .Where(i => i.EntityTypeEnum == EntityTypeEnum.Call)
                                      .Select(i => i.Attr.Name)
                                      .ToList();

            foreach (string proce in procNames)
            {
                Procedure findProcedure = ProcTable.ProcTable.Instance.GetProc(proce);
                if (findProcedure != null)
                {
                    procedures.Add(findProcedure);
                }
            }


            List <TNODE> ifOrWhileNodes = AST.AST.Instance
                                          .GetLinkedNodes(stmtNode, LinkTypeEnum.Child)
                                          .Where(i => i.EntityTypeEnum == EntityTypeEnum.While || i.EntityTypeEnum == EntityTypeEnum.If).ToList();

            foreach (var node in ifOrWhileNodes)
            {
                List <TNODE> stmtLstNodes = AST.AST.Instance
                                            .GetLinkedNodes(node, LinkTypeEnum.Child)
                                            .Where(i => i.EntityTypeEnum == EntityTypeEnum.Stmtlist).ToList();


                foreach (var stmtL in stmtLstNodes)
                {
                    GetCalls(procedures, stmtL);
                }
            }


            return(procedures);
        }
Пример #5
0
        /// <summary> Constructor.</summary>
        /// <param name="buf_size">- the maximum number of trie nodes
        /// </param>
        public Trie(int buf_size)
        {
            search_idx = new int[256];
            search_key = new char[256];
            search_end = 0;

            trie_buf = new TNODE[buf_size];
            for (int i = 0; i < buf_size; i++)
            {
                trie_buf[i] = new TNODE(this);
            }

            free_head = trie_buf[FREE_NODE].free;
            node_head = trie_buf[FREE_NODE];

            node_head.key = (char) (0);
            node_head.child_size = 0;
            node_head.info_list = new LinkedList < INFO >();
            node_head.child_idx = 0;

            free_head.size = 0;
            free_head.next_idx = 1;

            // the node number 0 is not used
            trie_buf[1].free.size = buf_size - 1;
            trie_buf[1].free.next_idx = FREE_NODE;
        }
Пример #6
0
        /// <summary> It stores the specified word in the trie structure.</summary>
        /// <param name="word">- the word to store
        /// </param>
        /// <param name="inode">- the information of the word
        /// </param>
        /// <returns> 0: done, -1: failed to store
        /// </returns>
        public virtual int store(char[] word, INFO inode)
        {
            int child_index, new_index;
            int i, j;
            int widx;

            TNODE parent;

            if (word.Length == 0)
            {
                return(-1);
            }


            // it first searches the trie structure with the word
            search(word);

            // it stores the part of the word not in the structure
            widx = search_end;
            if (search_end == 0)
            {
                parent = node_head;
            }
            else
            {
                parent = trie_buf[search_idx[search_end - 1]];
            }

            while (widx < word.Length)
            {
                char  c  = word[widx];
                short cs = parent.child_size;
                if (cs == 0)
                {
                    // if it has no child, allocates a new child
                    new_index = node_alloc(1);
                    trie_buf[new_index].key        = c;
                    trie_buf[new_index].child_idx  = 0;
                    trie_buf[new_index].child_size = 0;
                    parent.child_size      = 1;
                    parent.child_idx       = new_index;
                    search_idx[search_end] = new_index;
                    search_key[search_end] = c;
                    search_end++;
                    widx++;
                    parent = trie_buf[new_index];
                }
                else
                {
                    // if it has more than one child, allocates (cs + 1) nodes, and copy the existing children
                    new_index   = node_alloc(cs + 1);
                    child_index = parent.child_idx;
                    for (i = 0; i < cs; i++)
                    {
                        if (trie_buf[child_index + i].key < c)
                        {
                            TNODE tmp = trie_buf[new_index + i];
                            trie_buf[new_index + i]   = trie_buf[child_index + i];
                            trie_buf[child_index + i] = tmp;
                        }
                        else
                        {
                            break;
                        }
                    }
                    trie_buf[new_index + i].key        = c;
                    trie_buf[new_index + i].child_idx  = 0;
                    trie_buf[new_index + i].child_size = 0;
                    search_idx[search_end]             = new_index + i;
                    search_key[search_end]             = c;
                    search_end++;
                    widx++;

                    for (j = i; j < cs; j++)
                    {
                        TNODE tmp = trie_buf[new_index + j + 1];
                        trie_buf[new_index + j + 1] = trie_buf[child_index + j];
                        trie_buf[child_index + j]   = tmp;
                    }

                    parent.child_idx  = new_index;
                    parent.child_size = (short)(cs + 1);

                    node_free(child_index, cs);
                    parent = trie_buf[new_index + i];
                }
            }

            // inserts the information to the word
            if (parent.info_list == null)
            {
                parent.info_list = new LinkedList <INFO>();
            }

            INFO in_Renamed = new INFO(this);

            in_Renamed.phoneme = inode.phoneme;
            in_Renamed.tag     = inode.tag;

            parent.info_list.AddLast(in_Renamed);

            return(0);
        }