Beispiel #1
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Build the (internal) parser from the previously parsed specification.
        /// This includes:<ul>
        /// <li> Computing nullability of non-terminals.
        /// <li> Computing first sets of non-terminals and productions.
        /// <li> Building the viable prefix recognizer machine.
        /// <li> Filling in the (internal) parse tables.
        /// <li> Checking for unreduced productions.
        /// </ul>
        /// </summary>
        protected internal static void build_parser()
        {
            /* compute nullability of all non terminals */
            if (opt_do_debug || print_progress)
                System.Console.Error.WriteLine("  Computing non-terminal nullability...");
            non_terminal.compute_nullability();

            nullability_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* compute first sets of all non terminals */
            if (opt_do_debug || print_progress)
                System.Console.Error.WriteLine("  Computing first sets...");
            non_terminal.compute_first_sets();

            first_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* build the LR viable prefix recognition machine */
            if (opt_do_debug || print_progress)
                System.Console.Error.WriteLine("  Building state machine...");
            start_state = lalr_state.build_machine(emit.start_production);

            machine_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* build the LR parser action and reduce-goto tables */
            if (opt_do_debug || print_progress)
                System.Console.Error.WriteLine("  Filling in tables...");
            action_table = new parse_action_table();
            reduce_table = new parse_reduce_table();
             for (System.Collections.IEnumerator st = lalr_state.all(); st.MoveNext(); )
            {
                lalr_state lst = (lalr_state) st.Current;
                lst.build_table_entries(action_table, reduce_table);
            }

            table_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* check and warn for non-reduced productions */
            if (opt_do_debug || print_progress)
                System.Console.Error.WriteLine("  Checking for non-reduced productions...");
            action_table.check_reductions();

            reduce_check_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* if we have more conflicts than we expected issue a message and die */
            if (emit.num_conflicts > expect_conflicts)
            {
                System.Console.Error.WriteLine("*** More conflicts encountered than expected " + "-- parser generation aborted");
                lexer.error_count++; // indicate the problem.
                // we'll die on return, after clean up.
            }
        }
Beispiel #2
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Build the (internal) parser from the previously parsed specification.
        /// This includes:<ul>
        /// <li> Computing nullability of non-terminals.
        /// <li> Computing first sets of non-terminals and productions.
        /// <li> Building the viable prefix recognizer machine.
        /// <li> Filling in the (internal) parse tables.
        /// <li> Checking for unreduced productions.
        /// </ul>
        /// </summary>
        protected internal static void  build_parser()
        {
            /* compute nullability of all non terminals */
            if (opt_do_debug || print_progress)
            {
                System.Console.Error.WriteLine("  Computing non-terminal nullability...");
            }
            non_terminal.compute_nullability();

            nullability_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* compute first sets of all non terminals */
            if (opt_do_debug || print_progress)
            {
                System.Console.Error.WriteLine("  Computing first sets...");
            }
            non_terminal.compute_first_sets();

            first_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* build the LR viable prefix recognition machine */
            if (opt_do_debug || print_progress)
            {
                System.Console.Error.WriteLine("  Building state machine...");
            }
            start_state = lalr_state.build_machine(emit.start_production);

            machine_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* build the LR parser action and reduce-goto tables */
            if (opt_do_debug || print_progress)
            {
                System.Console.Error.WriteLine("  Filling in tables...");
            }
            action_table = new parse_action_table();
            reduce_table = new parse_reduce_table();
            for (System.Collections.IEnumerator st = lalr_state.all(); st.MoveNext();)
            {
                lalr_state lst = (lalr_state)st.Current;
                lst.build_table_entries(action_table, reduce_table);
            }

            table_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* check and warn for non-reduced productions */
            if (opt_do_debug || print_progress)
            {
                System.Console.Error.WriteLine("  Checking for non-reduced productions...");
            }
            action_table.check_reductions();

            reduce_check_end = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* if we have more conflicts than we expected issue a message and die */
            if (emit.num_conflicts > expect_conflicts)
            {
                System.Console.Error.WriteLine("*** More conflicts encountered than expected " + "-- parser generation aborted");
                lexer.error_count++;                 // indicate the problem.
                // we'll die on return, after clean up.
            }
        }