Logo Search packages:      
Sourcecode: jasmin-sable version File versions  Download package

static void java_cup::emit::parser ( PrintWriter  out,
parse_action_table  action_table,
parse_reduce_table  reduce_table,
int  start_st,
production  start_prod,
boolean  compact_reduces,
boolean  suppress_scanner 
) throws internal_error [inline, static]

Emit the parser subclass with embedded tables.

Parameters:
out stream to produce output on.
action_table internal representation of the action table.
reduce_table internal representation of the reduce-goto table.
start_st start state of the parse machine.
start_prod start production of the grammar.
compact_reduces do we use most frequent reduce as default?
suppress_scanner should scanner be suppressed for compatibility?

Definition at line 758 of file emit.java.

References do_action_table(), do_reduce_table(), emit_action_code(), emit_package(), emit_production_table(), import_list, java_cup::production::index(), init_code, parser_class_name, parser_code, parser_time, pre(), scan_code, and start_production.

    {
      long start_time = System.currentTimeMillis();

      /* top of file */
      out.println();
      out.println("//----------------------------------------------------"); 
      out.println("// The following code was generated by " + 
                                          version.title_str);
      out.println("// " + new Date());
      out.println("//----------------------------------------------------"); 
      out.println();
      emit_package(out);

      /* user supplied imports */
      for (int i = 0; i < import_list.size(); i++)
      out.println("import " + import_list.elementAt(i) + ";");

      /* class header */
      out.println();
      out.println("/** "+version.title_str+" generated parser.");
      out.println("  * @version " + new Date());
      out.println("  */");
      out.println("public class " + parser_class_name + 
              " extends java_cup.runtime.lr_parser {");

      /* constructors [CSA/davidm, 24-jul-99] */
      out.println();
      out.println("  /** Default constructor. */");
      out.println("  public " + parser_class_name + "() {super();}");
      if (!suppress_scanner) {
        out.println();
        out.println("  /** Constructor which sets the default scanner. */");
        out.println("  public " + parser_class_name + 
                  "(java_cup.runtime.Scanner s) {super(s);}");
      }

      /* emit the various tables */
      emit_production_table(out);
      do_action_table(out, action_table, compact_reduces);
      do_reduce_table(out, reduce_table);

      /* instance of the action encapsulation class */
      out.println("  /** Instance of action encapsulation class. */");
      out.println("  protected " + pre("actions") + " action_obj;");
      out.println();

      /* action object initializer */
      out.println("  /** Action encapsulation object initializer. */");
      out.println("  protected void init_actions()");
      out.println("    {");
      out.println("      action_obj = new " + pre("actions") + "(this);");
      out.println("    }");
      out.println();

      /* access to action code */
      out.println("  /** Invoke a user supplied parse action. */");
      out.println("  public java_cup.runtime.Symbol do_action(");
      out.println("    int                        act_num,");
      out.println("    java_cup.runtime.lr_parser parser,");
      out.println("    java.util.Stack            stack,");
      out.println("    int                        top)");
      out.println("    throws java.lang.Exception");
      out.println("  {");
      out.println("    /* call code in generated class */");
      out.println("    return action_obj." + pre("do_action(") +
                  "act_num, parser, stack, top);");
      out.println("  }");
      out.println("");


      /* method to tell the parser about the start state */
      out.println("  /** Indicates start state. */");
      out.println("  public int start_state() {return " + start_st + ";}");

      /* method to indicate start production */
      out.println("  /** Indicates start production. */");
      out.println("  public int start_production() {return " + 
                 start_production.index() + ";}");
      out.println();

      /* methods to indicate EOF and error symbol indexes */
      out.println("  /** <code>EOF</code> Symbol index. */");
      out.println("  public int EOF_sym() {return " + terminal.EOF.index() + 
                                ";}");
      out.println();
      out.println("  /** <code>error</code> Symbol index. */");
      out.println("  public int error_sym() {return " + terminal.error.index() +
                                ";}");
      out.println();

      /* user supplied code for user_init() */
      if (init_code != null)
      {
          out.println();
        out.println("  /** User initialization code. */");
        out.println("  public void user_init() throws java.lang.Exception");
        out.println("    {");
        out.println(init_code);
        out.println("    }");
      }

      /* user supplied code for scan */
      if (scan_code != null)
      {
          out.println();
        out.println("  /** Scan to get the next Symbol. */");
        out.println("  public java_cup.runtime.Symbol scan()");
        out.println("    throws java.lang.Exception");
        out.println("    {");
        out.println(scan_code);
        out.println("    }");
      }

      /* user supplied code */
      if (parser_code != null)
      {
        out.println();
          out.println(parser_code);
      }

      /* end of class */
      out.println("}");

      /* put out the action code class */
      emit_action_code(out, start_prod);

      parser_time = System.currentTimeMillis() - start_time;
    }


Generated by  Doxygen 1.6.0   Back to index