Exemplo n.º 1
0
        /// <summary>
        /// Gets the GSS label already in history for the given GSS generation and symbol
        /// </summary>
        /// <param name="generation">The index of a GSS generation</param>
        /// <param name="symbol">A symbol to look for</param>
        /// <returns>The existing GSS label, or the epsilon label</returns>
        public int GetLabelFor(int generation, TableElemRef symbol)
        {
            HistoryPart hp = GetHistoryPart(generation);

            if (hp == null)
            {
                return(SPPF.EPSILON);
            }
            for (int i = 0; i != hp.next; i++)
            {
                if (sppf.GetNode(hp.data[i]).OriginalSymbol == symbol)
                {
                    return(hp.data[i]);
                }
            }
            return(SPPF.EPSILON);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the specified GSS label to the current history
        /// </summary>
        /// <param name="generation">The current generation</param>
        /// <param name="label">The label identifier of the SPPF node to use as a GSS label</param>
        private void AddToHistory(int generation, int label)
        {
            HistoryPart hp = GetHistoryPart(generation);

            if (hp == null)
            {
                hp            = poolHPs.Acquire();
                hp.generation = generation;
                hp.next       = 0;
                if (history.Length == nextHP)
                {
                    Array.Resize(ref history, history.Length + INIT_HISTORY_SIZE);
                }
                history[nextHP++] = hp;
            }
            if (hp.next == hp.data.Length)
            {
                Array.Resize(ref hp.data, hp.data.Length + INIT_HISTORY_PART_SIZE);
            }
            hp.data[hp.next++] = label;
        }