📄 main.java
字号:
{ m_outstream.println(","); } else { m_outstream.println(); } } m_outstream.println("\t};"); } /*************************************************************** Function: emit_helpers Description: Emits helper functions, particularly error handling and input buffering. **************************************************************/ private void emit_helpers ( ) throws java.io.IOException { if (CUtility.DEBUG) { CUtility.Jassert(null != m_spec); CUtility.Jassert(null != m_outstream); } /* Function: yy_do_eof */ m_outstream.println("\tprivate boolean yy_eof_done = false;"); if (null != m_spec.m_eof_code) { m_outstream.print("\tprivate void yy_do_eof ()"); if (null != m_spec.m_eof_throw_code) { m_outstream.println(); m_outstream.print("\t\tthrows "); m_outstream.println(new String(m_spec.m_eof_throw_code,0, m_spec.m_eof_throw_read)); m_outstream.println("\t\t{"); } else { m_outstream.println(" {"); } m_outstream.println("\t\tif (false == yy_eof_done) {"); m_outstream.print(new String(m_spec.m_eof_code,0, m_spec.m_eof_read)); m_outstream.println("\t\t}"); m_outstream.println("\t\tyy_eof_done = true;"); m_outstream.println("\t}"); } emit_states(); /* Function: yybegin */ m_outstream.println("\tprivate void yybegin (int state) {"); m_outstream.println("\t\tyy_lexical_state = state;"); m_outstream.println("\t}"); /* Function: yy_initial_dtrans */ /*m_outstream.println("\tprivate int yy_initial_dtrans (int state) {"); m_outstream.println("\t\treturn yy_state_dtrans[state];"); m_outstream.println("\t}");*/ /* Function: yy_advance */ m_outstream.println("\tprivate int yy_advance ()"); m_outstream.println("\t\tthrows java.io.IOException {"); /*m_outstream.println("\t\t{");*/ m_outstream.println("\t\tint next_read;"); m_outstream.println("\t\tint i;"); m_outstream.println("\t\tint j;"); m_outstream.println(); m_outstream.println("\t\tif (yy_buffer_index < yy_buffer_read) {"); m_outstream.println("\t\t\treturn yy_buffer[yy_buffer_index++];"); /*m_outstream.println("\t\t\t++yy_buffer_index;");*/ m_outstream.println("\t\t}"); m_outstream.println(); m_outstream.println("\t\tif (0 != yy_buffer_start) {"); m_outstream.println("\t\t\ti = yy_buffer_start;"); m_outstream.println("\t\t\tj = 0;"); m_outstream.println("\t\t\twhile (i < yy_buffer_read) {"); m_outstream.println("\t\t\t\tyy_buffer[j] = yy_buffer[i];"); m_outstream.println("\t\t\t\t++i;"); m_outstream.println("\t\t\t\t++j;"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t\tyy_buffer_end = yy_buffer_end - yy_buffer_start;"); m_outstream.println("\t\t\tyy_buffer_start = 0;"); m_outstream.println("\t\t\tyy_buffer_read = j;"); m_outstream.println("\t\t\tyy_buffer_index = j;"); m_outstream.println("\t\t\tnext_read = yy_reader.read(yy_buffer,"); m_outstream.println("\t\t\t\t\tyy_buffer_read,"); m_outstream.println("\t\t\t\t\tyy_buffer.length - yy_buffer_read);"); m_outstream.println("\t\t\tif (-1 == next_read) {"); m_outstream.println("\t\t\t\treturn YY_EOF;"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t\tyy_buffer_read = yy_buffer_read + next_read;"); m_outstream.println("\t\t}"); m_outstream.println(); m_outstream.println("\t\twhile (yy_buffer_index >= yy_buffer_read) {"); m_outstream.println("\t\t\tif (yy_buffer_index >= yy_buffer.length) {"); m_outstream.println("\t\t\t\tyy_buffer = yy_double(yy_buffer);"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t\tnext_read = yy_reader.read(yy_buffer,"); m_outstream.println("\t\t\t\t\tyy_buffer_read,"); m_outstream.println("\t\t\t\t\tyy_buffer.length - yy_buffer_read);"); m_outstream.println("\t\t\tif (-1 == next_read) {"); m_outstream.println("\t\t\t\treturn YY_EOF;"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t\tyy_buffer_read = yy_buffer_read + next_read;"); m_outstream.println("\t\t}"); m_outstream.println("\t\treturn yy_buffer[yy_buffer_index++];"); m_outstream.println("\t}"); /* Function: yy_move_end */ m_outstream.println("\tprivate void yy_move_end () {"); m_outstream.println("\t\tif (yy_buffer_end > yy_buffer_start &&"); m_outstream.println("\t\t '\\n' == yy_buffer[yy_buffer_end-1])"); m_outstream.println("\t\t\tyy_buffer_end--;"); m_outstream.println("\t\tif (yy_buffer_end > yy_buffer_start &&"); m_outstream.println("\t\t '\\r' == yy_buffer[yy_buffer_end-1])"); m_outstream.println("\t\t\tyy_buffer_end--;"); m_outstream.println("\t}"); /* Function: yy_mark_start */ m_outstream.println("\tprivate boolean yy_last_was_cr=false;"); m_outstream.println("\tprivate void yy_mark_start () {"); if (m_spec.m_count_lines || true == m_spec.m_count_chars) { if (m_spec.m_count_lines) { m_outstream.println("\t\tint i;"); m_outstream.println("\t\tfor (i = yy_buffer_start; " + "i < yy_buffer_index; ++i) {"); m_outstream.println("\t\t\tif ('\\n' == yy_buffer[i] && !yy_last_was_cr) {"); m_outstream.println("\t\t\t\t++yyline;"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t\tif ('\\r' == yy_buffer[i]) {"); m_outstream.println("\t\t\t\t++yyline;"); m_outstream.println("\t\t\t\tyy_last_was_cr=true;"); m_outstream.println("\t\t\t} else yy_last_was_cr=false;"); m_outstream.println("\t\t}"); } if (m_spec.m_count_chars) { m_outstream.println("\t\tyychar = yychar"); m_outstream.println("\t\t\t+ yy_buffer_index - yy_buffer_start;"); } } m_outstream.println("\t\tyy_buffer_start = yy_buffer_index;"); m_outstream.println("\t}"); /* Function: yy_mark_end */ m_outstream.println("\tprivate void yy_mark_end () {"); m_outstream.println("\t\tyy_buffer_end = yy_buffer_index;"); m_outstream.println("\t}"); /* Function: yy_to_mark */ m_outstream.println("\tprivate void yy_to_mark () {"); m_outstream.println("\t\tyy_buffer_index = yy_buffer_end;"); m_outstream.println("\t\tyy_at_bol = "+ "(yy_buffer_end > yy_buffer_start) &&"); m_outstream.println("\t\t "+ "('\\r' == yy_buffer[yy_buffer_end-1] ||"); m_outstream.println("\t\t "+ " '\\n' == yy_buffer[yy_buffer_end-1] ||"); m_outstream.println("\t\t "+ /* unicode LS */ " 2028/*LS*/ == yy_buffer[yy_buffer_end-1] ||"); m_outstream.println("\t\t "+ /* unicode PS */ " 2029/*PS*/ == yy_buffer[yy_buffer_end-1]);"); m_outstream.println("\t}"); /* Function: yytext */ m_outstream.println("\tprivate java.lang.String yytext () {"); m_outstream.println("\t\treturn (new java.lang.String(yy_buffer,"); m_outstream.println("\t\t\tyy_buffer_start,"); m_outstream.println("\t\t\tyy_buffer_end - yy_buffer_start));"); m_outstream.println("\t}"); /* Function: yylength */ m_outstream.println("\tprivate int yylength () {"); m_outstream.println("\t\treturn yy_buffer_end - yy_buffer_start;"); m_outstream.println("\t}"); /* Function: yy_double */ m_outstream.println("\tprivate char[] yy_double (char buf[]) {"); m_outstream.println("\t\tint i;"); m_outstream.println("\t\tchar newbuf[];"); m_outstream.println("\t\tnewbuf = new char[2*buf.length];"); m_outstream.println("\t\tfor (i = 0; i < buf.length; ++i) {"); m_outstream.println("\t\t\tnewbuf[i] = buf[i];"); m_outstream.println("\t\t}"); m_outstream.println("\t\treturn newbuf;"); m_outstream.println("\t}"); /* Function: yy_error */ m_outstream.println("\tprivate final int YY_E_INTERNAL = 0;"); m_outstream.println("\tprivate final int YY_E_MATCH = 1;"); m_outstream.println("\tprivate java.lang.String yy_error_string[] = {"); m_outstream.println("\t\t\"Error: Internal error.\\n\","); m_outstream.println("\t\t\"Error: Unmatched input.\\n\""); m_outstream.println("\t};"); m_outstream.println("\tprivate void yy_error (int code,boolean fatal) {"); m_outstream.println("\t\tjava.lang.System.out.print(yy_error_string[code]);"); m_outstream.println("\t\tjava.lang.System.out.flush();"); m_outstream.println("\t\tif (fatal) {"); m_outstream.println("\t\t\tthrow new Error(\"Fatal Error.\\n\");"); m_outstream.println("\t\t}"); m_outstream.println("\t}"); /* Function: yy_next */ /*m_outstream.println("\tprivate int yy_next (int current,char lookahead) {"); m_outstream.println("\t\treturn yy_nxt[yy_rmap[current]][yy_cmap[lookahead]];"); m_outstream.println("\t}");*/ /* Function: yy_accept */ /*m_outstream.println("\tprivate int yy_accept (int current) {"); m_outstream.println("\t\treturn yy_acpt[current];"); m_outstream.println("\t}");*/ // Function: private int [][] unpackFromString(int size1, int size2, String st) // Added 6/24/98 Raimondas Lencevicius // May be made more efficient by replacing String operations // Assumes correctly formed input String. Performs no error checking m_outstream.println("\tprivate int[][] unpackFromString"+ "(int size1, int size2, String st) {"); m_outstream.println("\t\tint colonIndex = -1;"); m_outstream.println("\t\tString lengthString;"); m_outstream.println("\t\tint sequenceLength = 0;"); m_outstream.println("\t\tint sequenceInteger = 0;"); m_outstream.println(); m_outstream.println("\t\tint commaIndex;"); m_outstream.println("\t\tString workString;"); m_outstream.println(); m_outstream.println("\t\tint res[][] = new int[size1][size2];"); m_outstream.println("\t\tfor (int i= 0; i < size1; i++) {"); m_outstream.println("\t\t\tfor (int j= 0; j < size2; j++) {"); m_outstream.println("\t\t\t\tif (sequenceLength != 0) {"); m_outstream.println("\t\t\t\t\tres[i][j] = sequenceInteger;"); m_outstream.println("\t\t\t\t\tsequenceLength--;"); m_outstream.println("\t\t\t\t\tcontinue;"); m_outstream.println("\t\t\t\t}"); m_outstream.println("\t\t\t\tcommaIndex = st.indexOf(',');"); m_outstream.println("\t\t\t\tworkString = (commaIndex==-1) ? st :"); m_outstream.println("\t\t\t\t\tst.substring(0, commaIndex);"); m_outstream.println("\t\t\t\tst = st.substring(commaIndex+1);"); m_outstream.println("\t\t\t\tcolonIndex = workString.indexOf(':');"); m_outstream.println("\t\t\t\tif (colonIndex == -1) {"); m_outstream.println("\t\t\t\t\tres[i][j]=Integer.parseInt(workString);"); m_outstream.println("\t\t\t\t\tcontinue;"); m_outstream.println("\t\t\t\t}"); m_outstream.println("\t\t\t\tlengthString ="); m_outstream.println("\t\t\t\t\tworkString.substring(colonIndex+1);"); m_outstream.println("\t\t\t\tsequenceLength="+ "Integer.parseInt(lengthString);"); m_outstream.println("\t\t\t\tworkString="+ "workString.substring(0,colonIndex);"); m_outstream.println("\t\t\t\tsequenceInteger="+ "Integer.parseInt(workString);"); m_outstream.println("\t\t\t\tres[i][j] = sequenceInteger;"); m_outstream.println("\t\t\t\tsequenceLength--;"); m_outstream.println("\t\t\t}"); m_outstream.println("\t\t}"); m_outstream.println("\t\treturn res;"); m_outstream.println("\t}"); } /*************************************************************** Function: emit_header Description: Emits class header. **************************************************************/ private void emit_header ( ) throws java.io.IOException { if (CUtility.DEBUG) { CUtility.Jassert(null != m_spec); CUtility.Jassert(null != m_outstream); } m_outstream.println(); m_outstream.println(); if (true == m_spec.m_public) { m_outstream.print("public "); } m_outstream.print("class "); m_outstream.print(new String(m_spec.m_class_name,0, m_spec.m_class_name.length)); if (m_spec.m_implements_name.length > 0) { m_outstream.print(" implements "); m_outstream.print(new String(m_spec.m_implements_name,0, m_spec.m_implements_name.length)); } m_outstream.println(" {"); } /*************************************************************** Function: emit_table Description: Emits transition table. **************************************************************/ private void emit_table ( ) throws java.io.IOException { int i; int elem; int size; CDTrans dtrans; boolean is_start; boolean is_end; CAccept accept; if (CUtility.DEBUG) { CUtility.Jassert(null != m_spec); CUtility.Jassert(null != m_outstream); } m_outstream.println("\tprivate int yy_acpt[] = {"); size = m_spec.m_accept_vector.size(); for (elem = 0; elem < size; ++elem) { accept = (CAccept) m_spec.m_accept_vector.elementAt(elem); m_outstream.print("\t\t/* "+elem+" */ "); if (null != accept) { is_start = (0 != (m_spec.m_anchor_array[elem] & CSpec.START)); is_end = (0 != (m_spec.m_anchor_array[elem] & CSpec.END)); if (is_start && true == is_end) { m_outstream.print("YY_START | YY_END"); } else if (is_start) { m_outstream.print("YY_START"); } else if (is_end) { m_outstream.print("YY_END"); } else { m_outstream.print("YY_NO_ANCHOR"); } } else { m_outstream.print("YY_NOT_ACCEPT"); } if (elem < size - 1) { m_outstream.print(","); } m_outstream.println(); } m_outstream.println("\t};"); // CSA: modified yy_cmap to use string packing 9-Aug-1999 int[] yy_cmap = new int[m_spec.m_ccls_map.length]; for (i = 0; i < m_spec.m_ccls_map.length; ++i) yy_cmap[i] = m_spec.m_col_map[m_spec.m_ccls_map[i]]; m_outstream.print("\tprivate int yy_cmap[] = unpackFromString("); emit_table_as_string(new int[][] { yy_cmap }); m_outstream.println(")[0];"); m_outstream.println(); // CSA: modified yy_rmap to use string packing 9-Aug-1999 m_outstream.print("\tprivate int yy_rmap[] = unpackFromString("); emit_table_as_string(new int[][] { m_spec.m_row_map }); m_outstream.println(")[0];"); m_outstream.println(); // 6/24/98 Raimondas Lencevicius // modified to use // int[][] unpackFromString(int size1, int size2, String st) size = m_spec.m_dtrans_vector.size(); int[][] yy_nxt = new int[size][]; for (elem=0; elem<size; elem++) { dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(elem); CUtility.Jassert(dtrans.m_dtrans.length==m_spec.m_dtrans_ncols); yy_nxt[elem] = dtrans.m_dtrans; } m_outstream.print ("\tprivate int yy_nxt[][] = unpackFromString("); emit_table_as_string(yy_nxt); m_outstream.println(");"); m_outstream.println(); } /*************************************************************** Function: emit_driver Description: Output an integer table as a string. Written by Raimondas Lencevicius 6/24/98; reorganized by CSA 9-Aug-1999. From his original comments: yy_nxt[][] values are coded into a string by printing integers and representing integer sequences as "value:length" pairs. **************************************************************/ private void emit_table_as_string(int[][] ia) { int sequenceLength = 0; // RL - length of the number sequence boolean sequenceStarted = false; // RL - has number sequence started? int previousInt = -20; // RL - Bogus -20 state. // RL - Output matrix size m_outstream.print(ia.length); m_outstream.print(","); m_outstream.print(ia.length>0?ia[0].length:0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -