Esempio n. 1
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Emit the reduce-goto table.
        /// </summary>
        /// <param name="out">    stream to produce output on.
        /// </param>
        /// <param name="red_tab">the internal representation of the reduce-goto table.
        ///
        /// </param>
        protected internal static void  do_reduce_table(System.IO.StreamWriter out_Renamed, parse_reduce_table red_tab)
        {
            lalr_state goto_st;
            // parse_action act;

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

            /* collect values for reduce-goto table */
            short[][] reduce_goto_table = new short[red_tab.num_states()][];
            /* do each row of the reduce-goto table */
            for (int i = 0; i < red_tab.num_states(); i++)
            {
                /* make temporary table for the row. */
                short[] temp_table = new short[2 * CUP.parse_reduce_row.size()];
                int     nentries   = 0;
                /* do each entry in the row */
                for (int j = 0; j < CUP.parse_reduce_row.size(); j++)
                {
                    /* get the entry */
                    goto_st = red_tab.under_state[i].under_non_term[j];

                    /* if we have none, skip it */
                    if (goto_st != null)
                    {
                        /* make entries for the index and the value */
                        temp_table[nentries++] = (short)j;
                        temp_table[nentries++] = (short)goto_st.index();
                    }
                }
                /* now we know how big to make the row. */
                reduce_goto_table[i] = new short[nentries + 2];
                Array.Copy(temp_table, 0, reduce_goto_table[i], 0, nentries);

                /* end row with default value */
                reduce_goto_table[i][nentries++] = -1;
                reduce_goto_table[i][nentries++] = -1;
            }

            /* emit the table. */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** <code>reduce_goto</code> table. */");
            out_Renamed.Write("  private static string[] _strGotoTable = ");
            do_table_as_string(out_Renamed, reduce_goto_table);
            out_Renamed.WriteLine(";");
            out_Renamed.WriteLine("  protected static readonly short[][] _reduce_table = CUP.runtime.lr_parser.unpackFromStrings(_strGotoTable);");
            //out_Renamed.Write("    unpackFromStrings(");
            //do_table_as_string(out_Renamed, reduce_goto_table);
            //out_Renamed.WriteLine(");");

            /* do the public accessor method */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Access to <code>reduce_goto</code> table. */");
            out_Renamed.WriteLine("  public override short[][] reduce_table() {return _reduce_table;}");
            out_Renamed.WriteLine();

            goto_table_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Esempio n. 2
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Emit the reduce-goto table. 
        /// </summary>
        /// <param name="out">    stream to produce output on.
        /// </param>
        /// <param name="red_tab">the internal representation of the reduce-goto table.
        /// 
        /// </param>
        protected internal static void do_reduce_table(System.IO.StreamWriter out_Renamed, parse_reduce_table red_tab)
        {
            lalr_state goto_st;
            // parse_action act;

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

            /* collect values for reduce-goto table */
            short[][] reduce_goto_table = new short[red_tab.num_states()][];
            /* do each row of the reduce-goto table */
             for (int i = 0; i < red_tab.num_states(); i++)
            {
                /* make temporary table for the row. */
                short[] temp_table = new short[2 * CUP.parse_reduce_row.size()];
                int nentries = 0;
                /* do each entry in the row */
                 for (int j = 0; j < CUP.parse_reduce_row.size(); j++)
                {
                    /* get the entry */
                    goto_st = red_tab.under_state[i].under_non_term[j];

                    /* if we have none, skip it */
                    if (goto_st != null)
                    {
                        /* make entries for the index and the value */
                        temp_table[nentries++] = (short) j;
                        temp_table[nentries++] = (short) goto_st.index();
                    }
                }
                /* now we know how big to make the row. */
                reduce_goto_table[i] = new short[nentries + 2];
                Array.Copy(temp_table, 0, reduce_goto_table[i], 0, nentries);

                /* end row with default value */
                reduce_goto_table[i][nentries++] = - 1;
                reduce_goto_table[i][nentries++] = - 1;
            }

            /* emit the table. */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** <code>reduce_goto</code> table. */");
            out_Renamed.Write("  private static string[] _strGotoTable = ");
            do_table_as_string(out_Renamed, reduce_goto_table);
            out_Renamed.WriteLine(";");
            out_Renamed.WriteLine("  protected static readonly short[][] _reduce_table = CUP.runtime.lr_parser.unpackFromStrings(_strGotoTable);");
            //out_Renamed.Write("    unpackFromStrings(");
            //do_table_as_string(out_Renamed, reduce_goto_table);
            //out_Renamed.WriteLine(");");

            /* do the public accessor method */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Access to <code>reduce_goto</code> table. */");
            out_Renamed.WriteLine("  public override short[][] reduce_table() {return _reduce_table;}");
            out_Renamed.WriteLine();

            goto_table_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }