Example #1
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /** Call the emit routines necessary to write out the generated parser. */
        protected static void emit_parser()
        {
            emit.symbols(symbol_class_file, include_non_terms, sym_interface);
            emit.parser(parser_class_file, action_table, reduce_table,
                        start_state.index(), emit.start_production, opt_compact_red,
                        suppress_scanner);
        }
Example #2
0
        /*-----------------------------------------------------------*/
        /*--- Static Methods ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /** Helper routine for debugging -- produces a dump of the given state
         * onto System.out.
         */
        protected static void dump_state(lalr_state st)
        {
            lalr_item_set   itms;
            lalr_item       itm;
            production_part part;

            if (st == null)
            {
                Console.WriteLine("NULL lalr_state");
                return;
            }

            Console.WriteLine("lalr_state [" + st.index() + "] {");
            itms = st.items();
            IEnumerator e = itms.all();

            while (e.MoveNext())
            {
                itm = (lalr_item)e.Current;
                Console.Write("  [");
                Console.Write(itm.the_production().lhs().the_symbol().name());
                Console.Write(" ::= ");
                for (int i = 0; i < itm.the_production().rhs_length(); i++)
                {
                    if (i == itm.dot_pos())
                    {
                        Console.Write("(*) ");
                    }
                    part = itm.the_production().rhs(i);
                    if (part.is_action())
                    {
                        Console.Write("{action} ");
                    }
                    else
                    {
                        Console.Write(((symbol_part)part).the_symbol().name() + " ");
                    }
                }
                if (itm.dot_at_end())
                {
                    Console.Write("(*) ");
                }
                Console.WriteLine("]");
            }
            Console.WriteLine("}");
        }
Example #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /** Produce a (semi-) human readable dump of the complete viable prefix
         *  recognition state machine.
         */
        public static void dump_machine()
        {
            lalr_state[] ordered = new lalr_state[lalr_state.number()];

                /* put the states in sorted order for a nicer display */
                IEnumerator s = lalr_state.all();
                while ( s.MoveNext() )
                {
                    lalr_state st = (lalr_state)s.Current;
                    ordered[st.index()] = st;
                }

            System.Console.Error.WriteLine("===== Viable Prefix Recognizer =====");
            for (int i = 0; i<lalr_state.number(); i++)
            {
                if (ordered[i] == start_state) System.Console.Error.Write("START ");
                System.Console.Error.WriteLine(ordered[i]);
                System.Console.Error.WriteLine("-------------------");
            }
        }
        /*-----------------------------------------------------------*/
        /*--- Static Methods ----------------------------------------*/
        /*-----------------------------------------------------------*/
        /** Helper routine for debugging -- produces a dump of the given state
        * onto System.out.
        */
        protected static void dump_state(lalr_state st)
        {
            lalr_item_set itms;
              lalr_item itm;
              production_part part;

              if (st == null)
            {
              Console.WriteLine("NULL lalr_state");
              return;
            }

              Console.WriteLine("lalr_state [" + st.index() + "] {");
              itms = st.items();
              IEnumerator e = itms.all();
              while ( e.MoveNext() )
            {
              itm = (lalr_item)e.Current;
              Console.Write("  [");
              Console.Write(itm.the_production().lhs().the_symbol().name());
              Console.Write(" ::= ");
              for (int i = 0; i<itm.the_production().rhs_length(); i++)
            {
              if (i == itm.dot_pos()) Console.Write("(*) ");
              part = itm.the_production().rhs(i);
              if (part.is_action())
            Console.Write("{action} ");
              else
            Console.Write(((symbol_part)part).the_symbol().name() + " ");
            }
              if (itm.dot_at_end()) Console.Write("(*) ");
              Console.WriteLine("]");
            }
              Console.WriteLine("}");
        }