Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Add a production to our set of productions.
        /// </summary>
        public virtual void  add_production(production prod)
        {
            /* catch improper productions */
            if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this)
            {
                throw new internal_error("Attempt to add invalid production to non terminal production table");
            }

            /* add it to the table, keyed with itself */
            SupportClass.PutElement(_productions, prod, prod);
        }
Exemplo n.º 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();
        }
Exemplo n.º 4
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Add a production to our set of productions. 
        /// </summary>
        public virtual void add_production(production prod)
        {
            /* catch improper productions */
            if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this)
                throw new internal_error("Attempt to add invalid production to non terminal production table");

            /* add it to the table, keyed with itself */
            SupportClass.PutElement(_productions, prod, prod);
        }