source: vendor/flex/2.5.33/flexdef.h@ 3031

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

flex 2.5.33.

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