tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / flex / dist / flexdef.h
blob752924fee79a1c7aea2176b44b8de11a766cd0f3
1 /* $NetBSD: flexdef.h,v 1.5 2013/04/09 15:19:45 christos Exp $ */
4 /* flexdef - definitions file for flex */
6 /* Copyright (c) 1990 The Regents of the University of California. */
7 /* All rights reserved. */
9 /* This code is derived from software contributed to Berkeley by */
10 /* Vern Paxson. */
12 /* The United States Government has rights in this work pursuant */
13 /* to contract no. DE-AC03-76SF00098 between the United States */
14 /* Department of Energy and the University of California. */
16 /* This file is part of flex. */
18 /* Redistribution and use in source and binary forms, with or without */
19 /* modification, are permitted provided that the following conditions */
20 /* are met: */
22 /* 1. Redistributions of source code must retain the above copyright */
23 /* notice, this list of conditions and the following disclaimer. */
24 /* 2. Redistributions in binary form must reproduce the above copyright */
25 /* notice, this list of conditions and the following disclaimer in the */
26 /* documentation and/or other materials provided with the distribution. */
28 /* Neither the name of the University nor the names of its contributors */
29 /* may be used to endorse or promote products derived from this software */
30 /* without specific prior written permission. */
32 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
33 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
34 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
35 /* PURPOSE. */
37 #ifndef FLEXDEF_H
38 #define FLEXDEF_H 1
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
44 /* AIX requires this to be the first thing in the file. */
45 #ifndef __GNUC__
46 # if HAVE_ALLOCA_H
47 # include <alloca.h>
48 # else
49 # ifdef _AIX
50 #pragma alloca
51 # else
52 # ifndef alloca /* predefined by HP cc +Olibcalls */
53 char *alloca ();
54 # endif
55 # endif
56 # endif
57 #endif
59 #ifdef STDC_HEADERS
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <stdarg.h>
63 #include <setjmp.h>
64 #include <ctype.h>
65 #include <string.h>
66 #include <math.h>
67 #endif
68 #ifdef HAVE_ASSERT_H
69 #include <assert.h>
70 #else
71 #define assert(Pred)
72 #endif
74 #ifdef HAVE_LIMITS_H
75 #include <limits.h>
76 #endif
77 #ifdef HAVE_UNISTD_H
78 #include <unistd.h>
79 #endif
80 #ifdef HAVE_NETINET_IN_H
81 #include <netinet/in.h>
82 #endif
83 #ifdef HAVE_SYS_PARAMS_H
84 #include <sys/params.h>
85 #endif
86 #ifdef HAVE_SYS_WAIT_H
87 #include <sys/wait.h>
88 #endif
89 #ifdef HAVE_STDBOOL_H
90 #include <stdbool.h>
91 #else
92 #define bool int
93 #define true 1
94 #define false 0
95 #endif
96 #ifdef HAVE_REGEX_H
97 #include <regex.h>
98 #endif
99 #include "flexint.h"
101 /* We use gettext. So, when we write strings which should be translated, we mark them with _() */
102 #ifdef ENABLE_NLS
103 #ifdef HAVE_LOCALE_H
104 #include <locale.h>
105 #endif /* HAVE_LOCALE_H */
106 #include "gettext.h"
107 #define _(String) gettext (String)
108 #else
109 #define _(STRING) STRING
110 #endif /* ENABLE_NLS */
112 /* Always be prepared to generate an 8-bit scanner. */
113 #define CSIZE 256
114 #define Char unsigned char
116 /* Size of input alphabet - should be size of ASCII set. */
117 #ifndef DEFAULT_CSIZE
118 #define DEFAULT_CSIZE 128
119 #endif
121 #ifndef PROTO
122 #if defined(__STDC__)
123 #define PROTO(proto) proto
124 #else
125 #define PROTO(proto) ()
126 #endif
127 #endif
129 #ifdef VMS
130 #ifndef __VMS_POSIX
131 #define unlink remove
132 #define SHORT_FILE_NAMES
133 #endif
134 #endif
136 #ifdef MS_DOS
137 #define SHORT_FILE_NAMES
138 #endif
141 /* Maximum line length we'll have to deal with. */
142 #define MAXLINE 2048
144 #ifndef MIN
145 #define MIN(x,y) ((x) < (y) ? (x) : (y))
146 #endif
147 #ifndef MAX
148 #define MAX(x,y) ((x) > (y) ? (x) : (y))
149 #endif
150 #ifndef ABS
151 #define ABS(x) ((x) < 0 ? -(x) : (x))
152 #endif
155 /* ANSI C does not guarantee that isascii() is defined */
156 #ifndef isascii
157 #define isascii(c) ((c) <= 0177)
158 #endif
160 #define unspecified -1
162 /* Special chk[] values marking the slots taking by end-of-buffer and action
163 * numbers.
165 #define EOB_POSITION -1
166 #define ACTION_POSITION -2
168 /* Number of data items per line for -f output. */
169 #define NUMDATAITEMS 10
171 /* Number of lines of data in -f output before inserting a blank line for
172 * readability.
174 #define NUMDATALINES 10
176 /* transition_struct_out() definitions. */
177 #define TRANS_STRUCT_PRINT_LENGTH 14
179 /* Returns true if an nfa state has an epsilon out-transition slot
180 * that can be used. This definition is currently not used.
182 #define FREE_EPSILON(state) \
183 (transchar[state] == SYM_EPSILON && \
184 trans2[state] == NO_TRANSITION && \
185 finalst[state] != state)
187 /* Returns true if an nfa state has an epsilon out-transition character
188 * and both slots are free
190 #define SUPER_FREE_EPSILON(state) \
191 (transchar[state] == SYM_EPSILON && \
192 trans1[state] == NO_TRANSITION) \
194 /* Maximum number of NFA states that can comprise a DFA state. It's real
195 * big because if there's a lot of rules, the initial state will have a
196 * huge epsilon closure.
198 #define INITIAL_MAX_DFA_SIZE 750
199 #define MAX_DFA_SIZE_INCREMENT 750
202 /* A note on the following masks. They are used to mark accepting numbers
203 * as being special. As such, they implicitly limit the number of accepting
204 * numbers (i.e., rules) because if there are too many rules the rule numbers
205 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
206 * 8192) so unlikely to actually cause any problems. A check is made in
207 * new_rule() to ensure that this limit is not reached.
210 /* Mask to mark a trailing context accepting number. */
211 #define YY_TRAILING_MASK 0x2000
213 /* Mask to mark the accepting number of the "head" of a trailing context
214 * rule.
216 #define YY_TRAILING_HEAD_MASK 0x4000
218 /* Maximum number of rules, as outlined in the above note. */
219 #define MAX_RULE (YY_TRAILING_MASK - 1)
222 /* NIL must be 0. If not, its special meaning when making equivalence classes
223 * (it marks the representative of a given e.c.) will be unidentifiable.
225 #define NIL 0
227 #define JAM -1 /* to mark a missing DFA transition */
228 #define NO_TRANSITION NIL
229 #define UNIQUE -1 /* marks a symbol as an e.c. representative */
230 #define INFINITE_REPEAT -1 /* for x{5,} constructions */
232 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
233 #define MAX_CCLS_INCREMENT 100
235 /* Size of table holding members of character classes. */
236 #define INITIAL_MAX_CCL_TBL_SIZE 500
237 #define MAX_CCL_TBL_SIZE_INCREMENT 250
239 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
240 #define MAX_RULES_INCREMENT 100
242 #define INITIAL_MNS 2000 /* default maximum number of nfa states */
243 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
245 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
246 #define MAX_DFAS_INCREMENT 1000
248 #define JAMSTATE -32766 /* marks a reference to the state that always jams */
250 /* Maximum number of NFA states. */
251 #define MAXIMUM_MNS 31999
252 #define MAXIMUM_MNS_LONG 1999999999
254 /* Enough so that if it's subtracted from an NFA state number, the result
255 * is guaranteed to be negative.
257 #define MARKER_DIFFERENCE (maximum_mns+2)
259 /* Maximum number of nxt/chk pairs for non-templates. */
260 #define INITIAL_MAX_XPAIRS 2000
261 #define MAX_XPAIRS_INCREMENT 2000
263 /* Maximum number of nxt/chk pairs needed for templates. */
264 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
265 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
267 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
269 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
270 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
272 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
273 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
275 /* The following percentages are used to tune table compression:
277 * The percentage the number of out-transitions a state must be of the
278 * number of equivalence classes in order to be considered for table
279 * compaction by using protos.
281 #define PROTO_SIZE_PERCENTAGE 15
283 /* The percentage the number of homogeneous out-transitions of a state
284 * must be of the number of total out-transitions of the state in order
285 * that the state's transition table is first compared with a potential
286 * template of the most common out-transition instead of with the first
287 * proto in the proto queue.
289 #define CHECK_COM_PERCENTAGE 50
291 /* The percentage the number of differences between a state's transition
292 * table and the proto it was first compared with must be of the total
293 * number of out-transitions of the state in order to keep the first
294 * proto as a good match and not search any further.
296 #define FIRST_MATCH_DIFF_PERCENTAGE 10
298 /* The percentage the number of differences between a state's transition
299 * table and the most similar proto must be of the state's total number
300 * of out-transitions to use the proto as an acceptable close match.
302 #define ACCEPTABLE_DIFF_PERCENTAGE 50
304 /* The percentage the number of homogeneous out-transitions of a state
305 * must be of the number of total out-transitions of the state in order
306 * to consider making a template from the state.
308 #define TEMPLATE_SAME_PERCENTAGE 60
310 /* The percentage the number of differences between a state's transition
311 * table and the most similar proto must be of the state's total number
312 * of out-transitions to create a new proto from the state.
314 #define NEW_PROTO_DIFF_PERCENTAGE 20
316 /* The percentage the total number of out-transitions of a state must be
317 * of the number of equivalence classes in order to consider trying to
318 * fit the transition table into "holes" inside the nxt/chk table.
320 #define INTERIOR_FIT_PERCENTAGE 15
322 /* Size of region set aside to cache the complete transition table of
323 * protos on the proto queue to enable quick comparisons.
325 #define PROT_SAVE_SIZE 2000
327 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
329 /* Maximum number of out-transitions a state can have that we'll rummage
330 * around through the interior of the internal fast table looking for a
331 * spot for it.
333 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
335 /* Maximum number of rules which will be reported as being associated
336 * with a DFA state.
338 #define MAX_ASSOC_RULES 100
340 /* Number that, if used to subscript an array, has a good chance of producing
341 * an error; should be small enough to fit into a short.
343 #define BAD_SUBSCRIPT -32767
345 /* Absolute value of largest number that can be stored in a short, with a
346 * bit of slop thrown in for general paranoia.
348 #define MAX_SHORT 32700
351 /* Declarations for global variables. */
354 /* Variables for flags:
355 * printstats - if true (-v), dump statistics
356 * syntaxerror - true if a syntax error has been found
357 * eofseen - true if we've seen an eof in the input file
358 * ddebug - if true (-d), make a "debug" scanner
359 * trace - if true (-T), trace processing
360 * nowarn - if true (-w), do not generate warnings
361 * spprdflt - if true (-s), suppress the default rule
362 * interactive - if true (-I), generate an interactive scanner
363 * lex_compat - if true (-l), maximize compatibility with AT&T lex
364 * posix_compat - if true (-X), maximize compatibility with POSIX lex
365 * do_yylineno - if true, generate code to maintain yylineno
366 * useecs - if true (-Ce flag), use equivalence classes
367 * fulltbl - if true (-Cf flag), don't compress the DFA state table
368 * usemecs - if true (-Cm flag), use meta-equivalence classes
369 * fullspd - if true (-F flag), use Jacobson method of table representation
370 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
371 * performance_report - if > 0 (i.e., -p flag), generate a report relating
372 * to scanner performance; if > 1 (-p -p), report on minor performance
373 * problems, too
374 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
375 * listing backing-up states
376 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
377 * otherwise, a standard C scanner
378 * reentrant - if true (-R), generate a reentrant C scanner.
379 * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention.
380 * bison_bridge_lloc - if true (--bison-locations), bison yylloc.
381 * long_align - if true (-Ca flag), favor long-word alignment.
382 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
383 * otherwise, use fread().
384 * yytext_is_array - if true (i.e., %array directive), then declare
385 * yytext as a array instead of a character pointer. Nice and inefficient.
386 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
387 * "no more files".
388 * csize - size of character set for the scanner we're generating;
389 * 128 for 7-bit chars and 256 for 8-bit
390 * yymore_used - if true, yymore() is used in input rules
391 * reject - if true, generate back-up tables for REJECT macro
392 * real_reject - if true, scanner really uses REJECT (as opposed to just
393 * having "reject" set for variable trailing context)
394 * continued_action - true if this rule's action is to "fall through" to
395 * the next rule's action (i.e., the '|' action)
396 * in_rule - true if we're inside an individual rule, false if not.
397 * yymore_really_used - whether to treat yymore() as really used, regardless
398 * of what we think based on references to it in the user's actions.
399 * reject_really_used - same for REJECT
402 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn,
403 spprdflt;
404 extern int interactive, lex_compat, posix_compat, do_yylineno;
405 extern int useecs, fulltbl, usemecs, fullspd;
406 extern int gen_line_dirs, performance_report, backing_up_report;
407 extern int reentrant, bison_bridge_lval, bison_bridge_lloc;
408 extern bool ansi_func_defs, ansi_func_protos;
409 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
410 extern int csize;
411 extern int yymore_used, reject, real_reject, continued_action, in_rule;
413 extern int yymore_really_used, reject_really_used;
416 /* Variables used in the flex input routines:
417 * datapos - characters on current output line
418 * dataline - number of contiguous lines of data in current data
419 * statement. Used to generate readable -f output
420 * linenum - current input line number
421 * skelfile - the skeleton file
422 * skel - compiled-in skeleton array
423 * skel_ind - index into "skel" array, if skelfile is nil
424 * yyin - input file
425 * backing_up_file - file to summarize backing-up states to
426 * infilename - name of input file
427 * outfilename - name of output file
428 * headerfilename - name of the .h file to generate
429 * did_outfilename - whether outfilename was explicitly set
430 * prefix - the prefix used for externally visible names ("yy" by default)
431 * yyclass - yyFlexLexer subclass to use for YY_DECL
432 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
433 * use_stdout - the -t flag
434 * input_files - array holding names of input files
435 * num_input_files - size of input_files array
436 * program_name - name with which program was invoked
438 * action_array - array to hold the rule actions
439 * action_size - size of action_array
440 * defs1_offset - index where the user's section 1 definitions start
441 * in action_array
442 * prolog_offset - index where the prolog starts in action_array
443 * action_offset - index where the non-prolog starts in action_array
444 * action_index - index where the next action should go, with respect
445 * to "action_array"
448 extern int datapos, dataline, linenum;
449 extern FILE *skelfile, *yyin, *backing_up_file;
450 extern const char *skel[];
451 extern int skel_ind;
452 extern char *infilename, *outfilename, *headerfilename;
453 extern int did_outfilename;
454 extern char *prefix, *yyclass, *extra_type;
455 extern int do_stdinit, use_stdout;
456 extern char **input_files;
457 extern int num_input_files;
458 extern char *program_name;
460 extern char *action_array;
461 extern int action_size;
462 extern int defs1_offset, prolog_offset, action_offset, action_index;
465 /* Variables for stack of states having only one out-transition:
466 * onestate - state number
467 * onesym - transition symbol
468 * onenext - target state
469 * onedef - default base entry
470 * onesp - stack pointer
473 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
474 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
477 /* Variables for nfa machine data:
478 * maximum_mns - maximal number of NFA states supported by tables
479 * current_mns - current maximum on number of NFA states
480 * num_rules - number of the last accepting state; also is number of
481 * rules created so far
482 * num_eof_rules - number of <<EOF>> rules
483 * default_rule - number of the default rule
484 * current_max_rules - current maximum number of rules
485 * lastnfa - last nfa state number created
486 * firstst - physically the first state of a fragment
487 * lastst - last physical state of fragment
488 * finalst - last logical state of fragment
489 * transchar - transition character
490 * trans1 - transition state
491 * trans2 - 2nd transition state for epsilons
492 * accptnum - accepting number
493 * assoc_rule - rule associated with this NFA state (or 0 if none)
494 * state_type - a STATE_xxx type identifying whether the state is part
495 * of a normal rule, the leading state in a trailing context
496 * rule (i.e., the state which marks the transition from
497 * recognizing the text-to-be-matched to the beginning of
498 * the trailing context), or a subsequent state in a trailing
499 * context rule
500 * rule_type - a RULE_xxx type identifying whether this a ho-hum
501 * normal rule or one which has variable head & trailing
502 * context
503 * rule_linenum - line number associated with rule
504 * rule_useful - true if we've determined that the rule can be matched
505 * rule_has_nl - true if rule could possibly match a newline
506 * ccl_has_nl - true if current ccl could match a newline
507 * nlch - default eol char
510 extern int maximum_mns, current_mns, current_max_rules;
511 extern int num_rules, num_eof_rules, default_rule, lastnfa;
512 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
513 extern int *accptnum, *assoc_rule, *state_type;
514 extern int *rule_type, *rule_linenum, *rule_useful;
515 extern bool *rule_has_nl, *ccl_has_nl;
516 extern int nlch;
518 /* Different types of states; values are useful as masks, as well, for
519 * routines like check_trailing_context().
521 #define STATE_NORMAL 0x1
522 #define STATE_TRAILING_CONTEXT 0x2
524 /* Global holding current type of state we're making. */
526 extern int current_state_type;
528 /* Different types of rules. */
529 #define RULE_NORMAL 0
530 #define RULE_VARIABLE 1
532 /* True if the input rules include a rule with both variable-length head
533 * and trailing context, false otherwise.
535 extern int variable_trailing_context_rules;
538 /* Variables for protos:
539 * numtemps - number of templates created
540 * numprots - number of protos created
541 * protprev - backlink to a more-recently used proto
542 * protnext - forward link to a less-recently used proto
543 * prottbl - base/def table entry for proto
544 * protcomst - common state of proto
545 * firstprot - number of the most recently used proto
546 * lastprot - number of the least recently used proto
547 * protsave contains the entire state array for protos
550 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
551 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
554 /* Variables for managing equivalence classes:
555 * numecs - number of equivalence classes
556 * nextecm - forward link of Equivalence Class members
557 * ecgroup - class number or backward link of EC members
558 * nummecs - number of meta-equivalence classes (used to compress
559 * templates)
560 * tecfwd - forward link of meta-equivalence classes members
561 * tecbck - backward link of MEC's
564 /* Reserve enough room in the equivalence class arrays so that we
565 * can use the CSIZE'th element to hold equivalence class information
566 * for the NUL character. Later we'll move this information into
567 * the 0th element.
569 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
571 /* Meta-equivalence classes are indexed starting at 1, so it's possible
572 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
573 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
574 * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
576 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
579 /* Variables for start conditions:
580 * lastsc - last start condition created
581 * current_max_scs - current limit on number of start conditions
582 * scset - set of rules active in start condition
583 * scbol - set of rules active only at the beginning of line in a s.c.
584 * scxclu - true if start condition is exclusive
585 * sceof - true if start condition has EOF rule
586 * scname - start condition name
589 extern int lastsc, *scset, *scbol, *scxclu, *sceof;
590 extern int current_max_scs;
591 extern char **scname;
594 /* Variables for dfa machine data:
595 * current_max_dfa_size - current maximum number of NFA states in DFA
596 * current_max_xpairs - current maximum number of non-template xtion pairs
597 * current_max_template_xpairs - current maximum number of template pairs
598 * current_max_dfas - current maximum number DFA states
599 * lastdfa - last dfa state number created
600 * nxt - state to enter upon reading character
601 * chk - check value to see if "nxt" applies
602 * tnxt - internal nxt table for templates
603 * base - offset into "nxt" for given state
604 * def - where to go if "chk" disallows "nxt" entry
605 * nultrans - NUL transition for each state
606 * NUL_ec - equivalence class of the NUL character
607 * tblend - last "nxt/chk" table entry being used
608 * firstfree - first empty entry in "nxt/chk" table
609 * dss - nfa state set for each dfa
610 * dfasiz - size of nfa state set for each dfa
611 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
612 * number, if not
613 * accsiz - size of accepting set for each dfa state
614 * dhash - dfa state hash value
615 * numas - number of DFA accepting states created; note that this
616 * is not necessarily the same value as num_rules, which is the analogous
617 * value for the NFA
618 * numsnpairs - number of state/nextstate transition pairs
619 * jambase - position in base/def where the default jam table starts
620 * jamstate - state number corresponding to "jam" state
621 * end_of_buffer_state - end-of-buffer dfa state number
624 extern int current_max_dfa_size, current_max_xpairs;
625 extern int current_max_template_xpairs, current_max_dfas;
626 extern int lastdfa, *nxt, *chk, *tnxt;
627 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss,
628 *dfasiz;
629 extern union dfaacc_union {
630 int *dfaacc_set;
631 int dfaacc_state;
632 } *dfaacc;
633 extern int *accsiz, *dhash, numas;
634 extern int numsnpairs, jambase, jamstate;
635 extern int end_of_buffer_state;
637 /* Variables for ccl information:
638 * lastccl - ccl index of the last created ccl
639 * current_maxccls - current limit on the maximum number of unique ccl's
640 * cclmap - maps a ccl index to its set pointer
641 * ccllen - gives the length of a ccl
642 * cclng - true for a given ccl if the ccl is negated
643 * cclreuse - counts how many times a ccl is re-used
644 * current_max_ccl_tbl_size - current limit on number of characters needed
645 * to represent the unique ccl's
646 * ccltbl - holds the characters in each ccl - indexed by cclmap
649 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
650 extern int current_maxccls, current_max_ccl_tbl_size;
651 extern Char *ccltbl;
654 /* Variables for miscellaneous information:
655 * nmstr - last NAME scanned by the scanner
656 * sectnum - section number currently being parsed
657 * nummt - number of empty nxt/chk table entries
658 * hshcol - number of hash collisions detected by snstods
659 * dfaeql - number of times a newly created dfa was equal to an old one
660 * numeps - number of epsilon NFA states created
661 * eps2 - number of epsilon states which have 2 out-transitions
662 * num_reallocs - number of times it was necessary to realloc() a group
663 * of arrays
664 * tmpuses - number of DFA states that chain to templates
665 * totnst - total number of NFA states used to make DFA states
666 * peakpairs - peak number of transition pairs we had to store internally
667 * numuniq - number of unique transitions
668 * numdup - number of duplicate transitions
669 * hshsave - number of hash collisions saved by checking number of states
670 * num_backing_up - number of DFA states requiring backing up
671 * bol_needed - whether scanner needs beginning-of-line recognition
674 extern char nmstr[MAXLINE];
675 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
676 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
677 extern int num_backing_up, bol_needed;
679 void *allocate_array PROTO ((int, size_t));
680 void *reallocate_array PROTO ((void *, int, size_t));
682 void *flex_alloc PROTO ((size_t));
683 void *flex_realloc PROTO ((void *, size_t));
684 void flex_free PROTO ((void *));
686 #define allocate_integer_array(size) \
687 (int *) allocate_array( size, sizeof( int ) )
689 #define reallocate_integer_array(array,size) \
690 (int *) reallocate_array( (void *) array, size, sizeof( int ) )
692 #define allocate_bool_array(size) \
693 (bool *) allocate_array( size, sizeof( bool ) )
695 #define reallocate_bool_array(array,size) \
696 (bool *) reallocate_array( (void *) array, size, sizeof( bool ) )
698 #define allocate_int_ptr_array(size) \
699 (int **) allocate_array( size, sizeof( int * ) )
701 #define allocate_char_ptr_array(size) \
702 (char **) allocate_array( size, sizeof( char * ) )
704 #define allocate_dfaacc_union(size) \
705 (union dfaacc_union *) \
706 allocate_array( size, sizeof( union dfaacc_union ) )
708 #define reallocate_int_ptr_array(array,size) \
709 (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
711 #define reallocate_char_ptr_array(array,size) \
712 (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
714 #define reallocate_dfaacc_union(array, size) \
715 (union dfaacc_union *) \
716 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
718 #define allocate_character_array(size) \
719 (char *) allocate_array( size, sizeof( char ) )
721 #define reallocate_character_array(array,size) \
722 (char *) reallocate_array( (void *) array, size, sizeof( char ) )
724 #define allocate_Character_array(size) \
725 (Char *) allocate_array( size, sizeof( Char ) )
727 #define reallocate_Character_array(array,size) \
728 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
731 /* Used to communicate between scanner and parser. The type should really
732 * be YYSTYPE, but we can't easily get our hands on it.
734 extern int yylval;
737 /* External functions that are cross-referenced among the flex source files. */
740 /* from file ccl.c */
742 extern void ccladd PROTO ((int, int)); /* add a single character to a ccl */
743 extern int cclinit PROTO ((void)); /* make an empty ccl */
744 extern void cclnegate PROTO ((int)); /* negate a ccl */
745 extern int ccl_set_diff (int a, int b); /* set difference of two ccls. */
746 extern int ccl_set_union (int a, int b); /* set union of two ccls. */
748 /* List the members of a set of characters in CCL form. */
749 extern void list_character_set PROTO ((FILE *, int[]));
752 /* from file dfa.c */
754 /* Check a DFA state for backing up. */
755 extern void check_for_backing_up PROTO ((int, int[]));
757 /* Check to see if NFA state set constitutes "dangerous" trailing context. */
758 extern void check_trailing_context PROTO ((int *, int, int *, int));
760 /* Construct the epsilon closure of a set of ndfa states. */
761 extern int *epsclosure PROTO ((int *, int *, int[], int *, int *));
763 /* Increase the maximum number of dfas. */
764 extern void increase_max_dfas PROTO ((void));
766 extern void ntod PROTO ((void)); /* convert a ndfa to a dfa */
768 /* Converts a set of ndfa states into a dfa state. */
769 extern int snstods PROTO ((int[], int, int[], int, int, int *));
772 /* from file ecs.c */
774 /* Convert character classes to set of equivalence classes. */
775 extern void ccl2ecl PROTO ((void));
777 /* Associate equivalence class numbers with class members. */
778 extern int cre8ecs PROTO ((int[], int[], int));
780 /* Update equivalence classes based on character class transitions. */
781 extern void mkeccl PROTO ((Char[], int, int[], int[], int, int));
783 /* Create equivalence class for single character. */
784 extern void mkechar PROTO ((int, int[], int[]));
787 /* from file gen.c */
789 extern void do_indent PROTO ((void)); /* indent to the current level */
791 /* Generate the code to keep backing-up information. */
792 extern void gen_backing_up PROTO ((void));
794 /* Generate the code to perform the backing up. */
795 extern void gen_bu_action PROTO ((void));
797 /* Generate full speed compressed transition table. */
798 extern void genctbl PROTO ((void));
800 /* Generate the code to find the action number. */
801 extern void gen_find_action PROTO ((void));
803 extern void genftbl PROTO ((void)); /* generate full transition table */
805 /* Generate the code to find the next compressed-table state. */
806 extern void gen_next_compressed_state PROTO ((char *));
808 /* Generate the code to find the next match. */
809 extern void gen_next_match PROTO ((void));
811 /* Generate the code to find the next state. */
812 extern void gen_next_state PROTO ((int));
814 /* Generate the code to make a NUL transition. */
815 extern void gen_NUL_trans PROTO ((void));
817 /* Generate the code to find the start state. */
818 extern void gen_start_state PROTO ((void));
820 /* Generate data statements for the transition tables. */
821 extern void gentabs PROTO ((void));
823 /* Write out a formatted string at the current indentation level. */
824 extern void indent_put2s PROTO ((const char *, const char *));
826 /* Write out a string + newline at the current indentation level. */
827 extern void indent_puts PROTO ((const char *));
829 extern void make_tables PROTO ((void)); /* generate transition tables */
832 /* from file main.c */
834 extern void check_options PROTO ((void));
835 extern void flexend PROTO ((int));
836 extern void usage PROTO ((void));
839 /* from file misc.c */
841 /* Add a #define to the action file. */
842 extern void action_define PROTO ((const char *defname, int value));
844 /* Add the given text to the stored actions. */
845 extern void add_action PROTO ((const char *new_text));
847 /* True if a string is all lower case. */
848 extern int all_lower PROTO ((register char *));
850 /* True if a string is all upper case. */
851 extern int all_upper PROTO ((register char *));
853 /* Compare two integers for use by qsort. */
854 extern int intcmp PROTO ((const void *, const void *));
856 /* Check a character to make sure it's in the expected range. */
857 extern void check_char PROTO ((int c));
859 /* Replace upper-case letter to lower-case. */
860 extern Char clower PROTO ((int));
862 /* Returns a dynamically allocated copy of a string. */
863 extern char *copy_string PROTO ((register const char *));
865 /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
866 extern Char *copy_unsigned_string PROTO ((register Char *));
868 /* Compare two characters for use by qsort with '\0' sorting last. */
869 extern int cclcmp PROTO ((const void *, const void *));
871 /* Finish up a block of data declarations. */
872 extern void dataend PROTO ((void));
874 /* Flush generated data statements. */
875 extern void dataflush PROTO ((void));
877 /* Report an error message and terminate. */
878 extern void flexerror PROTO ((const char *));
880 /* Report a fatal error message and terminate. */
881 extern void flexfatal PROTO ((const char *));
883 /* Report a fatal error with a pinpoint, and terminate */
884 #if HAVE_DECL___FUNC__
885 #define flex_die(msg) \
886 do{ \
887 fprintf (stderr,\
888 _("%s: fatal internal error at %s:%d (%s): %s\n"),\
889 program_name, __FILE__, (int)__LINE__,\
890 __func__,msg);\
891 FLEX_EXIT(1);\
892 }while(0)
893 #else /* ! HAVE_DECL___FUNC__ */
894 #define flex_die(msg) \
895 do{ \
896 fprintf (stderr,\
897 _("%s: fatal internal error at %s:%d %s\n"),\
898 program_name, __FILE__, (int)__LINE__,\
899 msg);\
900 FLEX_EXIT(1);\
901 }while(0)
902 #endif /* ! HAVE_DECL___func__ */
904 /* Convert a hexadecimal digit string to an integer value. */
905 extern int htoi PROTO ((Char[]));
907 /* Report an error message formatted with one integer argument. */
908 extern void lerrif PROTO ((const char *, int));
910 /* Report an error message formatted with one string argument. */
911 extern void lerrsf PROTO ((const char *, const char *));
913 /* Spit out a "#line" statement. */
914 extern void line_directive_out PROTO ((FILE *, int));
916 /* Mark the current position in the action array as the end of the section 1
917 * user defs.
919 extern void mark_defs1 PROTO ((void));
921 /* Mark the current position in the action array as the end of the prolog. */
922 extern void mark_prolog PROTO ((void));
924 /* Generate a data statment for a two-dimensional array. */
925 extern void mk2data PROTO ((int));
927 extern void mkdata PROTO ((int)); /* generate a data statement */
929 /* Return the integer represented by a string of digits. */
930 extern int myctoi PROTO ((const char *));
932 /* Return character corresponding to escape sequence. */
933 extern Char myesc PROTO ((Char[]));
935 /* Convert an octal digit string to an integer value. */
936 extern int otoi PROTO ((Char[]));
938 /* Output a (possibly-formatted) string to the generated scanner. */
939 extern void out PROTO ((const char *));
940 extern void out_dec PROTO ((const char *, int));
941 extern void out_dec2 PROTO ((const char *, int, int));
942 extern void out_hex PROTO ((const char *, unsigned int));
943 extern void out_str PROTO ((const char *, const char *));
944 extern void out_str3
945 PROTO ((const char *, const char *, const char *, const char *));
946 extern void out_str_dec PROTO ((const char *, const char *, int));
947 extern void outc PROTO ((int));
948 extern void outn PROTO ((const char *));
949 extern void out_m4_define (const char* def, const char* val);
951 /* Return a printable version of the given character, which might be
952 * 8-bit.
954 extern char *readable_form PROTO ((int));
956 /* Write out one section of the skeleton file. */
957 extern void skelout PROTO ((void));
959 /* Output a yy_trans_info structure. */
960 extern void transition_struct_out PROTO ((int, int));
962 /* Only needed when using certain broken versions of bison to build parse.c. */
963 extern void *yy_flex_xmalloc PROTO ((int));
965 /* Set a region of memory to 0. */
966 extern void zero_out PROTO ((char *, size_t));
969 /* from file nfa.c */
971 /* Add an accepting state to a machine. */
972 extern void add_accept PROTO ((int, int));
974 /* Make a given number of copies of a singleton machine. */
975 extern int copysingl PROTO ((int, int));
977 /* Debugging routine to write out an nfa. */
978 extern void dumpnfa PROTO ((int));
980 /* Finish up the processing for a rule. */
981 extern void finish_rule PROTO ((int, int, int, int, int));
983 /* Connect two machines together. */
984 extern int link_machines PROTO ((int, int));
986 /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
987 * not trailing context associated) state.
989 extern void mark_beginning_as_normal PROTO ((register int));
991 /* Make a machine that branches to two machines. */
992 extern int mkbranch PROTO ((int, int));
994 extern int mkclos PROTO ((int)); /* convert a machine into a closure */
995 extern int mkopt PROTO ((int)); /* make a machine optional */
997 /* Make a machine that matches either one of two machines. */
998 extern int mkor PROTO ((int, int));
1000 /* Convert a machine into a positive closure. */
1001 extern int mkposcl PROTO ((int));
1003 extern int mkrep PROTO ((int, int, int)); /* make a replicated machine */
1005 /* Create a state with a transition on a given symbol. */
1006 extern int mkstate PROTO ((int));
1008 extern void new_rule PROTO ((void)); /* initialize for a new rule */
1011 /* from file parse.y */
1013 /* Build the "<<EOF>>" action for the active start conditions. */
1014 extern void build_eof_action PROTO ((void));
1016 /* Write out a message formatted with one string, pinpointing its location. */
1017 extern void format_pinpoint_message PROTO ((const char *, const char *));
1019 /* Write out a message, pinpointing its location. */
1020 extern void pinpoint_message PROTO ((const char *));
1022 /* Write out a warning, pinpointing it at the given line. */
1023 extern void line_warning PROTO ((const char *, int));
1025 /* Write out a message, pinpointing it at the given line. */
1026 extern void line_pinpoint PROTO ((const char *, int));
1028 /* Report a formatted syntax error. */
1029 extern void format_synerr PROTO ((const char *, const char *));
1030 extern void synerr PROTO ((const char *)); /* report a syntax error */
1031 extern void format_warn PROTO ((const char *, const char *));
1032 extern void lwarn PROTO ((const char *)); /* report a warning */
1033 extern void yyerror PROTO ((const char *)); /* report a parse error */
1034 extern int yyparse PROTO ((void)); /* the YACC parser */
1037 /* from file scan.l */
1039 /* The Flex-generated scanner for flex. */
1040 extern int flexscan PROTO ((void));
1042 /* Open the given file (if NULL, stdin) for scanning. */
1043 extern void set_input_file PROTO ((char *));
1045 /* Wrapup a file in the lexical analyzer. */
1046 extern int yywrap PROTO ((void));
1049 /* from file sym.c */
1051 /* Save the text of a character class. */
1052 extern void cclinstal PROTO ((Char[], int));
1054 /* Lookup the number associated with character class. */
1055 extern int ccllookup PROTO ((Char[]));
1057 extern void ndinstal PROTO ((const char *, Char[])); /* install a name definition */
1058 extern Char *ndlookup PROTO ((const char *)); /* lookup a name definition */
1060 /* Increase maximum number of SC's. */
1061 extern void scextend PROTO ((void));
1062 extern void scinstal PROTO ((const char *, int)); /* make a start condition */
1064 /* Lookup the number associated with a start condition. */
1065 extern int sclookup PROTO ((const char *));
1068 /* from file tblcmp.c */
1070 /* Build table entries for dfa state. */
1071 extern void bldtbl PROTO ((int[], int, int, int, int));
1073 extern void cmptmps PROTO ((void)); /* compress template table entries */
1074 extern void expand_nxt_chk PROTO ((void)); /* increase nxt/chk arrays */
1076 /* Finds a space in the table for a state to be placed. */
1077 extern int find_table_space PROTO ((int *, int));
1078 extern void inittbl PROTO ((void)); /* initialize transition tables */
1080 /* Make the default, "jam" table entries. */
1081 extern void mkdeftbl PROTO ((void));
1083 /* Create table entries for a state (or state fragment) which has
1084 * only one out-transition.
1086 extern void mk1tbl PROTO ((int, int, int, int));
1088 /* Place a state into full speed transition table. */
1089 extern void place_state PROTO ((int *, int, int));
1091 /* Save states with only one out-transition to be processed later. */
1092 extern void stack1 PROTO ((int, int, int, int));
1095 /* from file yylex.c */
1097 extern int yylex PROTO ((void));
1099 /* A growable array. See buf.c. */
1100 struct Buf {
1101 void *elts; /* elements. */
1102 int nelts; /* number of elements. */
1103 size_t elt_size; /* in bytes. */
1104 int nmax; /* max capacity of elements. */
1107 extern void buf_init PROTO ((struct Buf * buf, size_t elem_size));
1108 extern void buf_destroy PROTO ((struct Buf * buf));
1109 extern struct Buf *buf_append
1110 PROTO ((struct Buf * buf, const void *ptr, int n_elem));
1111 extern struct Buf *buf_concat PROTO((struct Buf* dest, const struct Buf* src));
1112 extern struct Buf *buf_strappend PROTO ((struct Buf *, const char *str));
1113 extern struct Buf *buf_strnappend
1114 PROTO ((struct Buf *, const char *str, int nchars));
1115 extern struct Buf *buf_strdefine
1116 PROTO ((struct Buf * buf, const char *str, const char *def));
1117 extern struct Buf *buf_prints PROTO((struct Buf *buf, const char *fmt, const char* s));
1118 extern struct Buf *buf_m4_define PROTO((struct Buf *buf, const char* def, const char* val));
1119 extern struct Buf *buf_m4_undefine PROTO((struct Buf *buf, const char* def));
1120 extern struct Buf *buf_print_strings PROTO((struct Buf * buf, FILE* out));
1121 extern struct Buf *buf_linedir PROTO((struct Buf *buf, const char* filename, int lineno));
1123 extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */
1124 extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */
1125 extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */
1126 extern struct Buf m4defs_buf; /* Holds m4 definitions. */
1127 extern struct Buf top_buf; /* contains %top code. String buffer. */
1129 /* For blocking out code from the header file. */
1130 #define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[")
1131 #define OUT_END_CODE() outn("]])")
1133 /* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */
1134 extern jmp_buf flex_main_jmp_buf;
1136 #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1)
1138 /* Removes all \n and \r chars from tail of str. returns str. */
1139 extern char *chomp (char *str);
1141 /* ctype functions forced to return boolean */
1142 #define b_isalnum(c) (isalnum(c)?true:false)
1143 #define b_isalpha(c) (isalpha(c)?true:false)
1144 #define b_isascii(c) (isascii(c)?true:false)
1145 #define b_isblank(c) (isblank(c)?true:false)
1146 #define b_iscntrl(c) (iscntrl(c)?true:false)
1147 #define b_isdigit(c) (isdigit(c)?true:false)
1148 #define b_isgraph(c) (isgraph(c)?true:false)
1149 #define b_islower(c) (islower(c)?true:false)
1150 #define b_isprint(c) (isprint(c)?true:false)
1151 #define b_ispunct(c) (ispunct(c)?true:false)
1152 #define b_isspace(c) (isspace(c)?true:false)
1153 #define b_isupper(c) (isupper(c)?true:false)
1154 #define b_isxdigit(c) (isxdigit(c)?true:false)
1156 /* return true if char is uppercase or lowercase. */
1157 bool has_case(int c);
1159 /* Change case of character if possible. */
1160 int reverse_case(int c);
1162 /* return false if [c1-c2] is ambiguous for a caseless scanner. */
1163 bool range_covers_case (int c1, int c2);
1166 * From "filter.c"
1169 /** A single stdio filter to execute.
1170 * The filter may be external, such as "sed", or it
1171 * may be internal, as a function call.
1173 struct filter {
1174 int (*filter_func)(struct filter*); /**< internal filter function */
1175 void * extra; /**< extra data passed to filter_func */
1176 int argc; /**< arg count */
1177 const char ** argv; /**< arg vector, \0-terminated */
1178 struct filter * next; /**< next filter or NULL */
1181 /* output filter chain */
1182 extern struct filter * output_chain;
1183 extern struct filter *filter_create_ext PROTO((struct filter * chain, const char *cmd, ...));
1184 struct filter *filter_create_int PROTO((struct filter *chain,
1185 int (*filter_func) (struct filter *),
1186 void *extra));
1187 extern bool filter_apply_chain PROTO((struct filter * chain));
1188 extern int filter_truncate (struct filter * chain, int max_len);
1189 extern int filter_tee_header PROTO((struct filter *chain));
1190 extern int filter_fix_linedirs PROTO((struct filter *chain));
1194 * From "regex.c"
1197 extern regex_t regex_linedir, regex_blank_line;
1198 bool flex_init_regex(void);
1199 void flex_regcomp(regex_t *preg, const char *regex, int cflags);
1200 char *regmatch_dup (regmatch_t * m, const char *src);
1201 char *regmatch_cpy (regmatch_t * m, char *dest, const char *src);
1202 int regmatch_len (regmatch_t * m);
1203 int regmatch_strtol (regmatch_t * m, const char *src, char **endptr, int base);
1204 bool regmatch_empty (regmatch_t * m);
1206 /* From "scanflags.h" */
1207 typedef unsigned int scanflags_t;
1208 extern scanflags_t* _sf_stk;
1209 extern size_t _sf_top_ix, _sf_max; /**< stack of scanner flags. */
1210 #define _SF_CASE_INS 0x0001
1211 #define _SF_DOT_ALL 0x0002
1212 #define _SF_SKIP_WS 0x0004
1213 #define sf_top() (_sf_stk[_sf_top_ix])
1214 #define sf_case_ins() (sf_top() & _SF_CASE_INS)
1215 #define sf_dot_all() (sf_top() & _SF_DOT_ALL)
1216 #define sf_skip_ws() (sf_top() & _SF_SKIP_WS)
1217 #define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS))
1218 #define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL))
1219 #define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS))
1220 extern void sf_init(void);
1221 extern void sf_push(void);
1222 extern void sf_pop(void);
1225 * From "misc.c"
1227 #ifdef __printflike
1228 __printflike(1, 2)
1229 #endif
1230 void lerrsf_fatal (const char *msg, ...);
1232 #endif /* not defined FLEXDEF_H */