示例#1
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Convert to a string (separated out from toString() so we can call it
        /// from subclass that overrides toString()).
        /// </summary>
        public virtual string to_simple_string()
        {
            System.String   result;
            production_part part;

            if (_the_production.lhs() != null && _the_production.lhs().the_symbol() != null && _the_production.lhs().the_symbol().name_Renamed_Method() != null)
            {
                result = _the_production.lhs().the_symbol().name_Renamed_Method();
            }
            else
            {
                result = "$$NULL$$";
            }

            result += " ::= ";

            for (int i = 0; i < _the_production.rhs_length(); i++)
            {
                /* do we need the dot before this one? */
                if (i == _dot_pos)
                {
                    result += "(*) ";
                }

                /* print the name of the part */
                if (_the_production.rhs(i) == null)
                {
                    result += "$$NULL$$ ";
                }
                else
                {
                    part = _the_production.rhs(i);
                    if (part == null)
                    {
                        result += "$$NULL$$ ";
                    }
                    else if (part.is_action())
                    {
                        result += "{ACTION} ";
                    }
                    else if (((symbol_part)part).the_symbol() != null && ((symbol_part)part).the_symbol().name_Renamed_Method() != null)
                    {
                        result += ((symbol_part)part).the_symbol().name_Renamed_Method() + " ";
                    }
                    else
                    {
                        result += "$$NULL$$ ";
                    }
                }
            }

            /* put the dot after if needed */
            if (_dot_pos == _the_production.rhs_length())
            {
                result += "(*) ";
            }

            return(result);
        }
示例#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
        /*-----------------------------------------------------------*/
        /*--- 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();
            }
        }