⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 我开发的一个用java语言实现的编译器,内含词法分析器,语法分析器,而且可以实现中间代码生成.用到了SLR算法和LR(1)算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	System.err.println("  Checking for non-reduced productions...");      action_table.check_reductions();      reduce_check_end = System.currentTimeMillis();      /* if we have more conflicts than we expected issue a message and die */      if (emit.num_conflicts > expect_conflicts)	{	  System.err.println("*** More conflicts encountered than expected " +			     "-- parser generation aborted");	  lexer.error_count++; // indicate the problem.	  // we'll die on return, after clean up.	}    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Call the emit routines necessary to write out the generated parser. */  protected static void emit_parser() throws internal_error    {      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);    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Helper routine to optionally return a plural or non-plural ending.    * @param val the numerical value determining plurality.   */  protected static String plural(int val)    {      if (val == 1)	return "";      else	return "s";    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Emit a long summary message to standard error (System.err) which    *  summarizes what was found in the specification, how many states were   *  produced, how many conflicts were found, etc.  A detailed timing    *  summary is also produced if it was requested by the user.   * @param output_produced did the system get far enough to generate code.   */  protected static void emit_summary(boolean output_produced)    {      final_time = System.currentTimeMillis();      if (no_summary) return;      System.err.println("------- " + version.title_str + 			 " Parser Generation Summary -------");      /* error and warning count */      System.err.println("  " + lexer.error_count + " error" + 	 plural(lexer.error_count) + " and " + lexer.warning_count + 	 " warning" + plural(lexer.warning_count));      /* basic stats */      System.err.print("  " + terminal.number() + " terminal" + 			 plural(terminal.number()) + ", ");      System.err.print(non_terminal.number() + " non-terminal" + 			 plural(non_terminal.number()) + ", and ");      System.err.println(production.number() + " production" + 			 plural(production.number()) + " declared, ");      System.err.println("  producing " + lalr_state.number() + 			 " unique parse states.");      /* unused symbols */      System.err.println("  " + emit.unused_term + " terminal" + 			 plural(emit.unused_term) + " declared but not used.");      System.err.println("  " + emit.unused_non_term + " non-terminal" + 			 plural(emit.unused_term) + " declared but not used.");      /* productions that didn't reduce */      System.err.println("  " + emit.not_reduced + " production" + 			 plural(emit.not_reduced) + " never reduced.");      /* conflicts */      System.err.println("  " + emit.num_conflicts + " conflict" +			 plural(emit.num_conflicts) + " detected" +	                 " (" + expect_conflicts + " expected).");      /* code location */      if (output_produced)	System.err.println("  Code written to \"" + emit.parser_class_name + 	        ".java\", and \"" + emit.symbol_const_class_name + ".java\".");      else	System.err.println("  No code produced.");      if (opt_show_timing) show_times();      System.err.println(	"---------------------------------------------------- (" + 	 version.version_str + ")");    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Produce the optional timing summary as part of an overall summary. */  protected static void show_times()    {      long total_time = final_time - start_time;      System.err.println(". . . . . . . . . . . . . . . . . . . . . . . . . ");      System.err.println("  Timing Summary");      System.err.println("    Total time       "        + timestr(final_time-start_time, total_time));      System.err.println("      Startup        "	+ timestr(prelim_end-start_time, total_time));      System.err.println("      Parse          "	+ timestr(parse_end-prelim_end, total_time) );      if (check_end != 0)        System.err.println("      Checking       "	    + timestr(check_end-parse_end, total_time));      if (check_end != 0 && build_end != 0)        System.err.println("      Parser Build   "	    + timestr(build_end-check_end, total_time));      if (nullability_end != 0 && check_end != 0)        System.err.println("        Nullability  "	    + timestr(nullability_end-check_end, total_time));      if (first_end != 0 && nullability_end != 0)        System.err.println("        First sets   "            + timestr(first_end-nullability_end, total_time));      if (machine_end != 0 && first_end != 0)        System.err.println("        State build  " 	    + timestr(machine_end-first_end, total_time));       if (table_end != 0 && machine_end != 0)        System.err.println("        Table build  " 	    + timestr(table_end-machine_end, total_time));       if (reduce_check_end != 0 && table_end != 0)        System.err.println("        Checking     " 	    + timestr(reduce_check_end-table_end, total_time));      if (emit_end != 0 && build_end != 0)        System.err.println("      Code Output    "	    + timestr(emit_end-build_end, total_time));      if (emit.symbols_time != 0)	System.err.println("        Symbols      "	    + timestr(emit.symbols_time, total_time));      if (emit.parser_time != 0)	System.err.println("        Parser class "	    + timestr(emit.parser_time, total_time));      if (emit.action_code_time != 0)	System.err.println("          Actions    "	    + timestr(emit.action_code_time, total_time));      if (emit.production_table_time != 0)	System.err.println("          Prod table "	    + timestr(emit.production_table_time, total_time));      if (emit.action_table_time != 0)	System.err.println("          Action tab "	    + timestr(emit.action_table_time, total_time));      if (emit.goto_table_time != 0)	System.err.println("          Reduce tab "	    + timestr(emit.goto_table_time, total_time));      System.err.println("      Dump Output    "	+ timestr(dump_end-emit_end, total_time));    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Helper routine to format a decimal based display of seconds and   *  percentage of total time given counts of milliseconds.   Note: this   *  is broken for use with some instances of negative time (since we don't    *  use any negative time here, we let if be for now).   * @param time_val   the value being formatted (in ms).   * @param total_time total time percentages are calculated against (in ms).   */  protected static String timestr(long time_val, long total_time)    {      boolean neg;      long    ms = 0;      long    sec = 0;      long    percent10;      String  pad;      /* work with positives only */      neg = time_val < 0;      if (neg) time_val = -time_val;      /* pull out seconds and ms */      ms = time_val % 1000;      sec = time_val / 1000;      /* construct a pad to blank fill seconds out to 4 places */      if (sec < 10)   	pad = "   ";      else if (sec < 100)  	pad = "  ";      else if (sec < 1000) 	pad = " ";      else	pad = "";      /* calculate 10 times the percentage of total */      percent10 = (time_val*1000)/total_time;      /* build and return the output string */      return (neg ? "-" : "") + pad + sec + "." + 	     ((ms%1000)/100) + ((ms%100)/10) + (ms%10) + "sec" +	     " (" + percent10/10 + "." + percent10%10 + "%)";    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Produce a human readable dump of the grammar. */  public static void dump_grammar() throws internal_error    {      System.err.println("===== Terminals =====");      for (int tidx=0, cnt=0; tidx < terminal.number(); tidx++, cnt++)	{	  System.err.print("["+tidx+"]"+terminal.find(tidx).name()+" ");	  if ((cnt+1) % 5 == 0) System.err.println();	}      System.err.println();      System.err.println();      System.err.println("===== Non terminals =====");      for (int nidx=0, cnt=0; nidx < non_terminal.number(); nidx++, cnt++)	{	  System.err.print("["+nidx+"]"+non_terminal.find(nidx).name()+" ");	  if ((cnt+1) % 5 == 0) System.err.println();	}      System.err.println();      System.err.println();      System.err.println("===== Productions =====");      for (int pidx=0; pidx < production.number(); pidx++)	{	  production prod = production.find(pidx);	  System.err.print("["+pidx+"] "+prod.lhs().the_symbol().name() + " ::= ");	  for (int i=0; i<prod.rhs_length(); i++)	    if (prod.rhs(i).is_action())	      System.err.print("{action} ");	    else	      System.err.print(			 ((symbol_part)prod.rhs(i)).the_symbol().name() + " ");	  System.err.println();	}      System.err.println();    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** 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 */      for (Enumeration s = lalr_state.all(); s.hasMoreElements(); )	{	  lalr_state st = (lalr_state)s.nextElement();	  ordered[st.index()] = st;	}      System.err.println("===== Viable Prefix Recognizer =====");      for (int i = 0; i<lalr_state.number(); i++)	{	  if (ordered[i] == start_state) System.err.print("START ");          System.err.println(ordered[i]);	  System.err.println("-------------------");	}    }  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/  /** Produce a (semi-) human readable dumps of the parse tables */  public static void dump_tables()    {      System.err.println(action_table);      System.err.println(reduce_table);    }  /*-----------------------------------------------------------*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -