📄 main.c
字号:
case 'I': interactive = true; interactive_given = true; break; case 'i': caseins = true; break; case 'l': lex_compat = true; break; case 'L': gen_line_dirs = false; break; case 'n': /* Stupid do-nothing deprecated * option. */ break; case 'P': if ( i != 1 ) flexerror( "-P flag must be given separately" ); prefix = arg + i + 1; goto get_next_arg; case 'p': ++performance_report; break; case 'S': if ( i != 1 ) flexerror( "-S flag must be given separately" ); skelname = arg + i + 1; goto get_next_arg; case 's': spprdflt = true; break; case 't': use_stdout = true; break; case 'T': trace = true; break; case 'v': printstats = true; break; case 'V': fprintf( stderr, "%s version %s\n", program_name, flex_version ); exit( 0 ); case 'w': nowarn = true; break; case '7': csize = 128; csize_given = true; break; case '8': csize = CSIZE; csize_given = true; break; default: fprintf( stderr, "%s: unknown flag '%c'\n", program_name, (int) arg[i] ); usage(); exit( 1 ); } /* Used by -C, -S and -P flags in lieu of a "continue 2" * control. */ get_next_arg: ; } if ( ! csize_given ) { if ( (fulltbl || fullspd) && ! useecs ) csize = DEFAULT_CSIZE; else csize = CSIZE; } if ( ! interactive_given ) { if ( fulltbl || fullspd ) interactive = false; else interactive = true; } 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; use_read = false; } if ( (fulltbl || fullspd) && usemecs ) flexerror( "-Cf/-CF and -Cm don't make sense together" ); if ( (fulltbl || fullspd) && interactive ) flexerror( "-Cf/-CF and -I 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 ( ! use_stdout ) { FILE *prev_stdout; char *suffix; if ( C_plus_plus ) suffix = "cc"; else suffix = "c"; sprintf( outfile_path, outfile_template, prefix, suffix ); prev_stdout = freopen( outfile_path, "w", stdout ); if ( prev_stdout == NULL ) lerrsf( "could not create %s", outfile_path ); outfile_created = 1; } num_input_files = argc; input_files = argv; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); if ( backing_up_report ) {#ifndef SHORT_FILE_NAMES backing_up_file = fopen( "lex.backup", "w" );#else backing_up_file = fopen( "lex.bck", "w" );#endif if ( backing_up_file == NULL ) flexerror( "could not create lex.backup" ); } else backing_up_file = NULL; lastccl = 0; lastsc = 0; if ( skelname && (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname ); if ( strcmp( prefix, "yy" ) ) {#define GEN_PREFIX(name) printf( "#define yy%s %s%s\n", name, prefix, name ); GEN_PREFIX( "FlexLexer" ); GEN_PREFIX( "_create_buffer" ); GEN_PREFIX( "_delete_buffer" ); GEN_PREFIX( "_flex_debug" ); GEN_PREFIX( "_init_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" ); GEN_PREFIX( "wrap" ); printf( "\n" ); } lastdfa = lastnfa = 0; num_rules = num_eof_rules = default_rule = 0; numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backing_up = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; linenum = sectnum = 1; firstprot = NIL; /* Used in mkprot() so that the first proto goes in slot 1 * of the proto queue. */ lastprot = 1; 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 */ } } set_up_initial_allocations(); }/* readin - read in the rules section of the input file(s) */void readin() { skelout(); line_directive_out( (FILE *) 0 ); if ( yyparse() ) { pinpoint_message( "fatal parse error" ); flexend( 1 ); } if ( syntaxerror ) flexend( 1 ); if ( yymore_really_used == REALLY_USED ) yymore_used = true; else if ( yymore_really_used == REALLY_NOT_USED ) yymore_used = false; if ( reject_really_used == REALLY_USED ) reject = true; else if ( reject_really_used == REALLY_NOT_USED ) 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" ); } 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 flexerror( "variable trailing context rules cannot be used with -f or -F" ); } if ( csize == 256 ) puts( "typedef unsigned char YY_CHAR;" ); else puts( "typedef char YY_CHAR;" ); if ( C_plus_plus ) { puts( "#define yytext_ptr yytext" ); if ( interactive ) puts( "#define YY_INTERACTIVE" ); } if ( fullspd ) printf( "typedef const struct yy_trans_info *yy_state_type;\n" ); else if ( ! C_plus_plus ) printf( "typedef int yy_state_type;\n" ); if ( reject ) printf( "\n#define YY_USES_REJECT\n" ); if ( ddebug ) puts( "\n#define FLEX_DEBUG" ); if ( lex_compat ) { printf( "FILE *yyin = stdin, *yyout = stdout;\n" ); printf( "extern int yylineno;\n" ); printf( "int yylineno = 1;\n" ); } else if ( ! C_plus_plus ) printf( "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;\n" ); if ( C_plus_plus ) printf( "\n#include <FlexLexer.h>\n" ); else { if ( yytext_is_array ) puts( "extern char yytext[];\n" ); else { puts( "extern char *yytext;" ); puts( "#define yytext_ptr yytext" ); } } 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(); }/* set_up_initial_allocations - allocate memory for internal tables */void set_up_initial_allocations() { current_mns = INITIAL_MNS; firstst = allocate_integer_array( current_mns ); lastst = allocate_integer_array( current_mns ); finalst = allocate_integer_array( current_mns ); transchar = allocate_integer_array( current_mns ); trans1 = allocate_integer_array( current_mns ); trans2 = allocate_integer_array( current_mns ); accptnum = allocate_integer_array( current_mns ); assoc_rule = allocate_integer_array( current_mns ); state_type = allocate_integer_array( current_mns ); current_max_rules = INITIAL_MAX_RULES; rule_type = allocate_integer_array( current_max_rules ); rule_linenum = allocate_integer_array( current_max_rules ); rule_useful = allocate_integer_array( current_max_rules ); current_max_scs = INITIAL_MAX_SCS; scset = allocate_integer_array( current_max_scs ); scbol = allocate_integer_array( current_max_scs ); scxclu = allocate_integer_array( current_max_scs ); sceof = allocate_integer_array( current_max_scs ); scname = allocate_char_ptr_array( current_max_scs ); actvsc = allocate_integer_array( current_max_scs ); current_maxccls = INITIAL_MAX_CCLS; cclmap = allocate_integer_array( current_maxccls ); ccllen = allocate_integer_array( current_maxccls ); cclng = allocate_integer_array( current_maxccls ); current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE; ccltbl = allocate_Character_array( current_max_ccl_tbl_size ); current_max_dfa_size = INITIAL_MAX_DFA_SIZE; current_max_xpairs = INITIAL_MAX_XPAIRS; nxt = allocate_integer_array( current_max_xpairs ); chk = allocate_integer_array( current_max_xpairs ); current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS; tnxt = allocate_integer_array( current_max_template_xpairs ); current_max_dfas = INITIAL_MAX_DFAS; base = allocate_integer_array( current_max_dfas ); def = allocate_integer_array( current_max_dfas ); dfasiz = allocate_integer_array( current_max_dfas ); accsiz = allocate_integer_array( current_max_dfas ); dhash = allocate_integer_array( current_max_dfas ); dss = allocate_int_ptr_array( current_max_dfas ); dfaacc = allocate_dfaacc_union( current_max_dfas ); nultrans = (int *) 0; }void usage() { fprintf( stderr,"%s [-bcdfhilnpstvwBFILTV78 -C[aefFmr] -Pprefix -Sskeleton] [file ...]\n", program_name ); fprintf( stderr, "\t-b generate backing-up information to lex.backup\n" ); fprintf( stderr, "\t-c do-nothing POSIX option\n" ); fprintf( stderr, "\t-d turn on debug mode in generated scanner\n" ); fprintf( stderr, "\t-f generate fast, large scanner\n" ); fprintf( stderr, "\t-h produce this help message\n" ); fprintf( stderr, "\t-i generate case-insensitive scanner\n" ); fprintf( stderr, "\t-l maximal compatibility with original lex\n" ); fprintf( stderr, "\t-n do-nothing POSIX option\n" ); fprintf( stderr, "\t-p generate performance report to stderr\n" ); fprintf( stderr, "\t-s suppress default rule to ECHO unmatched text\n" ); fprintf( stderr, "\t-t write generated scanner on stdout instead of lex.yy.c\n" ); fprintf( stderr, "\t-v write summary of scanner statistics to stderr\n" ); fprintf( stderr, "\t-w do not generate warnings\n" ); fprintf( stderr, "\t-B generate batch scanner (opposite of -I)\n" ); fprintf( stderr, "\t-F use alternative fast scanner representation\n" ); fprintf( stderr, "\t-I generate interactive scanner (opposite of -B)\n" ); fprintf( stderr, "\t-L suppress #line directives in scanner\n" ); fprintf( stderr, "\t-T %s should run in trace mode\n", program_name ); fprintf( stderr, "\t-V report %s version\n", program_name ); fprintf( stderr, "\t-7 generate 7-bit scanner\n" ); fprintf( stderr, "\t-8 generate 8-bit scanner\n" ); fprintf( stderr, "\t-C specify degree of table compression (default is -Cem):\n" ); fprintf( stderr, "\t\t-Ca trade off larger tables for better memory alignment\n" ); fprintf( stderr, "\t\t-Ce construct equivalence classes\n" ); fprintf( stderr, "\t\t-Cf do not compress scanner tables; use -f representation\n" ); fprintf( stderr, "\t\t-CF do not compress scanner tables; use -F representation\n" ); fprintf( stderr, "\t\t-Cm construct meta-equivalence classes\n" ); fprintf( stderr, "\t\t-Cr use read() instead of stdio for scanner input\n" ); fprintf( stderr, "\t-P specify scanner prefix other than \"yy\"\n" ); fprintf( stderr, "\t-S specify skeleton file\n" ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -