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

static void java_cup::emit::symbols ( PrintWriter  out,
boolean  emit_non_terms,
boolean  sym_interface 
) [inline, static]

Emit code for the symbol constant class, optionally including non terms, if they have been requested.

Parameters:
out stream to produce output on.
emit_non_terms do we emit constants for non terminals?
sym_interface should we emit an interface, rather than a class?

Definition at line 245 of file emit.java.

References emit_package(), java_cup::symbol::index(), java_cup::symbol::name(), symbol_const_class_name, and symbols_time.

    {
      terminal term;
      non_terminal nt;
      String class_or_interface = (sym_interface)?"interface":"class";

      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);

      /* class header */
      out.println("/** CUP generated " + class_or_interface + 
              " containing symbol constants. */");
      out.println("public " + class_or_interface + " " + 
              symbol_const_class_name + " {");

      out.println("  /* terminals */");

      /* walk over the terminals */              /* later might sort these */
      for (Enumeration e = terminal.all(); e.hasMoreElements(); )
      {
        term = (terminal)e.nextElement();

        /* output a constant decl for the terminal */
        out.println("  public static final int " + term.name() + " = " + 
                  term.index() + ";");
      }

      /* do the non terminals if they want them (parser doesn't need them) */
      if (emit_non_terms)
      {
          out.println();
          out.println("  /* non terminals */");

          /* walk over the non terminals */       /* later might sort these */
          for (Enumeration e = non_terminal.all(); e.hasMoreElements(); )
          {
            nt = (non_terminal)e.nextElement();
    
            /* output a constant decl for the terminal */
            out.println("  static final int " + nt.name() + " = " + 
                      nt.index() + ";");
          }
      }

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

      symbols_time = System.currentTimeMillis() - start_time;
    }


Generated by  Doxygen 1.6.0   Back to index