static char *out_fmt(char *buf, char *end, char format, const struct tm *t) { switch (format) { case 'a': return abbreviated_weekday_name(buf, end, t); case 'A': return full_weekday_name(buf, end, t); case 'b': return abbreviated_month_name(buf, end, t); case 'B': return full_month_name(buf, end, t); case 'c': return fmt(buf, end, "%m/%d/%y %H:%M:%S", t); case 'C': return fmt(buf, end, "%a %b %e %H:%M:%S %Y", t); case 'd': return out_dec(buf, end, 2, t->tm_mday, '0'); case 'D': return fmt(buf, end, "%m/%d/%y", t); case 'e': return out_dec(buf, end, 2, t->tm_mday, ' '); case 'F': return fmt(buf, end, "%Y-%m-%d", t); case 'g': return week_based_year(buf, end, 2, t); case 'G': return week_based_year(buf, end, 4, t); case 'h': return abbreviated_month_name(buf, end, t); case 'H': return out_dec(buf, end, 2, t->tm_hour, '0'); case 'I': return out_hour_12H(buf, end, t); // continue from here: // http://www.cplusplus.com/reference/ctime/strftime/ // examples: // http://www.opensource.apple.com/source/Libc/Libc-167/string.subproj/strftime.c // http://mirror.fsf.org/pmon2000/3.x/src/sdk/libc/time/strftime.c case '%': default: return out_ch(buf, end, format); } }
/* mkdata - generate a data statement * * Generates a data statement initializing the current array element to * "value". */ void mkdata(int value) { if ( datapos >= NUMDATAITEMS ) { outc( ',' ); dataflush(); } if ( datapos == 0 ) /* Indent. */ out( " " ); else outc( ',' ); ++datapos; out_dec( "%5d", value ); }
void gen_next_compressed_state(char *char_map) { indent_put2s( "YY_CHAR yy_c = %s;", char_map ); /* Save the backing-up info \before/ computing the next state * because we always compute one more state than needed - we * always proceed until we reach a jam state */ gen_backing_up(); indent_puts( "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" ); if ( usemecs ) { /* We've arrange it so that templates are never chained * to one another. This means we can afford to make a * very simple test to see if we need to convert to * yy_c's meta-equivalence class without worrying * about erroneously looking up the meta-equivalence * class twice */ do_indent(); /* lastdfa + 2 is the beginning of the templates */ out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 ); indent_up(); indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" ); indent_down(); } indent_puts( "}" ); indent_down(); indent_puts( "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" ); }
/* mkdata - generate a data statement * * Generates a data statement initializing the current array element to * "value". */ void mkdata (int value) { /* short circuit any output */ if (!gentables) return; if (datapos >= NUMDATAITEMS) { outc (','); dataflush (); } if (datapos == 0) /* Indent. */ out (" "); else outc (','); ++datapos; out_dec ("%5d", value); }
void genctbl() { register int i; int end_of_buffer_action = num_rules + 1; /* Table of verify for transition and offset to next state. */ out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n", tblend + numecs + 1 ); outn( " {" ); /* We want the transition to be represented as the offset to the * next state, not the actual state number, which is what it currently * is. The offset is base[nxt[i]] - (base of current state)]. That's * just the difference between the starting points of the two involved * states (to - from). * * First, though, we need to find some way to put in our end-of-buffer * flags and states. We do this by making a state with absolutely no * transitions. We put it at the end of the table. */ /* We need to have room in nxt/chk for two more slots: One for the * action and one for the end-of-buffer transition. We now *assume* * that we're guaranteed the only character we'll try to index this * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure * there's room for jam entries for other characters. */ while ( tblend + 2 >= current_max_xpairs ) expand_nxt_chk(); while ( lastdfa + 1 >= current_max_dfas ) increase_max_dfas(); base[lastdfa + 1] = tblend + 2; nxt[tblend + 1] = end_of_buffer_action; chk[tblend + 1] = numecs + 1; chk[tblend + 2] = 1; /* anything but EOB */ /* So that "make test" won't show arb. differences. */ nxt[tblend + 2] = 0; /* Make sure every state has an end-of-buffer transition and an * action #. */ for ( i = 0; i <= lastdfa; ++i ) { int anum = dfaacc[i].dfaacc_state; int offset = base[i]; chk[offset] = EOB_POSITION; chk[offset - 1] = ACTION_POSITION; nxt[offset - 1] = anum; /* action number */ } for ( i = 0; i <= tblend; ++i ) { if ( chk[i] == EOB_POSITION ) transition_struct_out( 0, base[lastdfa + 1] - i ); else if ( chk[i] == ACTION_POSITION ) transition_struct_out( 0, nxt[i] ); else if ( chk[i] > numecs || chk[i] == 0 ) transition_struct_out( 0, 0 ); /* unused slot */ else /* verify, transition */ transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) ); } /* Here's the final, end-of-buffer state. */ transition_struct_out( chk[tblend + 1], nxt[tblend + 1] ); transition_struct_out( chk[tblend + 2], nxt[tblend + 2] ); outn( " };\n" ); /* Table of pointers to start states. */ out_dec( "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1 ); outn( " {" ); /* } so vi doesn't get confused */ for ( i = 0; i <= lastsc * 2; ++i ) out_dec( " &yy_transition[%d],\n", base[i] ); dataend(); if ( useecs ) genecs(); }
static char *out_hour_12H(char *buf, char *end, const struct tm *t) { int hour = t->tm_hour % 12; return out_dec(buf, end, 2, hour? hour: 12, '0'); }
void ntod (void) { int *accset, ds, nacc, newds; int sym, hashval, numstates, dsize; int num_full_table_rows=0; /* used only for -f */ int *nset, *dset; int targptr, totaltrans, i, comstate, comfreq, targ; int symlist[CSIZE + 1]; int num_start_states; int todo_head, todo_next; struct yytbl_data *yynxt_tbl = 0; flex_int32_t *yynxt_data = 0, yynxt_curr = 0; /* Note that the following are indexed by *equivalence classes* * and not by characters. Since equivalence classes are indexed * beginning with 1, even if the scanner accepts NUL's, this * means that (since every character is potentially in its own * equivalence class) these arrays must have room for indices * from 1 to CSIZE, so their size must be CSIZE + 1. */ int duplist[CSIZE + 1], state[CSIZE + 1]; int targfreq[CSIZE + 1] = {0}, targstate[CSIZE + 1]; /* accset needs to be large enough to hold all of the rules present * in the input, *plus* their YY_TRAILING_HEAD_MASK variants. */ accset = allocate_integer_array ((num_rules + 1) * 2); nset = allocate_integer_array (current_max_dfa_size); /* The "todo" queue is represented by the head, which is the DFA * state currently being processed, and the "next", which is the * next DFA state number available (not in use). We depend on the * fact that snstods() returns DFA's \in increasing order/, and thus * need only know the bounds of the dfas to be processed. */ todo_head = todo_next = 0; for (i = 0; i <= csize; ++i) { duplist[i] = NIL; symlist[i] = false; } for (i = 0; i <= num_rules; ++i) accset[i] = NIL; if (trace) { dumpnfa (scset[1]); fputs (_("\n\nDFA Dump:\n\n"), stderr); } inittbl (); /* Check to see whether we should build a separate table for * transitions on NUL characters. We don't do this for full-speed * (-F) scanners, since for them we don't have a simple state * number lying around with which to index the table. We also * don't bother doing it for scanners unless (1) NUL is in its own * equivalence class (indicated by a positive value of * ecgroup[NUL]), (2) NUL's equivalence class is the last * equivalence class, and (3) the number of equivalence classes is * the same as the number of characters. This latter case comes * about when useecs is false or when it's true but every character * still manages to land in its own class (unlikely, but it's * cheap to check for). If all these things are true then the * character code needed to represent NUL's equivalence class for * indexing the tables is going to take one more bit than the * number of characters, and therefore we won't be assured of * being able to fit it into a YY_CHAR variable. This rules out * storing the transitions in a compressed table, since the code * for interpreting them uses a YY_CHAR variable (perhaps it * should just use an integer, though; this is worth pondering ... * ###). * * Finally, for full tables, we want the number of entries in the * table to be a power of two so the array references go fast (it * will just take a shift to compute the major index). If * encoding NUL's transitions in the table will spoil this, we * give it its own table (note that this will be the case if we're * not using equivalence classes). */ /* Note that the test for ecgroup[0] == numecs below accomplishes * both (1) and (2) above */ if (!fullspd && ecgroup[0] == numecs) { /* NUL is alone in its equivalence class, which is the * last one. */ int use_NUL_table = (numecs == csize); if (fulltbl && !use_NUL_table) { /* We still may want to use the table if numecs * is a power of 2. */ int power_of_two; for (power_of_two = 1; power_of_two <= csize; power_of_two *= 2) if (numecs == power_of_two) { use_NUL_table = true; break; } } if (use_NUL_table) nultrans = allocate_integer_array (current_max_dfas); /* From now on, nultrans != nil indicates that we're * saving null transitions for later, separate encoding. */ } if (fullspd) { for (i = 0; i <= numecs; ++i) state[i] = 0; place_state (state, 0, 0); dfaacc[0].dfaacc_state = 0; } else if (fulltbl) { if (nultrans) /* We won't be including NUL's transitions in the * table, so build it for entries from 0 .. numecs - 1. */ num_full_table_rows = numecs; else /* Take into account the fact that we'll be including * the NUL entries in the transition table. Build it * from 0 .. numecs. */ num_full_table_rows = numecs + 1; /* Begin generating yy_nxt[][] * This spans the entire LONG function. * This table is tricky because we don't know how big it will be. * So we'll have to realloc() on the way... * we'll wait until we can calculate yynxt_tbl->td_hilen. */ yynxt_tbl = calloc(1, sizeof (struct yytbl_data)); yytbl_data_init (yynxt_tbl, YYTD_ID_NXT); yynxt_tbl->td_hilen = 1; yynxt_tbl->td_lolen = (flex_uint32_t) num_full_table_rows; yynxt_tbl->td_data = yynxt_data = calloc(yynxt_tbl->td_lolen * yynxt_tbl->td_hilen, sizeof (flex_int32_t)); yynxt_curr = 0; buf_prints (&yydmap_buf, "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n", long_align ? "flex_int32_t" : "flex_int16_t"); /* Unless -Ca, declare it "short" because it's a real * long-shot that that won't be large enough. */ if (gentables) out_str_dec ("static const %s yy_nxt[][%d] =\n {\n", long_align ? "flex_int32_t" : "flex_int16_t", num_full_table_rows); else { out_dec ("#undef YY_NXT_LOLEN\n#define YY_NXT_LOLEN (%d)\n", num_full_table_rows); out_str ("static const %s *yy_nxt =0;\n", long_align ? "flex_int32_t" : "flex_int16_t"); } if (gentables) outn (" {"); /* Generate 0 entries for state #0. */ for (i = 0; i < num_full_table_rows; ++i) { mk2data (0); yynxt_data[yynxt_curr++] = 0; } dataflush (); if (gentables) outn (" },\n"); } /* Create the first states. */ num_start_states = lastsc * 2; for (i = 1; i <= num_start_states; ++i) { numstates = 1; /* For each start condition, make one state for the case when * we're at the beginning of the line (the '^' operator) and * one for the case when we're not. */ if (i % 2 == 1) nset[numstates] = scset[(i / 2) + 1]; else nset[numstates] = mkbranch (scbol[i / 2], scset[i / 2]); nset = epsclosure (nset, &numstates, accset, &nacc, &hashval); if (snstods (nset, numstates, accset, nacc, hashval, &ds)) { numas += nacc; totnst += numstates; ++todo_next; if (variable_trailing_context_rules && nacc > 0) check_trailing_context (nset, numstates, accset, nacc); } } if (!fullspd) { if (!snstods (nset, 0, accset, 0, 0, &end_of_buffer_state)) flexfatal (_ ("could not create unique end-of-buffer state")); ++numas; ++num_start_states; ++todo_next; } while (todo_head < todo_next) { targptr = 0; totaltrans = 0; for (i = 1; i <= numecs; ++i) state[i] = 0; ds = ++todo_head; dset = dss[ds]; dsize = dfasiz[ds]; if (trace) fprintf (stderr, _("state # %d:\n"), ds); sympartition (dset, dsize, symlist, duplist); for (sym = 1; sym <= numecs; ++sym) { if (symlist[sym]) { symlist[sym] = 0; if (duplist[sym] == NIL) { /* Symbol has unique out-transitions. */ numstates = symfollowset (dset, dsize, sym, nset); nset = epsclosure (nset, &numstates, accset, &nacc, &hashval); if (snstods (nset, numstates, accset, nacc, hashval, &newds)) { totnst = totnst + numstates; ++todo_next; numas += nacc; if (variable_trailing_context_rules && nacc > 0) check_trailing_context (nset, numstates, accset, nacc); } state[sym] = newds; if (trace) fprintf (stderr, "\t%d\t%d\n", sym, newds); targfreq[++targptr] = 1; targstate[targptr] = newds; ++numuniq; } else { /* sym's equivalence class has the same * transitions as duplist(sym)'s * equivalence class. */ targ = state[duplist[sym]]; state[sym] = targ; if (trace) fprintf (stderr, "\t%d\t%d\n", sym, targ); /* Update frequency count for * destination state. */ i = 0; while (targstate[++i] != targ) ; ++targfreq[i]; ++numdup; } ++totaltrans; duplist[sym] = NIL; } } numsnpairs += totaltrans; if (ds > num_start_states) check_for_backing_up (ds, state); if (nultrans) { nultrans[ds] = state[NUL_ec]; state[NUL_ec] = 0; /* remove transition */ } if (fulltbl) { /* Each time we hit here, it's another td_hilen, so we realloc. */ yynxt_tbl->td_hilen++; yynxt_tbl->td_data = yynxt_data = realloc (yynxt_data, yynxt_tbl->td_hilen * yynxt_tbl->td_lolen * sizeof (flex_int32_t)); if (gentables) outn (" {"); /* Supply array's 0-element. */ if (ds == end_of_buffer_state) { mk2data (-end_of_buffer_state); yynxt_data[yynxt_curr++] = -end_of_buffer_state; } else { mk2data (end_of_buffer_state); yynxt_data[yynxt_curr++] = end_of_buffer_state; } for (i = 1; i < num_full_table_rows; ++i) { /* Jams are marked by negative of state * number. */ mk2data (state[i] ? state[i] : -ds); yynxt_data[yynxt_curr++] = state[i] ? state[i] : -ds; } dataflush (); if (gentables) outn (" },\n"); } else if (fullspd) place_state (state, ds, totaltrans); else if (ds == end_of_buffer_state) /* Special case this state to make sure it does what * it's supposed to, i.e., jam on end-of-buffer. */ stack1 (ds, 0, 0, JAMSTATE); else { /* normal, compressed state */ /* Determine which destination state is the most * common, and how many transitions to it there are. */ comfreq = 0; comstate = 0; for (i = 1; i <= targptr; ++i) if (targfreq[i] > comfreq) { comfreq = targfreq[i]; comstate = targstate[i]; } bldtbl (state, ds, totaltrans, comstate, comfreq); } } if (fulltbl) { dataend (); if (tablesext) { yytbl_data_compress (yynxt_tbl); if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0) flexerror (_ ("Could not write yynxt_tbl[][]")); } if (yynxt_tbl) { yytbl_data_destroy (yynxt_tbl); yynxt_tbl = 0; } } else if (!fullspd) { cmptmps (); /* create compressed template entries */ /* Create tables for all the states with only one * out-transition. */ while (onesp > 0) { mk1tbl (onestate[onesp], onesym[onesp], onenext[onesp], onedef[onesp]); --onesp; } mkdeftbl (); } free(accset); free(nset); }
void gen_NUL_trans(void) { /* NOTE - changes in here should be reflected in gen_next_match() */ /* Only generate a definition for "yy_cp" if we'll generate code * that uses it. Otherwise lint and the like complain. */ int need_backing_up = (num_backing_up > 0 && ! reject); if ( need_backing_up && (! nultrans || fullspd || fulltbl) ) /* We're going to need yy_cp lying around for the call * below to gen_backing_up(). */ indent_puts( "char *yy_cp = yy_c_buf_p;" ); outc( '\n' ); if ( nultrans ) { indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" ); indent_puts( "yy_is_jam = (yy_current_state == 0);" ); } else if ( fulltbl ) { do_indent(); out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec ); indent_puts( "yy_is_jam = (yy_current_state <= 0);" ); } else if ( fullspd ) { do_indent(); out_dec( "int yy_c = %d;\n", NUL_ec ); indent_puts( "yyconst struct yy_trans_info *yy_trans_info;\n" ); indent_puts( "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" ); indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); indent_puts( "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" ); } else { char NUL_ec_str[20]; (void) sprintf( NUL_ec_str, "%d", NUL_ec ); gen_next_compressed_state( NUL_ec_str ); do_indent(); out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate ); if ( reject ) { /* Only stack this state if it's a transition we * actually make. If we stack it on a jam, then * the state stack and yy_c_buf_p get out of sync. */ indent_puts( "if ( ! yy_is_jam )" ); indent_up(); indent_puts( "*yy_state_ptr++ = yy_current_state;" ); indent_down(); } } /* If we've entered an accepting state, back up; note that * compressed tables have *already* done such backing up, so * we needn't bother with it again. */ if ( need_backing_up && (fullspd || fulltbl) ) { outc( '\n' ); indent_puts( "if ( ! yy_is_jam )" ); indent_up(); indent_puts( "{" ); gen_backing_up(); indent_puts( "}" ); indent_down(); } }
void gen_next_match(void) { /* NOTE - changes in here should be reflected in gen_next_state() and * gen_NUL_trans(). */ char *char_map = useecs ? "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)"; char *char_map_2 = useecs ? "yy_ec[YY_SC_TO_UI(*++yy_cp)]" : "YY_SC_TO_UI(*++yy_cp)"; if ( fulltbl ) { indent_put2s( "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )", char_map ); indent_up(); if ( num_backing_up > 0 ) { indent_puts( "{" ); /* } for vi */ gen_backing_up(); outc( '\n' ); } indent_puts( "++yy_cp;" ); if ( num_backing_up > 0 ) /* { for vi */ indent_puts( "}" ); indent_down(); outc( '\n' ); indent_puts( "yy_current_state = -yy_current_state;" ); } else if ( fullspd ) { indent_puts( "{" ); /* } for vi */ indent_puts( "yyconst struct yy_trans_info *yy_trans_info;\n" ); indent_puts( "YY_CHAR yy_c;\n" ); indent_put2s( "for ( yy_c = %s;", char_map ); indent_puts( " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" ); indent_puts( "yy_verify == yy_c;" ); indent_put2s( " yy_c = %s )", char_map_2 ); indent_up(); if ( num_backing_up > 0 ) indent_puts( "{" ); /* } for vi */ indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); if ( num_backing_up > 0 ) { outc( '\n' ); gen_backing_up(); /* { for vi */ indent_puts( "}" ); } indent_down(); /* { for vi */ indent_puts( "}" ); } else { /* compressed */ indent_puts( "do" ); indent_up(); indent_puts( "{" ); /* } for vi */ gen_next_state( false ); indent_puts( "++yy_cp;" ); /* { for vi */ indent_puts( "}" ); indent_down(); do_indent(); if ( interactive ) out_dec( "while ( yy_base[yy_current_state] != %d );\n", jambase ); else out_dec( "while ( yy_current_state != %d );\n", jamstate ); if ( ! reject && ! interactive ) { /* Do the guaranteed-needed backing up to figure out * the match. */ indent_puts( "yy_cp = yy_last_accepting_cpos;" ); indent_puts( "yy_current_state = yy_last_accepting_state;" ); } } }
void make_tables(void) { int i; int did_eof_rule = false; skelout(); /* First, take care of YY_DO_BEFORE_ACTION depending on yymore * being used. */ set_indent( 1 ); if ( yymore_used && ! yytext_is_array ) { indent_puts( "yytext_ptr -= yy_more_len; \\" ); indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" ); } else indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" ); /* Now also deal with copying yytext_ptr to yytext if needed. */ skelout(); if ( yytext_is_array ) { if ( yymore_used ) indent_puts( "if ( yyleng + yy_more_offset >= YYLMAX ) \\" ); else indent_puts( "if ( yyleng >= YYLMAX ) \\" ); indent_up(); indent_puts( "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" ); indent_down(); if ( yymore_used ) { indent_puts( "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" ); indent_puts( "yyleng += yy_more_offset; \\" ); indent_puts( "yy_prev_more_offset = yy_more_offset; \\" ); indent_puts( "yy_more_offset = 0; \\" ); } else { indent_puts( "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" ); } } set_indent( 0 ); skelout(); out_dec( "#define YY_NUM_RULES %d\n", num_rules ); out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 ); if ( fullspd ) { /* Need to define the transet type as a size large * enough to hold the biggest offset. */ int total_table_size = tblend + numecs + 1; char *trans_offset_type = (total_table_size >= MAX_SHORT || long_align) ? "long" : "short"; set_indent( 0 ); indent_puts( "struct yy_trans_info" ); indent_up(); indent_puts( "{" ); /* } for vi */ if ( long_align ) indent_puts( "long yy_verify;" ); else indent_puts( "short yy_verify;" ); /* In cases where its sister yy_verify *is* a "yes, there is * a transition", yy_nxt is the offset (in records) to the * next state. In most cases where there is no transition, * the value of yy_nxt is irrelevant. If yy_nxt is the -1th * record of a state, though, then yy_nxt is the action number * for that state. */ indent_put2s( "%s yy_nxt;", trans_offset_type ); indent_puts( "};" ); indent_down(); } if ( fullspd ) genctbl(); else if ( fulltbl ) genftbl(); else gentabs(); /* Definitions for backing up. We don't need them if REJECT * is being used because then we use an alternative backin-up * technique instead. */ if ( num_backing_up > 0 && ! reject ) { if ( ! C_plus_plus ) { indent_puts( "static yy_state_type yy_last_accepting_state;" ); indent_puts( "static char *yy_last_accepting_cpos;\n" ); } } if ( nultrans ) { out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 ); for ( i = 1; i <= lastdfa; ++i ) { if ( fullspd ) out_dec( " &yy_transition[%d],\n", base[i] ); else mkdata( nultrans[i] ); } dataend(); } if ( ddebug ) { /* Spit out table mapping rules to line numbers. */ if ( ! C_plus_plus ) { indent_puts( "extern int yy_flex_debug;" ); indent_puts( "int yy_flex_debug = 1;\n" ); } out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_rule_linenum", num_rules ); for ( i = 1; i < num_rules; ++i ) mkdata( rule_linenum[i] ); dataend(); } if ( reject ) { /* Declare state buffer variables. */ if ( ! C_plus_plus ) { outn( "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" ); outn( "static char *yy_full_match;" ); outn( "static int yy_lp;" ); } if ( variable_trailing_context_rules ) { if ( ! C_plus_plus ) { outn( "static int yy_looking_for_trail_begin = 0;" ); outn( "static int yy_full_lp;" ); outn( "static int *yy_full_state;" ); } out_hex( "#define YY_TRAILING_MASK 0x%x\n", (unsigned int) YY_TRAILING_MASK ); out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n", (unsigned int) YY_TRAILING_HEAD_MASK ); } outn( "#define REJECT \\" ); outn( "{ \\" ); /* } for vi */ outn( "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" ); outn( "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" ); if ( variable_trailing_context_rules ) { outn( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" ); outn( "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" ); outn( "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" ); } outn( "++yy_lp; \\" ); outn( "goto find_rule; \\" ); /* { for vi */ outn( "}" ); } else { outn( "/* The intent behind this definition is that it'll catch" ); outn( " * any uses of REJECT which flex missed." ); outn( " */" ); outn( "#define REJECT reject_used_but_not_detected" ); } if ( yymore_used ) { if ( ! C_plus_plus ) { if ( yytext_is_array ) { indent_puts( "static int yy_more_offset = 0;" ); indent_puts( "static int yy_prev_more_offset = 0;" ); } else { indent_puts( "static int yy_more_flag = 0;" ); indent_puts( "static int yy_more_len = 0;" ); } } if ( yytext_is_array ) { indent_puts( "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" ); indent_puts( "#define YY_NEED_STRLEN" ); indent_puts( "#define YY_MORE_ADJ 0" ); indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" ); indent_up(); indent_puts( "{ \\" ); indent_puts( "yy_more_offset = yy_prev_more_offset; \\" ); indent_puts( "yyleng -= yy_more_offset; \\" ); indent_puts( "}" ); indent_down(); } else { indent_puts( "#define yymore() (yy_more_flag = 1)" ); indent_puts( "#define YY_MORE_ADJ yy_more_len" ); indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" ); } } else { indent_puts( "#define yymore() yymore_used_but_not_detected" ); indent_puts( "#define YY_MORE_ADJ 0" ); indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" ); } if ( ! C_plus_plus ) { if ( yytext_is_array ) { outn( "#ifndef YYLMAX" ); outn( "#define YYLMAX 8192" ); outn( "#endif\n" ); outn( "char yytext[YYLMAX];" ); outn( "char *yytext_ptr;" ); } else outn( "char *yytext;" ); } out( &action_array[defs1_offset] ); line_directive_out( stdout, 0 ); skelout(); if ( ! C_plus_plus ) { if ( use_read ) { outn( "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" ); outn( "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" ); } else { outn( "\tif ( yy_current_buffer->yy_is_interactive ) \\" ); outn( "\t\t{ \\" ); outn( "\t\tint c = '*', n; \\" ); outn( "\t\tfor ( n = 0; n < max_size && \\" ); outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" ); outn( "\t\t\tbuf[n] = (char) c; \\" ); outn( "\t\tif ( c == '\\n' ) \\" ); outn( "\t\t\tbuf[n++] = (char) c; \\" ); outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" ); outn( "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" ); outn( "\t\tresult = n; \\" ); outn( "\t\t} \\" ); outn( "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" ); outn( "\t\t && ferror( yyin ) ) \\" ); outn( "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" ); } } skelout(); indent_puts( "#define YY_RULE_SETUP \\" ); indent_up(); if ( bol_needed ) { indent_puts( "if ( yyleng > 0 ) \\" ); indent_up(); indent_puts( "yy_current_buffer->yy_at_bol = \\" ); indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" ); indent_down(); } indent_puts( "YY_USER_ACTION" ); indent_down(); skelout(); /* Copy prolog to output file. */ out( &action_array[prolog_offset] ); line_directive_out( stdout, 0 ); skelout(); set_indent( 2 ); if ( yymore_used && ! yytext_is_array ) { indent_puts( "yy_more_len = 0;" ); indent_puts( "if ( yy_more_flag )" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" ); indent_puts( "yy_more_flag = 0;" ); indent_puts( "}" ); indent_down(); } skelout(); gen_start_state(); /* Note, don't use any indentation. */ outn( "yy_match:" ); gen_next_match(); skelout(); set_indent( 2 ); gen_find_action(); skelout(); if ( do_yylineno ) { indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" ); indent_up(); indent_puts( "{" ); indent_puts( "int yyl;" ); indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" ); indent_up(); indent_puts( "if ( yytext[yyl] == '\\n' )" ); indent_up(); indent_puts( "++yylineno;" ); indent_down(); indent_down(); indent_puts( "}" ); indent_down(); } skelout(); if ( ddebug ) { indent_puts( "if ( yy_flex_debug )" ); indent_up(); indent_puts( "{" ); indent_puts( "if ( yy_act == 0 )" ); indent_up(); indent_puts( C_plus_plus ? "cerr << \"--scanner backing up\\n\";" : "fprintf( stderr, \"--scanner backing up\\n\" );" ); indent_down(); do_indent(); out_dec( "else if ( yy_act < %d )\n", num_rules ); indent_up(); if ( C_plus_plus ) { indent_puts( "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" ); indent_puts( " \"(\\\"\" << yytext << \"\\\")\\n\";" ); } else { indent_puts( "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," ); indent_puts( " yy_rule_linenum[yy_act], yytext );" ); } indent_down(); do_indent(); out_dec( "else if ( yy_act == %d )\n", num_rules ); indent_up(); if ( C_plus_plus ) { indent_puts( "cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" ); } else { indent_puts( "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," ); indent_puts( " yytext );" ); } indent_down(); do_indent(); out_dec( "else if ( yy_act == %d )\n", num_rules + 1 ); indent_up(); indent_puts( C_plus_plus ? "cerr << \"--(end of buffer or a NUL)\\n\";" : "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" ); indent_down(); do_indent(); outn( "else" ); indent_up(); if ( C_plus_plus ) { indent_puts( "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" ); } else { indent_puts( "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" ); } indent_down(); indent_puts( "}" ); indent_down(); } /* Copy actions to output file. */ skelout(); indent_up(); gen_bu_action(); out( &action_array[action_offset] ); line_directive_out( stdout, 0 ); /* generate cases for any missing EOF rules */ for ( i = 1; i <= lastsc; ++i ) if ( ! sceof[i] ) { do_indent(); out_str( "case YY_STATE_EOF(%s):\n", scname[i] ); did_eof_rule = true; } if ( did_eof_rule ) { indent_up(); indent_puts( "yyterminate();" ); indent_down(); } /* Generate code for handling NUL's, if needed. */ /* First, deal with backing up and setting up yy_cp if the scanner * finds that it should JAM on the NUL. */ skelout(); set_indent( 4 ); if ( fullspd || fulltbl ) indent_puts( "yy_cp = yy_c_buf_p;" ); else { /* compressed table */ if ( ! reject && ! interactive ) { /* Do the guaranteed-needed backing up to figure * out the match. */ indent_puts( "yy_cp = yy_last_accepting_cpos;" ); indent_puts( "yy_current_state = yy_last_accepting_state;" ); } else /* Still need to initialize yy_cp, though * yy_current_state was set up by * yy_get_previous_state(). */ indent_puts( "yy_cp = yy_c_buf_p;" ); } /* Generate code for yy_get_previous_state(). */ set_indent( 1 ); skelout(); gen_start_state(); set_indent( 2 ); skelout(); gen_next_state( true ); set_indent( 1 ); skelout(); gen_NUL_trans(); skelout(); if ( do_yylineno ) { /* update yylineno inside of unput() */ indent_puts( "if ( c == '\\n' )" ); indent_up(); indent_puts( "--yylineno;" ); indent_down(); } skelout(); /* Update BOL and yylineno inside of input(). */ if ( bol_needed ) { indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" ); if ( do_yylineno ) { indent_puts( "if ( yy_current_buffer->yy_at_bol )" ); indent_up(); indent_puts( "++yylineno;" ); indent_down(); } } else if ( do_yylineno ) { indent_puts( "if ( c == '\\n' )" ); indent_up(); indent_puts( "++yylineno;" ); indent_down(); } skelout(); /* Copy remainder of input to output. */ line_directive_out( stdout, 1 ); if ( sectnum == 3 ) (void) flexscan(); /* copy remainder of input to output */ }