1 /* $NetBSD: flexdef.h,v 1.7 2014/10/30 18:44:05 christos Exp $ */
3 /* flexdef - definitions file for flex */
5 /* Copyright (c) 1990 The Regents of the University of California. */
6 /* All rights reserved. */
8 /* This code is derived from software contributed to Berkeley by */
11 /* The United States Government has rights in this work pursuant */
12 /* to contract no. DE-AC03-76SF00098 between the United States */
13 /* Department of Energy and the University of California. */
15 /* This file is part of flex. */
17 /* Redistribution and use in source and binary forms, with or without */
18 /* modification, are permitted provided that the following conditions */
21 /* 1. Redistributions of source code must retain the above copyright */
22 /* notice, this list of conditions and the following disclaimer. */
23 /* 2. Redistributions in binary form must reproduce the above copyright */
24 /* notice, this list of conditions and the following disclaimer in the */
25 /* documentation and/or other materials provided with the distribution. */
27 /* Neither the name of the University nor the names of its contributors */
28 /* may be used to endorse or promote products derived from this software */
29 /* without specific prior written permission. */
31 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
43 /* AIX requires this to be the first thing in the file. */
52 # ifndef alloca /* predefined by HP cc +Olibcalls */
81 #ifdef HAVE_NETINET_IN_H
82 #include <netinet/in.h>
84 #ifdef HAVE_SYS_PARAMS_H
85 #include <sys/params.h>
87 #ifdef HAVE_SYS_WAIT_H
102 /* We use gettext. So, when we write strings which should be translated, we mark them with _() */
106 #endif /* HAVE_LOCALE_H */
108 #define _(String) gettext (String)
110 #define _(STRING) STRING
111 #endif /* ENABLE_NLS */
113 /* Always be prepared to generate an 8-bit scanner. */
115 #define Char unsigned char
117 /* Size of input alphabet - should be size of ASCII set. */
118 #ifndef DEFAULT_CSIZE
119 #define DEFAULT_CSIZE 128
123 #if defined(__STDC__)
124 #define PROTO(proto) proto
126 #define PROTO(proto) ()
132 #define unlink remove
133 #define SHORT_FILE_NAMES
138 #define SHORT_FILE_NAMES
142 /* Maximum line length we'll have to deal with. */
146 #define MIN(x,y) ((x) < (y) ? (x) : (y))
149 #define MAX(x,y) ((x) > (y) ? (x) : (y))
152 #define ABS(x) ((x) < 0 ? -(x) : (x))
156 /* ANSI C does not guarantee that isascii() is defined */
158 #define isascii(c) ((c) <= 0177)
161 #define unspecified -1
163 /* Special chk[] values marking the slots taking by end-of-buffer and action
166 #define EOB_POSITION -1
167 #define ACTION_POSITION -2
169 /* Number of data items per line for -f output. */
170 #define NUMDATAITEMS 10
172 /* Number of lines of data in -f output before inserting a blank line for
175 #define NUMDATALINES 10
177 /* transition_struct_out() definitions. */
178 #define TRANS_STRUCT_PRINT_LENGTH 14
180 /* Returns true if an nfa state has an epsilon out-transition slot
181 * that can be used. This definition is currently not used.
183 #define FREE_EPSILON(state) \
184 (transchar[state] == SYM_EPSILON && \
185 trans2[state] == NO_TRANSITION && \
186 finalst[state] != state)
188 /* Returns true if an nfa state has an epsilon out-transition character
189 * and both slots are free
191 #define SUPER_FREE_EPSILON(state) \
192 (transchar[state] == SYM_EPSILON && \
193 trans1[state] == NO_TRANSITION) \
195 /* Maximum number of NFA states that can comprise a DFA state. It's real
196 * big because if there's a lot of rules, the initial state will have a
197 * huge epsilon closure.
199 #define INITIAL_MAX_DFA_SIZE 750
200 #define MAX_DFA_SIZE_INCREMENT 750
203 /* A note on the following masks. They are used to mark accepting numbers
204 * as being special. As such, they implicitly limit the number of accepting
205 * numbers (i.e., rules) because if there are too many rules the rule numbers
206 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
207 * 8192) so unlikely to actually cause any problems. A check is made in
208 * new_rule() to ensure that this limit is not reached.
211 /* Mask to mark a trailing context accepting number. */
212 #define YY_TRAILING_MASK 0x2000
214 /* Mask to mark the accepting number of the "head" of a trailing context
217 #define YY_TRAILING_HEAD_MASK 0x4000
219 /* Maximum number of rules, as outlined in the above note. */
220 #define MAX_RULE (YY_TRAILING_MASK - 1)
223 /* NIL must be 0. If not, its special meaning when making equivalence classes
224 * (it marks the representative of a given e.c.) will be unidentifiable.
228 #define JAM -1 /* to mark a missing DFA transition */
229 #define NO_TRANSITION NIL
230 #define UNIQUE -1 /* marks a symbol as an e.c. representative */
231 #define INFINITE_REPEAT -1 /* for x{5,} constructions */
233 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
234 #define MAX_CCLS_INCREMENT 100
236 /* Size of table holding members of character classes. */
237 #define INITIAL_MAX_CCL_TBL_SIZE 500
238 #define MAX_CCL_TBL_SIZE_INCREMENT 250
240 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
241 #define MAX_RULES_INCREMENT 100
243 #define INITIAL_MNS 2000 /* default maximum number of nfa states */
244 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
246 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
247 #define MAX_DFAS_INCREMENT 1000
249 #define JAMSTATE -32766 /* marks a reference to the state that always jams */
251 /* Maximum number of NFA states. */
252 #define MAXIMUM_MNS 31999
253 #define MAXIMUM_MNS_LONG 1999999999
255 /* Enough so that if it's subtracted from an NFA state number, the result
256 * is guaranteed to be negative.
258 #define MARKER_DIFFERENCE (maximum_mns+2)
260 /* Maximum number of nxt/chk pairs for non-templates. */
261 #define INITIAL_MAX_XPAIRS 2000
262 #define MAX_XPAIRS_INCREMENT 2000
264 /* Maximum number of nxt/chk pairs needed for templates. */
265 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
266 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
268 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
270 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
271 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
273 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
274 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
276 /* The following percentages are used to tune table compression:
278 * The percentage the number of out-transitions a state must be of the
279 * number of equivalence classes in order to be considered for table
280 * compaction by using protos.
282 #define PROTO_SIZE_PERCENTAGE 15
284 /* The percentage the number of homogeneous out-transitions of a state
285 * must be of the number of total out-transitions of the state in order
286 * that the state's transition table is first compared with a potential
287 * template of the most common out-transition instead of with the first
288 * proto in the proto queue.
290 #define CHECK_COM_PERCENTAGE 50
292 /* The percentage the number of differences between a state's transition
293 * table and the proto it was first compared with must be of the total
294 * number of out-transitions of the state in order to keep the first
295 * proto as a good match and not search any further.
297 #define FIRST_MATCH_DIFF_PERCENTAGE 10
299 /* The percentage the number of differences between a state's transition
300 * table and the most similar proto must be of the state's total number
301 * of out-transitions to use the proto as an acceptable close match.
303 #define ACCEPTABLE_DIFF_PERCENTAGE 50
305 /* The percentage the number of homogeneous out-transitions of a state
306 * must be of the number of total out-transitions of the state in order
307 * to consider making a template from the state.
309 #define TEMPLATE_SAME_PERCENTAGE 60
311 /* The percentage the number of differences between a state's transition
312 * table and the most similar proto must be of the state's total number
313 * of out-transitions to create a new proto from the state.
315 #define NEW_PROTO_DIFF_PERCENTAGE 20
317 /* The percentage the total number of out-transitions of a state must be
318 * of the number of equivalence classes in order to consider trying to
319 * fit the transition table into "holes" inside the nxt/chk table.
321 #define INTERIOR_FIT_PERCENTAGE 15
323 /* Size of region set aside to cache the complete transition table of
324 * protos on the proto queue to enable quick comparisons.
326 #define PROT_SAVE_SIZE 2000
328 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
330 /* Maximum number of out-transitions a state can have that we'll rummage
331 * around through the interior of the internal fast table looking for a
334 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
336 /* Maximum number of rules which will be reported as being associated
339 #define MAX_ASSOC_RULES 100
341 /* Number that, if used to subscript an array, has a good chance of producing
342 * an error; should be small enough to fit into a short.
344 #define BAD_SUBSCRIPT -32767
346 /* Absolute value of largest number that can be stored in a short, with a
347 * bit of slop thrown in for general paranoia.
349 #define MAX_SHORT 32700
352 /* Declarations for global variables. */
355 /* Variables for flags:
356 * printstats - if true (-v), dump statistics
357 * syntaxerror - true if a syntax error has been found
358 * eofseen - true if we've seen an eof in the input file
359 * ddebug - if true (-d), make a "debug" scanner
360 * trace - if true (-T), trace processing
361 * nowarn - if true (-w), do not generate warnings
362 * spprdflt - if true (-s), suppress the default rule
363 * interactive - if true (-I), generate an interactive scanner
364 * lex_compat - if true (-l), maximize compatibility with AT&T lex
365 * posix_compat - if true (-X), maximize compatibility with POSIX lex
366 * do_yylineno - if true, generate code to maintain yylineno
367 * useecs - if true (-Ce flag), use equivalence classes
368 * fulltbl - if true (-Cf flag), don't compress the DFA state table
369 * usemecs - if true (-Cm flag), use meta-equivalence classes
370 * fullspd - if true (-F flag), use Jacobson method of table representation
371 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
372 * performance_report - if > 0 (i.e., -p flag), generate a report relating
373 * to scanner performance; if > 1 (-p -p), report on minor performance
375 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
376 * listing backing-up states
377 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
378 * otherwise, a standard C scanner
379 * reentrant - if true (-R), generate a reentrant C scanner.
380 * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention.
381 * bison_bridge_lloc - if true (--bison-locations), bison yylloc.
382 * long_align - if true (-Ca flag), favor long-word alignment.
383 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
384 * otherwise, use fread().
385 * yytext_is_array - if true (i.e., %array directive), then declare
386 * yytext as a array instead of a character pointer. Nice and inefficient.
387 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
389 * csize - size of character set for the scanner we're generating;
390 * 128 for 7-bit chars and 256 for 8-bit
391 * yymore_used - if true, yymore() is used in input rules
392 * reject - if true, generate back-up tables for REJECT macro
393 * real_reject - if true, scanner really uses REJECT (as opposed to just
394 * having "reject" set for variable trailing context)
395 * continued_action - true if this rule's action is to "fall through" to
396 * the next rule's action (i.e., the '|' action)
397 * in_rule - true if we're inside an individual rule, false if not.
398 * yymore_really_used - whether to treat yymore() as really used, regardless
399 * of what we think based on references to it in the user's actions.
400 * reject_really_used - same for REJECT
403 extern int printstats
, syntaxerror
, eofseen
, ddebug
, trace
, nowarn
,
405 extern int interactive
, lex_compat
, posix_compat
, do_yylineno
;
406 extern int useecs
, fulltbl
, usemecs
, fullspd
;
407 extern int gen_line_dirs
, performance_report
, backing_up_report
;
408 extern int reentrant
, bison_bridge_lval
, bison_bridge_lloc
;
409 extern bool ansi_func_defs
, ansi_func_protos
;
410 extern int C_plus_plus
, long_align
, use_read
, yytext_is_array
, do_yywrap
;
412 extern int yymore_used
, reject
, real_reject
, continued_action
, in_rule
;
414 extern int yymore_really_used
, reject_really_used
;
417 /* Variables used in the flex input routines:
418 * datapos - characters on current output line
419 * dataline - number of contiguous lines of data in current data
420 * statement. Used to generate readable -f output
421 * linenum - current input line number
422 * skelfile - the skeleton file
423 * skel - compiled-in skeleton array
424 * skel_ind - index into "skel" array, if skelfile is nil
426 * backing_up_file - file to summarize backing-up states to
427 * infilename - name of input file
428 * outfilename - name of output file
429 * headerfilename - name of the .h file to generate
430 * did_outfilename - whether outfilename was explicitly set
431 * prefix - the prefix used for externally visible names ("yy" by default)
432 * yyclass - yyFlexLexer subclass to use for YY_DECL
433 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
434 * use_stdout - the -t flag
435 * input_files - array holding names of input files
436 * num_input_files - size of input_files array
437 * program_name - name with which program was invoked
439 * action_array - array to hold the rule actions
440 * action_size - size of action_array
441 * defs1_offset - index where the user's section 1 definitions start
443 * prolog_offset - index where the prolog starts in action_array
444 * action_offset - index where the non-prolog starts in action_array
445 * action_index - index where the next action should go, with respect
449 extern int datapos
, dataline
, linenum
;
450 extern FILE *skelfile
, *yyin
, *backing_up_file
;
451 extern const char *skel
[];
453 extern char *infilename
, *outfilename
, *headerfilename
;
454 extern int did_outfilename
;
455 extern char *prefix
, *yyclass
, *extra_type
;
456 extern int do_stdinit
, use_stdout
;
457 extern char **input_files
;
458 extern int num_input_files
;
459 extern char *program_name
;
461 extern char *action_array
;
462 extern int action_size
;
463 extern int defs1_offset
, prolog_offset
, action_offset
, action_index
;
466 /* Variables for stack of states having only one out-transition:
467 * onestate - state number
468 * onesym - transition symbol
469 * onenext - target state
470 * onedef - default base entry
471 * onesp - stack pointer
474 extern int onestate
[ONE_STACK_SIZE
], onesym
[ONE_STACK_SIZE
];
475 extern int onenext
[ONE_STACK_SIZE
], onedef
[ONE_STACK_SIZE
], onesp
;
478 /* Variables for nfa machine data:
479 * maximum_mns - maximal number of NFA states supported by tables
480 * current_mns - current maximum on number of NFA states
481 * num_rules - number of the last accepting state; also is number of
482 * rules created so far
483 * num_eof_rules - number of <<EOF>> rules
484 * default_rule - number of the default rule
485 * current_max_rules - current maximum number of rules
486 * lastnfa - last nfa state number created
487 * firstst - physically the first state of a fragment
488 * lastst - last physical state of fragment
489 * finalst - last logical state of fragment
490 * transchar - transition character
491 * trans1 - transition state
492 * trans2 - 2nd transition state for epsilons
493 * accptnum - accepting number
494 * assoc_rule - rule associated with this NFA state (or 0 if none)
495 * state_type - a STATE_xxx type identifying whether the state is part
496 * of a normal rule, the leading state in a trailing context
497 * rule (i.e., the state which marks the transition from
498 * recognizing the text-to-be-matched to the beginning of
499 * the trailing context), or a subsequent state in a trailing
501 * rule_type - a RULE_xxx type identifying whether this a ho-hum
502 * normal rule or one which has variable head & trailing
504 * rule_linenum - line number associated with rule
505 * rule_useful - true if we've determined that the rule can be matched
506 * rule_has_nl - true if rule could possibly match a newline
507 * ccl_has_nl - true if current ccl could match a newline
508 * nlch - default eol char
511 extern int maximum_mns
, current_mns
, current_max_rules
;
512 extern int num_rules
, num_eof_rules
, default_rule
, lastnfa
;
513 extern int *firstst
, *lastst
, *finalst
, *transchar
, *trans1
, *trans2
;
514 extern int *accptnum
, *assoc_rule
, *state_type
;
515 extern int *rule_type
, *rule_linenum
, *rule_useful
;
516 extern bool *rule_has_nl
, *ccl_has_nl
;
519 /* Different types of states; values are useful as masks, as well, for
520 * routines like check_trailing_context().
522 #define STATE_NORMAL 0x1
523 #define STATE_TRAILING_CONTEXT 0x2
525 /* Global holding current type of state we're making. */
527 extern int current_state_type
;
529 /* Different types of rules. */
530 #define RULE_NORMAL 0
531 #define RULE_VARIABLE 1
533 /* True if the input rules include a rule with both variable-length head
534 * and trailing context, false otherwise.
536 extern int variable_trailing_context_rules
;
539 /* Variables for protos:
540 * numtemps - number of templates created
541 * numprots - number of protos created
542 * protprev - backlink to a more-recently used proto
543 * protnext - forward link to a less-recently used proto
544 * prottbl - base/def table entry for proto
545 * protcomst - common state of proto
546 * firstprot - number of the most recently used proto
547 * lastprot - number of the least recently used proto
548 * protsave contains the entire state array for protos
551 extern int numtemps
, numprots
, protprev
[MSP
], protnext
[MSP
], prottbl
[MSP
];
552 extern int protcomst
[MSP
], firstprot
, lastprot
, protsave
[PROT_SAVE_SIZE
];
555 /* Variables for managing equivalence classes:
556 * numecs - number of equivalence classes
557 * nextecm - forward link of Equivalence Class members
558 * ecgroup - class number or backward link of EC members
559 * nummecs - number of meta-equivalence classes (used to compress
561 * tecfwd - forward link of meta-equivalence classes members
562 * tecbck - backward link of MEC's
565 /* Reserve enough room in the equivalence class arrays so that we
566 * can use the CSIZE'th element to hold equivalence class information
567 * for the NUL character. Later we'll move this information into
570 extern int numecs
, nextecm
[CSIZE
+ 1], ecgroup
[CSIZE
+ 1], nummecs
;
572 /* Meta-equivalence classes are indexed starting at 1, so it's possible
573 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
574 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
575 * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
577 extern int tecfwd
[CSIZE
+ 1], tecbck
[CSIZE
+ 1];
580 /* Variables for start conditions:
581 * lastsc - last start condition created
582 * current_max_scs - current limit on number of start conditions
583 * scset - set of rules active in start condition
584 * scbol - set of rules active only at the beginning of line in a s.c.
585 * scxclu - true if start condition is exclusive
586 * sceof - true if start condition has EOF rule
587 * scname - start condition name
590 extern int lastsc
, *scset
, *scbol
, *scxclu
, *sceof
;
591 extern int current_max_scs
;
592 extern char **scname
;
595 /* Variables for dfa machine data:
596 * current_max_dfa_size - current maximum number of NFA states in DFA
597 * current_max_xpairs - current maximum number of non-template xtion pairs
598 * current_max_template_xpairs - current maximum number of template pairs
599 * current_max_dfas - current maximum number DFA states
600 * lastdfa - last dfa state number created
601 * nxt - state to enter upon reading character
602 * chk - check value to see if "nxt" applies
603 * tnxt - internal nxt table for templates
604 * base - offset into "nxt" for given state
605 * def - where to go if "chk" disallows "nxt" entry
606 * nultrans - NUL transition for each state
607 * NUL_ec - equivalence class of the NUL character
608 * tblend - last "nxt/chk" table entry being used
609 * firstfree - first empty entry in "nxt/chk" table
610 * dss - nfa state set for each dfa
611 * dfasiz - size of nfa state set for each dfa
612 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
614 * accsiz - size of accepting set for each dfa state
615 * dhash - dfa state hash value
616 * numas - number of DFA accepting states created; note that this
617 * is not necessarily the same value as num_rules, which is the analogous
619 * numsnpairs - number of state/nextstate transition pairs
620 * jambase - position in base/def where the default jam table starts
621 * jamstate - state number corresponding to "jam" state
622 * end_of_buffer_state - end-of-buffer dfa state number
625 extern int current_max_dfa_size
, current_max_xpairs
;
626 extern int current_max_template_xpairs
, current_max_dfas
;
627 extern int lastdfa
, *nxt
, *chk
, *tnxt
;
628 extern int *base
, *def
, *nultrans
, NUL_ec
, tblend
, firstfree
, **dss
,
630 extern union dfaacc_union
{
634 extern int *accsiz
, *dhash
, numas
;
635 extern int numsnpairs
, jambase
, jamstate
;
636 extern int end_of_buffer_state
;
638 /* Variables for ccl information:
639 * lastccl - ccl index of the last created ccl
640 * current_maxccls - current limit on the maximum number of unique ccl's
641 * cclmap - maps a ccl index to its set pointer
642 * ccllen - gives the length of a ccl
643 * cclng - true for a given ccl if the ccl is negated
644 * cclreuse - counts how many times a ccl is re-used
645 * current_max_ccl_tbl_size - current limit on number of characters needed
646 * to represent the unique ccl's
647 * ccltbl - holds the characters in each ccl - indexed by cclmap
650 extern int lastccl
, *cclmap
, *ccllen
, *cclng
, cclreuse
;
651 extern int current_maxccls
, current_max_ccl_tbl_size
;
655 /* Variables for miscellaneous information:
656 * nmstr - last NAME scanned by the scanner
657 * sectnum - section number currently being parsed
658 * nummt - number of empty nxt/chk table entries
659 * hshcol - number of hash collisions detected by snstods
660 * dfaeql - number of times a newly created dfa was equal to an old one
661 * numeps - number of epsilon NFA states created
662 * eps2 - number of epsilon states which have 2 out-transitions
663 * num_reallocs - number of times it was necessary to realloc() a group
665 * tmpuses - number of DFA states that chain to templates
666 * totnst - total number of NFA states used to make DFA states
667 * peakpairs - peak number of transition pairs we had to store internally
668 * numuniq - number of unique transitions
669 * numdup - number of duplicate transitions
670 * hshsave - number of hash collisions saved by checking number of states
671 * num_backing_up - number of DFA states requiring backing up
672 * bol_needed - whether scanner needs beginning-of-line recognition
675 extern char nmstr
[MAXLINE
];
676 extern int sectnum
, nummt
, hshcol
, dfaeql
, numeps
, eps2
, num_reallocs
;
677 extern int tmpuses
, totnst
, peakpairs
, numuniq
, numdup
, hshsave
;
678 extern int num_backing_up
, bol_needed
;
680 void *allocate_array
PROTO ((int, size_t));
681 void *reallocate_array
PROTO ((void *, int, size_t));
683 void *flex_alloc
PROTO ((size_t));
684 void *flex_realloc
PROTO ((void *, size_t));
685 void flex_free
PROTO ((void *));
687 #define allocate_integer_array(size) \
688 (int *) allocate_array( size, sizeof( int ) )
690 #define reallocate_integer_array(array,size) \
691 (int *) reallocate_array( (void *) array, size, sizeof( int ) )
693 #define allocate_bool_array(size) \
694 (bool *) allocate_array( size, sizeof( bool ) )
696 #define reallocate_bool_array(array,size) \
697 (bool *) reallocate_array( (void *) array, size, sizeof( bool ) )
699 #define allocate_int_ptr_array(size) \
700 (int **) allocate_array( size, sizeof( int * ) )
702 #define allocate_char_ptr_array(size) \
703 (char **) allocate_array( size, sizeof( char * ) )
705 #define allocate_dfaacc_union(size) \
706 (union dfaacc_union *) \
707 allocate_array( size, sizeof( union dfaacc_union ) )
709 #define reallocate_int_ptr_array(array,size) \
710 (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
712 #define reallocate_char_ptr_array(array,size) \
713 (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
715 #define reallocate_dfaacc_union(array, size) \
716 (union dfaacc_union *) \
717 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
719 #define allocate_character_array(size) \
720 (char *) allocate_array( size, sizeof( char ) )
722 #define reallocate_character_array(array,size) \
723 (char *) reallocate_array( (void *) array, size, sizeof( char ) )
725 #define allocate_Character_array(size) \
726 (Char *) allocate_array( size, sizeof( Char ) )
728 #define reallocate_Character_array(array,size) \
729 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
732 /* Used to communicate between scanner and parser. The type should really
733 * be YYSTYPE, but we can't easily get our hands on it.
738 /* External functions that are cross-referenced among the flex source files. */
741 /* from file ccl.c */
743 extern void ccladd
PROTO ((int, int)); /* add a single character to a ccl */
744 extern int cclinit
PROTO ((void)); /* make an empty ccl */
745 extern void cclnegate
PROTO ((int)); /* negate a ccl */
746 extern int ccl_set_diff (int a
, int b
); /* set difference of two ccls. */
747 extern int ccl_set_union (int a
, int b
); /* set union of two ccls. */
749 /* List the members of a set of characters in CCL form. */
750 extern void list_character_set
PROTO ((FILE *, int[]));
753 /* from file dfa.c */
755 /* Check a DFA state for backing up. */
756 extern void check_for_backing_up
PROTO ((int, int[]));
758 /* Check to see if NFA state set constitutes "dangerous" trailing context. */
759 extern void check_trailing_context
PROTO ((int *, int, int *, int));
761 /* Construct the epsilon closure of a set of ndfa states. */
762 extern int *epsclosure
PROTO ((int *, int *, int[], int *, int *));
764 /* Increase the maximum number of dfas. */
765 extern void increase_max_dfas
PROTO ((void));
767 extern void ntod
PROTO ((void)); /* convert a ndfa to a dfa */
769 /* Converts a set of ndfa states into a dfa state. */
770 extern int snstods
PROTO ((int[], int, int[], int, int, int *));
773 /* from file ecs.c */
775 /* Convert character classes to set of equivalence classes. */
776 extern void ccl2ecl
PROTO ((void));
778 /* Associate equivalence class numbers with class members. */
779 extern int cre8ecs
PROTO ((int[], int[], int));
781 /* Update equivalence classes based on character class transitions. */
782 extern void mkeccl
PROTO ((Char
[], int, int[], int[], int, int));
784 /* Create equivalence class for single character. */
785 extern void mkechar
PROTO ((int, int[], int[]));
788 /* from file gen.c */
790 extern void do_indent
PROTO ((void)); /* indent to the current level */
792 /* Generate the code to keep backing-up information. */
793 extern void gen_backing_up
PROTO ((void));
795 /* Generate the code to perform the backing up. */
796 extern void gen_bu_action
PROTO ((void));
798 /* Generate full speed compressed transition table. */
799 extern void genctbl
PROTO ((void));
801 /* Generate the code to find the action number. */
802 extern void gen_find_action
PROTO ((void));
804 extern void genftbl
PROTO ((void)); /* generate full transition table */
806 /* Generate the code to find the next compressed-table state. */
807 extern void gen_next_compressed_state
PROTO ((char *));
809 /* Generate the code to find the next match. */
810 extern void gen_next_match
PROTO ((void));
812 /* Generate the code to find the next state. */
813 extern void gen_next_state
PROTO ((int));
815 /* Generate the code to make a NUL transition. */
816 extern void gen_NUL_trans
PROTO ((void));
818 /* Generate the code to find the start state. */
819 extern void gen_start_state
PROTO ((void));
821 /* Generate data statements for the transition tables. */
822 extern void gentabs
PROTO ((void));
824 /* Write out a formatted string at the current indentation level. */
825 extern void indent_put2s
PROTO ((const char *, const char *));
827 /* Write out a string + newline at the current indentation level. */
828 extern void indent_puts
PROTO ((const char *));
830 extern void make_tables
PROTO ((void)); /* generate transition tables */
833 /* from file main.c */
835 extern void check_options
PROTO ((void));
836 extern void flexend
PROTO ((int));
837 extern void usage
PROTO ((void));
840 /* from file misc.c */
842 /* Add a #define to the action file. */
843 extern void action_define
PROTO ((const char *defname
, int value
));
845 /* Add the given text to the stored actions. */
846 extern void add_action
PROTO ((const char *new_text
));
848 /* True if a string is all lower case. */
849 extern int all_lower
PROTO ((register char *));
851 /* True if a string is all upper case. */
852 extern int all_upper
PROTO ((register char *));
854 /* Compare two integers for use by qsort. */
855 extern int intcmp
PROTO ((const void *, const void *));
857 /* Check a character to make sure it's in the expected range. */
858 extern void check_char
PROTO ((int c
));
860 /* Replace upper-case letter to lower-case. */
861 extern Char clower
PROTO ((int));
863 /* Returns a dynamically allocated copy of a string. */
864 extern char *copy_string
PROTO ((register const char *));
866 /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
867 extern Char
*copy_unsigned_string
PROTO ((register Char
*));
869 /* Compare two characters for use by qsort with '\0' sorting last. */
870 extern int cclcmp
PROTO ((const void *, const void *));
872 /* Finish up a block of data declarations. */
873 extern void dataend
PROTO ((void));
875 /* Flush generated data statements. */
876 extern void dataflush
PROTO ((void));
878 /* Report an error message and terminate. */
879 extern void flexerror
PROTO ((const char *));
881 /* Report a fatal error message and terminate. */
882 extern void flexfatal
PROTO ((const char *));
884 /* Report a fatal error with a pinpoint, and terminate */
885 #if HAVE_DECL___FUNC__
886 #define flex_die(msg) \
889 _("%s: fatal internal error at %s:%d (%s): %s\n"),\
890 program_name, __FILE__, (int)__LINE__,\
894 #else /* ! HAVE_DECL___FUNC__ */
895 #define flex_die(msg) \
898 _("%s: fatal internal error at %s:%d %s\n"),\
899 program_name, __FILE__, (int)__LINE__,\
903 #endif /* ! HAVE_DECL___func__ */
905 /* Convert a hexadecimal digit string to an integer value. */
906 extern int htoi
PROTO ((Char
[]));
908 /* Report an error message formatted with one integer argument. */
909 extern void lerrif
PROTO ((const char *, int));
911 /* Report an error message formatted with one string argument. */
912 extern void lerrsf
PROTO ((const char *, const char *));
914 /* Like lerrsf, but also exit after displaying message. */
919 void lerrsf_fatal (const char *msg
, ...);
921 /* Spit out a "#line" statement. */
922 extern void line_directive_out
PROTO ((FILE *, int));
924 /* Mark the current position in the action array as the end of the section 1
927 extern void mark_defs1
PROTO ((void));
929 /* Mark the current position in the action array as the end of the prolog. */
930 extern void mark_prolog
PROTO ((void));
932 /* Generate a data statment for a two-dimensional array. */
933 extern void mk2data
PROTO ((int));
935 extern void mkdata
PROTO ((int)); /* generate a data statement */
937 /* Return the integer represented by a string of digits. */
938 extern int myctoi
PROTO ((const char *));
940 /* Return character corresponding to escape sequence. */
941 extern Char myesc
PROTO ((Char
[]));
943 /* Convert an octal digit string to an integer value. */
944 extern int otoi
PROTO ((Char
[]));
946 /* Output a (possibly-formatted) string to the generated scanner. */
947 extern void out
PROTO ((const char *));
948 extern void out_dec
PROTO ((const char *, int));
949 extern void out_dec2
PROTO ((const char *, int, int));
950 extern void out_hex
PROTO ((const char *, unsigned int));
951 extern void out_str
PROTO ((const char *, const char *));
953 PROTO ((const char *, const char *, const char *, const char *));
954 extern void out_str_dec
PROTO ((const char *, const char *, int));
955 extern void outc
PROTO ((int));
956 extern void outn
PROTO ((const char *));
957 extern void out_m4_define (const char* def
, const char* val
);
959 /* Return a printable version of the given character, which might be
962 extern char *readable_form
PROTO ((int));
964 /* Write out one section of the skeleton file. */
965 extern void skelout
PROTO ((void));
967 /* Output a yy_trans_info structure. */
968 extern void transition_struct_out
PROTO ((int, int));
970 /* Only needed when using certain broken versions of bison to build parse.c. */
971 extern void *yy_flex_xmalloc
PROTO ((int));
973 /* Set a region of memory to 0. */
974 extern void zero_out
PROTO ((char *, size_t));
977 /* from file nfa.c */
979 /* Add an accepting state to a machine. */
980 extern void add_accept
PROTO ((int, int));
982 /* Make a given number of copies of a singleton machine. */
983 extern int copysingl
PROTO ((int, int));
985 /* Debugging routine to write out an nfa. */
986 extern void dumpnfa
PROTO ((int));
988 /* Finish up the processing for a rule. */
989 extern void finish_rule
PROTO ((int, int, int, int, int));
991 /* Connect two machines together. */
992 extern int link_machines
PROTO ((int, int));
994 /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
995 * not trailing context associated) state.
997 extern void mark_beginning_as_normal
PROTO ((register int));
999 /* Make a machine that branches to two machines. */
1000 extern int mkbranch
PROTO ((int, int));
1002 extern int mkclos
PROTO ((int)); /* convert a machine into a closure */
1003 extern int mkopt
PROTO ((int)); /* make a machine optional */
1005 /* Make a machine that matches either one of two machines. */
1006 extern int mkor
PROTO ((int, int));
1008 /* Convert a machine into a positive closure. */
1009 extern int mkposcl
PROTO ((int));
1011 extern int mkrep
PROTO ((int, int, int)); /* make a replicated machine */
1013 /* Create a state with a transition on a given symbol. */
1014 extern int mkstate
PROTO ((int));
1016 extern void new_rule
PROTO ((void)); /* initialize for a new rule */
1019 /* from file parse.y */
1021 /* Build the "<<EOF>>" action for the active start conditions. */
1022 extern void build_eof_action
PROTO ((void));
1024 /* Write out a message formatted with one string, pinpointing its location. */
1025 extern void format_pinpoint_message
PROTO ((const char *, const char *));
1027 /* Write out a message, pinpointing its location. */
1028 extern void pinpoint_message
PROTO ((const char *));
1030 /* Write out a warning, pinpointing it at the given line. */
1031 extern void line_warning
PROTO ((const char *, int));
1033 /* Write out a message, pinpointing it at the given line. */
1034 extern void line_pinpoint
PROTO ((const char *, int));
1036 /* Report a formatted syntax error. */
1037 extern void format_synerr
PROTO ((const char *, const char *));
1038 extern void synerr
PROTO ((const char *)); /* report a syntax error */
1039 extern void format_warn
PROTO ((const char *, const char *));
1040 extern void lwarn
PROTO ((const char *)); /* report a warning */
1041 extern void yyerror
PROTO ((const char *)); /* report a parse error */
1042 extern int yyparse
PROTO ((void)); /* the YACC parser */
1045 /* from file scan.l */
1047 /* The Flex-generated scanner for flex. */
1048 extern int flexscan
PROTO ((void));
1050 /* Open the given file (if NULL, stdin) for scanning. */
1051 extern void set_input_file
PROTO ((char *));
1053 /* Wrapup a file in the lexical analyzer. */
1054 extern int yywrap
PROTO ((void));
1057 /* from file sym.c */
1059 /* Save the text of a character class. */
1060 extern void cclinstal
PROTO ((Char
[], int));
1062 /* Lookup the number associated with character class. */
1063 extern int ccllookup
PROTO ((Char
[]));
1065 extern void ndinstal
PROTO ((const char *, Char
[])); /* install a name definition */
1066 extern Char
*ndlookup
PROTO ((const char *)); /* lookup a name definition */
1068 /* Increase maximum number of SC's. */
1069 extern void scextend
PROTO ((void));
1070 extern void scinstal
PROTO ((const char *, int)); /* make a start condition */
1072 /* Lookup the number associated with a start condition. */
1073 extern int sclookup
PROTO ((const char *));
1076 /* from file tblcmp.c */
1078 /* Build table entries for dfa state. */
1079 extern void bldtbl
PROTO ((int[], int, int, int, int));
1081 extern void cmptmps
PROTO ((void)); /* compress template table entries */
1082 extern void expand_nxt_chk
PROTO ((void)); /* increase nxt/chk arrays */
1084 /* Finds a space in the table for a state to be placed. */
1085 extern int find_table_space
PROTO ((int *, int));
1086 extern void inittbl
PROTO ((void)); /* initialize transition tables */
1088 /* Make the default, "jam" table entries. */
1089 extern void mkdeftbl
PROTO ((void));
1091 /* Create table entries for a state (or state fragment) which has
1092 * only one out-transition.
1094 extern void mk1tbl
PROTO ((int, int, int, int));
1096 /* Place a state into full speed transition table. */
1097 extern void place_state
PROTO ((int *, int, int));
1099 /* Save states with only one out-transition to be processed later. */
1100 extern void stack1
PROTO ((int, int, int, int));
1103 /* from file yylex.c */
1105 extern int yylex
PROTO ((void));
1107 /* A growable array. See buf.c. */
1109 void *elts
; /* elements. */
1110 int nelts
; /* number of elements. */
1111 size_t elt_size
; /* in bytes. */
1112 int nmax
; /* max capacity of elements. */
1115 extern void buf_init
PROTO ((struct Buf
* buf
, size_t elem_size
));
1116 extern void buf_destroy
PROTO ((struct Buf
* buf
));
1117 extern struct Buf
*buf_append
1118 PROTO ((struct Buf
* buf
, const void *ptr
, int n_elem
));
1119 extern struct Buf
*buf_concat
PROTO((struct Buf
* dest
, const struct Buf
* src
));
1120 extern struct Buf
*buf_strappend
PROTO ((struct Buf
*, const char *str
));
1121 extern struct Buf
*buf_strnappend
1122 PROTO ((struct Buf
*, const char *str
, int nchars
));
1123 extern struct Buf
*buf_strdefine
1124 PROTO ((struct Buf
* buf
, const char *str
, const char *def
));
1125 extern struct Buf
*buf_prints
PROTO((struct Buf
*buf
, const char *fmt
, const char* s
));
1126 extern struct Buf
*buf_m4_define
PROTO((struct Buf
*buf
, const char* def
, const char* val
));
1127 extern struct Buf
*buf_m4_undefine
PROTO((struct Buf
*buf
, const char* def
));
1128 extern struct Buf
*buf_print_strings
PROTO((struct Buf
* buf
, FILE* out
));
1129 extern struct Buf
*buf_linedir
PROTO((struct Buf
*buf
, const char* filename
, int lineno
));
1131 extern struct Buf userdef_buf
; /* a string buffer for #define's generated by user-options on cmd line. */
1132 extern struct Buf defs_buf
; /* a char* buffer to save #define'd some symbols generated by flex. */
1133 extern struct Buf yydmap_buf
; /* a string buffer to hold yydmap elements */
1134 extern struct Buf m4defs_buf
; /* Holds m4 definitions. */
1135 extern struct Buf top_buf
; /* contains %top code. String buffer. */
1137 /* For blocking out code from the header file. */
1138 #define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[")
1139 #define OUT_END_CODE() outn("]])")
1141 /* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */
1142 extern jmp_buf flex_main_jmp_buf
;
1144 #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1)
1146 /* Removes all \n and \r chars from tail of str. returns str. */
1147 extern char *chomp (char *str
);
1149 /* ctype functions forced to return boolean */
1150 #define b_isalnum(c) (isalnum(c)?true:false)
1151 #define b_isalpha(c) (isalpha(c)?true:false)
1152 #define b_isascii(c) (isascii(c)?true:false)
1153 #define b_isblank(c) (isblank(c)?true:false)
1154 #define b_iscntrl(c) (iscntrl(c)?true:false)
1155 #define b_isdigit(c) (isdigit(c)?true:false)
1156 #define b_isgraph(c) (isgraph(c)?true:false)
1157 #define b_islower(c) (islower(c)?true:false)
1158 #define b_isprint(c) (isprint(c)?true:false)
1159 #define b_ispunct(c) (ispunct(c)?true:false)
1160 #define b_isspace(c) (isspace(c)?true:false)
1161 #define b_isupper(c) (isupper(c)?true:false)
1162 #define b_isxdigit(c) (isxdigit(c)?true:false)
1164 /* return true if char is uppercase or lowercase. */
1165 bool has_case(int c
);
1167 /* Change case of character if possible. */
1168 int reverse_case(int c
);
1170 /* return false if [c1-c2] is ambiguous for a caseless scanner. */
1171 bool range_covers_case (int c1
, int c2
);
1177 /** A single stdio filter to execute.
1178 * The filter may be external, such as "sed", or it
1179 * may be internal, as a function call.
1182 int (*filter_func
)(struct filter
*); /**< internal filter function */
1183 void * extra
; /**< extra data passed to filter_func */
1184 int argc
; /**< arg count */
1185 const char ** argv
; /**< arg vector, \0-terminated */
1186 struct filter
* next
; /**< next filter or NULL */
1189 /* output filter chain */
1190 extern struct filter
* output_chain
;
1191 extern struct filter
*filter_create_ext
PROTO((struct filter
* chain
, const char *cmd
, ...));
1192 struct filter
*filter_create_int
PROTO((struct filter
*chain
,
1193 int (*filter_func
) (struct filter
*),
1195 extern bool filter_apply_chain
PROTO((struct filter
* chain
));
1196 extern int filter_truncate (struct filter
* chain
, int max_len
);
1197 extern int filter_tee_header
PROTO((struct filter
*chain
));
1198 extern int filter_fix_linedirs
PROTO((struct filter
*chain
));
1205 extern regex_t regex_linedir
, regex_blank_line
;
1206 bool flex_init_regex(void);
1207 void flex_regcomp(regex_t
*preg
, const char *regex
, int cflags
);
1208 char *regmatch_dup (regmatch_t
* m
, const char *src
);
1209 char *regmatch_cpy (regmatch_t
* m
, char *dest
, const char *src
);
1210 int regmatch_len (regmatch_t
* m
);
1211 int regmatch_strtol (regmatch_t
* m
, const char *src
, char **endptr
, int base
);
1212 bool regmatch_empty (regmatch_t
* m
);
1214 /* From "scanflags.h" */
1215 typedef unsigned int scanflags_t
;
1216 extern scanflags_t
* _sf_stk
;
1217 extern size_t _sf_top_ix
, _sf_max
; /**< stack of scanner flags. */
1218 #define _SF_CASE_INS 0x0001
1219 #define _SF_DOT_ALL 0x0002
1220 #define _SF_SKIP_WS 0x0004
1221 #define sf_top() (_sf_stk[_sf_top_ix])
1222 #define sf_case_ins() (sf_top() & _SF_CASE_INS)
1223 #define sf_dot_all() (sf_top() & _SF_DOT_ALL)
1224 #define sf_skip_ws() (sf_top() & _SF_SKIP_WS)
1225 #define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS))
1226 #define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL))
1227 #define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS))
1228 extern void sf_init(void);
1229 extern void sf_push(void);
1230 extern void sf_pop(void);
1236 #endif /* not defined FLEXDEF_H */