📄 main.c
字号:
* synopsis * int argc; * char **argv; * flexinit( argc, argv ); */void flexinit( argc, argv )int argc;char **argv; { int i, sawcmpflag; char *arg, *flex_gettime(), *mktemp(); printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; backtrack_report = performance_report = ddebug = fulltbl = fullspd = false; yymore_used = continued_action = reject = false; yymore_really_used = reject_really_used = false; gen_line_dirs = usemecs = useecs = true; sawcmpflag = false; use_stdout = false; csize = DEFAULT_CSIZE; program_name = argv[0]; /* read flags */ for ( --argc, ++argv; argc ; --argc, ++argv ) { if ( argv[0][0] != '-' || argv[0][1] == '\0' ) break; arg = argv[0]; for ( i = 1; arg[i] != '\0'; ++i ) switch ( arg[i] ) { case 'b': backtrack_report = true; break; case 'c': fprintf( stderr, "%s: Assuming use of deprecated -c flag is really intended to be -C\n", program_name ); /* fall through */ case 'C': if ( i != 1 ) flexerror( "-C flag must be given separately" ); if ( ! sawcmpflag ) { useecs = false; usemecs = false; fulltbl = false; sawcmpflag = true; } for ( ++i; arg[i] != '\0'; ++i ) switch ( arg[i] ) { case 'e': useecs = true; break; case 'F': fullspd = true; break; case 'f': fulltbl = true; break; case 'm': usemecs = true; break; default: lerrif( "unknown -C option '%c'", (int) arg[i] ); break; } goto get_next_arg; case 'd': ddebug = true; break; case 'f': useecs = usemecs = false; fulltbl = true; break; case 'F': useecs = usemecs = false; fullspd = true; break; case 'I': interactive = true; break; case 'i': caseins = true; break; case 'L': gen_line_dirs = false; break; case 'n': /* stupid do-nothing deprecated option */ break; case 'p': performance_report = true; 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 '8': csize = CSIZE; break; default: lerrif( "unknown flag '%c'", (int) arg[i] ); break; }get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */ ; } if ( (fulltbl || fullspd) && usemecs ) flexerror( "full table and -Cm don't make sense together" ); if ( (fulltbl || fullspd) && interactive ) flexerror( "full table and -I are (currently) incompatible" ); if ( fulltbl && fullspd ) flexerror( "full table and -F are mutually exclusive" ); if ( ! skelname ) { static char skeleton_name_storage[400]; skelname = skeleton_name_storage; (void) strcpy( skelname, DEFAULT_SKELETON_FILE ); } if ( ! use_stdout ) { FILE *prev_stdout = freopen( outfile, "w", stdout ); if ( prev_stdout == NULL ) lerrsf( "could not create %s", outfile ); outfile_created = 1; } num_input_files = argc; input_files = argv; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); if ( backtrack_report ) {#ifndef SHORT_FILE_NAMES backtrack_file = fopen( "lex.backtrack", "w" );#else backtrack_file = fopen( "lex.bck", "w" );#endif if ( backtrack_file == NULL ) flexerror( "could not create lex.backtrack" ); } else backtrack_file = NULL; lastccl = 0; lastsc = 0; /* initialize the statistics */ starttime = flex_gettime(); if ( (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname );#ifdef SYS_V action_file_name = tmpnam( NULL );#endif if ( action_file_name == NULL ) { static char temp_action_file_name[32];#ifndef SHORT_FILE_NAMES (void) strcpy( temp_action_file_name, "/tmp/flexXXXXXX" );#else (void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" );#endif (void) mktemp( temp_action_file_name ); action_file_name = temp_action_file_name; } if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL ) lerrsf( "can't open temporary action file %s", action_file_name ); lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backtracking = 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) * * synopsis * readin(); */void readin() { skelout(); if ( ddebug ) puts( "#define FLEX_DEBUG" ); if ( csize == 256 ) puts( "#define YY_CHAR unsigned char" ); else puts( "#define YY_CHAR char" ); line_directive_out( stdout ); if ( yyparse() ) { pinpoint_message( "fatal parse error" ); flexend( 1 ); } if ( xlation ) { numecs = ecs_from_xlation( ecgroup ); useecs = true; } else 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 ); 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -