source: vendor/flex/2.5.33/main.c@ 3682

Last change on this file since 3682 was 3031, checked in by bird, 18 years ago

flex 2.5.33.

File size: 48.5 KB
Line 
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
41static char flex_version[] = FLEX_VERSION;
42
43/* declare functions that have forward references */
44
45void flexinit PROTO ((int, char **));
46void readin PROTO ((void));
47void set_up_initial_allocations PROTO ((void));
48static char *basename2 PROTO ((char *path, int should_strip_ext));
49
50
51/* these globals are all defined and commented in flexdef.h */
52int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
53int interactive, caseins, lex_compat, posix_compat, do_yylineno,
54 useecs, fulltbl, usemecs;
55int fullspd, gen_line_dirs, performance_report, backing_up_report;
56int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap,
57 csize;
58int reentrant, bison_bridge_lval, bison_bridge_lloc;
59int yymore_used, reject, real_reject, continued_action, in_rule;
60int yymore_really_used, reject_really_used;
61int datapos, dataline, linenum, out_linenum;
62FILE *skelfile = NULL;
63int skel_ind = 0;
64char *action_array;
65int action_size, defs1_offset, prolog_offset, action_offset,
66 action_index;
67char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL;
68int did_outfilename;
69char *prefix, *yyclass;
70int do_stdinit, use_stdout;
71int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
72int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
73int maximum_mns, current_mns, current_max_rules;
74int num_rules, num_eof_rules, default_rule, lastnfa;
75int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
76int *accptnum, *assoc_rule, *state_type;
77int *rule_type, *rule_linenum, *rule_useful;
78int current_state_type;
79int variable_trailing_context_rules;
80int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
81int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
82int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs,
83 tecfwd[CSIZE + 1];
84int tecbck[CSIZE + 1];
85int lastsc, *scset, *scbol, *scxclu, *sceof;
86int current_max_scs;
87char **scname;
88int current_max_dfa_size, current_max_xpairs;
89int current_max_template_xpairs, current_max_dfas;
90int lastdfa, *nxt, *chk, *tnxt;
91int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
92union dfaacc_union *dfaacc;
93int *accsiz, *dhash, numas;
94int numsnpairs, jambase, jamstate;
95int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
96int current_maxccls, current_max_ccl_tbl_size;
97Char *ccltbl;
98char nmstr[MAXLINE];
99int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
100int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
101int num_backing_up, bol_needed;
102FILE *backing_up_file;
103int end_of_buffer_state;
104char **input_files;
105int num_input_files;
106jmp_buf flex_main_jmp_buf;
107bool *rule_has_nl, *ccl_has_nl;
108int nlch = '\n';
109bool ansi_func_defs, ansi_func_protos;
110
111bool tablesext, tablesverify, gentables;
112char *tablesfilename=0,*tablesname=0;
113struct 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 */
118char *program_name = "flex";
119
120#ifndef SHORT_FILE_NAMES
121static char *outfile_template = "lex.%s.%s";
122static char *backing_name = "lex.backup";
123static char *tablesfile_template = "lex.%s.tables";
124#else
125static char *outfile_template = "lex%s.%s";
126static char *backing_name = "lex.bck";
127static char *tablesfile_template = "lex%s.tbl";
128#endif
129
130#ifdef MS_DOS
131extern unsigned _stklen = 16384;
132#endif
133
134/* From scan.l */
135extern FILE* yyout;
136
137static char outfile_path[MAXLINE];
138static int outfile_created = 0;
139static char *skelname = NULL;
140static int _stdout_closed = 0; /* flag to prevent double-fclose() on stdout. */
141
142/* For debugging. The max number of filters to apply to skeleton. */
143static int preproc_level = 1000;
144
145int flex_main PROTO ((int argc, char *argv[]));
146int main PROTO ((int argc, char *argv[]));
147
148int 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. */
208int 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
225void 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+", 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, "w")) == 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
489void 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
924void 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;
1191
1192 case OPT_NO_WARN:
1193 nowarn = true;
1194 break;
1195
1196 case OPT_7BIT:
1197 csize = 128;
1198 break;
1199
1200 case OPT_8BIT:
1201 csize = CSIZE;
1202 break;
1203
1204 case OPT_ALIGN:
1205 long_align = true;
1206 break;
1207
1208 case OPT_NO_ALIGN:
1209 long_align = false;
1210 break;
1211
1212 case OPT_ALWAYS_INTERACTIVE:
1213 buf_m4_define (&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0);
1214 break;
1215
1216 case OPT_NEVER_INTERACTIVE:
1217 buf_m4_define( &m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0);
1218 break;
1219
1220 case OPT_ARRAY:
1221 yytext_is_array = true;
1222 break;
1223
1224 case OPT_POINTER:
1225 yytext_is_array = false;
1226 break;
1227
1228 case OPT_ECS:
1229 useecs = true;
1230 break;
1231
1232 case OPT_NO_ECS:
1233 useecs = false;
1234 break;
1235
1236 case OPT_HEADER_FILE:
1237 headerfilename = arg;
1238 break;
1239
1240 case OPT_META_ECS:
1241 usemecs = true;
1242 break;
1243
1244 case OPT_NO_META_ECS:
1245 usemecs = false;
1246 break;
1247
1248 case OPT_PREPROCDEFINE:
1249 {
1250 /* arg is "symbol" or "symbol=definition". */
1251 char *def;
1252
1253 for (def = arg;
1254 *def != '\0' && *def != '='; ++def) ;
1255
1256 buf_strappend (&userdef_buf, "#define ");
1257 if (*def == '\0') {
1258 buf_strappend (&userdef_buf, arg);
1259 buf_strappend (&userdef_buf,
1260 " 1\n");
1261 }
1262 else {
1263 buf_strnappend (&userdef_buf, arg,
1264 def - arg);
1265 buf_strappend (&userdef_buf, " ");
1266 buf_strappend (&userdef_buf,
1267 def + 1);
1268 buf_strappend (&userdef_buf, "\n");
1269 }
1270 }
1271 break;
1272
1273 case OPT_READ:
1274 use_read = true;
1275 break;
1276
1277 case OPT_STACK:
1278 //buf_strdefine (&userdef_buf, "YY_STACK_USED", "1");
1279 buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0);
1280 break;
1281
1282 case OPT_STDINIT:
1283 do_stdinit = true;
1284 break;
1285
1286 case OPT_NO_STDINIT:
1287 do_stdinit = false;
1288 break;
1289
1290 case OPT_YYCLASS:
1291 yyclass = arg;
1292 break;
1293
1294 case OPT_YYLINENO:
1295 do_yylineno = true;
1296 break;
1297
1298 case OPT_NO_YYLINENO:
1299 do_yylineno = false;
1300 break;
1301
1302 case OPT_YYWRAP:
1303 do_yywrap = true;
1304 break;
1305
1306 case OPT_NO_YYWRAP:
1307 do_yywrap = false;
1308 break;
1309
1310 case OPT_YYMORE:
1311 yymore_really_used = true;
1312 break;
1313
1314 case OPT_NO_YYMORE:
1315 yymore_really_used = false;
1316 break;
1317
1318 case OPT_REJECT:
1319 reject_really_used = true;
1320 break;
1321
1322 case OPT_NO_REJECT:
1323 reject_really_used = false;
1324 break;
1325
1326 case OPT_NO_ANSI_FUNC_DEFS:
1327 ansi_func_defs = false;
1328 break;
1329
1330 case OPT_NO_ANSI_FUNC_PROTOS:
1331 ansi_func_protos = false;
1332 break;
1333
1334 case OPT_NO_YY_PUSH_STATE:
1335 //buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1");
1336 buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0);
1337 break;
1338 case OPT_NO_YY_POP_STATE:
1339 //buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1");
1340 buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0);
1341 break;
1342 case OPT_NO_YY_TOP_STATE:
1343 //buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1");
1344 buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0);
1345 break;
1346 case OPT_NO_UNPUT:
1347 //buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1");
1348 buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0);
1349 break;
1350 case OPT_NO_YY_SCAN_BUFFER:
1351 //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1");
1352 buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0);
1353 break;
1354 case OPT_NO_YY_SCAN_BYTES:
1355 //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1");
1356 buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0);
1357 break;
1358 case OPT_NO_YY_SCAN_STRING:
1359 //buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1");
1360 buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0);
1361 break;
1362 case OPT_NO_YYGET_EXTRA:
1363 //buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1");
1364 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0);
1365 break;
1366 case OPT_NO_YYSET_EXTRA:
1367 //buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1");
1368 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0);
1369 break;
1370 case OPT_NO_YYGET_LENG:
1371 //buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1");
1372 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0);
1373 break;
1374 case OPT_NO_YYGET_TEXT:
1375 //buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1");
1376 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0);
1377 break;
1378 case OPT_NO_YYGET_LINENO:
1379 //buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1");
1380 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0);
1381 break;
1382 case OPT_NO_YYSET_LINENO:
1383 //buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1");
1384 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0);
1385 break;
1386 case OPT_NO_YYGET_IN:
1387 //buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1");
1388 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0);
1389 break;
1390 case OPT_NO_YYSET_IN:
1391 //buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1");
1392 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0);
1393 break;
1394 case OPT_NO_YYGET_OUT:
1395 //buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1");
1396 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0);
1397 break;
1398 case OPT_NO_YYSET_OUT:
1399 //buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1");
1400 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0);
1401 break;
1402 case OPT_NO_YYGET_LVAL:
1403 //buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1");
1404 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0);
1405 break;
1406 case OPT_NO_YYSET_LVAL:
1407 //buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1");
1408 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0);
1409 break;
1410 case OPT_NO_YYGET_LLOC:
1411 //buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1");
1412 buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0);
1413 break;
1414 case OPT_NO_YYSET_LLOC:
1415 //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1");
1416 buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
1417 break;
1418
1419 } /* switch */
1420 } /* while scanopt() */
1421
1422 scanopt_destroy (sopt);
1423
1424 num_input_files = argc - optind;
1425 input_files = argv + optind;
1426 set_input_file (num_input_files > 0 ? input_files[0] : NULL);
1427
1428 lastccl = lastsc = lastdfa = lastnfa = 0;
1429 num_rules = num_eof_rules = default_rule = 0;
1430 numas = numsnpairs = tmpuses = 0;
1431 numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst =
1432 0;
1433 numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
1434 num_backing_up = onesp = numprots = 0;
1435 variable_trailing_context_rules = bol_needed = false;
1436
1437 out_linenum = linenum = sectnum = 1;
1438 firstprot = NIL;
1439
1440 /* Used in mkprot() so that the first proto goes in slot 1
1441 * of the proto queue.
1442 */
1443 lastprot = 1;
1444
1445 set_up_initial_allocations ();
1446}
1447
1448
1449/* readin - read in the rules section of the input file(s) */
1450
1451void readin ()
1452{
1453 static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;";
1454 static char yy_nostdinit[] =
1455 "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;";
1456
1457 line_directive_out ((FILE *) 0, 1);
1458
1459 if (yyparse ()) {
1460 pinpoint_message (_("fatal parse error"));
1461 flexend (1);
1462 }
1463
1464 if (syntaxerror)
1465 flexend (1);
1466
1467 /* If the user explicitly requested posix compatibility by specifing the
1468 * posix-compat option, then we check for conflicting options. However, if
1469 * the POSIXLY_CORRECT variable is set, then we quietly make flex as
1470 * posix-compatible as possible. This is the recommended behavior
1471 * according to the GNU Coding Standards.
1472 *
1473 * Note: The posix option was added to flex to provide the posix behavior
1474 * of the repeat operator in regular expressions, e.g., `ab{3}'
1475 */
1476 if (posix_compat) {
1477 /* TODO: This is where we try to make flex behave according to
1478 * posiz, AND check for conflicting options. How far should we go
1479 * with this? Should we disable all the neat-o flex features?
1480 */
1481 /* Update: Estes says no, since other flex features don't violate posix. */
1482 }
1483
1484 if (getenv ("POSIXLY_CORRECT")) {
1485 posix_compat = true;
1486 }
1487
1488 if (backing_up_report) {
1489 backing_up_file = fopen (backing_name, "w");
1490 if (backing_up_file == NULL)
1491 lerrsf (_
1492 ("could not create backing-up info file %s"),
1493 backing_name);
1494 }
1495
1496 else
1497 backing_up_file = NULL;
1498
1499 if (yymore_really_used == true)
1500 yymore_used = true;
1501 else if (yymore_really_used == false)
1502 yymore_used = false;
1503
1504 if (reject_really_used == true)
1505 reject = true;
1506 else if (reject_really_used == false)
1507 reject = false;
1508
1509 if (performance_report > 0) {
1510 if (lex_compat) {
1511 fprintf (stderr,
1512 _
1513 ("-l AT&T lex compatibility option entails a large performance penalty\n"));
1514 fprintf (stderr,
1515 _
1516 (" and may be the actual source of other reported performance penalties\n"));
1517 }
1518
1519 else if (do_yylineno) {
1520 fprintf (stderr,
1521 _
1522 ("%%option yylineno entails a performance penalty ONLY on rules that can match newline characters\n"));
1523 }
1524
1525 if (performance_report > 1) {
1526 if (interactive)
1527 fprintf (stderr,
1528 _
1529 ("-I (interactive) entails a minor performance penalty\n"));
1530
1531 if (yymore_used)
1532 fprintf (stderr,
1533 _
1534 ("yymore() entails a minor performance penalty\n"));
1535 }
1536
1537 if (reject)
1538 fprintf (stderr,
1539 _
1540 ("REJECT entails a large performance penalty\n"));
1541
1542 if (variable_trailing_context_rules)
1543 fprintf (stderr,
1544 _
1545 ("Variable trailing context rules entail a large performance penalty\n"));
1546 }
1547
1548 if (reject)
1549 real_reject = true;
1550
1551 if (variable_trailing_context_rules)
1552 reject = true;
1553
1554 if ((fulltbl || fullspd) && reject) {
1555 if (real_reject)
1556 flexerror (_
1557 ("REJECT cannot be used with -f or -F"));
1558 else if (do_yylineno)
1559 flexerror (_
1560 ("%option yylineno cannot be used with REJECT"));
1561 else
1562 flexerror (_
1563 ("variable trailing context rules cannot be used with -f or -F"));
1564 }
1565
1566 if (reject){
1567 out_m4_define( "M4_YY_USES_REJECT", NULL);
1568 //outn ("\n#define YY_USES_REJECT");
1569 }
1570
1571 if (!do_yywrap) {
1572 outn ("\n#define yywrap(n) 1");
1573 outn ("#define YY_SKIP_YYWRAP");
1574 }
1575
1576 if (ddebug)
1577 outn ("\n#define FLEX_DEBUG");
1578
1579 OUT_BEGIN_CODE ();
1580 if (csize == 256)
1581 outn ("typedef unsigned char YY_CHAR;");
1582 else
1583 outn ("typedef char YY_CHAR;");
1584 OUT_END_CODE ();
1585
1586 if (C_plus_plus) {
1587 outn ("#define yytext_ptr yytext");
1588
1589 if (interactive)
1590 outn ("#define YY_INTERACTIVE");
1591 }
1592
1593 else {
1594 OUT_BEGIN_CODE ();
1595 /* In reentrant scanner, stdinit is handled in flex.skl. */
1596 if (do_stdinit) {
1597 if (reentrant){
1598 outn ("#ifdef VMS");
1599 outn ("#ifdef __VMS_POSIX");
1600 outn ("#define YY_STDINIT");
1601 outn ("#endif");
1602 outn ("#else");
1603 outn ("#define YY_STDINIT");
1604 outn ("#endif");
1605 }
1606
1607 outn ("#ifdef VMS");
1608 outn ("#ifndef __VMS_POSIX");
1609 outn (yy_nostdinit);
1610 outn ("#else");
1611 outn (yy_stdinit);
1612 outn ("#endif");
1613 outn ("#else");
1614 outn (yy_stdinit);
1615 outn ("#endif");
1616 }
1617
1618 else {
1619 if(!reentrant)
1620 outn (yy_nostdinit);
1621 }
1622 OUT_END_CODE ();
1623 }
1624
1625 OUT_BEGIN_CODE ();
1626 if (fullspd)
1627 outn ("typedef yyconst struct yy_trans_info *yy_state_type;");
1628 else if (!C_plus_plus)
1629 outn ("typedef int yy_state_type;");
1630 OUT_END_CODE ();
1631
1632 if (lex_compat)
1633 outn ("#define YY_FLEX_LEX_COMPAT");
1634
1635 if (!C_plus_plus && !reentrant) {
1636 outn ("extern int yylineno;");
1637 OUT_BEGIN_CODE ();
1638 outn ("int yylineno = 1;");
1639 OUT_END_CODE ();
1640 }
1641
1642 if (C_plus_plus) {
1643 outn ("\n#include <FlexLexer.h>");
1644
1645 if (yyclass) {
1646 outn ("int yyFlexLexer::yylex()");
1647 outn ("\t{");
1648 outn ("\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );");
1649 outn ("\treturn 0;");
1650 outn ("\t}");
1651
1652 out_str ("\n#define YY_DECL int %s::yylex()\n",
1653 yyclass);
1654 }
1655 }
1656
1657 else {
1658
1659 /* Watch out: yytext_ptr is a variable when yytext is an array,
1660 * but it's a macro when yytext is a pointer.
1661 */
1662 if (yytext_is_array) {
1663 if (!reentrant)
1664 outn ("extern char yytext[];\n");
1665 }
1666 else {
1667 if (reentrant) {
1668 outn ("#define yytext_ptr yytext_r");
1669 }
1670 else {
1671 outn ("extern char *yytext;");
1672 outn ("#define yytext_ptr yytext");
1673 }
1674 }
1675
1676 if (yyclass)
1677 flexerror (_
1678 ("%option yyclass only meaningful for C++ scanners"));
1679 }
1680
1681 if (useecs)
1682 numecs = cre8ecs (nextecm, ecgroup, csize);
1683 else
1684 numecs = csize;
1685
1686 /* Now map the equivalence class for NUL to its expected place. */
1687 ecgroup[0] = ecgroup[csize];
1688 NUL_ec = ABS (ecgroup[0]);
1689
1690 if (useecs)
1691 ccl2ecl ();
1692}
1693
1694
1695/* set_up_initial_allocations - allocate memory for internal tables */
1696
1697void set_up_initial_allocations ()
1698{
1699 maximum_mns = (long_align ? MAXIMUM_MNS_LONG : MAXIMUM_MNS);
1700 current_mns = INITIAL_MNS;
1701 firstst = allocate_integer_array (current_mns);
1702 lastst = allocate_integer_array (current_mns);
1703 finalst = allocate_integer_array (current_mns);
1704 transchar = allocate_integer_array (current_mns);
1705 trans1 = allocate_integer_array (current_mns);
1706 trans2 = allocate_integer_array (current_mns);
1707 accptnum = allocate_integer_array (current_mns);
1708 assoc_rule = allocate_integer_array (current_mns);
1709 state_type = allocate_integer_array (current_mns);
1710
1711 current_max_rules = INITIAL_MAX_RULES;
1712 rule_type = allocate_integer_array (current_max_rules);
1713 rule_linenum = allocate_integer_array (current_max_rules);
1714 rule_useful = allocate_integer_array (current_max_rules);
1715 rule_has_nl = allocate_bool_array (current_max_rules);
1716
1717 current_max_scs = INITIAL_MAX_SCS;
1718 scset = allocate_integer_array (current_max_scs);
1719 scbol = allocate_integer_array (current_max_scs);
1720 scxclu = allocate_integer_array (current_max_scs);
1721 sceof = allocate_integer_array (current_max_scs);
1722 scname = allocate_char_ptr_array (current_max_scs);
1723
1724 current_maxccls = INITIAL_MAX_CCLS;
1725 cclmap = allocate_integer_array (current_maxccls);
1726 ccllen = allocate_integer_array (current_maxccls);
1727 cclng = allocate_integer_array (current_maxccls);
1728 ccl_has_nl = allocate_bool_array (current_maxccls);
1729
1730 current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE;
1731 ccltbl = allocate_Character_array (current_max_ccl_tbl_size);
1732
1733 current_max_dfa_size = INITIAL_MAX_DFA_SIZE;
1734
1735 current_max_xpairs = INITIAL_MAX_XPAIRS;
1736 nxt = allocate_integer_array (current_max_xpairs);
1737 chk = allocate_integer_array (current_max_xpairs);
1738
1739 current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS;
1740 tnxt = allocate_integer_array (current_max_template_xpairs);
1741
1742 current_max_dfas = INITIAL_MAX_DFAS;
1743 base = allocate_integer_array (current_max_dfas);
1744 def = allocate_integer_array (current_max_dfas);
1745 dfasiz = allocate_integer_array (current_max_dfas);
1746 accsiz = allocate_integer_array (current_max_dfas);
1747 dhash = allocate_integer_array (current_max_dfas);
1748 dss = allocate_int_ptr_array (current_max_dfas);
1749 dfaacc = allocate_dfaacc_union (current_max_dfas);
1750
1751 nultrans = (int *) 0;
1752}
1753
1754
1755/* extracts basename from path, optionally stripping the extension "\.*"
1756 * (same concept as /bin/sh `basename`, but different handling of extension). */
1757static char *basename2 (path, strip_ext)
1758 char *path;
1759 int strip_ext; /* boolean */
1760{
1761 char *b, *e = 0;
1762
1763 b = path;
1764 for (b = path; *path; path++)
1765 if (*path == '/')
1766 b = path + 1;
1767 else if (*path == '.')
1768 e = path;
1769
1770 if (strip_ext && e && e > b)
1771 *e = '\0';
1772 return b;
1773}
1774
1775void usage ()
1776{
1777 FILE *f = stdout;
1778
1779 if (!did_outfilename) {
1780 sprintf (outfile_path, outfile_template,
1781 prefix, C_plus_plus ? "cc" : "c");
1782 outfilename = outfile_path;
1783 }
1784
1785 fprintf (f, _("Usage: %s [OPTIONS] [FILE]...\n"), program_name);
1786 fprintf (f,
1787 _
1788 ("Generates programs that perform pattern-matching on text.\n"
1789 "\n" "Table Compression:\n"
1790 " -Ca, --align trade off larger tables for better memory alignment\n"
1791 " -Ce, --ecs construct equivalence classes\n"
1792 " -Cf do not compress tables; use -f representation\n"
1793 " -CF do not compress tables; use -F representation\n"
1794 " -Cm, --meta-ecs construct meta-equivalence classes\n"
1795 " -Cr, --read use read() instead of stdio for scanner input\n"
1796 " -f, --full generate fast, large scanner. Same as -Cfr\n"
1797 " -F, --fast use alternate table representation. Same as -CFr\n"
1798 " -Cem default compression (same as --ecs --meta-ecs)\n"
1799 "\n" "Debugging:\n"
1800 " -d, --debug enable debug mode in scanner\n"
1801 " -b, --backup write backing-up information to %s\n"
1802 " -p, --perf-report write performance report to stderr\n"
1803 " -s, --nodefault suppress default rule to ECHO unmatched text\n"
1804 " -T, --trace %s should run in trace mode\n"
1805 " -w, --nowarn do not generate warnings\n"
1806 " -v, --verbose write summary of scanner statistics to stdout\n"
1807 "\n" "Files:\n"
1808 " -o, --outfile=FILE specify output filename\n"
1809 " -S, --skel=FILE specify skeleton file\n"
1810 " -t, --stdout write scanner on stdout instead of %s\n"
1811 " --yyclass=NAME name of C++ class\n"
1812 " --header-file=FILE create a C header file in addition to the scanner\n"
1813 " --tables-file[=FILE] write tables to FILE\n" "\n"
1814 "Scanner behavior:\n"
1815 " -7, --7bit generate 7-bit scanner\n"
1816 " -8, --8bit generate 8-bit scanner\n"
1817 " -B, --batch generate batch scanner (opposite of -I)\n"
1818 " -i, --case-insensitive ignore case in patterns\n"
1819 " -l, --lex-compat maximal compatibility with original lex\n"
1820 " -X, --posix-compat maximal compatibility with POSIX lex\n"
1821 " -I, --interactive generate interactive scanner (opposite of -B)\n"
1822 " --yylineno track line count in yylineno\n"
1823 "\n" "Generated code:\n"
1824 " -+, --c++ generate C++ scanner class\n"
1825 " -Dmacro[=defn] #define macro defn (default defn is '1')\n"
1826 " -L, --noline suppress #line directives in scanner\n"
1827 " -P, --prefix=STRING use STRING as prefix instead of \"yy\"\n"
1828 " -R, --reentrant generate a reentrant C scanner\n"
1829 " --bison-bridge scanner for bison pure parser.\n"
1830 " --bison-locations include yylloc support.\n"
1831 " --stdinit initialize yyin/yyout to stdin/stdout\n"
1832 " --noansi-definitions old-style function definitions\n"
1833 " --noansi-prototypes empty parameter list in prototypes\n"
1834 " --nounistd do not include <unistd.h>\n"
1835 " --noFUNCTION do not generate a particular FUNCTION\n"
1836 "\n" "Miscellaneous:\n"
1837 " -c do-nothing POSIX option\n"
1838 " -n do-nothing POSIX option\n"
1839 " -?\n"
1840 " -h, --help produce this help message\n"
1841 " -V, --version report %s version\n"),
1842 backing_name, program_name, outfile_path, program_name);
1843
1844}
Note: See TracBrowser for help on using the repository browser.