| 1 | /* flex - tool to generate fast lexical analyzers */
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (c) 1990 The Regents of the University of California. */
|
|---|
| 4 | /* All rights reserved. */
|
|---|
| 5 |
|
|---|
| 6 | /* This code is derived from software contributed to Berkeley by */
|
|---|
| 7 | /* Vern Paxson. */
|
|---|
| 8 |
|
|---|
| 9 | /* The United States Government has rights in this work pursuant */
|
|---|
| 10 | /* to contract no. DE-AC03-76SF00098 between the United States */
|
|---|
| 11 | /* Department of Energy and the University of California. */
|
|---|
| 12 |
|
|---|
| 13 | /* This file is part of flex. */
|
|---|
| 14 |
|
|---|
| 15 | /* Redistribution and use in source and binary forms, with or without */
|
|---|
| 16 | /* modification, are permitted provided that the following conditions */
|
|---|
| 17 | /* are met: */
|
|---|
| 18 |
|
|---|
| 19 | /* 1. Redistributions of source code must retain the above copyright */
|
|---|
| 20 | /* notice, this list of conditions and the following disclaimer. */
|
|---|
| 21 | /* 2. Redistributions in binary form must reproduce the above copyright */
|
|---|
| 22 | /* notice, this list of conditions and the following disclaimer in the */
|
|---|
| 23 | /* documentation and/or other materials provided with the distribution. */
|
|---|
| 24 |
|
|---|
| 25 | /* Neither the name of the University nor the names of its contributors */
|
|---|
| 26 | /* may be used to endorse or promote products derived from this software */
|
|---|
| 27 | /* without specific prior written permission. */
|
|---|
| 28 |
|
|---|
| 29 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
|
|---|
| 30 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
|
|---|
| 31 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
|
|---|
| 32 | /* PURPOSE. */
|
|---|
| 33 | |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | #include "flexdef.h"
|
|---|
| 37 | #include "version.h"
|
|---|
| 38 | #include "options.h"
|
|---|
| 39 | #include "tables.h"
|
|---|
| 40 |
|
|---|
| 41 | static char flex_version[] = FLEX_VERSION;
|
|---|
| 42 |
|
|---|
| 43 | /* declare functions that have forward references */
|
|---|
| 44 |
|
|---|
| 45 | void flexinit PROTO ((int, char **));
|
|---|
| 46 | void readin PROTO ((void));
|
|---|
| 47 | void set_up_initial_allocations PROTO ((void));
|
|---|
| 48 | static char *basename2 PROTO ((char *path, int should_strip_ext));
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | /* these globals are all defined and commented in flexdef.h */
|
|---|
| 52 | int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
|
|---|
| 53 | int interactive, caseins, lex_compat, posix_compat, do_yylineno,
|
|---|
| 54 | useecs, fulltbl, usemecs;
|
|---|
| 55 | int fullspd, gen_line_dirs, performance_report, backing_up_report;
|
|---|
| 56 | int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap,
|
|---|
| 57 | csize;
|
|---|
| 58 | int reentrant, bison_bridge_lval, bison_bridge_lloc;
|
|---|
| 59 | int yymore_used, reject, real_reject, continued_action, in_rule;
|
|---|
| 60 | int yymore_really_used, reject_really_used;
|
|---|
| 61 | int datapos, dataline, linenum, out_linenum;
|
|---|
| 62 | FILE *skelfile = NULL;
|
|---|
| 63 | int skel_ind = 0;
|
|---|
| 64 | char *action_array;
|
|---|
| 65 | int action_size, defs1_offset, prolog_offset, action_offset,
|
|---|
| 66 | action_index;
|
|---|
| 67 | char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL;
|
|---|
| 68 | int did_outfilename;
|
|---|
| 69 | char *prefix, *yyclass;
|
|---|
| 70 | int do_stdinit, use_stdout;
|
|---|
| 71 | int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
|
|---|
| 72 | int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
|
|---|
| 73 | int maximum_mns, current_mns, current_max_rules;
|
|---|
| 74 | int num_rules, num_eof_rules, default_rule, lastnfa;
|
|---|
| 75 | int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
|
|---|
| 76 | int *accptnum, *assoc_rule, *state_type;
|
|---|
| 77 | int *rule_type, *rule_linenum, *rule_useful;
|
|---|
| 78 | int current_state_type;
|
|---|
| 79 | int variable_trailing_context_rules;
|
|---|
| 80 | int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
|
|---|
| 81 | int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
|
|---|
| 82 | int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs,
|
|---|
| 83 | tecfwd[CSIZE + 1];
|
|---|
| 84 | int tecbck[CSIZE + 1];
|
|---|
| 85 | int lastsc, *scset, *scbol, *scxclu, *sceof;
|
|---|
| 86 | int current_max_scs;
|
|---|
| 87 | char **scname;
|
|---|
| 88 | int current_max_dfa_size, current_max_xpairs;
|
|---|
| 89 | int current_max_template_xpairs, current_max_dfas;
|
|---|
| 90 | int lastdfa, *nxt, *chk, *tnxt;
|
|---|
| 91 | int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
|
|---|
| 92 | union dfaacc_union *dfaacc;
|
|---|
| 93 | int *accsiz, *dhash, numas;
|
|---|
| 94 | int numsnpairs, jambase, jamstate;
|
|---|
| 95 | int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
|
|---|
| 96 | int current_maxccls, current_max_ccl_tbl_size;
|
|---|
| 97 | Char *ccltbl;
|
|---|
| 98 | char nmstr[MAXLINE];
|
|---|
| 99 | int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
|
|---|
| 100 | int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
|
|---|
| 101 | int num_backing_up, bol_needed;
|
|---|
| 102 | FILE *backing_up_file;
|
|---|
| 103 | int end_of_buffer_state;
|
|---|
| 104 | char **input_files;
|
|---|
| 105 | int num_input_files;
|
|---|
| 106 | jmp_buf flex_main_jmp_buf;
|
|---|
| 107 | bool *rule_has_nl, *ccl_has_nl;
|
|---|
| 108 | int nlch = '\n';
|
|---|
| 109 | bool ansi_func_defs, ansi_func_protos;
|
|---|
| 110 |
|
|---|
| 111 | bool tablesext, tablesverify, gentables;
|
|---|
| 112 | char *tablesfilename=0,*tablesname=0;
|
|---|
| 113 | struct yytbl_writer tableswr;
|
|---|
| 114 |
|
|---|
| 115 | /* Make sure program_name is initialized so we don't crash if writing
|
|---|
| 116 | * out an error message before getting the program name from argv[0].
|
|---|
| 117 | */
|
|---|
| 118 | char *program_name = "flex";
|
|---|
| 119 |
|
|---|
| 120 | #ifndef SHORT_FILE_NAMES
|
|---|
| 121 | static char *outfile_template = "lex.%s.%s";
|
|---|
| 122 | static char *backing_name = "lex.backup";
|
|---|
| 123 | static char *tablesfile_template = "lex.%s.tables";
|
|---|
| 124 | #else
|
|---|
| 125 | static char *outfile_template = "lex%s.%s";
|
|---|
| 126 | static char *backing_name = "lex.bck";
|
|---|
| 127 | static char *tablesfile_template = "lex%s.tbl";
|
|---|
| 128 | #endif
|
|---|
| 129 |
|
|---|
| 130 | #ifdef MS_DOS
|
|---|
| 131 | extern unsigned _stklen = 16384;
|
|---|
| 132 | #endif
|
|---|
| 133 |
|
|---|
| 134 | /* From scan.l */
|
|---|
| 135 | extern FILE* yyout;
|
|---|
| 136 |
|
|---|
| 137 | static char outfile_path[MAXLINE];
|
|---|
| 138 | static int outfile_created = 0;
|
|---|
| 139 | static char *skelname = NULL;
|
|---|
| 140 | static int _stdout_closed = 0; /* flag to prevent double-fclose() on stdout. */
|
|---|
| 141 |
|
|---|
| 142 | /* For debugging. The max number of filters to apply to skeleton. */
|
|---|
| 143 | static int preproc_level = 1000;
|
|---|
| 144 |
|
|---|
| 145 | int flex_main PROTO ((int argc, char *argv[]));
|
|---|
| 146 | int main PROTO ((int argc, char *argv[]));
|
|---|
| 147 |
|
|---|
| 148 | int flex_main (argc, argv)
|
|---|
| 149 | int argc;
|
|---|
| 150 | char *argv[];
|
|---|
| 151 | {
|
|---|
| 152 | int i, exit_status, child_status;
|
|---|
| 153 |
|
|---|
| 154 | /* Set a longjmp target. Yes, I know it's a hack, but it gets worse: The
|
|---|
| 155 | * return value of setjmp, if non-zero, is the desired exit code PLUS ONE.
|
|---|
| 156 | * For example, if you want 'main' to return with code '2', then call
|
|---|
| 157 | * longjmp() with an argument of 3. This is because it is invalid to
|
|---|
| 158 | * specify a value of 0 to longjmp. FLEX_EXIT(n) should be used instead of
|
|---|
| 159 | * exit(n);
|
|---|
| 160 | */
|
|---|
| 161 | exit_status = setjmp (flex_main_jmp_buf);
|
|---|
| 162 | if (exit_status){
|
|---|
| 163 | if (stdout && !_stdout_closed && !ferror(stdout)){
|
|---|
| 164 | fflush(stdout);
|
|---|
| 165 | fclose(stdout);
|
|---|
| 166 | }
|
|---|
| 167 | while (wait(&child_status) > 0){
|
|---|
| 168 | if (!WIFEXITED (child_status)
|
|---|
| 169 | || WEXITSTATUS (child_status) != 0){
|
|---|
| 170 | /* report an error of a child
|
|---|
| 171 | */
|
|---|
| 172 | if( exit_status <= 1 )
|
|---|
| 173 | exit_status = 2;
|
|---|
| 174 |
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 | return exit_status - 1;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | flexinit (argc, argv);
|
|---|
| 181 |
|
|---|
| 182 | readin ();
|
|---|
| 183 |
|
|---|
| 184 | ntod ();
|
|---|
| 185 |
|
|---|
| 186 | for (i = 1; i <= num_rules; ++i)
|
|---|
| 187 | if (!rule_useful[i] && i != default_rule)
|
|---|
| 188 | line_warning (_("rule cannot be matched"),
|
|---|
| 189 | rule_linenum[i]);
|
|---|
| 190 |
|
|---|
| 191 | if (spprdflt && !reject && rule_useful[default_rule])
|
|---|
| 192 | line_warning (_
|
|---|
| 193 | ("-s option given but default rule can be matched"),
|
|---|
| 194 | rule_linenum[default_rule]);
|
|---|
| 195 |
|
|---|
| 196 | /* Generate the C state transition tables from the DFA. */
|
|---|
| 197 | make_tables ();
|
|---|
| 198 |
|
|---|
| 199 | /* Note, flexend does not return. It exits with its argument
|
|---|
| 200 | * as status.
|
|---|
| 201 | */
|
|---|
| 202 | flexend (0);
|
|---|
| 203 |
|
|---|
| 204 | return 0; /* keep compilers/lint happy */
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | /* Wrapper around flex_main, so flex_main can be built as a library. */
|
|---|
| 208 | int main (argc, argv)
|
|---|
| 209 | int argc;
|
|---|
| 210 | char *argv[];
|
|---|
| 211 | {
|
|---|
| 212 | #if ENABLE_NLS
|
|---|
| 213 | #if HAVE_LOCALE_H
|
|---|
| 214 | setlocale (LC_MESSAGES, "");
|
|---|
| 215 | textdomain (PACKAGE);
|
|---|
| 216 | bindtextdomain (PACKAGE, LOCALEDIR);
|
|---|
| 217 | #endif
|
|---|
| 218 | #endif
|
|---|
| 219 |
|
|---|
| 220 | return flex_main (argc, argv);
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | /* check_options - check user-specified options */
|
|---|
| 224 |
|
|---|
| 225 | void check_options ()
|
|---|
| 226 | {
|
|---|
| 227 | int i;
|
|---|
| 228 | const char * m4 = NULL;
|
|---|
| 229 |
|
|---|
| 230 | if (lex_compat) {
|
|---|
| 231 | if (C_plus_plus)
|
|---|
| 232 | flexerror (_("Can't use -+ with -l option"));
|
|---|
| 233 |
|
|---|
| 234 | if (fulltbl || fullspd)
|
|---|
| 235 | flexerror (_("Can't use -f or -F with -l option"));
|
|---|
| 236 |
|
|---|
| 237 | if (reentrant || bison_bridge_lval)
|
|---|
| 238 | flexerror (_
|
|---|
| 239 | ("Can't use --reentrant or --bison-bridge with -l option"));
|
|---|
| 240 |
|
|---|
| 241 | /* Don't rely on detecting use of yymore() and REJECT,
|
|---|
| 242 | * just assume they'll be used.
|
|---|
| 243 | */
|
|---|
| 244 | yymore_really_used = reject_really_used = true;
|
|---|
| 245 |
|
|---|
| 246 | yytext_is_array = true;
|
|---|
| 247 | do_yylineno = true;
|
|---|
| 248 | use_read = false;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 | #if 0
|
|---|
| 253 | /* This makes no sense whatsoever. I'm removing it. */
|
|---|
| 254 | if (do_yylineno)
|
|---|
| 255 | /* This should really be "maintain_backup_tables = true" */
|
|---|
| 256 | reject_really_used = true;
|
|---|
| 257 | #endif
|
|---|
| 258 |
|
|---|
| 259 | if (csize == unspecified) {
|
|---|
| 260 | if ((fulltbl || fullspd) && !useecs)
|
|---|
| 261 | csize = DEFAULT_CSIZE;
|
|---|
| 262 | else
|
|---|
| 263 | csize = CSIZE;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | if (interactive == unspecified) {
|
|---|
| 267 | if (fulltbl || fullspd)
|
|---|
| 268 | interactive = false;
|
|---|
| 269 | else
|
|---|
| 270 | interactive = true;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | if (fulltbl || fullspd) {
|
|---|
| 274 | if (usemecs)
|
|---|
| 275 | flexerror (_
|
|---|
| 276 | ("-Cf/-CF and -Cm don't make sense together"));
|
|---|
| 277 |
|
|---|
| 278 | if (interactive)
|
|---|
| 279 | flexerror (_("-Cf/-CF and -I are incompatible"));
|
|---|
| 280 |
|
|---|
| 281 | if (lex_compat)
|
|---|
| 282 | flexerror (_
|
|---|
| 283 | ("-Cf/-CF are incompatible with lex-compatibility mode"));
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 | if (fulltbl && fullspd)
|
|---|
| 287 | flexerror (_
|
|---|
| 288 | ("-Cf and -CF are mutually exclusive"));
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | if (C_plus_plus && fullspd)
|
|---|
| 292 | flexerror (_("Can't use -+ with -CF option"));
|
|---|
| 293 |
|
|---|
| 294 | if (C_plus_plus && yytext_is_array) {
|
|---|
| 295 | warn (_("%array incompatible with -+ option"));
|
|---|
| 296 | yytext_is_array = false;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | if (C_plus_plus && (reentrant))
|
|---|
| 300 | flexerror (_("Options -+ and --reentrant are mutually exclusive."));
|
|---|
| 301 |
|
|---|
| 302 | if (C_plus_plus && bison_bridge_lval)
|
|---|
| 303 | flexerror (_("bison bridge not supported for the C++ scanner."));
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 | if (useecs) { /* Set up doubly-linked equivalence classes. */
|
|---|
| 307 |
|
|---|
| 308 | /* We loop all the way up to csize, since ecgroup[csize] is
|
|---|
| 309 | * the position used for NUL characters.
|
|---|
| 310 | */
|
|---|
| 311 | ecgroup[1] = NIL;
|
|---|
| 312 |
|
|---|
| 313 | for (i = 2; i <= csize; ++i) {
|
|---|
| 314 | ecgroup[i] = i - 1;
|
|---|
| 315 | nextecm[i - 1] = i;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | nextecm[csize] = NIL;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | else {
|
|---|
| 322 | /* Put everything in its own equivalence class. */
|
|---|
| 323 | for (i = 1; i <= csize; ++i) {
|
|---|
| 324 | ecgroup[i] = i;
|
|---|
| 325 | nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */
|
|---|
| 326 | }
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | if (!ansi_func_defs)
|
|---|
| 330 | buf_m4_define( &m4defs_buf, "M4_YY_NO_ANSI_FUNC_DEFS", NULL);
|
|---|
| 331 |
|
|---|
| 332 | if (!ansi_func_protos)
|
|---|
| 333 | buf_m4_define( &m4defs_buf, "M4_YY_NO_ANSI_FUNC_PROTOS", NULL);
|
|---|
| 334 |
|
|---|
| 335 | if (!use_stdout) {
|
|---|
| 336 | FILE *prev_stdout;
|
|---|
| 337 |
|
|---|
| 338 | if (!did_outfilename) {
|
|---|
| 339 | char *suffix;
|
|---|
| 340 |
|
|---|
| 341 | if (C_plus_plus)
|
|---|
| 342 | suffix = "cc";
|
|---|
| 343 | else
|
|---|
| 344 | suffix = "c";
|
|---|
| 345 |
|
|---|
| 346 | sprintf (outfile_path, outfile_template,
|
|---|
| 347 | prefix, suffix);
|
|---|
| 348 |
|
|---|
| 349 | outfilename = outfile_path;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | prev_stdout = freopen (outfilename, "w+b", stdout);
|
|---|
| 353 |
|
|---|
| 354 | if (prev_stdout == NULL)
|
|---|
| 355 | lerrsf (_("could not create %s"), outfilename);
|
|---|
| 356 |
|
|---|
| 357 | outfile_created = 1;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 | /* Setup the filter chain. */
|
|---|
| 362 | output_chain = filter_create_int(NULL, filter_tee_header, headerfilename);
|
|---|
| 363 | if ( !(m4 = getenv("M4")))
|
|---|
| 364 | m4 = M4;
|
|---|
| 365 | filter_create_ext(output_chain, m4, "-P", 0);
|
|---|
| 366 | filter_create_int(output_chain, filter_fix_linedirs, NULL);
|
|---|
| 367 |
|
|---|
| 368 | /* For debugging, only run the requested number of filters. */
|
|---|
| 369 | if (preproc_level > 0) {
|
|---|
| 370 | filter_truncate(output_chain, preproc_level);
|
|---|
| 371 | filter_apply_chain(output_chain);
|
|---|
| 372 | }
|
|---|
| 373 | yyout = stdout;
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 | /* always generate the tablesverify flag. */
|
|---|
| 377 | buf_m4_define (&m4defs_buf, "M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0");
|
|---|
| 378 | if (tablesext)
|
|---|
| 379 | gentables = false;
|
|---|
| 380 |
|
|---|
| 381 | if (tablesverify)
|
|---|
| 382 | /* force generation of C tables. */
|
|---|
| 383 | gentables = true;
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 | if (tablesext) {
|
|---|
| 387 | FILE *tablesout;
|
|---|
| 388 | struct yytbl_hdr hdr;
|
|---|
| 389 | char *pname = 0;
|
|---|
| 390 | int nbytes = 0;
|
|---|
| 391 |
|
|---|
| 392 | buf_m4_define (&m4defs_buf, "M4_YY_TABLES_EXTERNAL", NULL);
|
|---|
| 393 |
|
|---|
| 394 | if (!tablesfilename) {
|
|---|
| 395 | nbytes = strlen (prefix) +
|
|---|
| 396 | strlen (tablesfile_template) + 2;
|
|---|
| 397 | tablesfilename = pname =
|
|---|
| 398 | (char *) calloc (nbytes, 1);
|
|---|
| 399 | sprintf (pname, tablesfile_template, prefix);
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | if ((tablesout = fopen (tablesfilename, "wb")) == NULL)
|
|---|
| 403 | lerrsf (_("could not create %s"), tablesfilename);
|
|---|
| 404 | if (pname)
|
|---|
| 405 | free (pname);
|
|---|
| 406 | tablesfilename = 0;
|
|---|
| 407 |
|
|---|
| 408 | yytbl_writer_init (&tableswr, tablesout);
|
|---|
| 409 |
|
|---|
| 410 | nbytes = strlen (prefix) + strlen ("tables") + 2;
|
|---|
| 411 | tablesname = (char *) calloc (nbytes, 1);
|
|---|
| 412 | sprintf (tablesname, "%stables", prefix);
|
|---|
| 413 | yytbl_hdr_init (&hdr, flex_version, tablesname);
|
|---|
| 414 |
|
|---|
| 415 | if (yytbl_hdr_fwrite (&tableswr, &hdr) <= 0)
|
|---|
| 416 | flexerror (_("could not write tables header"));
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | if (skelname && (skelfile = fopen (skelname, "r")) == NULL)
|
|---|
| 420 | lerrsf (_("can't open skeleton file %s"), skelname);
|
|---|
| 421 |
|
|---|
| 422 | if (reentrant) {
|
|---|
| 423 | buf_m4_define (&m4defs_buf, "M4_YY_REENTRANT", NULL);
|
|---|
| 424 | if (yytext_is_array)
|
|---|
| 425 | buf_m4_define (&m4defs_buf, "M4_YY_TEXT_IS_ARRAY", NULL);
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | if ( bison_bridge_lval)
|
|---|
| 429 | buf_m4_define (&m4defs_buf, "M4_YY_BISON_LVAL", NULL);
|
|---|
| 430 |
|
|---|
| 431 | if ( bison_bridge_lloc)
|
|---|
| 432 | buf_m4_define (&m4defs_buf, "<M4_YY_BISON_LLOC>", NULL);
|
|---|
| 433 |
|
|---|
| 434 | buf_m4_define(&m4defs_buf, "M4_YY_PREFIX", prefix);
|
|---|
| 435 |
|
|---|
| 436 | if (did_outfilename)
|
|---|
| 437 | line_directive_out (stdout, 0);
|
|---|
| 438 |
|
|---|
| 439 | if (do_yylineno)
|
|---|
| 440 | buf_m4_define (&m4defs_buf, "M4_YY_USE_LINENO", NULL);
|
|---|
| 441 |
|
|---|
| 442 | /* Create the alignment type. */
|
|---|
| 443 | buf_strdefine (&userdef_buf, "YY_INT_ALIGNED",
|
|---|
| 444 | long_align ? "long int" : "short int");
|
|---|
| 445 |
|
|---|
| 446 | /* Define the start condition macros. */
|
|---|
| 447 | {
|
|---|
| 448 | struct Buf tmpbuf;
|
|---|
| 449 | buf_init(&tmpbuf, sizeof(char));
|
|---|
| 450 | for (i = 1; i <= lastsc; i++) {
|
|---|
| 451 | char *str, *fmt = "#define %s %d\n";
|
|---|
| 452 |
|
|---|
| 453 | str = (char*)flex_alloc(strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2);
|
|---|
| 454 | sprintf(str, fmt, scname[i], i - 1);
|
|---|
| 455 | buf_strappend(&tmpbuf, str);
|
|---|
| 456 | free(str);
|
|---|
| 457 | }
|
|---|
| 458 | buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts);
|
|---|
| 459 | buf_destroy(&tmpbuf);
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | /* This is where we begin writing to the file. */
|
|---|
| 463 |
|
|---|
| 464 | /* Dump the %top code. */
|
|---|
| 465 | if( top_buf.elts)
|
|---|
| 466 | outn((char*) top_buf.elts);
|
|---|
| 467 |
|
|---|
| 468 | /* Dump the m4 definitions. */
|
|---|
| 469 | buf_print_strings(&m4defs_buf, stdout);
|
|---|
| 470 | m4defs_buf.nelts = 0; /* memory leak here. */
|
|---|
| 471 |
|
|---|
| 472 | /* Place a bogus line directive, it will be fixed in the filter. */
|
|---|
| 473 | outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n");
|
|---|
| 474 |
|
|---|
| 475 | /* Dump the user defined preproc directives. */
|
|---|
| 476 | if (userdef_buf.elts)
|
|---|
| 477 | outn ((char *) (userdef_buf.elts));
|
|---|
| 478 |
|
|---|
| 479 | skelout ();
|
|---|
| 480 | /* %% [1.0] */
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | /* flexend - terminate flex
|
|---|
| 484 | *
|
|---|
| 485 | * note
|
|---|
| 486 | * This routine does not return.
|
|---|
| 487 | */
|
|---|
| 488 |
|
|---|
| 489 | void flexend (exit_status)
|
|---|
| 490 | int exit_status;
|
|---|
| 491 |
|
|---|
| 492 | {
|
|---|
| 493 | static int called_before = -1; /* prevent infinite recursion. */
|
|---|
| 494 | int tblsiz;
|
|---|
| 495 |
|
|---|
| 496 | if (++called_before)
|
|---|
| 497 | FLEX_EXIT (exit_status);
|
|---|
| 498 |
|
|---|
| 499 | if (skelfile != NULL) {
|
|---|
| 500 | if (ferror (skelfile))
|
|---|
| 501 | lerrsf (_("input error reading skeleton file %s"),
|
|---|
| 502 | skelname);
|
|---|
| 503 |
|
|---|
| 504 | else if (fclose (skelfile))
|
|---|
| 505 | lerrsf (_("error closing skeleton file %s"),
|
|---|
| 506 | skelname);
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | #if 0
|
|---|
| 510 | fprintf (header_out,
|
|---|
| 511 | "#ifdef YY_HEADER_EXPORT_START_CONDITIONS\n");
|
|---|
| 512 | fprintf (header_out,
|
|---|
| 513 | "/* Beware! Start conditions are not prefixed. */\n");
|
|---|
| 514 |
|
|---|
| 515 | /* Special case for "INITIAL" */
|
|---|
| 516 | fprintf (header_out,
|
|---|
| 517 | "#undef INITIAL\n#define INITIAL 0\n");
|
|---|
| 518 | for (i = 2; i <= lastsc; i++)
|
|---|
| 519 | fprintf (header_out, "#define %s %d\n", scname[i], i - 1);
|
|---|
| 520 | fprintf (header_out,
|
|---|
| 521 | "#endif /* YY_HEADER_EXPORT_START_CONDITIONS */\n\n");
|
|---|
| 522 |
|
|---|
| 523 | /* Kill ALL flex-related macros. This is so the user
|
|---|
| 524 | * can #include more than one generated header file. */
|
|---|
| 525 | fprintf (header_out, "#ifndef YY_HEADER_NO_UNDEFS\n");
|
|---|
| 526 | fprintf (header_out,
|
|---|
| 527 | "/* Undefine all internal macros, etc., that do no belong in the header. */\n\n");
|
|---|
| 528 |
|
|---|
| 529 | {
|
|---|
| 530 | const char * undef_list[] = {
|
|---|
| 531 |
|
|---|
| 532 | "BEGIN",
|
|---|
| 533 | "ECHO",
|
|---|
| 534 | "EOB_ACT_CONTINUE_SCAN",
|
|---|
| 535 | "EOB_ACT_END_OF_FILE",
|
|---|
| 536 | "EOB_ACT_LAST_MATCH",
|
|---|
| 537 | "FLEX_SCANNER",
|
|---|
| 538 | "FLEX_STD",
|
|---|
| 539 | "REJECT",
|
|---|
| 540 | "YYFARGS0",
|
|---|
| 541 | "YYFARGS1",
|
|---|
| 542 | "YYFARGS2",
|
|---|
| 543 | "YYFARGS3",
|
|---|
| 544 | "YYLMAX",
|
|---|
| 545 | "YYSTATE",
|
|---|
| 546 | "YY_AT_BOL",
|
|---|
| 547 | "YY_BREAK",
|
|---|
| 548 | "YY_BUFFER_EOF_PENDING",
|
|---|
| 549 | "YY_BUFFER_NEW",
|
|---|
| 550 | "YY_BUFFER_NORMAL",
|
|---|
| 551 | "YY_BUF_SIZE",
|
|---|
| 552 | "M4_YY_CALL_LAST_ARG",
|
|---|
| 553 | "M4_YY_CALL_ONLY_ARG",
|
|---|
| 554 | "YY_CURRENT_BUFFER",
|
|---|
| 555 | "YY_DECL",
|
|---|
| 556 | "M4_YY_DECL_LAST_ARG",
|
|---|
| 557 | "M4_YY_DEF_LAST_ARG",
|
|---|
| 558 | "M4_YY_DEF_ONLY_ARG",
|
|---|
| 559 | "YY_DO_BEFORE_ACTION",
|
|---|
| 560 | "YY_END_OF_BUFFER",
|
|---|
| 561 | "YY_END_OF_BUFFER_CHAR",
|
|---|
| 562 | "YY_EXIT_FAILURE",
|
|---|
| 563 | "YY_EXTRA_TYPE",
|
|---|
| 564 | "YY_FATAL_ERROR",
|
|---|
| 565 | "YY_FLEX_DEFINED_ECHO",
|
|---|
| 566 | "YY_FLEX_LEX_COMPAT",
|
|---|
| 567 | "YY_FLEX_MAJOR_VERSION",
|
|---|
| 568 | "YY_FLEX_MINOR_VERSION",
|
|---|
| 569 | "YY_FLEX_SUBMINOR_VERSION",
|
|---|
| 570 | "YY_FLUSH_BUFFER",
|
|---|
| 571 | "YY_G",
|
|---|
| 572 | "YY_INPUT",
|
|---|
| 573 | "YY_INTERACTIVE",
|
|---|
| 574 | "YY_INT_ALIGNED",
|
|---|
| 575 | "YY_LAST_ARG",
|
|---|
| 576 | "YY_LESS_LINENO",
|
|---|
| 577 | "YY_LEX_ARGS",
|
|---|
| 578 | "YY_LEX_DECLARATION",
|
|---|
| 579 | "YY_LEX_PROTO",
|
|---|
| 580 | "YY_MAIN",
|
|---|
| 581 | "YY_MORE_ADJ",
|
|---|
| 582 | "YY_NEED_STRLEN",
|
|---|
| 583 | "YY_NEW_FILE",
|
|---|
| 584 | "YY_NULL",
|
|---|
| 585 | "YY_NUM_RULES",
|
|---|
| 586 | "YY_ONLY_ARG",
|
|---|
| 587 | "YY_PARAMS",
|
|---|
| 588 | "YY_PROTO",
|
|---|
| 589 | "M4_YY_PROTO_LAST_ARG",
|
|---|
| 590 | "M4_YY_PROTO_ONLY_ARG void",
|
|---|
| 591 | "YY_READ_BUF_SIZE",
|
|---|
| 592 | "YY_REENTRANT",
|
|---|
| 593 | "YY_RESTORE_YY_MORE_OFFSET",
|
|---|
| 594 | "YY_RULE_SETUP",
|
|---|
| 595 | "YY_SC_TO_UI",
|
|---|
| 596 | "YY_SKIP_YYWRAP",
|
|---|
| 597 | "YY_START",
|
|---|
| 598 | "YY_START_STACK_INCR",
|
|---|
| 599 | "YY_STATE_EOF",
|
|---|
| 600 | "YY_STDINIT",
|
|---|
| 601 | "YY_TRAILING_HEAD_MASK",
|
|---|
| 602 | "YY_TRAILING_MASK",
|
|---|
| 603 | "YY_USER_ACTION",
|
|---|
| 604 | "YY_USE_CONST",
|
|---|
| 605 | "YY_USE_PROTOS",
|
|---|
| 606 | "unput",
|
|---|
| 607 | "yyTABLES_NAME",
|
|---|
| 608 | "yy_create_buffer",
|
|---|
| 609 | "yy_delete_buffer",
|
|---|
| 610 | "yy_flex_debug",
|
|---|
| 611 | "yy_flush_buffer",
|
|---|
| 612 | "yy_init_buffer",
|
|---|
| 613 | "yy_load_buffer_state",
|
|---|
| 614 | "yy_new_buffer",
|
|---|
| 615 | "yy_scan_buffer",
|
|---|
| 616 | "yy_scan_bytes",
|
|---|
| 617 | "yy_scan_string",
|
|---|
| 618 | "yy_set_bol",
|
|---|
| 619 | "yy_set_interactive",
|
|---|
| 620 | "yy_switch_to_buffer",
|
|---|
| 621 | "yypush_buffer_state",
|
|---|
| 622 | "yypop_buffer_state",
|
|---|
| 623 | "yyensure_buffer_stack",
|
|---|
| 624 | "yyalloc",
|
|---|
| 625 | "yyconst",
|
|---|
| 626 | "yyextra",
|
|---|
| 627 | "yyfree",
|
|---|
| 628 | "yyget_debug",
|
|---|
| 629 | "yyget_extra",
|
|---|
| 630 | "yyget_in",
|
|---|
| 631 | "yyget_leng",
|
|---|
| 632 | "yyget_lineno",
|
|---|
| 633 | "yyget_lloc",
|
|---|
| 634 | "yyget_lval",
|
|---|
| 635 | "yyget_out",
|
|---|
| 636 | "yyget_text",
|
|---|
| 637 | "yyin",
|
|---|
| 638 | "yyleng",
|
|---|
| 639 | "yyless",
|
|---|
| 640 | "yylex",
|
|---|
| 641 | "yylex_destroy",
|
|---|
| 642 | "yylex_init",
|
|---|
| 643 | "yylineno",
|
|---|
| 644 | "yylloc",
|
|---|
| 645 | "yylval",
|
|---|
| 646 | "yymore",
|
|---|
| 647 | "yyout",
|
|---|
| 648 | "yyrealloc",
|
|---|
| 649 | "yyrestart",
|
|---|
| 650 | "yyset_debug",
|
|---|
| 651 | "yyset_extra",
|
|---|
| 652 | "yyset_in",
|
|---|
| 653 | "yyset_lineno",
|
|---|
| 654 | "yyset_lloc",
|
|---|
| 655 | "yyset_lval",
|
|---|
| 656 | "yyset_out",
|
|---|
| 657 | "yytables_destroy",
|
|---|
| 658 | "yytables_fload",
|
|---|
| 659 | "yyterminate",
|
|---|
| 660 | "yytext",
|
|---|
| 661 | "yytext_ptr",
|
|---|
| 662 | "yywrap",
|
|---|
| 663 |
|
|---|
| 664 | /* must be null-terminated */
|
|---|
| 665 | NULL};
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 | for (i=0; undef_list[i] != NULL; i++)
|
|---|
| 669 | fprintf (header_out, "#undef %s\n", undef_list[i]);
|
|---|
| 670 | }
|
|---|
| 671 |
|
|---|
| 672 | /* undef any of the auto-generated symbols. */
|
|---|
| 673 | for (i = 0; i < defs_buf.nelts; i++) {
|
|---|
| 674 |
|
|---|
| 675 | /* don't undef start conditions */
|
|---|
| 676 | if (sclookup (((char **) defs_buf.elts)[i]) > 0)
|
|---|
| 677 | continue;
|
|---|
| 678 | fprintf (header_out, "#undef %s\n",
|
|---|
| 679 | ((char **) defs_buf.elts)[i]);
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | fprintf (header_out,
|
|---|
| 683 | "#endif /* !YY_HEADER_NO_UNDEFS */\n");
|
|---|
| 684 | fprintf (header_out, "\n");
|
|---|
| 685 | fprintf (header_out, "#undef %sIN_HEADER\n", prefix);
|
|---|
| 686 | fprintf (header_out, "#endif /* %sHEADER_H */\n", prefix);
|
|---|
| 687 |
|
|---|
| 688 | if (ferror (header_out))
|
|---|
| 689 | lerrsf (_("error creating header file %s"),
|
|---|
| 690 | headerfilename);
|
|---|
| 691 | fflush (header_out);
|
|---|
| 692 | fclose (header_out);
|
|---|
| 693 | #endif
|
|---|
| 694 |
|
|---|
| 695 | if (exit_status != 0 && outfile_created) {
|
|---|
| 696 | if (ferror (stdout))
|
|---|
| 697 | lerrsf (_("error writing output file %s"),
|
|---|
| 698 | outfilename);
|
|---|
| 699 |
|
|---|
| 700 | else if ((_stdout_closed = 1) && fclose (stdout))
|
|---|
| 701 | lerrsf (_("error closing output file %s"),
|
|---|
| 702 | outfilename);
|
|---|
| 703 |
|
|---|
| 704 | else if (unlink (outfilename))
|
|---|
| 705 | lerrsf (_("error deleting output file %s"),
|
|---|
| 706 | outfilename);
|
|---|
| 707 | }
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 | if (backing_up_report && backing_up_file) {
|
|---|
| 711 | if (num_backing_up == 0)
|
|---|
| 712 | fprintf (backing_up_file, _("No backing up.\n"));
|
|---|
| 713 | else if (fullspd || fulltbl)
|
|---|
| 714 | fprintf (backing_up_file,
|
|---|
| 715 | _
|
|---|
| 716 | ("%d backing up (non-accepting) states.\n"),
|
|---|
| 717 | num_backing_up);
|
|---|
| 718 | else
|
|---|
| 719 | fprintf (backing_up_file,
|
|---|
| 720 | _("Compressed tables always back up.\n"));
|
|---|
| 721 |
|
|---|
| 722 | if (ferror (backing_up_file))
|
|---|
| 723 | lerrsf (_("error writing backup file %s"),
|
|---|
| 724 | backing_name);
|
|---|
| 725 |
|
|---|
| 726 | else if (fclose (backing_up_file))
|
|---|
| 727 | lerrsf (_("error closing backup file %s"),
|
|---|
| 728 | backing_name);
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | if (printstats) {
|
|---|
| 732 | fprintf (stderr, _("%s version %s usage statistics:\n"),
|
|---|
| 733 | program_name, flex_version);
|
|---|
| 734 |
|
|---|
| 735 | fprintf (stderr, _(" scanner options: -"));
|
|---|
| 736 |
|
|---|
| 737 | if (C_plus_plus)
|
|---|
| 738 | putc ('+', stderr);
|
|---|
| 739 | if (backing_up_report)
|
|---|
| 740 | putc ('b', stderr);
|
|---|
| 741 | if (ddebug)
|
|---|
| 742 | putc ('d', stderr);
|
|---|
| 743 | if (caseins)
|
|---|
| 744 | putc ('i', stderr);
|
|---|
| 745 | if (lex_compat)
|
|---|
| 746 | putc ('l', stderr);
|
|---|
| 747 | if (posix_compat)
|
|---|
| 748 | putc ('X', stderr);
|
|---|
| 749 | if (performance_report > 0)
|
|---|
| 750 | putc ('p', stderr);
|
|---|
| 751 | if (performance_report > 1)
|
|---|
| 752 | putc ('p', stderr);
|
|---|
| 753 | if (spprdflt)
|
|---|
| 754 | putc ('s', stderr);
|
|---|
| 755 | if (reentrant)
|
|---|
| 756 | fputs ("--reentrant", stderr);
|
|---|
| 757 | if (bison_bridge_lval)
|
|---|
| 758 | fputs ("--bison-bridge", stderr);
|
|---|
| 759 | if (bison_bridge_lloc)
|
|---|
| 760 | fputs ("--bison-locations", stderr);
|
|---|
| 761 | if (use_stdout)
|
|---|
| 762 | putc ('t', stderr);
|
|---|
| 763 | if (printstats)
|
|---|
| 764 | putc ('v', stderr); /* always true! */
|
|---|
| 765 | if (nowarn)
|
|---|
| 766 | putc ('w', stderr);
|
|---|
| 767 | if (interactive == false)
|
|---|
| 768 | putc ('B', stderr);
|
|---|
| 769 | if (interactive == true)
|
|---|
| 770 | putc ('I', stderr);
|
|---|
| 771 | if (!gen_line_dirs)
|
|---|
| 772 | putc ('L', stderr);
|
|---|
| 773 | if (trace)
|
|---|
| 774 | putc ('T', stderr);
|
|---|
| 775 |
|
|---|
| 776 | if (csize == unspecified)
|
|---|
| 777 | /* We encountered an error fairly early on, so csize
|
|---|
| 778 | * never got specified. Define it now, to prevent
|
|---|
| 779 | * bogus table sizes being written out below.
|
|---|
| 780 | */
|
|---|
| 781 | csize = 256;
|
|---|
| 782 |
|
|---|
| 783 | if (csize == 128)
|
|---|
| 784 | putc ('7', stderr);
|
|---|
| 785 | else
|
|---|
| 786 | putc ('8', stderr);
|
|---|
| 787 |
|
|---|
| 788 | fprintf (stderr, " -C");
|
|---|
| 789 |
|
|---|
| 790 | if (long_align)
|
|---|
| 791 | putc ('a', stderr);
|
|---|
| 792 | if (fulltbl)
|
|---|
| 793 | putc ('f', stderr);
|
|---|
| 794 | if (fullspd)
|
|---|
| 795 | putc ('F', stderr);
|
|---|
| 796 | if (useecs)
|
|---|
| 797 | putc ('e', stderr);
|
|---|
| 798 | if (usemecs)
|
|---|
| 799 | putc ('m', stderr);
|
|---|
| 800 | if (use_read)
|
|---|
| 801 | putc ('r', stderr);
|
|---|
| 802 |
|
|---|
| 803 | if (did_outfilename)
|
|---|
| 804 | fprintf (stderr, " -o%s", outfilename);
|
|---|
| 805 |
|
|---|
| 806 | if (skelname)
|
|---|
| 807 | fprintf (stderr, " -S%s", skelname);
|
|---|
| 808 |
|
|---|
| 809 | if (strcmp (prefix, "yy"))
|
|---|
| 810 | fprintf (stderr, " -P%s", prefix);
|
|---|
| 811 |
|
|---|
| 812 | putc ('\n', stderr);
|
|---|
| 813 |
|
|---|
| 814 | fprintf (stderr, _(" %d/%d NFA states\n"),
|
|---|
| 815 | lastnfa, current_mns);
|
|---|
| 816 | fprintf (stderr, _(" %d/%d DFA states (%d words)\n"),
|
|---|
| 817 | lastdfa, current_max_dfas, totnst);
|
|---|
| 818 | fprintf (stderr, _(" %d rules\n"),
|
|---|
| 819 | num_rules + num_eof_rules -
|
|---|
| 820 | 1 /* - 1 for def. rule */ );
|
|---|
| 821 |
|
|---|
| 822 | if (num_backing_up == 0)
|
|---|
| 823 | fprintf (stderr, _(" No backing up\n"));
|
|---|
| 824 | else if (fullspd || fulltbl)
|
|---|
| 825 | fprintf (stderr,
|
|---|
| 826 | _
|
|---|
| 827 | (" %d backing-up (non-accepting) states\n"),
|
|---|
| 828 | num_backing_up);
|
|---|
| 829 | else
|
|---|
| 830 | fprintf (stderr,
|
|---|
| 831 | _
|
|---|
| 832 | (" Compressed tables always back-up\n"));
|
|---|
| 833 |
|
|---|
| 834 | if (bol_needed)
|
|---|
| 835 | fprintf (stderr,
|
|---|
| 836 | _(" Beginning-of-line patterns used\n"));
|
|---|
| 837 |
|
|---|
| 838 | fprintf (stderr, _(" %d/%d start conditions\n"), lastsc,
|
|---|
| 839 | current_max_scs);
|
|---|
| 840 | fprintf (stderr,
|
|---|
| 841 | _
|
|---|
| 842 | (" %d epsilon states, %d double epsilon states\n"),
|
|---|
| 843 | numeps, eps2);
|
|---|
| 844 |
|
|---|
| 845 | if (lastccl == 0)
|
|---|
| 846 | fprintf (stderr, _(" no character classes\n"));
|
|---|
| 847 | else
|
|---|
| 848 | fprintf (stderr,
|
|---|
| 849 | _
|
|---|
| 850 | (" %d/%d character classes needed %d/%d words of storage, %d reused\n"),
|
|---|
| 851 | lastccl, current_maxccls,
|
|---|
| 852 | cclmap[lastccl] + ccllen[lastccl],
|
|---|
| 853 | current_max_ccl_tbl_size, cclreuse);
|
|---|
| 854 |
|
|---|
| 855 | fprintf (stderr, _(" %d state/nextstate pairs created\n"),
|
|---|
| 856 | numsnpairs);
|
|---|
| 857 | fprintf (stderr,
|
|---|
| 858 | _(" %d/%d unique/duplicate transitions\n"),
|
|---|
| 859 | numuniq, numdup);
|
|---|
| 860 |
|
|---|
| 861 | if (fulltbl) {
|
|---|
| 862 | tblsiz = lastdfa * numecs;
|
|---|
| 863 | fprintf (stderr, _(" %d table entries\n"),
|
|---|
| 864 | tblsiz);
|
|---|
| 865 | }
|
|---|
| 866 |
|
|---|
| 867 | else {
|
|---|
| 868 | tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend;
|
|---|
| 869 |
|
|---|
| 870 | fprintf (stderr,
|
|---|
| 871 | _(" %d/%d base-def entries created\n"),
|
|---|
| 872 | lastdfa + numtemps, current_max_dfas);
|
|---|
| 873 | fprintf (stderr,
|
|---|
| 874 | _
|
|---|
| 875 | (" %d/%d (peak %d) nxt-chk entries created\n"),
|
|---|
| 876 | tblend, current_max_xpairs, peakpairs);
|
|---|
| 877 | fprintf (stderr,
|
|---|
| 878 | _
|
|---|
| 879 | (" %d/%d (peak %d) template nxt-chk entries created\n"),
|
|---|
| 880 | numtemps * nummecs,
|
|---|
| 881 | current_max_template_xpairs,
|
|---|
| 882 | numtemps * numecs);
|
|---|
| 883 | fprintf (stderr, _(" %d empty table entries\n"),
|
|---|
| 884 | nummt);
|
|---|
| 885 | fprintf (stderr, _(" %d protos created\n"),
|
|---|
| 886 | numprots);
|
|---|
| 887 | fprintf (stderr,
|
|---|
| 888 | _(" %d templates created, %d uses\n"),
|
|---|
| 889 | numtemps, tmpuses);
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 | if (useecs) {
|
|---|
| 893 | tblsiz = tblsiz + csize;
|
|---|
| 894 | fprintf (stderr,
|
|---|
| 895 | _
|
|---|
| 896 | (" %d/%d equivalence classes created\n"),
|
|---|
| 897 | numecs, csize);
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 | if (usemecs) {
|
|---|
| 901 | tblsiz = tblsiz + numecs;
|
|---|
| 902 | fprintf (stderr,
|
|---|
| 903 | _
|
|---|
| 904 | (" %d/%d meta-equivalence classes created\n"),
|
|---|
| 905 | nummecs, csize);
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | fprintf (stderr,
|
|---|
| 909 | _
|
|---|
| 910 | (" %d (%d saved) hash collisions, %d DFAs equal\n"),
|
|---|
| 911 | hshcol, hshsave, dfaeql);
|
|---|
| 912 | fprintf (stderr, _(" %d sets of reallocations needed\n"),
|
|---|
| 913 | num_reallocs);
|
|---|
| 914 | fprintf (stderr, _(" %d total table entries needed\n"),
|
|---|
| 915 | tblsiz);
|
|---|
| 916 | }
|
|---|
| 917 |
|
|---|
| 918 | FLEX_EXIT (exit_status);
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 |
|
|---|
| 922 | /* flexinit - initialize flex */
|
|---|
| 923 |
|
|---|
| 924 | void flexinit (argc, argv)
|
|---|
| 925 | int argc;
|
|---|
| 926 | char **argv;
|
|---|
| 927 | {
|
|---|
| 928 | int i, sawcmpflag, rv, optind;
|
|---|
| 929 | char *arg;
|
|---|
| 930 | scanopt_t sopt;
|
|---|
| 931 |
|
|---|
| 932 | printstats = syntaxerror = trace = spprdflt = caseins = false;
|
|---|
| 933 | lex_compat = posix_compat = C_plus_plus = backing_up_report =
|
|---|
| 934 | ddebug = fulltbl = false;
|
|---|
| 935 | fullspd = long_align = nowarn = yymore_used = continued_action =
|
|---|
| 936 | false;
|
|---|
| 937 | do_yylineno = yytext_is_array = in_rule = reject = do_stdinit =
|
|---|
| 938 | false;
|
|---|
| 939 | yymore_really_used = reject_really_used = unspecified;
|
|---|
| 940 | interactive = csize = unspecified;
|
|---|
| 941 | do_yywrap = gen_line_dirs = usemecs = useecs = true;
|
|---|
| 942 | reentrant = bison_bridge_lval = bison_bridge_lloc = false;
|
|---|
| 943 | performance_report = 0;
|
|---|
| 944 | did_outfilename = 0;
|
|---|
| 945 | prefix = "yy";
|
|---|
| 946 | yyclass = 0;
|
|---|
| 947 | use_read = use_stdout = false;
|
|---|
| 948 | tablesext = tablesverify = false;
|
|---|
| 949 | gentables = true;
|
|---|
| 950 | tablesfilename = tablesname = NULL;
|
|---|
| 951 | ansi_func_defs = ansi_func_protos = true;
|
|---|
| 952 |
|
|---|
| 953 | sawcmpflag = false;
|
|---|
| 954 |
|
|---|
| 955 | /* Initialize dynamic array for holding the rule actions. */
|
|---|
| 956 | action_size = 2048; /* default size of action array in bytes */
|
|---|
| 957 | action_array = allocate_character_array (action_size);
|
|---|
| 958 | defs1_offset = prolog_offset = action_offset = action_index = 0;
|
|---|
| 959 | action_array[0] = '\0';
|
|---|
| 960 |
|
|---|
| 961 | /* Initialize any buffers. */
|
|---|
| 962 | buf_init (&userdef_buf, sizeof (char)); /* one long string */
|
|---|
| 963 | buf_init (&defs_buf, sizeof (char *)); /* list of strings */
|
|---|
| 964 | buf_init (&yydmap_buf, sizeof (char)); /* one long string */
|
|---|
| 965 | buf_init (&top_buf, sizeof (char)); /* one long string */
|
|---|
| 966 |
|
|---|
| 967 | {
|
|---|
| 968 | const char * m4defs_init_str[] = {"m4_changequote\n",
|
|---|
| 969 | "m4_changequote([[, ]])\n"};
|
|---|
| 970 | buf_init (&m4defs_buf, sizeof (char *));
|
|---|
| 971 | buf_append (&m4defs_buf, &m4defs_init_str, 2);
|
|---|
| 972 | }
|
|---|
| 973 |
|
|---|
| 974 | /* initialize regex lib */
|
|---|
| 975 | flex_init_regex();
|
|---|
| 976 |
|
|---|
| 977 | /* Enable C++ if program name ends with '+'. */
|
|---|
| 978 | program_name = basename2 (argv[0], 0);
|
|---|
| 979 |
|
|---|
| 980 | if (program_name[0] != '\0' &&
|
|---|
| 981 | program_name[strlen (program_name) - 1] == '+')
|
|---|
| 982 | C_plus_plus = true;
|
|---|
| 983 |
|
|---|
| 984 | /* read flags */
|
|---|
| 985 | sopt = scanopt_init (flexopts, argc, argv, 0);
|
|---|
| 986 | if (!sopt) {
|
|---|
| 987 | /* This will only happen when flexopts array is altered. */
|
|---|
| 988 | fprintf (stderr,
|
|---|
| 989 | _("Internal error. flexopts are malformed.\n"));
|
|---|
| 990 | FLEX_EXIT (1);
|
|---|
| 991 | }
|
|---|
| 992 |
|
|---|
| 993 | while ((rv = scanopt (sopt, &arg, &optind)) != 0) {
|
|---|
| 994 |
|
|---|
| 995 | if (rv < 0) {
|
|---|
| 996 | /* Scanopt has already printed an option-specific error message. */
|
|---|
| 997 | fprintf (stderr,
|
|---|
| 998 | _
|
|---|
| 999 | ("Try `%s --help' for more information.\n"),
|
|---|
| 1000 | program_name);
|
|---|
| 1001 | FLEX_EXIT (1);
|
|---|
| 1002 | }
|
|---|
| 1003 |
|
|---|
| 1004 | switch ((enum flexopt_flag_t) rv) {
|
|---|
| 1005 | case OPT_CPLUSPLUS:
|
|---|
| 1006 | C_plus_plus = true;
|
|---|
| 1007 | break;
|
|---|
| 1008 |
|
|---|
| 1009 | case OPT_BATCH:
|
|---|
| 1010 | interactive = false;
|
|---|
| 1011 | break;
|
|---|
| 1012 |
|
|---|
| 1013 | case OPT_BACKUP:
|
|---|
| 1014 | backing_up_report = true;
|
|---|
| 1015 | break;
|
|---|
| 1016 |
|
|---|
| 1017 | case OPT_DONOTHING:
|
|---|
| 1018 | break;
|
|---|
| 1019 |
|
|---|
| 1020 | case OPT_COMPRESSION:
|
|---|
| 1021 | if (!sawcmpflag) {
|
|---|
| 1022 | useecs = false;
|
|---|
| 1023 | usemecs = false;
|
|---|
| 1024 | fulltbl = false;
|
|---|
| 1025 | sawcmpflag = true;
|
|---|
| 1026 | }
|
|---|
| 1027 |
|
|---|
| 1028 | for (i = 0; arg && arg[i] != '\0'; i++)
|
|---|
| 1029 | switch (arg[i]) {
|
|---|
| 1030 | case 'a':
|
|---|
| 1031 | long_align = true;
|
|---|
| 1032 | break;
|
|---|
| 1033 |
|
|---|
| 1034 | case 'e':
|
|---|
| 1035 | useecs = true;
|
|---|
| 1036 | break;
|
|---|
| 1037 |
|
|---|
| 1038 | case 'F':
|
|---|
| 1039 | fullspd = true;
|
|---|
| 1040 | break;
|
|---|
| 1041 |
|
|---|
| 1042 | case 'f':
|
|---|
| 1043 | fulltbl = true;
|
|---|
| 1044 | break;
|
|---|
| 1045 |
|
|---|
| 1046 | case 'm':
|
|---|
| 1047 | usemecs = true;
|
|---|
| 1048 | break;
|
|---|
| 1049 |
|
|---|
| 1050 | case 'r':
|
|---|
| 1051 | use_read = true;
|
|---|
| 1052 | break;
|
|---|
| 1053 |
|
|---|
| 1054 | default:
|
|---|
| 1055 | lerrif (_
|
|---|
| 1056 | ("unknown -C option '%c'"),
|
|---|
| 1057 | (int) arg[i]);
|
|---|
| 1058 | break;
|
|---|
| 1059 | }
|
|---|
| 1060 | break;
|
|---|
| 1061 |
|
|---|
| 1062 | case OPT_DEBUG:
|
|---|
| 1063 | ddebug = true;
|
|---|
| 1064 | break;
|
|---|
| 1065 |
|
|---|
| 1066 | case OPT_NO_DEBUG:
|
|---|
| 1067 | ddebug = false;
|
|---|
| 1068 | break;
|
|---|
| 1069 |
|
|---|
| 1070 | case OPT_FULL:
|
|---|
| 1071 | useecs = usemecs = false;
|
|---|
| 1072 | use_read = fulltbl = true;
|
|---|
| 1073 | break;
|
|---|
| 1074 |
|
|---|
| 1075 | case OPT_FAST:
|
|---|
| 1076 | useecs = usemecs = false;
|
|---|
| 1077 | use_read = fullspd = true;
|
|---|
| 1078 | break;
|
|---|
| 1079 |
|
|---|
| 1080 | case OPT_HELP:
|
|---|
| 1081 | usage ();
|
|---|
| 1082 | FLEX_EXIT (0);
|
|---|
| 1083 |
|
|---|
| 1084 | case OPT_INTERACTIVE:
|
|---|
| 1085 | interactive = true;
|
|---|
| 1086 | break;
|
|---|
| 1087 |
|
|---|
| 1088 | case OPT_CASE_INSENSITIVE:
|
|---|
| 1089 | caseins = true;
|
|---|
| 1090 | break;
|
|---|
| 1091 |
|
|---|
| 1092 | case OPT_LEX_COMPAT:
|
|---|
| 1093 | lex_compat = true;
|
|---|
| 1094 | break;
|
|---|
| 1095 |
|
|---|
| 1096 | case OPT_POSIX_COMPAT:
|
|---|
| 1097 | posix_compat = true;
|
|---|
| 1098 | break;
|
|---|
| 1099 |
|
|---|
| 1100 | case OPT_PREPROC_LEVEL:
|
|---|
| 1101 | preproc_level = strtol(arg,NULL,0);
|
|---|
| 1102 | break;
|
|---|
| 1103 |
|
|---|
| 1104 | case OPT_MAIN:
|
|---|
| 1105 | buf_strdefine (&userdef_buf, "YY_MAIN", "1");
|
|---|
| 1106 | do_yywrap = false;
|
|---|
| 1107 | break;
|
|---|
| 1108 |
|
|---|
| 1109 | case OPT_NO_MAIN:
|
|---|
| 1110 | buf_strdefine (&userdef_buf, "YY_MAIN", "0");
|
|---|
| 1111 | break;
|
|---|
| 1112 |
|
|---|
| 1113 | case OPT_NO_LINE:
|
|---|
| 1114 | gen_line_dirs = false;
|
|---|
| 1115 | break;
|
|---|
| 1116 |
|
|---|
| 1117 | case OPT_OUTFILE:
|
|---|
| 1118 | outfilename = arg;
|
|---|
| 1119 | did_outfilename = 1;
|
|---|
| 1120 | break;
|
|---|
| 1121 |
|
|---|
| 1122 | case OPT_PREFIX:
|
|---|
| 1123 | prefix = arg;
|
|---|
| 1124 | break;
|
|---|
| 1125 |
|
|---|
| 1126 | case OPT_PERF_REPORT:
|
|---|
| 1127 | ++performance_report;
|
|---|
| 1128 | break;
|
|---|
| 1129 |
|
|---|
| 1130 | case OPT_BISON_BRIDGE:
|
|---|
| 1131 | bison_bridge_lval = true;
|
|---|
| 1132 | break;
|
|---|
| 1133 |
|
|---|
| 1134 | case OPT_BISON_BRIDGE_LOCATIONS:
|
|---|
| 1135 | bison_bridge_lval = bison_bridge_lloc = true;
|
|---|
| 1136 | break;
|
|---|
| 1137 |
|
|---|
| 1138 | case OPT_REENTRANT:
|
|---|
| 1139 | reentrant = true;
|
|---|
| 1140 | break;
|
|---|
| 1141 |
|
|---|
| 1142 | case OPT_NO_REENTRANT:
|
|---|
| 1143 | reentrant = false;
|
|---|
| 1144 | break;
|
|---|
| 1145 |
|
|---|
| 1146 | case OPT_SKEL:
|
|---|
| 1147 | skelname = arg;
|
|---|
| 1148 | break;
|
|---|
| 1149 |
|
|---|
| 1150 | case OPT_DEFAULT:
|
|---|
| 1151 | spprdflt = false;
|
|---|
| 1152 | break;
|
|---|
| 1153 |
|
|---|
| 1154 | case OPT_NO_DEFAULT:
|
|---|
| 1155 | spprdflt = true;
|
|---|
| 1156 | break;
|
|---|
| 1157 |
|
|---|
| 1158 | case OPT_STDOUT:
|
|---|
| 1159 | use_stdout = true;
|
|---|
| 1160 | break;
|
|---|
| 1161 |
|
|---|
| 1162 | case OPT_NO_UNISTD_H:
|
|---|
| 1163 | //buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1");
|
|---|
| 1164 | buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0);
|
|---|
| 1165 | break;
|
|---|
| 1166 |
|
|---|
| 1167 | case OPT_TABLES_FILE:
|
|---|
| 1168 | tablesext = true;
|
|---|
| 1169 | tablesfilename = arg;
|
|---|
| 1170 | break;
|
|---|
| 1171 |
|
|---|
| 1172 | case OPT_TABLES_VERIFY:
|
|---|
| 1173 | tablesverify = true;
|
|---|
| 1174 | break;
|
|---|
| 1175 |
|
|---|
| 1176 | case OPT_TRACE:
|
|---|
| 1177 | trace = true;
|
|---|
| 1178 | break;
|
|---|
| 1179 |
|
|---|
| 1180 | case OPT_VERBOSE:
|
|---|
| 1181 | printstats = true;
|
|---|
| 1182 | break;
|
|---|
| 1183 |
|
|---|
| 1184 | case OPT_VERSION:
|
|---|
| 1185 | printf (_("%s %s\n"), program_name, flex_version);
|
|---|
| 1186 | FLEX_EXIT (0);
|
|---|
| 1187 |
|
|---|
| 1188 | case OPT_WARN:
|
|---|
| 1189 | nowarn = false;
|
|---|
| 1190 | break;
|
|---|
|
|---|