Пример #1
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /// <summary>Full constructor.
        /// </summary>
        /// <param name="prod">production this item uses.
        /// </param>
        /// <param name="pos"> position of the "dot" within the item.
        ///
        /// </param>
        public lr_item_core(production prod, int pos)
        {
            // symbol after_dot = null;
            production_part part;

            if (prod == null)
            {
                throw new internal_error("Attempt to create an lr_item_core with a null production");
            }

            _the_production = prod;

            if (pos < 0 || pos > _the_production.rhs_length())
            {
                throw new internal_error("Attempt to create an lr_item_core with a bad dot position");
            }

            _dot_pos = pos;

            /* compute and cache hash code now */
            _core_hash_cache = 13 * _the_production.GetHashCode() + pos;

            /* cache the symbol after the dot */
            if (_dot_pos < _the_production.rhs_length())
            {
                part = _the_production.rhs(_dot_pos);
                if (!part.is_action())
                {
                    _symbol_after_dot = ((symbol_part)part).the_symbol();
                }
            }
        }
Пример #2
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/
        /// <summary>Full constructor.
        /// </summary>
        /// <param name="prod">production this item uses.
        /// </param>
        /// <param name="pos"> position of the "dot" within the item.
        /// 
        /// </param>
        public lr_item_core(production prod, int pos)
        {
            // symbol after_dot = null;
            production_part part;

            if (prod == null)
                throw new internal_error("Attempt to create an lr_item_core with a null production");

            _the_production = prod;

            if (pos < 0 || pos > _the_production.rhs_length())
                throw new internal_error("Attempt to create an lr_item_core with a bad dot position");

            _dot_pos = pos;

            /* compute and cache hash code now */
            _core_hash_cache = 13 * _the_production.GetHashCode() + pos;

            /* cache the symbol after the dot */
            if (_dot_pos < _the_production.rhs_length())
            {
                part = _the_production.rhs(_dot_pos);
                if (!part.is_action())
                    _symbol_after_dot = ((symbol_part) part).the_symbol();
            }
        }
Пример #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Produce a human readable dump of the grammar.
        /// </summary>
        public static void  dump_grammar()
        {
            System.Console.Error.WriteLine("===== Terminals =====");
            for (int tidx = 0, cnt = 0; tidx < terminal.number(); tidx++, cnt++)
            {
                System.Console.Error.Write("[" + tidx + "]" + terminal.find(tidx).name_Renamed_Method() + " ");
                if ((cnt + 1) % 5 == 0)
                {
                    System.Console.Error.WriteLine();
                }
            }
            System.Console.Error.WriteLine();
            System.Console.Error.WriteLine();

            System.Console.Error.WriteLine("===== Non terminals =====");
            for (int nidx = 0, cnt = 0; nidx < non_terminal.number(); nidx++, cnt++)
            {
                System.Console.Error.Write("[" + nidx + "]" + non_terminal.find(nidx).name_Renamed_Method() + " ");
                if ((cnt + 1) % 5 == 0)
                {
                    System.Console.Error.WriteLine();
                }
            }
            System.Console.Error.WriteLine();
            System.Console.Error.WriteLine();


            System.Console.Error.WriteLine("===== Productions =====");
            for (int pidx = 0; pidx < production.number(); pidx++)
            {
                production prod = production.find(pidx);
                System.Console.Error.Write("[" + pidx + "] " + prod.lhs().the_symbol().name_Renamed_Method() + " ::= ");
                for (int i = 0; i < prod.rhs_length(); i++)
                {
                    if (prod.rhs(i).is_action())
                    {
                        System.Console.Error.Write("{action} ");
                    }
                    else
                    {
                        System.Console.Error.Write(((symbol_part)prod.rhs(i)).the_symbol().name_Renamed_Method() + " ");
                    }
                }
                System.Console.Error.WriteLine();
            }
            System.Console.Error.WriteLine();
        }
Пример #4
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Is the dot at the end of the production?
        /// </summary>
        public virtual bool dot_at_end()
        {
            return(_dot_pos >= _the_production.rhs_length());
        }