2 /* flexdef - definitions file for flex */
4 /* Copyright (c) 1990 The Regents of the University of California. */
5 /* All rights reserved. */
7 /* This code is derived from software contributed to Berkeley by */
10 /* The United States Government has rights in this work pursuant */
11 /* to contract no. DE-AC03-76SF00098 between the United States */
12 /* Department of Energy and the University of California. */
14 /* This file is part of flex. */
16 /* Redistribution and use in source and binary forms, with or without */
17 /* modification, are permitted provided that the following conditions */
20 /* 1. Redistributions of source code must retain the above copyright */
21 /* notice, this list of conditions and the following disclaimer. */
22 /* 2. Redistributions in binary form must reproduce the above copyright */
23 /* notice, this list of conditions and the following disclaimer in the */
24 /* documentation and/or other materials provided with the distribution. */
26 /* Neither the name of the University nor the names of its contributors */
27 /* may be used to endorse or promote products derived from this software */
28 /* without specific prior written permission. */
30 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
31 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
32 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
47 #include <libgen.h> /* for XPG version of basename(3) */
60 /* Required: dup() and dup2() in <unistd.h> */
62 #ifdef HAVE_NETINET_IN_H
63 #include <netinet/in.h>
65 #ifdef HAVE_SYS_PARAMS_H
66 #include <sys/params.h>
68 /* Required: stat() in <sys/stat.h> */
70 /* Required: wait() in <sys/wait.h> */
74 /* Required: regcomp(), regexec() and regerror() in <regex.h> */
76 /* Required: strcasecmp() in <strings.h> */
80 /* We use gettext. So, when we write strings which should be translated, we mark them with _() */
84 #endif /* HAVE_LOCALE_H */
86 #define _(String) gettext (String)
88 #define _(STRING) STRING
89 #endif /* ENABLE_NLS */
91 /* Always be prepared to generate an 8-bit scanner. */
94 /* Size of input alphabet - should be size of ASCII set. */
96 #define DEFAULT_CSIZE 128
99 /* Maximum line length we'll have to deal with. */
103 #define MIN(x,y) ((x) < (y) ? (x) : (y))
106 #define MAX(x,y) ((x) > (y) ? (x) : (y))
109 #define ABS(x) ((x) < 0 ? -(x) : (x))
112 /* Whether an integer is a power of two */
113 #define is_power_of_2(n) ((n) > 0 && ((n) & ((n) - 1)) == 0)
115 #define unspecified -1
117 /* Special chk[] values marking the slots taking by end-of-buffer and action
120 #define EOB_POSITION -1
121 #define ACTION_POSITION -2
123 /* Number of data items per line for -f output. */
124 #define NUMDATAITEMS 10
126 /* Number of lines of data in -f output before inserting a blank line for
129 #define NUMDATALINES 10
131 /* transition_struct_out() definitions. */
132 #define TRANS_STRUCT_PRINT_LENGTH 14
134 /* Returns true if an nfa state has an epsilon out-transition slot
135 * that can be used. This definition is currently not used.
137 #define FREE_EPSILON(state) \
138 (transchar[state] == SYM_EPSILON && \
139 trans2[state] == NO_TRANSITION && \
140 finalst[state] != state)
142 /* Returns true if an nfa state has an epsilon out-transition character
143 * and both slots are free
145 #define SUPER_FREE_EPSILON(state) \
146 (transchar[state] == SYM_EPSILON && \
147 trans1[state] == NO_TRANSITION) \
149 /* Maximum number of NFA states that can comprise a DFA state. It's real
150 * big because if there's a lot of rules, the initial state will have a
151 * huge epsilon closure.
153 #define INITIAL_MAX_DFA_SIZE 750
154 #define MAX_DFA_SIZE_INCREMENT 750
157 /* A note on the following masks. They are used to mark accepting numbers
158 * as being special. As such, they implicitly limit the number of accepting
159 * numbers (i.e., rules) because if there are too many rules the rule numbers
160 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
161 * 8192) so unlikely to actually cause any problems. A check is made in
162 * new_rule() to ensure that this limit is not reached.
165 /* Mask to mark a trailing context accepting number. */
166 #define YY_TRAILING_MASK 0x2000
168 /* Mask to mark the accepting number of the "head" of a trailing context
171 #define YY_TRAILING_HEAD_MASK 0x4000
173 /* Maximum number of rules, as outlined in the above note. */
174 #define MAX_RULE (YY_TRAILING_MASK - 1)
177 /* NIL must be 0. If not, its special meaning when making equivalence classes
178 * (it marks the representative of a given e.c.) will be unidentifiable.
182 #define JAM -1 /* to mark a missing DFA transition */
183 #define NO_TRANSITION NIL
184 #define UNIQUE -1 /* marks a symbol as an e.c. representative */
185 #define INFINITE_REPEAT -1 /* for x{5,} constructions */
187 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
188 #define MAX_CCLS_INCREMENT 100
190 /* Size of table holding members of character classes. */
191 #define INITIAL_MAX_CCL_TBL_SIZE 500
192 #define MAX_CCL_TBL_SIZE_INCREMENT 250
194 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
195 #define MAX_RULES_INCREMENT 100
197 #define INITIAL_MNS 2000 /* default maximum number of nfa states */
198 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
200 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
201 #define MAX_DFAS_INCREMENT 1000
203 #define JAMSTATE -32766 /* marks a reference to the state that always jams */
205 /* Maximum number of NFA states. */
206 #define MAXIMUM_MNS 31999
207 #define MAXIMUM_MNS_LONG 1999999999
209 /* Enough so that if it's subtracted from an NFA state number, the result
210 * is guaranteed to be negative.
212 #define MARKER_DIFFERENCE (maximum_mns+2)
214 /* Maximum number of nxt/chk pairs for non-templates. */
215 #define INITIAL_MAX_XPAIRS 2000
216 #define MAX_XPAIRS_INCREMENT 2000
218 /* Maximum number of nxt/chk pairs needed for templates. */
219 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
220 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
222 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
224 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
225 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
227 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
228 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
230 /* The following percentages are used to tune table compression:
232 * The percentage the number of out-transitions a state must be of the
233 * number of equivalence classes in order to be considered for table
234 * compaction by using protos.
236 #define PROTO_SIZE_PERCENTAGE 15
238 /* The percentage the number of homogeneous out-transitions of a state
239 * must be of the number of total out-transitions of the state in order
240 * that the state's transition table is first compared with a potential
241 * template of the most common out-transition instead of with the first
242 * proto in the proto queue.
244 #define CHECK_COM_PERCENTAGE 50
246 /* The percentage the number of differences between a state's transition
247 * table and the proto it was first compared with must be of the total
248 * number of out-transitions of the state in order to keep the first
249 * proto as a good match and not search any further.
251 #define FIRST_MATCH_DIFF_PERCENTAGE 10
253 /* The percentage the number of differences between a state's transition
254 * table and the most similar proto must be of the state's total number
255 * of out-transitions to use the proto as an acceptable close match.
257 #define ACCEPTABLE_DIFF_PERCENTAGE 50
259 /* The percentage the number of homogeneous out-transitions of a state
260 * must be of the number of total out-transitions of the state in order
261 * to consider making a template from the state.
263 #define TEMPLATE_SAME_PERCENTAGE 60
265 /* The percentage the number of differences between a state's transition
266 * table and the most similar proto must be of the state's total number
267 * of out-transitions to create a new proto from the state.
269 #define NEW_PROTO_DIFF_PERCENTAGE 20
271 /* The percentage the total number of out-transitions of a state must be
272 * of the number of equivalence classes in order to consider trying to
273 * fit the transition table into "holes" inside the nxt/chk table.
275 #define INTERIOR_FIT_PERCENTAGE 15
277 /* Size of region set aside to cache the complete transition table of
278 * protos on the proto queue to enable quick comparisons.
280 #define PROT_SAVE_SIZE 2000
282 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
284 /* Maximum number of out-transitions a state can have that we'll rummage
285 * around through the interior of the internal fast table looking for a
288 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
290 /* Maximum number of rules which will be reported as being associated
293 #define MAX_ASSOC_RULES 100
295 /* Number that, if used to subscript an array, has a good chance of producing
296 * an error; should be small enough to fit into a short.
298 #define BAD_SUBSCRIPT -32767
300 /* Absolute value of largest number that can be stored in a short, with a
301 * bit of slop thrown in for general paranoia.
303 #define MAX_SHORT 32700
306 /* Declarations for global variables. */
309 /* Variables for flags:
310 * printstats - if true (-v), dump statistics
311 * syntaxerror - true if a syntax error has been found
312 * eofseen - true if we've seen an eof in the input file
313 * ddebug - if true (-d), make a "debug" scanner
314 * trace - if true (-T), trace processing
315 * nowarn - if true (-w), do not generate warnings
316 * spprdflt - if true (-s), suppress the default rule
317 * interactive - if true (-I), generate an interactive scanner
318 * lex_compat - if true (-l), maximize compatibility with AT&T lex
319 * posix_compat - if true (-X), maximize compatibility with POSIX lex
320 * do_yylineno - if true, generate code to maintain yylineno
321 * useecs - if true (-Ce flag), use equivalence classes
322 * fulltbl - if true (-Cf flag), don't compress the DFA state table
323 * usemecs - if true (-Cm flag), use meta-equivalence classes
324 * fullspd - if true (-F flag), use Jacobson method of table representation
325 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
326 * performance_report - if > 0 (i.e., -p flag), generate a report relating
327 * to scanner performance; if > 1 (-p -p), report on minor performance
329 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
330 * listing backing-up states
331 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
332 * otherwise, a standard C scanner
333 * reentrant - if true (-R), generate a reentrant C scanner.
334 * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention.
335 * bison_bridge_lloc - if true (--bison-locations), bison yylloc.
336 * long_align - if true (-Ca flag), favor long-word alignment.
337 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
338 * otherwise, use fread().
339 * yytext_is_array - if true (i.e., %array directive), then declare
340 * yytext as a array instead of a character pointer. Nice and inefficient.
341 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
343 * csize - size of character set for the scanner we're generating;
344 * 128 for 7-bit chars and 256 for 8-bit
345 * yymore_used - if true, yymore() is used in input rules
346 * reject - if true, generate back-up tables for REJECT macro
347 * real_reject - if true, scanner really uses REJECT (as opposed to just
348 * having "reject" set for variable trailing context)
349 * continued_action - true if this rule's action is to "fall through" to
350 * the next rule's action (i.e., the '|' action)
351 * in_rule - true if we're inside an individual rule, false if not.
352 * yymore_really_used - whether to treat yymore() as really used, regardless
353 * of what we think based on references to it in the user's actions.
354 * reject_really_used - same for REJECT
355 * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals
358 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn,
360 extern int interactive, lex_compat, posix_compat, do_yylineno;
361 extern int useecs, fulltbl, usemecs, fullspd;
362 extern int gen_line_dirs, performance_report, backing_up_report;
363 extern int reentrant, bison_bridge_lval, bison_bridge_lloc;
364 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
366 extern int yymore_used, reject, real_reject, continued_action, in_rule;
368 extern int yymore_really_used, reject_really_used;
369 extern int trace_hex;
371 /* Variables used in the flex input routines:
372 * datapos - characters on current output line
373 * dataline - number of contiguous lines of data in current data
374 * statement. Used to generate readable -f output
375 * linenum - current input line number
376 * skelfile - the skeleton file
377 * skel - compiled-in skeleton array
378 * skel_ind - index into "skel" array, if skelfile is nil
380 * backing_up_file - file to summarize backing-up states to
381 * infilename - name of input file
382 * outfilename - name of output file
383 * headerfilename - name of the .h file to generate
384 * did_outfilename - whether outfilename was explicitly set
385 * prefix - the prefix used for externally visible names ("yy" by default)
386 * yyclass - yyFlexLexer subclass to use for YY_DECL
387 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
388 * use_stdout - the -t flag
389 * input_files - array holding names of input files
390 * num_input_files - size of input_files array
391 * program_name - name with which program was invoked
393 * action_array - array to hold the rule actions
394 * action_size - size of action_array
395 * defs1_offset - index where the user's section 1 definitions start
397 * prolog_offset - index where the prolog starts in action_array
398 * action_offset - index where the non-prolog starts in action_array
399 * action_index - index where the next action should go, with respect
403 extern int datapos, dataline, linenum;
404 extern FILE *skelfile, *backing_up_file;
405 extern const char *skel[];
407 extern char *infilename, *outfilename, *headerfilename;
408 extern int did_outfilename;
409 extern char *prefix, *yyclass, *extra_type;
410 extern int do_stdinit, use_stdout;
411 extern char **input_files;
412 extern int num_input_files;
413 extern char *program_name;
415 extern char *action_array;
416 extern int action_size;
417 extern int defs1_offset, prolog_offset, action_offset, action_index;
420 /* Variables for stack of states having only one out-transition:
421 * onestate - state number
422 * onesym - transition symbol
423 * onenext - target state
424 * onedef - default base entry
425 * onesp - stack pointer
428 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
429 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
432 /* Variables for nfa machine data:
433 * maximum_mns - maximal number of NFA states supported by tables
434 * current_mns - current maximum on number of NFA states
435 * num_rules - number of the last accepting state; also is number of
436 * rules created so far
437 * num_eof_rules - number of <<EOF>> rules
438 * default_rule - number of the default rule
439 * current_max_rules - current maximum number of rules
440 * lastnfa - last nfa state number created
441 * firstst - physically the first state of a fragment
442 * lastst - last physical state of fragment
443 * finalst - last logical state of fragment
444 * transchar - transition character
445 * trans1 - transition state
446 * trans2 - 2nd transition state for epsilons
447 * accptnum - accepting number
448 * assoc_rule - rule associated with this NFA state (or 0 if none)
449 * state_type - a STATE_xxx type identifying whether the state is part
450 * of a normal rule, the leading state in a trailing context
451 * rule (i.e., the state which marks the transition from
452 * recognizing the text-to-be-matched to the beginning of
453 * the trailing context), or a subsequent state in a trailing
455 * rule_type - a RULE_xxx type identifying whether this a ho-hum
456 * normal rule or one which has variable head & trailing
458 * rule_linenum - line number associated with rule
459 * rule_useful - true if we've determined that the rule can be matched
460 * rule_has_nl - true if rule could possibly match a newline
461 * ccl_has_nl - true if current ccl could match a newline
462 * nlch - default eol char
465 extern int maximum_mns, current_mns, current_max_rules;
466 extern int num_rules, num_eof_rules, default_rule, lastnfa;
467 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
468 extern int *accptnum, *assoc_rule, *state_type;
469 extern int *rule_type, *rule_linenum, *rule_useful;
470 extern bool *rule_has_nl, *ccl_has_nl;
473 /* Different types of states; values are useful as masks, as well, for
474 * routines like check_trailing_context().
476 #define STATE_NORMAL 0x1
477 #define STATE_TRAILING_CONTEXT 0x2
479 /* Global holding current type of state we're making. */
481 extern int current_state_type;
483 /* Different types of rules. */
484 #define RULE_NORMAL 0
485 #define RULE_VARIABLE 1
487 /* True if the input rules include a rule with both variable-length head
488 * and trailing context, false otherwise.
490 extern int variable_trailing_context_rules;
493 /* Variables for protos:
494 * numtemps - number of templates created
495 * numprots - number of protos created
496 * protprev - backlink to a more-recently used proto
497 * protnext - forward link to a less-recently used proto
498 * prottbl - base/def table entry for proto
499 * protcomst - common state of proto
500 * firstprot - number of the most recently used proto
501 * lastprot - number of the least recently used proto
502 * protsave contains the entire state array for protos
505 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
506 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
509 /* Variables for managing equivalence classes:
510 * numecs - number of equivalence classes
511 * nextecm - forward link of Equivalence Class members
512 * ecgroup - class number or backward link of EC members
513 * nummecs - number of meta-equivalence classes (used to compress
515 * tecfwd - forward link of meta-equivalence classes members
516 * tecbck - backward link of MEC's
519 /* Reserve enough room in the equivalence class arrays so that we
520 * can use the CSIZE'th element to hold equivalence class information
521 * for the NUL character. Later we'll move this information into
524 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
526 /* Meta-equivalence classes are indexed starting at 1, so it's possible
527 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
528 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
529 * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
531 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
534 /* Variables for start conditions:
535 * lastsc - last start condition created
536 * current_max_scs - current limit on number of start conditions
537 * scset - set of rules active in start condition
538 * scbol - set of rules active only at the beginning of line in a s.c.
539 * scxclu - true if start condition is exclusive
540 * sceof - true if start condition has EOF rule
541 * scname - start condition name
544 extern int lastsc, *scset, *scbol, *scxclu, *sceof;
545 extern int current_max_scs;
546 extern char **scname;
549 /* Variables for dfa machine data:
550 * current_max_dfa_size - current maximum number of NFA states in DFA
551 * current_max_xpairs - current maximum number of non-template xtion pairs
552 * current_max_template_xpairs - current maximum number of template pairs
553 * current_max_dfas - current maximum number DFA states
554 * lastdfa - last dfa state number created
555 * nxt - state to enter upon reading character
556 * chk - check value to see if "nxt" applies
557 * tnxt - internal nxt table for templates
558 * base - offset into "nxt" for given state
559 * def - where to go if "chk" disallows "nxt" entry
560 * nultrans - NUL transition for each state
561 * NUL_ec - equivalence class of the NUL character
562 * tblend - last "nxt/chk" table entry being used
563 * firstfree - first empty entry in "nxt/chk" table
564 * dss - nfa state set for each dfa
565 * dfasiz - size of nfa state set for each dfa
566 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
568 * accsiz - size of accepting set for each dfa state
569 * dhash - dfa state hash value
570 * numas - number of DFA accepting states created; note that this
571 * is not necessarily the same value as num_rules, which is the analogous
573 * numsnpairs - number of state/nextstate transition pairs
574 * jambase - position in base/def where the default jam table starts
575 * jamstate - state number corresponding to "jam" state
576 * end_of_buffer_state - end-of-buffer dfa state number
579 extern int current_max_dfa_size, current_max_xpairs;
580 extern int current_max_template_xpairs, current_max_dfas;
581 extern int lastdfa, *nxt, *chk, *tnxt;
582 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss,
584 extern union dfaacc_union {
588 extern int *accsiz, *dhash, numas;
589 extern int numsnpairs, jambase, jamstate;
590 extern int end_of_buffer_state;
592 /* Variables for ccl information:
593 * lastccl - ccl index of the last created ccl
594 * current_maxccls - current limit on the maximum number of unique ccl's
595 * cclmap - maps a ccl index to its set pointer
596 * ccllen - gives the length of a ccl
597 * cclng - true for a given ccl if the ccl is negated
598 * cclreuse - counts how many times a ccl is re-used
599 * current_max_ccl_tbl_size - current limit on number of characters needed
600 * to represent the unique ccl's
601 * ccltbl - holds the characters in each ccl - indexed by cclmap
604 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
605 extern int current_maxccls, current_max_ccl_tbl_size;
606 extern unsigned char *ccltbl;
609 /* Variables for miscellaneous information:
610 * nmstr - last NAME scanned by the scanner
611 * sectnum - section number currently being parsed
612 * nummt - number of empty nxt/chk table entries
613 * hshcol - number of hash collisions detected by snstods
614 * dfaeql - number of times a newly created dfa was equal to an old one
615 * numeps - number of epsilon NFA states created
616 * eps2 - number of epsilon states which have 2 out-transitions
617 * num_reallocs - number of times it was necessary to realloc() a group
619 * tmpuses - number of DFA states that chain to templates
620 * totnst - total number of NFA states used to make DFA states
621 * peakpairs - peak number of transition pairs we had to store internally
622 * numuniq - number of unique transitions
623 * numdup - number of duplicate transitions
624 * hshsave - number of hash collisions saved by checking number of states
625 * num_backing_up - number of DFA states requiring backing up
626 * bol_needed - whether scanner needs beginning-of-line recognition
629 extern char nmstr[MAXLINE];
630 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
631 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
632 extern int num_backing_up, bol_needed;
634 #ifndef HAVE_REALLOCARRAY
635 void *reallocarray(void *, size_t, size_t);
638 void *allocate_array(int, size_t);
639 void *reallocate_array(void *, int, size_t);
641 #define allocate_integer_array(size) \
642 allocate_array(size, sizeof(int))
644 #define reallocate_integer_array(array,size) \
645 reallocate_array((void *) array, size, sizeof(int))
647 #define allocate_bool_array(size) \
648 allocate_array(size, sizeof(bool))
650 #define reallocate_bool_array(array,size) \
651 reallocate_array((void *) array, size, sizeof(bool))
653 #define allocate_int_ptr_array(size) \
654 allocate_array(size, sizeof(int *))
656 #define allocate_char_ptr_array(size) \
657 allocate_array(size, sizeof(char *))
659 #define allocate_dfaacc_union(size) \
660 allocate_array(size, sizeof(union dfaacc_union))
662 #define reallocate_int_ptr_array(array,size) \
663 reallocate_array((void *) array, size, sizeof(int *))
665 #define reallocate_char_ptr_array(array,size) \
666 reallocate_array((void *) array, size, sizeof(char *))
668 #define reallocate_dfaacc_union(array, size) \
669 reallocate_array((void *) array, size, sizeof(union dfaacc_union))
671 #define allocate_character_array(size) \
672 allocate_array( size, sizeof(char))
674 #define reallocate_character_array(array,size) \
675 reallocate_array((void *) array, size, sizeof(char))
677 #define allocate_Character_array(size) \
678 allocate_array(size, sizeof(unsigned char))
680 #define reallocate_Character_array(array,size) \
681 reallocate_array((void *) array, size, sizeof(unsigned char))
684 /* External functions that are cross-referenced among the flex source files. */
687 /* from file ccl.c */
689 extern void ccladd(int, int); /* add a single character to a ccl */
690 extern int cclinit(void); /* make an empty ccl */
691 extern void cclnegate(int); /* negate a ccl */
692 extern int ccl_set_diff (int a, int b); /* set difference of two ccls. */
693 extern int ccl_set_union (int a, int b); /* set union of two ccls. */
695 /* List the members of a set of characters in CCL form. */
696 extern void list_character_set(FILE *, int[]);
699 /* from file dfa.c */
701 /* Check a DFA state for backing up. */
702 extern void check_for_backing_up(int, int[]);
704 /* Check to see if NFA state set constitutes "dangerous" trailing context. */
705 extern void check_trailing_context(int *, int, int *, int);
707 /* Construct the epsilon closure of a set of ndfa states. */
708 extern int *epsclosure(int *, int *, int[], int *, int *);
710 /* Increase the maximum number of dfas. */
711 extern void increase_max_dfas(void);
713 extern void ntod(void); /* convert a ndfa to a dfa */
715 /* Converts a set of ndfa states into a dfa state. */
716 extern int snstods(int[], int, int[], int, int, int *);
719 /* from file ecs.c */
721 /* Convert character classes to set of equivalence classes. */
722 extern void ccl2ecl(void);
724 /* Associate equivalence class numbers with class members. */
725 extern int cre8ecs(int[], int[], int);
727 /* Update equivalence classes based on character class transitions. */
728 extern void mkeccl(unsigned char[], int, int[], int[], int, int);
730 /* Create equivalence class for single character. */
731 extern void mkechar(int, int[], int[]);
734 /* from file gen.c */
736 extern void do_indent(void); /* indent to the current level */
738 /* Generate the code to keep backing-up information. */
739 extern void gen_backing_up(void);
741 /* Generate the code to perform the backing up. */
742 extern void gen_bu_action(void);
744 /* Generate full speed compressed transition table. */
745 extern void genctbl(void);
747 /* Generate the code to find the action number. */
748 extern void gen_find_action(void);
750 extern void genftbl(void); /* generate full transition table */
752 /* Generate the code to find the next compressed-table state. */
753 extern void gen_next_compressed_state(char *);
755 /* Generate the code to find the next match. */
756 extern void gen_next_match(void);
758 /* Generate the code to find the next state. */
759 extern void gen_next_state(int);
761 /* Generate the code to make a NUL transition. */
762 extern void gen_NUL_trans(void);
764 /* Generate the code to find the start state. */
765 extern void gen_start_state(void);
767 /* Generate data statements for the transition tables. */
768 extern void gentabs(void);
770 /* Write out a formatted string at the current indentation level. */
771 extern void indent_put2s(const char *, const char *);
773 /* Write out a string + newline at the current indentation level. */
774 extern void indent_puts(const char *);
776 extern void make_tables(void); /* generate transition tables */
779 /* from file main.c */
781 extern void check_options(void);
782 extern void flexend(int);
783 extern void usage(void);
786 /* from file misc.c */
788 /* Add a #define to the action file. */
789 extern void action_define(const char *defname, int value);
791 /* Add the given text to the stored actions. */
792 extern void add_action(const char *new_text);
794 /* True if a string is all lower case. */
795 extern int all_lower(char *);
797 /* True if a string is all upper case. */
798 extern int all_upper(char *);
800 /* Compare two integers for use by qsort. */
801 extern int intcmp(const void *, const void *);
803 /* Check a character to make sure it's in the expected range. */
804 extern void check_char(int c);
806 /* Replace upper-case letter to lower-case. */
807 extern unsigned char clower(int);
809 /* strdup() that fails fatally on allocation failures. */
810 extern char *xstrdup(const char *);
812 /* Compare two characters for use by qsort with '\0' sorting last. */
813 extern int cclcmp(const void *, const void *);
815 /* Finish up a block of data declarations. */
816 extern void dataend(void);
818 /* Flush generated data statements. */
819 extern void dataflush(void);
821 /* Report an error message and terminate. */
822 extern void flexerror(const char *);
824 /* Report a fatal error message and terminate. */
825 extern void flexfatal(const char *);
827 /* Report a fatal error with a pinpoint, and terminate */
828 #if HAVE_DECL___FUNC__
829 #define flex_die(msg) \
832 _("%s: fatal internal error at %s:%d (%s): %s\n"),\
833 program_name, __FILE__, (int)__LINE__,\
837 #else /* ! HAVE_DECL___FUNC__ */
838 #define flex_die(msg) \
841 _("%s: fatal internal error at %s:%d %s\n"),\
842 program_name, __FILE__, (int)__LINE__,\
846 #endif /* ! HAVE_DECL___func__ */
848 /* Report an error message formatted */
849 extern void lerr(const char *, ...)
850 #if defined(__GNUC__) && __GNUC__ >= 3
851 __attribute__((__format__(__printf__, 1, 2)))
855 /* Like lerr, but also exit after displaying message. */
856 extern void lerr_fatal(const char *, ...)
857 #if defined(__GNUC__) && __GNUC__ >= 3
858 __attribute__((__format__(__printf__, 1, 2)))
862 /* Spit out a "#line" statement. */
863 extern void line_directive_out(FILE *, int);
865 /* Mark the current position in the action array as the end of the section 1
868 extern void mark_defs1(void);
870 /* Mark the current position in the action array as the end of the prolog. */
871 extern void mark_prolog(void);
873 /* Generate a data statment for a two-dimensional array. */
874 extern void mk2data(int);
876 extern void mkdata(int); /* generate a data statement */
878 /* Return the integer represented by a string of digits. */
879 extern int myctoi(const char *);
881 /* Return character corresponding to escape sequence. */
882 extern unsigned char myesc(unsigned char[]);
884 /* Output a (possibly-formatted) string to the generated scanner. */
885 extern void out(const char *);
886 extern void out_dec(const char *, int);
887 extern void out_dec2(const char *, int, int);
888 extern void out_hex(const char *, unsigned int);
889 extern void out_str(const char *, const char *);
890 extern void out_str3(const char *, const char *, const char *, const char *);
891 extern void out_str_dec(const char *, const char *, int);
892 extern void outc(int);
893 extern void outn(const char *);
894 extern void out_m4_define(const char* def, const char* val);
896 /* Return a printable version of the given character, which might be
899 extern char *readable_form(int);
901 /* Write out one section of the skeleton file. */
902 extern void skelout(void);
904 /* Output a yy_trans_info structure. */
905 extern void transition_struct_out(int, int);
907 /* Only needed when using certain broken versions of bison to build parse.c. */
908 extern void *yy_flex_xmalloc(int);
911 /* from file nfa.c */
913 /* Add an accepting state to a machine. */
914 extern void add_accept(int, int);
916 /* Make a given number of copies of a singleton machine. */
917 extern int copysingl(int, int);
919 /* Debugging routine to write out an nfa. */
920 extern void dumpnfa(int);
922 /* Finish up the processing for a rule. */
923 extern void finish_rule(int, int, int, int, int);
925 /* Connect two machines together. */
926 extern int link_machines(int, int);
928 /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
929 * not trailing context associated) state.
931 extern void mark_beginning_as_normal(int);
933 /* Make a machine that branches to two machines. */
934 extern int mkbranch(int, int);
936 extern int mkclos(int); /* convert a machine into a closure */
937 extern int mkopt(int); /* make a machine optional */
939 /* Make a machine that matches either one of two machines. */
940 extern int mkor(int, int);
942 /* Convert a machine into a positive closure. */
943 extern int mkposcl(int);
945 extern int mkrep(int, int, int); /* make a replicated machine */
947 /* Create a state with a transition on a given symbol. */
948 extern int mkstate(int);
950 extern void new_rule(void); /* initialize for a new rule */
953 /* from file parse.y */
955 /* Build the "<<EOF>>" action for the active start conditions. */
956 extern void build_eof_action(void);
958 /* Write out a message formatted with one string, pinpointing its location. */
959 extern void format_pinpoint_message(const char *, const char *);
961 /* Write out a message, pinpointing its location. */
962 extern void pinpoint_message(const char *);
964 /* Write out a warning, pinpointing it at the given line. */
965 extern void line_warning(const char *, int);
967 /* Write out a message, pinpointing it at the given line. */
968 extern void line_pinpoint(const char *, int);
970 /* Report a formatted syntax error. */
971 extern void format_synerr(const char *, const char *);
972 extern void synerr(const char *); /* report a syntax error */
973 extern void format_warn(const char *, const char *);
974 extern void lwarn(const char *); /* report a warning */
975 extern void yyerror(const char *); /* report a parse error */
976 extern int yyparse(void); /* the YACC parser */
979 /* from file scan.l */
981 /* The Flex-generated scanner for flex. */
982 extern int flexscan(void);
984 /* Open the given file (if NULL, stdin) for scanning. */
985 extern void set_input_file(char *);
988 /* from file sym.c */
990 /* Save the text of a character class. */
991 extern void cclinstal(char[], int);
993 /* Lookup the number associated with character class. */
994 extern int ccllookup(char[]);
996 extern void ndinstal(const char *, char[]); /* install a name definition */
997 extern char *ndlookup(const char *); /* lookup a name definition */
999 /* Increase maximum number of SC's. */
1000 extern void scextend(void);
1001 extern void scinstal(const char *, int); /* make a start condition */
1003 /* Lookup the number associated with a start condition. */
1004 extern int sclookup(const char *);
1007 /* from file tblcmp.c */
1009 /* Build table entries for dfa state. */
1010 extern void bldtbl(int[], int, int, int, int);
1012 extern void cmptmps(void); /* compress template table entries */
1013 extern void expand_nxt_chk(void); /* increase nxt/chk arrays */
1015 /* Finds a space in the table for a state to be placed. */
1016 extern int find_table_space(int *, int);
1017 extern void inittbl(void); /* initialize transition tables */
1019 /* Make the default, "jam" table entries. */
1020 extern void mkdeftbl(void);
1022 /* Create table entries for a state (or state fragment) which has
1023 * only one out-transition.
1025 extern void mk1tbl(int, int, int, int);
1027 /* Place a state into full speed transition table. */
1028 extern void place_state(int *, int, int);
1030 /* Save states with only one out-transition to be processed later. */
1031 extern void stack1(int, int, int, int);
1034 /* from file yylex.c */
1036 extern int yylex(void);
1038 /* A growable array. See buf.c. */
1040 void *elts; /* elements. */
1041 int nelts; /* number of elements. */
1042 size_t elt_size; /* in bytes. */
1043 int nmax; /* max capacity of elements. */
1046 extern void buf_init(struct Buf * buf, size_t elem_size);
1047 extern void buf_destroy(struct Buf * buf);
1048 extern struct Buf *buf_append(struct Buf * buf, const void *ptr, int n_elem);
1049 extern struct Buf *buf_concat(struct Buf* dest, const struct Buf* src);
1050 extern struct Buf *buf_strappend(struct Buf *, const char *str);
1051 extern struct Buf *buf_strnappend(struct Buf *, const char *str, int nchars);
1052 extern struct Buf *buf_strdefine(struct Buf * buf, const char *str, const char *def);
1053 extern struct Buf *buf_prints(struct Buf *buf, const char *fmt, const char* s);
1054 extern struct Buf *buf_m4_define(struct Buf *buf, const char* def, const char* val);
1055 extern struct Buf *buf_m4_undefine(struct Buf *buf, const char* def);
1056 extern struct Buf *buf_print_strings(struct Buf * buf, FILE* out);
1057 extern struct Buf *buf_linedir(struct Buf *buf, const char* filename, int lineno);
1059 extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */
1060 extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */
1061 extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */
1062 extern struct Buf m4defs_buf; /* Holds m4 definitions. */
1063 extern struct Buf top_buf; /* contains %top code. String buffer. */
1064 extern bool no_section3_escape; /* True if the undocumented option --unsafe-no-m4-sect3-escape was passed */
1066 /* For blocking out code from the header file. */
1067 #define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[m4_dnl")
1068 #define OUT_END_CODE() outn("]])")
1070 /* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */
1071 extern jmp_buf flex_main_jmp_buf;
1073 #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1)
1075 /* Removes all \n and \r chars from tail of str. returns str. */
1076 extern char *chomp (char *str);
1078 /* ctype functions forced to return boolean */
1079 #define b_isalnum(c) (isalnum(c)?true:false)
1080 #define b_isalpha(c) (isalpha(c)?true:false)
1081 #define b_isascii(c) (isascii(c)?true:false)
1082 #define b_isblank(c) (isblank(c)?true:false)
1083 #define b_iscntrl(c) (iscntrl(c)?true:false)
1084 #define b_isdigit(c) (isdigit(c)?true:false)
1085 #define b_isgraph(c) (isgraph(c)?true:false)
1086 #define b_islower(c) (islower(c)?true:false)
1087 #define b_isprint(c) (isprint(c)?true:false)
1088 #define b_ispunct(c) (ispunct(c)?true:false)
1089 #define b_isspace(c) (isspace(c)?true:false)
1090 #define b_isupper(c) (isupper(c)?true:false)
1091 #define b_isxdigit(c) (isxdigit(c)?true:false)
1093 /* return true if char is uppercase or lowercase. */
1094 bool has_case(int c);
1096 /* Change case of character if possible. */
1097 int reverse_case(int c);
1099 /* return false if [c1-c2] is ambiguous for a caseless scanner. */
1100 bool range_covers_case (int c1, int c2);
1106 /** A single stdio filter to execute.
1107 * The filter may be external, such as "sed", or it
1108 * may be internal, as a function call.
1111 int (*filter_func)(struct filter*); /**< internal filter function */
1112 void * extra; /**< extra data passed to filter_func */
1113 int argc; /**< arg count */
1114 const char ** argv; /**< arg vector, \0-terminated */
1115 struct filter * next; /**< next filter or NULL */
1118 /* output filter chain */
1119 extern struct filter * output_chain;
1120 extern struct filter *filter_create_ext (struct filter * chain, const char *cmd, ...);
1121 struct filter *filter_create_int(struct filter *chain,
1122 int (*filter_func) (struct filter *),
1124 extern bool filter_apply_chain(struct filter * chain);
1125 extern int filter_truncate(struct filter * chain, int max_len);
1126 extern int filter_tee_header(struct filter *chain);
1127 extern int filter_fix_linedirs(struct filter *chain);
1134 extern regex_t regex_linedir, regex_blank_line;
1135 bool flex_init_regex(void);
1136 void flex_regcomp(regex_t *preg, const char *regex, int cflags);
1137 char *regmatch_dup (regmatch_t * m, const char *src);
1138 char *regmatch_cpy (regmatch_t * m, char *dest, const char *src);
1139 int regmatch_len (regmatch_t * m);
1140 int regmatch_strtol (regmatch_t * m, const char *src, char **endptr, int base);
1141 bool regmatch_empty (regmatch_t * m);
1143 /* From "scanflags.h" */
1144 typedef unsigned int scanflags_t;
1145 extern scanflags_t* _sf_stk;
1146 extern size_t _sf_top_ix, _sf_max; /**< stack of scanner flags. */
1147 #define _SF_CASE_INS ((scanflags_t) 0x0001)
1148 #define _SF_DOT_ALL ((scanflags_t) 0x0002)
1149 #define _SF_SKIP_WS ((scanflags_t) 0x0004)
1150 #define sf_top() (_sf_stk[_sf_top_ix])
1151 #define sf_case_ins() (sf_top() & _SF_CASE_INS)
1152 #define sf_dot_all() (sf_top() & _SF_DOT_ALL)
1153 #define sf_skip_ws() (sf_top() & _SF_SKIP_WS)
1154 #define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS))
1155 #define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL))
1156 #define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS))
1157 extern void sf_init(void);
1158 extern void sf_push(void);
1159 extern void sf_pop(void);
1162 #endif /* not defined FLEXDEF_H */