Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.bin / lex / flexdef.h
blobf986330d94cf504d3ba9f3e017751570614210b1
1 /* flexdef - definitions file for flex */
3 /*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
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.
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 /* $NetBSD: flexdef.h,v 1.14 2002/01/29 10:20:34 tv Exp $ */
31 #include <stdio.h>
32 #include <ctype.h>
34 #include <config.h>
36 #ifdef __TURBOC__
37 #define HAVE_STRING_H 1
38 #define MS_DOS 1
39 #ifndef __STDC__
40 #define __STDC__ 1
41 #endif
42 #pragma warn -pro
43 #pragma warn -rch
44 #pragma warn -use
45 #pragma warn -aus
46 #pragma warn -par
47 #pragma warn -pia
48 #endif
50 #ifdef HAVE_STRING_H
51 #include <string.h>
52 #else
53 #include <strings.h>
54 #endif
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
58 #endif
60 #ifdef STDC_HEADERS
61 #include <stdlib.h>
62 #else
63 #ifdef HAVE_MALLOC_H
64 #include <malloc.h>
65 #endif
66 #endif
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
72 /* As an aid for the internationalization patch to flex, which
73 * is maintained outside this distribution for copyright reasons.
75 #define _(String) (String)
77 /* Always be prepared to generate an 8-bit scanner. */
78 #define CSIZE 256
79 #define Char unsigned char
81 /* Size of input alphabet - should be size of ASCII set. */
82 #ifndef DEFAULT_CSIZE
83 #define DEFAULT_CSIZE 128
84 #endif
86 #ifndef PROTO
87 #if __STDC__
88 #define PROTO(proto) proto
89 #else
90 #define PROTO(proto) ()
91 #endif
92 #endif
94 #ifdef VMS
95 #ifndef __VMS_POSIX
96 #define unlink remove
97 #define SHORT_FILE_NAMES
98 #endif
99 #endif
101 #ifdef MS_DOS
102 #define SHORT_FILE_NAMES
103 #endif
106 /* Maximum line length we'll have to deal with. */
107 #define MAXLINE 2048
109 #ifndef MIN
110 #define MIN(x,y) ((x) < (y) ? (x) : (y))
111 #endif
112 #ifndef MAX
113 #define MAX(x,y) ((x) > (y) ? (x) : (y))
114 #endif
115 #ifndef ABS
116 #define ABS(x) ((x) < 0 ? -(x) : (x))
117 #endif
120 /* ANSI C does not guarantee that isascii() is defined */
121 #ifndef isascii
122 #define isascii(c) ((c) <= 0177)
123 #endif
126 #define true 1
127 #define false 0
128 #define unspecified -1
131 /* Special chk[] values marking the slots taking by end-of-buffer and action
132 * numbers.
134 #define EOB_POSITION -1
135 #define ACTION_POSITION -2
137 /* Number of data items per line for -f output. */
138 #define NUMDATAITEMS 10
140 /* Number of lines of data in -f output before inserting a blank line for
141 * readability.
143 #define NUMDATALINES 10
145 /* transition_struct_out() definitions. */
146 #define TRANS_STRUCT_PRINT_LENGTH 14
148 /* Returns true if an nfa state has an epsilon out-transition slot
149 * that can be used. This definition is currently not used.
151 #define FREE_EPSILON(state) \
152 (transchar[state] == SYM_EPSILON && \
153 trans2[state] == NO_TRANSITION && \
154 finalst[state] != state)
156 /* Returns true if an nfa state has an epsilon out-transition character
157 * and both slots are free
159 #define SUPER_FREE_EPSILON(state) \
160 (transchar[state] == SYM_EPSILON && \
161 trans1[state] == NO_TRANSITION) \
163 /* Maximum number of NFA states that can comprise a DFA state. It's real
164 * big because if there's a lot of rules, the initial state will have a
165 * huge epsilon closure.
167 #define INITIAL_MAX_DFA_SIZE 750
168 #define MAX_DFA_SIZE_INCREMENT 750
171 /* A note on the following masks. They are used to mark accepting numbers
172 * as being special. As such, they implicitly limit the number of accepting
173 * numbers (i.e., rules) because if there are too many rules the rule numbers
174 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
175 * 8192) so unlikely to actually cause any problems. A check is made in
176 * new_rule() to ensure that this limit is not reached.
179 /* Mask to mark a trailing context accepting number. */
180 #define YY_TRAILING_MASK 0x2000
182 /* Mask to mark the accepting number of the "head" of a trailing context
183 * rule.
185 #define YY_TRAILING_HEAD_MASK 0x4000
187 /* Maximum number of rules, as outlined in the above note. */
188 #define MAX_RULE (YY_TRAILING_MASK - 1)
191 /* NIL must be 0. If not, its special meaning when making equivalence classes
192 * (it marks the representative of a given e.c.) will be unidentifiable.
194 #define NIL 0
196 #define JAM -1 /* to mark a missing DFA transition */
197 #define NO_TRANSITION NIL
198 #define UNIQUE -1 /* marks a symbol as an e.c. representative */
199 #define INFINITY -1 /* for x{5,} constructions */
201 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
202 #define MAX_CCLS_INCREMENT 100
204 /* Size of table holding members of character classes. */
205 #define INITIAL_MAX_CCL_TBL_SIZE 500
206 #define MAX_CCL_TBL_SIZE_INCREMENT 250
208 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
209 #define MAX_RULES_INCREMENT 100
211 #define INITIAL_MNS 2000 /* default maximum number of nfa states */
212 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
214 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
215 #define MAX_DFAS_INCREMENT 1000
217 #define JAMSTATE -32766 /* marks a reference to the state that always jams */
219 /* Maximum number of NFA states. */
220 #define MAXIMUM_MNS 31999
222 /* Enough so that if it's subtracted from an NFA state number, the result
223 * is guaranteed to be negative.
225 #define MARKER_DIFFERENCE (MAXIMUM_MNS+2)
227 /* Maximum number of nxt/chk pairs for non-templates. */
228 #define INITIAL_MAX_XPAIRS 2000
229 #define MAX_XPAIRS_INCREMENT 2000
231 /* Maximum number of nxt/chk pairs needed for templates. */
232 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
233 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
235 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
237 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
238 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
240 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
241 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
243 /* The following percentages are used to tune table compression:
245 * The percentage the number of out-transitions a state must be of the
246 * number of equivalence classes in order to be considered for table
247 * compaction by using protos.
249 #define PROTO_SIZE_PERCENTAGE 15
251 /* The percentage the number of homogeneous out-transitions of a state
252 * must be of the number of total out-transitions of the state in order
253 * that the state's transition table is first compared with a potential
254 * template of the most common out-transition instead of with the first
255 * proto in the proto queue.
257 #define CHECK_COM_PERCENTAGE 50
259 /* The percentage the number of differences between a state's transition
260 * table and the proto it was first compared with must be of the total
261 * number of out-transitions of the state in order to keep the first
262 * proto as a good match and not search any further.
264 #define FIRST_MATCH_DIFF_PERCENTAGE 10
266 /* The percentage the number of differences between a state's transition
267 * table and the most similar proto must be of the state's total number
268 * of out-transitions to use the proto as an acceptable close match.
270 #define ACCEPTABLE_DIFF_PERCENTAGE 50
272 /* The percentage the number of homogeneous out-transitions of a state
273 * must be of the number of total out-transitions of the state in order
274 * to consider making a template from the state.
276 #define TEMPLATE_SAME_PERCENTAGE 60
278 /* The percentage the number of differences between a state's transition
279 * table and the most similar proto must be of the state's total number
280 * of out-transitions to create a new proto from the state.
282 #define NEW_PROTO_DIFF_PERCENTAGE 20
284 /* The percentage the total number of out-transitions of a state must be
285 * of the number of equivalence classes in order to consider trying to
286 * fit the transition table into "holes" inside the nxt/chk table.
288 #define INTERIOR_FIT_PERCENTAGE 15
290 /* Size of region set aside to cache the complete transition table of
291 * protos on the proto queue to enable quick comparisons.
293 #define PROT_SAVE_SIZE 2000
295 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
297 /* Maximum number of out-transitions a state can have that we'll rummage
298 * around through the interior of the internal fast table looking for a
299 * spot for it.
301 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
303 /* Maximum number of rules which will be reported as being associated
304 * with a DFA state.
306 #define MAX_ASSOC_RULES 100
308 /* Number that, if used to subscript an array, has a good chance of producing
309 * an error; should be small enough to fit into a short.
311 #define BAD_SUBSCRIPT -32767
313 /* Absolute value of largest number that can be stored in a short, with a
314 * bit of slop thrown in for general paranoia.
316 #define MAX_SHORT 32700
319 /* Declarations for global variables. */
321 /* Variables for symbol tables:
322 * sctbl - start-condition symbol table
323 * ndtbl - name-definition symbol table
324 * ccltab - character class text symbol table
327 struct hash_entry
329 struct hash_entry *prev, *next;
330 char *name;
331 char *str_val;
332 int int_val;
335 typedef struct hash_entry **hash_table;
337 #define NAME_TABLE_HASH_SIZE 101
338 #define START_COND_HASH_SIZE 101
339 #define CCL_HASH_SIZE 101
341 extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
342 extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
343 extern struct hash_entry *ccltab[CCL_HASH_SIZE];
346 /* Variables for flags:
347 * printstats - if true (-v), dump statistics
348 * syntaxerror - true if a syntax error has been found
349 * eofseen - true if we've seen an eof in the input file
350 * ddebug - if true (-d), make a "debug" scanner
351 * trace - if true (-T), trace processing
352 * nowarn - if true (-w), do not generate warnings
353 * spprdflt - if true (-s), suppress the default rule
354 * interactive - if true (-I), generate an interactive scanner
355 * caseins - if true (-i), generate a case-insensitive scanner
356 * lex_compat - if true (-l), maximize compatibility with AT&T lex
357 * do_yylineno - if true, generate code to maintain yylineno
358 * useecs - if true (-Ce flag), use equivalence classes
359 * fulltbl - if true (-Cf flag), don't compress the DFA state table
360 * usemecs - if true (-Cm flag), use meta-equivalence classes
361 * fullspd - if true (-F flag), use Jacobson method of table representation
362 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
363 * performance_report - if > 0 (i.e., -p flag), generate a report relating
364 * to scanner performance; if > 1 (-p -p), report on minor performance
365 * problems, too
366 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
367 * listing backing-up states
368 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
369 * otherwise, a standard C scanner
370 * long_align - if true (-Ca flag), favor long-word alignment.
371 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
372 * otherwise, use fread().
373 * yytext_is_array - if true (i.e., %array directive), then declare
374 * yytext as a array instead of a character pointer. Nice and inefficient.
375 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
376 * "no more files".
377 * csize - size of character set for the scanner we're generating;
378 * 128 for 7-bit chars and 256 for 8-bit
379 * yymore_used - if true, yymore() is used in input rules
380 * reject - if true, generate back-up tables for REJECT macro
381 * real_reject - if true, scanner really uses REJECT (as opposed to just
382 * having "reject" set for variable trailing context)
383 * continued_action - true if this rule's action is to "fall through" to
384 * the next rule's action (i.e., the '|' action)
385 * in_rule - true if we're inside an individual rule, false if not.
386 * yymore_really_used - whether to treat yymore() as really used, regardless
387 * of what we think based on references to it in the user's actions.
388 * reject_really_used - same for REJECT
391 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
392 extern int interactive, caseins, lex_compat, do_yylineno;
393 extern int useecs, fulltbl, usemecs, fullspd;
394 extern int gen_line_dirs, performance_report, backing_up_report;
395 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
396 extern int csize;
397 extern int yymore_used, reject, real_reject, continued_action, in_rule;
399 extern int yymore_really_used, reject_really_used;
402 /* Variables used in the flex input routines:
403 * datapos - characters on current output line
404 * dataline - number of contiguous lines of data in current data
405 * statement. Used to generate readable -f output
406 * linenum - current input line number
407 * out_linenum - current output line number
408 * skelfile - the skeleton file
409 * skel - compiled-in skeleton array
410 * skel_ind - index into "skel" array, if skelfile is nil
411 * yyin - input file
412 * backing_up_file - file to summarize backing-up states to
413 * infilename - name of input file
414 * outfilename - name of output file
415 * did_outfilename - whether outfilename was explicitly set
416 * prefix - the prefix used for externally visible names ("yy" by default)
417 * yyclass - yyFlexLexer subclass to use for YY_DECL
418 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
419 * use_stdout - the -t flag
420 * input_files - array holding names of input files
421 * num_input_files - size of input_files array
422 * program_name - name with which program was invoked
424 * action_array - array to hold the rule actions
425 * action_size - size of action_array
426 * defs1_offset - index where the user's section 1 definitions start
427 * in action_array
428 * prolog_offset - index where the prolog starts in action_array
429 * action_offset - index where the non-prolog starts in action_array
430 * action_index - index where the next action should go, with respect
431 * to "action_array"
434 extern int datapos, dataline, linenum, out_linenum;
435 extern FILE *skelfile, *yyin, *backing_up_file;
436 extern const char *skel[];
437 extern int skel_ind;
438 extern char *infilename, *outfilename;
439 extern int did_outfilename;
440 extern char *prefix, *yyclass;
441 extern int do_stdinit, use_stdout;
442 extern char **input_files;
443 extern int num_input_files;
444 extern char *program_name;
446 extern char *action_array;
447 extern int action_size;
448 extern int defs1_offset, prolog_offset, action_offset, action_index;
451 /* Variables for stack of states having only one out-transition:
452 * onestate - state number
453 * onesym - transition symbol
454 * onenext - target state
455 * onedef - default base entry
456 * onesp - stack pointer
459 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
460 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
463 /* Variables for nfa machine data:
464 * current_mns - current maximum on number of NFA states
465 * num_rules - number of the last accepting state; also is number of
466 * rules created so far
467 * num_eof_rules - number of <<EOF>> rules
468 * default_rule - number of the default rule
469 * current_max_rules - current maximum number of rules
470 * lastnfa - last nfa state number created
471 * firstst - physically the first state of a fragment
472 * lastst - last physical state of fragment
473 * finalst - last logical state of fragment
474 * transchar - transition character
475 * trans1 - transition state
476 * trans2 - 2nd transition state for epsilons
477 * accptnum - accepting number
478 * assoc_rule - rule associated with this NFA state (or 0 if none)
479 * state_type - a STATE_xxx type identifying whether the state is part
480 * of a normal rule, the leading state in a trailing context
481 * rule (i.e., the state which marks the transition from
482 * recognizing the text-to-be-matched to the beginning of
483 * the trailing context), or a subsequent state in a trailing
484 * context rule
485 * rule_type - a RULE_xxx type identifying whether this a ho-hum
486 * normal rule or one which has variable head & trailing
487 * context
488 * rule_linenum - line number associated with rule
489 * rule_useful - true if we've determined that the rule can be matched
492 extern int current_mns, current_max_rules;
493 extern int num_rules, num_eof_rules, default_rule, lastnfa;
494 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
495 extern int *accptnum, *assoc_rule, *state_type;
496 extern int *rule_type, *rule_linenum, *rule_useful;
498 /* Different types of states; values are useful as masks, as well, for
499 * routines like check_trailing_context().
501 #define STATE_NORMAL 0x1
502 #define STATE_TRAILING_CONTEXT 0x2
504 /* Global holding current type of state we're making. */
506 extern int current_state_type;
508 /* Different types of rules. */
509 #define RULE_NORMAL 0
510 #define RULE_VARIABLE 1
512 /* True if the input rules include a rule with both variable-length head
513 * and trailing context, false otherwise.
515 extern int variable_trailing_context_rules;
518 /* Variables for protos:
519 * numtemps - number of templates created
520 * numprots - number of protos created
521 * protprev - backlink to a more-recently used proto
522 * protnext - forward link to a less-recently used proto
523 * prottbl - base/def table entry for proto
524 * protcomst - common state of proto
525 * firstprot - number of the most recently used proto
526 * lastprot - number of the least recently used proto
527 * protsave contains the entire state array for protos
530 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
531 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
534 /* Variables for managing equivalence classes:
535 * numecs - number of equivalence classes
536 * nextecm - forward link of Equivalence Class members
537 * ecgroup - class number or backward link of EC members
538 * nummecs - number of meta-equivalence classes (used to compress
539 * templates)
540 * tecfwd - forward link of meta-equivalence classes members
541 * tecbck - backward link of MEC's
544 /* Reserve enough room in the equivalence class arrays so that we
545 * can use the CSIZE'th element to hold equivalence class information
546 * for the NUL character. Later we'll move this information into
547 * the 0th element.
549 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
551 /* Meta-equivalence classes are indexed starting at 1, so it's possible
552 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
553 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
554 * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
556 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
559 /* Variables for start conditions:
560 * lastsc - last start condition created
561 * current_max_scs - current limit on number of start conditions
562 * scset - set of rules active in start condition
563 * scbol - set of rules active only at the beginning of line in a s.c.
564 * scxclu - true if start condition is exclusive
565 * sceof - true if start condition has EOF rule
566 * scname - start condition name
569 extern int lastsc, *scset, *scbol, *scxclu, *sceof;
570 extern int current_max_scs;
571 extern char **scname;
574 /* Variables for dfa machine data:
575 * current_max_dfa_size - current maximum number of NFA states in DFA
576 * current_max_xpairs - current maximum number of non-template xtion pairs
577 * current_max_template_xpairs - current maximum number of template pairs
578 * current_max_dfas - current maximum number DFA states
579 * lastdfa - last dfa state number created
580 * nxt - state to enter upon reading character
581 * chk - check value to see if "nxt" applies
582 * tnxt - internal nxt table for templates
583 * base - offset into "nxt" for given state
584 * def - where to go if "chk" disallows "nxt" entry
585 * nultrans - NUL transition for each state
586 * NUL_ec - equivalence class of the NUL character
587 * tblend - last "nxt/chk" table entry being used
588 * firstfree - first empty entry in "nxt/chk" table
589 * dss - nfa state set for each dfa
590 * dfasiz - size of nfa state set for each dfa
591 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
592 * number, if not
593 * accsiz - size of accepting set for each dfa state
594 * dhash - dfa state hash value
595 * numas - number of DFA accepting states created; note that this
596 * is not necessarily the same value as num_rules, which is the analogous
597 * value for the NFA
598 * numsnpairs - number of state/nextstate transition pairs
599 * jambase - position in base/def where the default jam table starts
600 * jamstate - state number corresponding to "jam" state
601 * end_of_buffer_state - end-of-buffer dfa state number
604 extern int current_max_dfa_size, current_max_xpairs;
605 extern int current_max_template_xpairs, current_max_dfas;
606 extern int lastdfa, *nxt, *chk, *tnxt;
607 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
608 extern union dfaacc_union
610 int *dfaacc_set;
611 int dfaacc_state;
612 } *dfaacc;
613 extern int *accsiz, *dhash, numas;
614 extern int numsnpairs, jambase, jamstate;
615 extern int end_of_buffer_state;
617 /* Variables for ccl information:
618 * lastccl - ccl index of the last created ccl
619 * current_maxccls - current limit on the maximum number of unique ccl's
620 * cclmap - maps a ccl index to its set pointer
621 * ccllen - gives the length of a ccl
622 * cclng - true for a given ccl if the ccl is negated
623 * cclreuse - counts how many times a ccl is re-used
624 * current_max_ccl_tbl_size - current limit on number of characters needed
625 * to represent the unique ccl's
626 * ccltbl - holds the characters in each ccl - indexed by cclmap
629 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
630 extern int current_maxccls, current_max_ccl_tbl_size;
631 extern Char *ccltbl;
634 /* Variables for miscellaneous information:
635 * nmstr - last NAME scanned by the scanner
636 * sectnum - section number currently being parsed
637 * nummt - number of empty nxt/chk table entries
638 * hshcol - number of hash collisions detected by snstods
639 * dfaeql - number of times a newly created dfa was equal to an old one
640 * numeps - number of epsilon NFA states created
641 * eps2 - number of epsilon states which have 2 out-transitions
642 * num_reallocs - number of times it was necessary to realloc() a group
643 * of arrays
644 * tmpuses - number of DFA states that chain to templates
645 * totnst - total number of NFA states used to make DFA states
646 * peakpairs - peak number of transition pairs we had to store internally
647 * numuniq - number of unique transitions
648 * numdup - number of duplicate transitions
649 * hshsave - number of hash collisions saved by checking number of states
650 * num_backing_up - number of DFA states requiring backing up
651 * bol_needed - whether scanner needs beginning-of-line recognition
654 extern char nmstr[MAXLINE];
655 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
656 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
657 extern int num_backing_up, bol_needed;
659 void *allocate_array PROTO((int, size_t));
660 void *reallocate_array PROTO((void*, int, size_t));
662 void *flex_alloc PROTO((size_t));
663 void *flex_realloc PROTO((void*, size_t));
664 void flex_free PROTO((void*));
666 #define allocate_integer_array(size) \
667 (int *) allocate_array( size, sizeof( int ) )
669 #define reallocate_integer_array(array,size) \
670 (int *) reallocate_array( (void *) array, size, sizeof( int ) )
672 #define allocate_int_ptr_array(size) \
673 (int **) allocate_array( size, sizeof( int * ) )
675 #define allocate_char_ptr_array(size) \
676 (char **) allocate_array( size, sizeof( char * ) )
678 #define allocate_dfaacc_union(size) \
679 (union dfaacc_union *) \
680 allocate_array( size, sizeof( union dfaacc_union ) )
682 #define reallocate_int_ptr_array(array,size) \
683 (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
685 #define reallocate_char_ptr_array(array,size) \
686 (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
688 #define reallocate_dfaacc_union(array, size) \
689 (union dfaacc_union *) \
690 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
692 #define allocate_character_array(size) \
693 (char *) allocate_array( size, sizeof( char ) )
695 #define reallocate_character_array(array,size) \
696 (char *) reallocate_array( (void *) array, size, sizeof( char ) )
698 #define allocate_Character_array(size) \
699 (Char *) allocate_array( size, sizeof( Char ) )
701 #define reallocate_Character_array(array,size) \
702 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
705 /* Used to communicate between scanner and parser. The type should really
706 * be YYSTYPE, but we can't easily get our hands on it.
708 extern int yylval;
711 /* External functions that are cross-referenced among the flex source files. */
714 /* from file ccl.c */
716 extern void ccladd PROTO((int, int)); /* add a single character to a ccl */
717 extern int cclinit PROTO((void)); /* make an empty ccl */
718 extern void cclnegate PROTO((int)); /* negate a ccl */
720 /* List the members of a set of characters in CCL form. */
721 extern void list_character_set PROTO((FILE*, int[]));
724 /* from file dfa.c */
726 /* Check a DFA state for backing up. */
727 extern void check_for_backing_up PROTO((int, int[]));
729 /* Check to see if NFA state set constitutes "dangerous" trailing context. */
730 extern void check_trailing_context PROTO((int*, int, int*, int));
732 /* Construct the epsilon closure of a set of ndfa states. */
733 extern int *epsclosure PROTO((int*, int*, int[], int*, int*));
735 /* Increase the maximum number of dfas. */
736 extern void increase_max_dfas PROTO((void));
738 extern void ntod PROTO((void)); /* convert a ndfa to a dfa */
740 /* Converts a set of ndfa states into a dfa state. */
741 extern int snstods PROTO((int[], int, int[], int, int, int*));
744 /* from file ecs.c */
746 /* Convert character classes to set of equivalence classes. */
747 extern void ccl2ecl PROTO((void));
749 /* Associate equivalence class numbers with class members. */
750 extern int cre8ecs PROTO((int[], int[], int));
752 /* Update equivalence classes based on character class transitions. */
753 extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
755 /* Create equivalence class for single character. */
756 extern void mkechar PROTO((int, int[], int[]));
759 /* from file gen.c */
761 extern void do_indent PROTO((void)); /* indent to the current level */
763 /* Generate the code to keep backing-up information. */
764 extern void gen_backing_up PROTO((void));
766 /* Generate the code to perform the backing up. */
767 extern void gen_bu_action PROTO((void));
769 /* Generate full speed compressed transition table. */
770 extern void genctbl PROTO((void));
772 /* Generate the code to find the action number. */
773 extern void gen_find_action PROTO((void));
775 extern void genftbl PROTO((void)); /* generate full transition table */
777 /* Generate the code to find the next compressed-table state. */
778 extern void gen_next_compressed_state PROTO((char*));
780 /* Generate the code to find the next match. */
781 extern void gen_next_match PROTO((void));
783 /* Generate the code to find the next state. */
784 extern void gen_next_state PROTO((int));
786 /* Generate the code to make a NUL transition. */
787 extern void gen_NUL_trans PROTO((void));
789 /* Generate the code to find the start state. */
790 extern void gen_start_state PROTO((void));
792 /* Generate data statements for the transition tables. */
793 extern void gentabs PROTO((void));
795 /* Write out a formatted string at the current indentation level. */
796 extern void indent_put2s PROTO((char[], char[]));
798 /* Write out a string + newline at the current indentation level. */
799 extern void indent_puts PROTO((char[]));
801 extern void make_tables PROTO((void)); /* generate transition tables */
804 /* from file main.c */
806 extern void check_options PROTO((void));
807 extern void flexend PROTO((int));
808 extern void usage PROTO((void));
811 /* from file misc.c */
813 /* Add a #define to the action file. */
814 extern void action_define PROTO(( char *defname, int value ));
816 /* Add the given text to the stored actions. */
817 extern void add_action PROTO(( char *new_text ));
819 /* True if a string is all lower case. */
820 extern int all_lower PROTO((register char *));
822 /* True if a string is all upper case. */
823 extern int all_upper PROTO((register char *));
825 /* Bubble sort an integer array. */
826 extern void bubble PROTO((int [], int));
828 /* Check a character to make sure it's in the expected range. */
829 extern void check_char PROTO((int c));
831 /* Replace upper-case letter to lower-case. */
832 extern Char clower PROTO((int));
834 /* Returns a dynamically allocated copy of a string. */
835 extern char *copy_string PROTO((register const char *));
837 /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
838 extern Char *copy_unsigned_string PROTO((register Char *));
840 /* Shell sort a character array. */
841 extern void cshell PROTO((Char [], int, int));
843 /* Finish up a block of data declarations. */
844 extern void dataend PROTO((void));
846 /* Flush generated data statements. */
847 extern void dataflush PROTO((void));
849 /* Report an error message and terminate. */
850 extern void flexerror PROTO((const char[]));
852 /* Report a fatal error message and terminate. */
853 extern void flexfatal PROTO((const char[]));
855 /* Convert a hexadecimal digit string to an integer value. */
856 extern int htoi PROTO((Char[]));
858 /* Report an error message formatted with one integer argument. */
859 extern void lerrif PROTO((const char[], int));
861 /* Report an error message formatted with one string argument. */
862 extern void lerrsf PROTO((const char[], const char[]));
864 /* Spit out a "#line" statement. */
865 extern void line_directive_out PROTO((FILE*, int));
867 /* Mark the current position in the action array as the end of the section 1
868 * user defs.
870 extern void mark_defs1 PROTO((void));
872 /* Mark the current position in the action array as the end of the prolog. */
873 extern void mark_prolog PROTO((void));
875 /* Generate a data statment for a two-dimensional array. */
876 extern void mk2data PROTO((int));
878 extern void mkdata PROTO((int)); /* generate a data statement */
880 /* Return the integer represented by a string of digits. */
881 extern int myctoi PROTO((char []));
883 /* Return character corresponding to escape sequence. */
884 extern Char myesc PROTO((Char[]));
886 /* Convert an octal digit string to an integer value. */
887 extern int otoi PROTO((Char [] ));
889 /* Output a (possibly-formatted) string to the generated scanner. */
890 extern void out PROTO((const char []));
891 extern void out_dec PROTO((const char [], int));
892 extern void out_dec2 PROTO((const char [], int, int));
893 extern void out_hex PROTO((const char [], unsigned int));
894 extern void out_line_count PROTO((const char []));
895 extern void out_str PROTO((const char [], const char []));
896 extern void out_str3
897 PROTO((const char [], const char [], const char [], const char []));
898 extern void out_str_dec PROTO((const char [], const char [], int));
899 extern void outc PROTO((int));
900 extern void outn PROTO((const char []));
902 /* Return a printable version of the given character, which might be
903 * 8-bit.
905 extern char *readable_form PROTO((int));
907 /* Write out one section of the skeleton file. */
908 extern void skelout PROTO((void));
910 /* Output a yy_trans_info structure. */
911 extern void transition_struct_out PROTO((int, int));
913 /* Only needed when using certain broken versions of bison to build parse.c. */
914 extern void *yy_flex_xmalloc PROTO(( int ));
916 /* Set a region of memory to 0. */
917 extern void zero_out PROTO((char *, size_t));
920 /* from file nfa.c */
922 /* Add an accepting state to a machine. */
923 extern void add_accept PROTO((int, int));
925 /* Make a given number of copies of a singleton machine. */
926 extern int copysingl PROTO((int, int));
928 /* Debugging routine to write out an nfa. */
929 extern void dumpnfa PROTO((int));
931 /* Finish up the processing for a rule. */
932 extern void finish_rule PROTO((int, int, int, int));
934 /* Connect two machines together. */
935 extern int link_machines PROTO((int, int));
937 /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
938 * not trailing context associated) state.
940 extern void mark_beginning_as_normal PROTO((register int));
942 /* Make a machine that branches to two machines. */
943 extern int mkbranch PROTO((int, int));
945 extern int mkclos PROTO((int)); /* convert a machine into a closure */
946 extern int mkopt PROTO((int)); /* make a machine optional */
948 /* Make a machine that matches either one of two machines. */
949 extern int mkor PROTO((int, int));
951 /* Convert a machine into a positive closure. */
952 extern int mkposcl PROTO((int));
954 extern int mkrep PROTO((int, int, int)); /* make a replicated machine */
956 /* Create a state with a transition on a given symbol. */
957 extern int mkstate PROTO((int));
959 extern void new_rule PROTO((void)); /* initialize for a new rule */
962 /* from file parse.y */
964 /* Build the "<<EOF>>" action for the active start conditions. */
965 extern void build_eof_action PROTO((void));
967 /* Write out a message formatted with one string, pinpointing its location. */
968 extern void format_pinpoint_message PROTO((char[], char[]));
970 /* Write out a message, pinpointing its location. */
971 extern void pinpoint_message PROTO((char[]));
973 /* Write out a warning, pinpointing it at the given line. */
974 extern void line_warning PROTO(( char[], int ));
976 /* Write out a message, pinpointing it at the given line. */
977 extern void line_pinpoint PROTO(( char[], int ));
979 /* Report a formatted syntax error. */
980 extern void format_synerr PROTO((char [], char[]));
981 extern void synerr PROTO((char [])); /* report a syntax error */
982 extern void format_warn PROTO((char [], char[]));
983 extern void lwarn PROTO((char [])); /* report a warning */
984 extern void yyerror PROTO((char [])); /* report a parse error */
985 #ifndef YYRECOVERING
986 extern int yyparse PROTO((void)); /* the YACC parser */
987 #endif
990 /* from file scan.l */
992 /* The Flex-generated scanner for flex. */
993 extern int flexscan PROTO((void));
995 /* Open the given file (if NULL, stdin) for scanning. */
996 extern void set_input_file PROTO((char*));
998 /* Wrapup a file in the lexical analyzer. */
999 extern int yywrap PROTO((void));
1002 /* from file sym.c */
1004 /* Add symbol and definitions to symbol table. */
1005 extern int addsym PROTO((register char[], char*, int, hash_table, int));
1007 /* Save the text of a character class. */
1008 extern void cclinstal PROTO ((Char [], int));
1010 /* Lookup the number associated with character class. */
1011 extern int ccllookup PROTO((Char []));
1013 /* Find symbol in symbol table. */
1014 extern struct hash_entry *findsym PROTO((register char[], hash_table, int ));
1016 extern void ndinstal PROTO((char[], Char[])); /* install a name definition */
1017 extern Char *ndlookup PROTO((char[])); /* lookup a name definition */
1019 /* Increase maximum number of SC's. */
1020 extern void scextend PROTO((void));
1021 extern void scinstal PROTO((char[], int)); /* make a start condition */
1023 /* Lookup the number associated with a start condition. */
1024 extern int sclookup PROTO((char[]));
1027 /* from file tblcmp.c */
1029 /* Build table entries for dfa state. */
1030 extern void bldtbl PROTO((int[], int, int, int, int));
1032 extern void cmptmps PROTO((void)); /* compress template table entries */
1033 extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */
1034 /* Finds a space in the table for a state to be placed. */
1035 extern int find_table_space PROTO((int*, int));
1036 extern void inittbl PROTO((void)); /* initialize transition tables */
1037 /* Make the default, "jam" table entries. */
1038 extern void mkdeftbl PROTO((void));
1040 /* Create table entries for a state (or state fragment) which has
1041 * only one out-transition.
1043 extern void mk1tbl PROTO((int, int, int, int));
1045 /* Place a state into full speed transition table. */
1046 extern void place_state PROTO((int*, int, int));
1048 /* Save states with only one out-transition to be processed later. */
1049 extern void stack1 PROTO((int, int, int, int));
1052 /* from file yylex.c */
1054 extern int yylex PROTO((void));