void parse(int c) { printf("\x1b[01;31m%c:%c[%.*s]\x1b[00m",state,c,(int)(stack-b_stack),b_stack); switch(state) { case 'C': if(c=='I') { out1("arg"); } if(c=='{') { *stack++='('; state='X'; } break; case 'F': state='X'; if(c=='=' && stack>b_stack && stack[-1]=='v') { out1("local"); } out1(c=='=' ? "ident" : "get"); case 'P': if(c=='(') { *stack++='f'; *stack++='('; outo('('); break; } case 'X': if(c=='N') { out1("num"); } else if(c=='I') { int l=ident-b_ident; if(l==8&&memcmp("function",b_ident,ident-b_ident)==0) { state='C'; outn("def",closuren); outn("args",closuren); *fstack++=closuren++; } else if(l==3&&memcmp("var",b_ident,ident-b_ident)==0) { *stack++='v'; } else if(l==6&&memcmp("return",b_ident,ident-b_ident)==0) { *stack++='r'; } else { state='F'; } } else if(c==';') { unstack(0); outo(';'); } else if(c=='(') { *stack++='('; out1("com ("); } else if(c==')') { unstack(0); stack--; state='P'; } else if(c=='}') { unstack(0); stack--; outn("end",*(--fstack)); } else { unstack(c); *stack++=c; } break; default: goto abort; } return; abort: printf("\n Parse abort: char '%c' state '%c'\n",c,state); abort(); }
void dataend(void) { if ( datapos > 0 ) dataflush(); /* add terminator for initialization; { for vi */ outn( " } ;\n" ); dataline = 0; datapos = 0; }
void gen_points_3d(std::vector<Plane>& planes_out, cv::Mat_<unsigned char> &plane_mask, cv::Mat& points3d, cv::Mat& normals, int n_planes) { std::vector<Plane> planes; for (int i = 0; i < n_planes; i++) { Plane px; for (int j = 0; j < 1; j++) { px.set_d(rng.uniform(-3.f, -0.5f)); planes.push_back(px); } } cv::Mat_ < cv::Vec3f > outp(H, W); cv::Mat_ < cv::Vec3f > outn(H, W); plane_mask.create(H, W); // n ( r - r_0) = 0 // n * r_0 = d // // r_0 = (0,0,0) // r[0] for (int v = 0; v < H; v++) { for (int u = 0; u < W; u++) { unsigned int plane_index = (u / float(W)) * planes.size(); Plane plane = planes[plane_index]; outp(v, u) = plane.intersection(u, v, Kinv); outn(v, u) = plane.n; plane_mask(v, u) = plane_index; } } planes_out = planes; points3d = outp; normals = outn; }
/* skelout - write out one section of the skeleton file * * Description * Copies skelfile or skel array to stdout until a line beginning with * "%%" or EOF is found. */ void skelout(void) { char buf_storage[MAXLINE]; char *buf = buf_storage; int do_copy = 1; /* Loop pulling lines either from the skelfile, if we're using * one, or from the skel[] array. */ while ( skelfile ? (fgets( buf, MAXLINE, skelfile ) != NULL) : ((buf = (char *) skel[skel_ind++]) != 0) ) { /* copy from skel array */ if ( buf[0] == '%' ) { /* control line */ switch ( buf[1] ) { case '%': return; case '+': do_copy = C_plus_plus; break; case '-': do_copy = ! C_plus_plus; break; case '*': do_copy = 1; break; default: flexfatal( _( "bad line in skeleton file" ) ); } } else if ( do_copy ) { if ( skelfile ) /* Skeleton file reads include final * newline, skel[] array does not. */ out( buf ); else outn( buf ); } } }
void dataend (void) { /* short circuit any output */ if (gentables) { if (datapos > 0) dataflush (); /* add terminator for initialization; { for vi */ outn (" } ;\n"); } dataline = 0; datapos = 0; }
int main() { int const n = 1000000000; double const delta = 1.0 / n; long long const startTimeMicros = microsecondTime(); double sum = 0.0; #pragma omp parallel for reduction(+: sum) for (int i = 1; i <= n; ++i) { double const x = ( i - 0.5 ) * delta; sum += 1.0 / ( 1.0 + x * x ); } double const pi = 4.0 * delta * sum; double const elapseTime = (microsecondTime() - startTimeMicros) / 1e6; outn("OpenMP Implicit", pi, n, elapseTime, 0, omp_get_num_procs()); return 0; }
void execute (const int numberOfThreads) { long long const startTimeMicros = microsecondTime(); sum = 0.0; // Only one thread at this point so safe to access without locking. sliceSize = n / numberOfThreads; // Only one thread at this point so safe to access without locking. pthread_mutex_init(&sumMutex, NULL); pthread_attr_t attributes; pthread_attr_init(&attributes); pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE); pthread_t threads[numberOfThreads]; for (long i = 0; i < numberOfThreads; ++i) { if (pthread_create (&threads[i], &attributes, partialSum, (void *)i) != 0) { exit(1); } } pthread_attr_destroy(&attributes); int status; for (int i = 0; i < numberOfThreads; ++i) { pthread_join (threads[i], (void **)&status); } double const pi = 4.0 * delta * sum; double const elapseTime = (microsecondTime() - startTimeMicros) / 1e6; outn("PThread Global", pi, n, elapseTime, numberOfThreads, sysconf(_SC_NPROCESSORS_ONLN)); }
/* skelout - write out one section of the skeleton file * * Description * Copies skelfile or skel array to stdout until a line beginning with * "%%" or EOF is found. */ void skelout (void) { char buf_storage[MAXLINE]; char *buf = buf_storage; bool do_copy = true; /* "reset" the state by clearing the buffer and pushing a '1' */ if(sko_len > 0) sko_peek(&do_copy); sko_len = 0; sko_push(do_copy=true); /* Loop pulling lines either from the skelfile, if we're using * one, or from the skel[] array. */ while (skelfile ? (fgets (buf, MAXLINE, skelfile) != NULL) : ((buf = (char *) skel[skel_ind++]) != 0)) { if (skelfile) chomp (buf); /* copy from skel array */ if (buf[0] == '%') { /* control line */ /* print the control line as a comment. */ if (ddebug && buf[1] != '#') { if (buf[strlen (buf) - 1] == '\\') out_str ("/* %s */\\\n", buf); else out_str ("/* %s */\n", buf); } /* We've been accused of using cryptic markers in the skel. * So we'll use emacs-style-hyphenated-commands. * We might consider a hash if this if-else-if-else * chain gets too large. */ #define cmd_match(s) (strncmp(buf,(s),strlen(s))==0) if (buf[1] == '#') { /* %# indicates comment line to be ignored */ } else if (buf[1] == '%') { /* %% is a break point for skelout() */ return; } else if (cmd_match (CMD_PUSH)){ sko_push(do_copy); if(ddebug){ out_str("/*(state = (%s) */",do_copy?"true":"false"); } out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : ""); } else if (cmd_match (CMD_POP)){ sko_pop(&do_copy); if(ddebug){ out_str("/*(state = (%s) */",do_copy?"true":"false"); } out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : ""); } else if (cmd_match (CMD_IF_REENTRANT)){ sko_push(do_copy); do_copy = reentrant && do_copy; } else if (cmd_match (CMD_IF_NOT_REENTRANT)){ sko_push(do_copy); do_copy = !reentrant && do_copy; } else if (cmd_match(CMD_IF_BISON_BRIDGE)){ sko_push(do_copy); do_copy = bison_bridge_lval && do_copy; } else if (cmd_match(CMD_IF_NOT_BISON_BRIDGE)){ sko_push(do_copy); do_copy = !bison_bridge_lval && do_copy; } else if (cmd_match (CMD_ENDIF)){ sko_pop(&do_copy); } else if (cmd_match (CMD_IF_TABLES_SER)) { do_copy = do_copy && tablesext; } else if (cmd_match (CMD_TABLES_YYDMAP)) { if (tablesext && yydmap_buf.elts) outn ((char *) (yydmap_buf.elts)); } else if (cmd_match (CMD_DEFINE_YYTABLES)) { if ( tablesext ) out_str( "#define YYTABLES_NAME \"%s\"\n", tablesname ? tablesname : "yytables" ); } else if (cmd_match (CMD_IF_CPP_ONLY)) { /* only for C++ */ sko_push(do_copy); do_copy = C_plus_plus; } else if (cmd_match (CMD_IF_C_ONLY)) { /* %- only for C */ sko_push(do_copy); do_copy = !C_plus_plus; } else if (cmd_match (CMD_IF_C_OR_CPP)) { /* %* for C and C++ */ sko_push(do_copy); do_copy = true; } else if (cmd_match (CMD_NOT_FOR_HEADER)) { /* %c begin linkage-only (non-header) code. */ OUT_BEGIN_CODE (); } else if (cmd_match (CMD_OK_FOR_HEADER)) { /* %e end linkage-only code. */ OUT_END_CODE (); } else { flexfatal (_("bad line in skeleton file")); } } else if (do_copy) outn (buf); } /* end while */ }
void readin(void) { static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;"; static char yy_nostdinit[] = "FILE *yyin = NULL, *yyout = NULL;"; line_directive_out( NULL, 1 ); if ( yyparse() ) { pinpoint_message( _( "fatal parse error" ) ); flexend( 1 ); } if ( syntaxerror ) flexend( 1 ); if ( backing_up_report ) { backing_up_file = fopen( backing_name, "w" ); if ( backing_up_file == NULL ) lerrsf( _( "could not create backing-up info file %s" ), backing_name ); } else backing_up_file = NULL; if ( yymore_really_used == true ) yymore_used = true; else if ( yymore_really_used == false ) yymore_used = false; if ( reject_really_used == true ) reject = true; else if ( reject_really_used == false ) reject = false; if ( performance_report > 0 ) { if ( lex_compat ) { fprintf( stderr, _( "-l AT&T lex compatibility option entails a large performance penalty\n" ) ); fprintf( stderr, _( " and may be the actual source of other reported performance penalties\n" ) ); } else if ( do_yylineno ) { fprintf( stderr, _( "%%option yylineno entails a large performance penalty\n" ) ); } if ( performance_report > 1 ) { if ( interactive ) fprintf( stderr, _( "-I (interactive) entails a minor performance penalty\n" ) ); if ( yymore_used ) fprintf( stderr, _( "yymore() entails a minor performance penalty\n" ) ); } if ( reject ) fprintf( stderr, _( "REJECT entails a large performance penalty\n" ) ); if ( variable_trailing_context_rules ) fprintf( stderr, _( "Variable trailing context rules entail a large performance penalty\n" ) ); } if ( reject ) real_reject = true; if ( variable_trailing_context_rules ) reject = true; if ( (fulltbl || fullspd) && reject ) { if ( real_reject ) flexerror( _( "REJECT cannot be used with -f or -F" ) ); else if ( do_yylineno ) flexerror( _( "%option yylineno cannot be used with -f or -F" ) ); else flexerror( _( "variable trailing context rules cannot be used with -f or -F" ) ); } if ( reject ) outn( "\n#define YY_USES_REJECT" ); if ( ! do_yywrap ) { outn( "\n#define yywrap() 1" ); outn( "#define YY_SKIP_YYWRAP" ); } if ( ddebug ) outn( "\n#define FLEX_DEBUG" ); if ( csize == 256 ) outn( "typedef unsigned char YY_CHAR;" ); else outn( "typedef char YY_CHAR;" ); if ( C_plus_plus ) { outn( "#define yytext_ptr yytext" ); if ( interactive ) outn( "#define YY_INTERACTIVE" ); } else { if ( do_stdinit ) { outn( yy_stdinit ); } else outn( yy_nostdinit ); } if ( fullspd ) outn( "typedef yyconst struct yy_trans_info *yy_state_type;" ); else if ( ! C_plus_plus ) outn( "typedef int yy_state_type;" ); if ( ddebug ) outn( "\n#define FLEX_DEBUG" ); if ( lex_compat ) outn( "#define YY_FLEX_LEX_COMPAT" ); if ( do_yylineno && ! C_plus_plus ) { outn( "extern int yylineno;" ); outn( "int yylineno = 1;" ); } if ( C_plus_plus ) { outn( "\n#include <FlexLexer.h>" ); if ( yyclass ) { outn( "int yyFlexLexer::yylex()" ); outn( "\t{" ); outn( "\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );" ); outn( "\treturn 0;" ); outn( "\t}" ); out_str( "\n#define YY_DECL int %s::yylex()\n", yyclass ); } } else { if ( yytext_is_array ) outn( "extern char yytext[];\n" ); else { outn( "extern char *yytext;" ); outn( "#define yytext_ptr yytext" ); } if ( yyclass ) flexerror( _( "%option yyclass only meaningful for C++ scanners" ) ); } if ( useecs ) numecs = cre8ecs( nextecm, ecgroup, csize ); else numecs = csize; /* Now map the equivalence class for NUL to its expected place. */ ecgroup[0] = ecgroup[csize]; NUL_ec = ABS( ecgroup[0] ); if ( useecs ) ccl2ecl(); }
void check_options(void) { int i; if ( lex_compat ) { if ( C_plus_plus ) flexerror( _( "Can't use -+ with -l option" ) ); if ( fulltbl || fullspd ) flexerror( _( "Can't use -f or -F with -l option" ) ); /* Don't rely on detecting use of yymore() and REJECT, * just assume they'll be used. */ yymore_really_used = reject_really_used = true; yytext_is_array = true; do_yylineno = true; use_read = false; } if ( do_yylineno ) /* This should really be "maintain_backup_tables = true" */ reject_really_used = true; if ( csize == unspecified ) { if ( (fulltbl || fullspd) && ! useecs ) csize = DEFAULT_CSIZE; else csize = CSIZE; } if ( interactive == unspecified ) { if ( fulltbl || fullspd ) interactive = false; else interactive = true; } if ( fulltbl || fullspd ) { if ( usemecs ) flexerror( _( "-Cf/-CF and -Cm don't make sense together" ) ); if ( interactive ) flexerror( _( "-Cf/-CF and -I are incompatible" ) ); if ( lex_compat ) flexerror( _( "-Cf/-CF are incompatible with lex-compatibility mode" ) ); if ( do_yylineno ) flexerror( _( "-Cf/-CF and %option yylineno are incompatible" ) ); if ( fulltbl && fullspd ) flexerror( _( "-Cf and -CF are mutually exclusive" ) ); } if ( C_plus_plus && fullspd ) flexerror( _( "Can't use -+ with -CF option" ) ); if ( C_plus_plus && yytext_is_array ) { warn( _( "%array incompatible with -+ option" ) ); yytext_is_array = false; } if ( useecs ) { /* Set up doubly-linked equivalence classes. */ /* We loop all the way up to csize, since ecgroup[csize] is * the position used for NUL characters. */ ecgroup[1] = NIL; for ( i = 2; i <= csize; ++i ) { ecgroup[i] = i - 1; nextecm[i - 1] = i; } nextecm[csize] = NIL; } else { /* Put everything in its own equivalence class. */ for ( i = 1; i <= csize; ++i ) { ecgroup[i] = i; nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ } } if ( ! use_stdout ) { FILE *prev_stdout; if ( ! did_outfilename ) { char *suffix; if ( C_plus_plus ) suffix = "cc"; else suffix = "c"; sprintf( outfile_path, outfile_template, prefix, suffix ); outfilename = outfile_path; } prev_stdout = freopen( outfilename, "w", stdout ); if ( prev_stdout == NULL ) lerrsf( _( "could not create %s" ), outfilename ); outfile_created = 1; } if ( skelname && (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( _( "can't open skeleton file %s" ), skelname ); if ( strcmp( prefix, "yy" ) ) { #define GEN_PREFIX(name) out_str3( "#define yy%s %s%s\n", name, prefix, name ) if ( C_plus_plus ) GEN_PREFIX( "FlexLexer" ); else { GEN_PREFIX( "_create_buffer" ); GEN_PREFIX( "_delete_buffer" ); GEN_PREFIX( "_scan_buffer" ); GEN_PREFIX( "_scan_string" ); GEN_PREFIX( "_scan_bytes" ); GEN_PREFIX( "_flex_debug" ); GEN_PREFIX( "_init_buffer" ); GEN_PREFIX( "_flush_buffer" ); GEN_PREFIX( "_load_buffer_state" ); GEN_PREFIX( "_switch_to_buffer" ); GEN_PREFIX( "in" ); GEN_PREFIX( "leng" ); GEN_PREFIX( "lex" ); GEN_PREFIX( "out" ); GEN_PREFIX( "restart" ); GEN_PREFIX( "text" ); if ( do_yylineno ) GEN_PREFIX( "lineno" ); } if ( do_yywrap ) GEN_PREFIX( "wrap" ); outn( "" ); } if ( did_outfilename ) line_directive_out( stdout, 0 ); skelout(); }
void indent_puts(char *str) { do_indent(); outn( str ); }
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 check_options (void) { int i; const char * m4 = NULL; if (lex_compat) { if (C_plus_plus) flexerror (_("Can't use -+ with -l option")); if (fulltbl || fullspd) flexerror (_("Can't use -f or -F with -l option")); if (reentrant || bison_bridge_lval) flexerror (_ ("Can't use --reentrant or --bison-bridge with -l option")); yytext_is_array = true; do_yylineno = true; use_read = false; } #if 0 /* This makes no sense whatsoever. I'm removing it. */ if (do_yylineno) /* This should really be "maintain_backup_tables = true" */ reject_really_used = true; #endif if (csize == unspecified) { if ((fulltbl || fullspd) && !useecs) csize = DEFAULT_CSIZE; else csize = CSIZE; } if (interactive == unspecified) { if (fulltbl || fullspd) interactive = false; else interactive = true; } if (fulltbl || fullspd) { if (usemecs) flexerror (_ ("-Cf/-CF and -Cm don't make sense together")); if (interactive) flexerror (_("-Cf/-CF and -I are incompatible")); if (lex_compat) flexerror (_ ("-Cf/-CF are incompatible with lex-compatibility mode")); if (fulltbl && fullspd) flexerror (_ ("-Cf and -CF are mutually exclusive")); } if (C_plus_plus && fullspd) flexerror (_("Can't use -+ with -CF option")); if (C_plus_plus && yytext_is_array) { lwarn (_("%array incompatible with -+ option")); yytext_is_array = false; } if (C_plus_plus && (reentrant)) flexerror (_("Options -+ and --reentrant are mutually exclusive.")); if (C_plus_plus && bison_bridge_lval) flexerror (_("bison bridge not supported for the C++ scanner.")); if (useecs) { /* Set up doubly-linked equivalence classes. */ /* We loop all the way up to csize, since ecgroup[csize] is * the position used for NUL characters. */ ecgroup[1] = NIL; for (i = 2; i <= csize; ++i) { ecgroup[i] = i - 1; nextecm[i - 1] = i; } nextecm[csize] = NIL; } else { /* Put everything in its own equivalence class. */ for (i = 1; i <= csize; ++i) { ecgroup[i] = i; nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ } } if (extra_type) buf_m4_define( &m4defs_buf, "M4_EXTRA_TYPE_DEFS", extra_type); if (!use_stdout) { FILE *prev_stdout; if (!did_outfilename) { char *suffix; if (C_plus_plus) suffix = "cc"; else suffix = "c"; snprintf (outfile_path, sizeof(outfile_path), outfile_template, prefix, suffix); outfilename = outfile_path; } prev_stdout = freopen (outfilename, "w+", stdout); if (prev_stdout == NULL) lerr (_("could not create %s"), outfilename); outfile_created = 1; } /* Setup the filter chain. */ output_chain = filter_create_int(NULL, filter_tee_header, headerfilename); if ( !(m4 = getenv("M4"))) { char *slash; m4 = M4; if ((slash = strrchr(M4, '/')) != NULL) { m4 = slash+1; /* break up $PATH */ const char *path = getenv("PATH"); if (!path) { m4 = M4; } else { int m4_length = strlen(m4); do { size_t length = strlen(path); struct stat sbuf; const char *endOfDir = strchr(path, ':'); if (!endOfDir) endOfDir = path+length; { char *m4_path = calloc(endOfDir-path + 1 + m4_length + 1, 1); memcpy(m4_path, path, endOfDir-path); m4_path[endOfDir-path] = '/'; memcpy(m4_path + (endOfDir-path) + 1, m4, m4_length + 1); if (stat(m4_path, &sbuf) == 0 && (S_ISREG(sbuf.st_mode)) && sbuf.st_mode & S_IXUSR) { m4 = m4_path; break; } free(m4_path); } path = endOfDir+1; } while (path[0]); if (!path[0]) m4 = M4; } } } filter_create_ext(output_chain, m4, "-P", 0); filter_create_int(output_chain, filter_fix_linedirs, NULL); /* For debugging, only run the requested number of filters. */ if (preproc_level > 0) { filter_truncate(output_chain, preproc_level); filter_apply_chain(output_chain); } yyout = stdout; /* always generate the tablesverify flag. */ buf_m4_define (&m4defs_buf, "M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0"); if (tablesext) gentables = false; if (tablesverify) /* force generation of C tables. */ gentables = true; if (tablesext) { FILE *tablesout; struct yytbl_hdr hdr; char *pname = 0; size_t nbytes = 0; buf_m4_define (&m4defs_buf, "M4_YY_TABLES_EXTERNAL", NULL); if (!tablesfilename) { nbytes = strlen (prefix) + strlen (tablesfile_template) + 2; tablesfilename = pname = calloc(nbytes, 1); snprintf (pname, nbytes, tablesfile_template, prefix); } if ((tablesout = fopen (tablesfilename, "w")) == NULL) lerr (_("could not create %s"), tablesfilename); free(pname); tablesfilename = 0; yytbl_writer_init (&tableswr, tablesout); nbytes = strlen (prefix) + strlen ("tables") + 2; tablesname = calloc(nbytes, 1); snprintf (tablesname, nbytes, "%stables", prefix); yytbl_hdr_init (&hdr, flex_version, tablesname); if (yytbl_hdr_fwrite (&tableswr, &hdr) <= 0) flexerror (_("could not write tables header")); } if (skelname && (skelfile = fopen (skelname, "r")) == NULL) lerr (_("can't open skeleton file %s"), skelname); if (reentrant) { buf_m4_define (&m4defs_buf, "M4_YY_REENTRANT", NULL); if (yytext_is_array) buf_m4_define (&m4defs_buf, "M4_YY_TEXT_IS_ARRAY", NULL); } if ( bison_bridge_lval) buf_m4_define (&m4defs_buf, "M4_YY_BISON_LVAL", NULL); if ( bison_bridge_lloc) buf_m4_define (&m4defs_buf, "<M4_YY_BISON_LLOC>", NULL); if (strchr(prefix, '[') || strchr(prefix, ']')) flexerror(_("Prefix cannot include '[' or ']'")); buf_m4_define(&m4defs_buf, "M4_YY_PREFIX", prefix); if (did_outfilename) line_directive_out (stdout, 0); if (do_yylineno) buf_m4_define (&m4defs_buf, "M4_YY_USE_LINENO", NULL); /* Create the alignment type. */ buf_strdefine (&userdef_buf, "YY_INT_ALIGNED", long_align ? "long int" : "short int"); /* Define the start condition macros. */ { struct Buf tmpbuf; buf_init(&tmpbuf, sizeof(char)); for (i = 1; i <= lastsc; i++) { char *str, *fmt = "#define %s %d\n"; size_t strsz; strsz = strlen(fmt) + strlen(scname[i]) + (size_t)(1 + ceil (log10(i))) + 2; str = malloc(strsz); if (!str) flexfatal(_("allocation of macro definition failed")); snprintf(str, strsz, fmt, scname[i], i - 1); buf_strappend(&tmpbuf, str); free(str); } buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts); buf_destroy(&tmpbuf); } /* This is where we begin writing to the file. */ /* Dump the %top code. */ if( top_buf.elts) outn((char*) top_buf.elts); /* Dump the m4 definitions. */ buf_print_strings(&m4defs_buf, stdout); m4defs_buf.nelts = 0; /* memory leak here. */ /* Place a bogus line directive, it will be fixed in the filter. */ if (gen_line_dirs) outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n"); /* Dump the user defined preproc directives. */ if (userdef_buf.elts) outn ((char *) (userdef_buf.elts)); skelout (); /* %% [1.0] */ }
void readin (void) { static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;"; static char yy_nostdinit[] = "FILE *yyin = NULL, *yyout = NULL;"; line_directive_out(NULL, 1); if (yyparse ()) { pinpoint_message (_("fatal parse error")); flexend (1); } if (syntaxerror) flexend (1); /* If the user explicitly requested posix compatibility by specifing the * posix-compat option, then we check for conflicting options. However, if * the POSIXLY_CORRECT variable is set, then we quietly make flex as * posix-compatible as possible. This is the recommended behavior * according to the GNU Coding Standards. * * Note: The posix option was added to flex to provide the posix behavior * of the repeat operator in regular expressions, e.g., `ab{3}' */ if (posix_compat) { /* TODO: This is where we try to make flex behave according to * posiz, AND check for conflicting options. How far should we go * with this? Should we disable all the neat-o flex features? */ /* Update: Estes says no, since other flex features don't violate posix. */ } if (getenv ("POSIXLY_CORRECT")) { posix_compat = true; } if (backing_up_report) { backing_up_file = fopen (backing_name, "w"); if (backing_up_file == NULL) lerr (_ ("could not create backing-up info file %s"), backing_name); } else backing_up_file = NULL; if (yymore_really_used == true) yymore_used = true; else if (yymore_really_used == false) yymore_used = false; if (reject_really_used == true) reject = true; else if (reject_really_used == false) reject = false; if (performance_report > 0) { if (lex_compat) { fprintf (stderr, _ ("-l AT&T lex compatibility option entails a large performance penalty\n")); fprintf (stderr, _ (" and may be the actual source of other reported performance penalties\n")); } else if (do_yylineno) { fprintf (stderr, _ ("%%option yylineno entails a performance penalty ONLY on rules that can match newline characters\n")); } if (performance_report > 1) { if (interactive) fprintf (stderr, _ ("-I (interactive) entails a minor performance penalty\n")); if (yymore_used) fprintf (stderr, _ ("yymore() entails a minor performance penalty\n")); } if (reject) fprintf (stderr, _ ("REJECT entails a large performance penalty\n")); if (variable_trailing_context_rules) fprintf (stderr, _ ("Variable trailing context rules entail a large performance penalty\n")); } if (reject) real_reject = true; if (variable_trailing_context_rules) reject = true; if ((fulltbl || fullspd) && reject) { if (real_reject) flexerror (_ ("REJECT cannot be used with -f or -F")); else if (do_yylineno) flexerror (_ ("%option yylineno cannot be used with REJECT")); else flexerror (_ ("variable trailing context rules cannot be used with -f or -F")); } if (reject){ out_m4_define( "M4_YY_USES_REJECT", NULL); //outn ("\n#define YY_USES_REJECT"); } if (!do_yywrap) { if (!C_plus_plus) { if (reentrant) out_str ("\n#define %swrap(yyscanner) (/*CONSTCOND*/1)\n", prefix); else out_str ("\n#define %swrap() (/*CONSTCOND*/1)\n", prefix); } outn ("#define YY_SKIP_YYWRAP"); } if (ddebug) outn ("\n#define FLEX_DEBUG"); OUT_BEGIN_CODE (); outn ("typedef flex_uint8_t YY_CHAR;"); OUT_END_CODE (); if (C_plus_plus) { outn ("#define yytext_ptr yytext"); if (interactive) outn ("#define YY_INTERACTIVE"); } else { OUT_BEGIN_CODE (); /* In reentrant scanner, stdinit is handled in flex.skl. */ if (do_stdinit) { if (reentrant){ outn ("#ifdef VMS"); outn ("#ifdef __VMS_POSIX"); outn ("#define YY_STDINIT"); outn ("#endif"); outn ("#else"); outn ("#define YY_STDINIT"); outn ("#endif"); } outn ("#ifdef VMS"); outn ("#ifndef __VMS_POSIX"); outn (yy_nostdinit); outn ("#else"); outn (yy_stdinit); outn ("#endif"); outn ("#else"); outn (yy_stdinit); outn ("#endif"); } else { if(!reentrant) outn (yy_nostdinit); } OUT_END_CODE (); } OUT_BEGIN_CODE (); if (fullspd) outn ("typedef const struct yy_trans_info *yy_state_type;"); else if (!C_plus_plus) outn ("typedef int yy_state_type;"); OUT_END_CODE (); if (lex_compat) outn ("#define YY_FLEX_LEX_COMPAT"); if (!C_plus_plus && !reentrant) { outn ("extern int yylineno;"); OUT_BEGIN_CODE (); outn ("int yylineno = 1;"); OUT_END_CODE (); } if (C_plus_plus) { outn ("\n#include <FlexLexer.h>"); if (!do_yywrap) { outn("\nint yyFlexLexer::yywrap() { return 1; }"); } if (yyclass) { outn ("int yyFlexLexer::yylex()"); outn ("\t{"); outn ("\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );"); outn ("\treturn 0;"); outn ("\t}"); out_str ("\n#define YY_DECL int %s::yylex()\n", yyclass); } } else { /* Watch out: yytext_ptr is a variable when yytext is an array, * but it's a macro when yytext is a pointer. */ if (yytext_is_array) { if (!reentrant) outn ("extern char yytext[];\n"); } else { if (reentrant) { outn ("#define yytext_ptr yytext_r"); } else { outn ("extern char *yytext;"); outn("#ifdef yytext_ptr"); outn("#undef yytext_ptr"); outn("#endif"); outn ("#define yytext_ptr yytext"); } } if (yyclass) flexerror (_ ("%option yyclass only meaningful for C++ scanners")); } if (useecs) numecs = cre8ecs (nextecm, ecgroup, csize); else numecs = csize; /* Now map the equivalence class for NUL to its expected place. */ ecgroup[0] = ecgroup[csize]; NUL_ec = ABS (ecgroup[0]); if (useecs) ccl2ecl (); }
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 */ }
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(); }
void gen_find_action() { if ( fullspd ) indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" ); else if ( fulltbl ) indent_puts( "yy_act = yy_accept[yy_current_state];" ); else if ( reject ) { indent_puts( "yy_current_state = *--yy_state_ptr;" ); indent_puts( "yy_lp = yy_accept[yy_current_state];" ); outn( "find_rule: /* we branch to this label when backing up */" ); indent_puts( "for ( ; ; ) /* until we find what rule we matched */" ); indent_up(); indent_puts( "{" ); indent_puts( "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_act = yy_acclist[yy_lp];" ); if ( variable_trailing_context_rules ) { indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" ); indent_puts( " yy_looking_for_trail_begin )" ); indent_up(); indent_puts( "{" ); indent_puts( "if ( yy_act == yy_looking_for_trail_begin )" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_looking_for_trail_begin = 0;" ); indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" ); indent_puts( "break;" ); indent_puts( "}" ); indent_down(); indent_puts( "}" ); indent_down(); indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" ); indent_puts( "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" ); if ( real_reject ) { /* Remember matched text in case we back up * due to REJECT. */ indent_puts( "yy_full_match = yy_cp;" ); indent_puts( "yy_full_state = yy_state_ptr;" ); indent_puts( "yy_full_lp = yy_lp;" ); } indent_puts( "}" ); indent_down(); indent_puts( "else" ); indent_up(); indent_puts( "{" ); indent_puts( "yy_full_match = yy_cp;" ); indent_puts( "yy_full_state = yy_state_ptr;" ); indent_puts( "yy_full_lp = yy_lp;" ); indent_puts( "break;" ); indent_puts( "}" ); indent_down(); indent_puts( "++yy_lp;" ); indent_puts( "goto find_rule;" ); } else { /* Remember matched text in case we back up due to * trailing context plus REJECT. */ indent_up(); indent_puts( "{" ); indent_puts( "yy_full_match = yy_cp;" ); indent_puts( "break;" ); indent_puts( "}" ); indent_down(); } indent_puts( "}" ); indent_down(); indent_puts( "--yy_cp;" ); /* We could consolidate the following two lines with those at * the beginning, but at the cost of complaints that we're * branching inside a loop. */ indent_puts( "yy_current_state = *--yy_state_ptr;" ); indent_puts( "yy_lp = yy_accept[yy_current_state];" ); indent_puts( "}" ); indent_down(); } else { /* compressed */ indent_puts( "yy_act = yy_accept[yy_current_state];" ); if ( interactive && ! reject ) { /* Do the guaranteed-needed backing up to figure out * the match. */ indent_puts( "if ( yy_act == 0 )" ); indent_up(); indent_puts( "{ /* have to back up */" ); indent_puts( "yy_cp = yy_last_accepting_cpos;" ); indent_puts( "yy_current_state = yy_last_accepting_state;" ); indent_puts( "yy_act = yy_accept[yy_current_state];" ); indent_puts( "}" ); indent_down(); } } }
void indent_put2s(char *fmt, char *arg) { do_indent(); out_str( fmt, arg ); outn( "" ); }