- fix UP build
[dragonfly.git] / usr.bin / lex / flexdef.h
blobc3a7df7bd9aa85d973cf5ef9cb9ae0e72753ce7c
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 /* @(#) $Header: /home/daffy/u0/vern/flex/RCS/flexdef.h,v 2.53 95/04/20 11:17:36 vern Exp $ (LBL) */
30 /* $FreeBSD: src/usr.bin/lex/flexdef.h,v 1.5 1999/10/27 07:56:44 obrien Exp $ */
31 /* $DragonFly: src/usr.bin/lex/flexdef.h,v 1.4 2005/08/04 17:31:22 drhodus Exp $ */
33 #include <stdio.h>
34 #include <ctype.h>
36 #include "config.h"
38 #ifdef HAVE_STRING_H
39 #include <string.h>
40 #else
41 #include <strings.h>
42 #endif
44 #ifdef HAVE_SYS_TYPES_H
45 #include <sys/types.h>
46 #endif
48 #ifdef HAVE_MALLOC_H
49 #include <malloc.h>
50 #endif
52 #ifdef STDC_HEADERS
53 #include <stdlib.h>
54 #endif
56 /* As an aid for the internationalization patch to flex, which
57 * is maintained outside this distribution for copyright reasons.
59 #define _(String) (String)
61 /* Always be prepared to generate an 8-bit scanner. */
62 #define CSIZE 256
63 #define Char unsigned char
65 /* Size of input alphabet - should be size of ASCII set. */
66 #ifndef DEFAULT_CSIZE
67 #define DEFAULT_CSIZE 128
68 #endif
70 #ifndef PROTO
71 #if __STDC__
72 #define PROTO(proto) proto
73 #else
74 #define PROTO(proto) ()
75 #endif
76 #endif
80 /* Maximum line length we'll have to deal with. */
81 #define MAXLINE 2048
83 #ifndef MIN
84 #define MIN(x,y) ((x) < (y) ? (x) : (y))
85 #endif
86 #ifndef MAX
87 #define MAX(x,y) ((x) > (y) ? (x) : (y))
88 #endif
89 #ifndef ABS
90 #define ABS(x) ((x) < 0 ? -(x) : (x))
91 #endif
94 /* ANSI C does not guarantee that isascii() is defined */
95 #ifndef isascii
96 #define isascii(c) ((c) <= 0177)
97 #endif
100 #define true 1
101 #define false 0
102 #define unspecified -1
105 /* Special chk[] values marking the slots taking by end-of-buffer and action
106 * numbers.
108 #define EOB_POSITION -1
109 #define ACTION_POSITION -2
111 /* Number of data items per line for -f output. */
112 #define NUMDATAITEMS 10
114 /* Number of lines of data in -f output before inserting a blank line for
115 * readability.
117 #define NUMDATALINES 10
119 /* transition_struct_out() definitions. */
120 #define TRANS_STRUCT_PRINT_LENGTH 14
122 /* Returns true if an nfa state has an epsilon out-transition slot
123 * that can be used. This definition is currently not used.
125 #define FREE_EPSILON(state) \
126 (transchar[state] == SYM_EPSILON && \
127 trans2[state] == NO_TRANSITION && \
128 finalst[state] != state)
130 /* Returns true if an nfa state has an epsilon out-transition character
131 * and both slots are free
133 #define SUPER_FREE_EPSILON(state) \
134 (transchar[state] == SYM_EPSILON && \
135 trans1[state] == NO_TRANSITION) \
137 /* Maximum number of NFA states that can comprise a DFA state. It's real
138 * big because if there's a lot of rules, the initial state will have a
139 * huge epsilon closure.
141 #define INITIAL_MAX_DFA_SIZE 750
142 #define MAX_DFA_SIZE_INCREMENT 750
145 /* A note on the following masks. They are used to mark accepting numbers
146 * as being special. As such, they implicitly limit the number of accepting
147 * numbers (i.e., rules) because if there are too many rules the rule numbers
148 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
149 * 8192) so unlikely to actually cause any problems. A check is made in
150 * new_rule() to ensure that this limit is not reached.
153 /* Mask to mark a trailing context accepting number. */
154 #define YY_TRAILING_MASK 0x2000
156 /* Mask to mark the accepting number of the "head" of a trailing context
157 * rule.
159 #define YY_TRAILING_HEAD_MASK 0x4000
161 /* Maximum number of rules, as outlined in the above note. */
162 #define MAX_RULE (YY_TRAILING_MASK - 1)
165 /* NIL must be 0. If not, its special meaning when making equivalence classes
166 * (it marks the representative of a given e.c.) will be unidentifiable.
168 #define NIL 0
170 #define JAM -1 /* to mark a missing DFA transition */
171 #define NO_TRANSITION NIL
172 #define UNIQUE -1 /* marks a symbol as an e.c. representative */
173 #define INFINITY -1 /* for x{5,} constructions */
175 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
176 #define MAX_CCLS_INCREMENT 100
178 /* Size of table holding members of character classes. */
179 #define INITIAL_MAX_CCL_TBL_SIZE 500
180 #define MAX_CCL_TBL_SIZE_INCREMENT 250
182 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
183 #define MAX_RULES_INCREMENT 100
185 #define INITIAL_MNS 2000 /* default maximum number of nfa states */
186 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
188 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
189 #define MAX_DFAS_INCREMENT 1000
191 #define JAMSTATE -32766 /* marks a reference to the state that always jams */
193 /* Maximum number of NFA states. */
194 #define MAXIMUM_MNS 31999
196 /* Enough so that if it's subtracted from an NFA state number, the result
197 * is guaranteed to be negative.
199 #define MARKER_DIFFERENCE (MAXIMUM_MNS+2)
201 /* Maximum number of nxt/chk pairs for non-templates. */
202 #define INITIAL_MAX_XPAIRS 2000
203 #define MAX_XPAIRS_INCREMENT 2000
205 /* Maximum number of nxt/chk pairs needed for templates. */
206 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
207 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
209 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
211 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
212 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
214 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
215 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
217 /* The following percentages are used to tune table compression:
219 * The percentage the number of out-transitions a state must be of the
220 * number of equivalence classes in order to be considered for table
221 * compaction by using protos.
223 #define PROTO_SIZE_PERCENTAGE 15
225 /* The percentage the number of homogeneous out-transitions of a state
226 * must be of the number of total out-transitions of the state in order
227 * that the state's transition table is first compared with a potential
228 * template of the most common out-transition instead of with the first
229 * proto in the proto queue.
231 #define CHECK_COM_PERCENTAGE 50
233 /* The percentage the number of differences between a state's transition
234 * table and the proto it was first compared with must be of the total
235 * number of out-transitions of the state in order to keep the first
236 * proto as a good match and not search any further.
238 #define FIRST_MATCH_DIFF_PERCENTAGE 10
240 /* The percentage the number of differences between a state's transition
241 * table and the most similar proto must be of the state's total number
242 * of out-transitions to use the proto as an acceptable close match.
244 #define ACCEPTABLE_DIFF_PERCENTAGE 50
246 /* The percentage the number of homogeneous out-transitions of a state
247 * must be of the number of total out-transitions of the state in order
248 * to consider making a template from the state.
250 #define TEMPLATE_SAME_PERCENTAGE 60
252 /* The percentage the number of differences between a state's transition
253 * table and the most similar proto must be of the state's total number
254 * of out-transitions to create a new proto from the state.
256 #define NEW_PROTO_DIFF_PERCENTAGE 20
258 /* The percentage the total number of out-transitions of a state must be
259 * of the number of equivalence classes in order to consider trying to
260 * fit the transition table into "holes" inside the nxt/chk table.
262 #define INTERIOR_FIT_PERCENTAGE 15
264 /* Size of region set aside to cache the complete transition table of
265 * protos on the proto queue to enable quick comparisons.
267 #define PROT_SAVE_SIZE 2000
269 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
271 /* Maximum number of out-transitions a state can have that we'll rummage
272 * around through the interior of the internal fast table looking for a
273 * spot for it.
275 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
277 /* Maximum number of rules which will be reported as being associated
278 * with a DFA state.
280 #define MAX_ASSOC_RULES 100
282 /* Number that, if used to subscript an array, has a good chance of producing
283 * an error; should be small enough to fit into a short.
285 #define BAD_SUBSCRIPT -32767
287 /* Absolute value of largest number that can be stored in a short, with a
288 * bit of slop thrown in for general paranoia.
290 #define MAX_SHORT 32700
293 /* Declarations for global variables. */
295 /* Variables for symbol tables:
296 * sctbl - start-condition symbol table
297 * ndtbl - name-definition symbol table
298 * ccltab - character class text symbol table
301 struct hash_entry
303 struct hash_entry *prev, *next;
304 char *name;
305 char *str_val;
306 int int_val;
309 typedef struct hash_entry **hash_table;
311 #define NAME_TABLE_HASH_SIZE 101
312 #define START_COND_HASH_SIZE 101
313 #define CCL_HASH_SIZE 101
315 extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
316 extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
317 extern struct hash_entry *ccltab[CCL_HASH_SIZE];
320 /* Variables for flags:
321 * printstats - if true (-v), dump statistics
322 * syntaxerror - true if a syntax error has been found
323 * eofseen - true if we've seen an eof in the input file
324 * ddebug - if true (-d), make a "debug" scanner
325 * trace - if true (-T), trace processing
326 * nowarn - if true (-w), do not generate warnings
327 * spprdflt - if true (-s), suppress the default rule
328 * interactive - if true (-I), generate an interactive scanner
329 * caseins - if true (-i), generate a case-insensitive scanner
330 * lex_compat - if true (-l), maximize compatibility with AT&T lex
331 * do_yylineno - if true, generate code to maintain yylineno
332 * useecs - if true (-Ce flag), use equivalence classes
333 * fulltbl - if true (-Cf flag), don't compress the DFA state table
334 * usemecs - if true (-Cm flag), use meta-equivalence classes
335 * fullspd - if true (-F flag), use Jacobson method of table representation
336 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
337 * performance_report - if > 0 (i.e., -p flag), generate a report relating
338 * to scanner performance; if > 1 (-p -p), report on minor performance
339 * problems, too
340 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
341 * listing backing-up states
342 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
343 * otherwise, a standard C scanner
344 * long_align - if true (-Ca flag), favor long-word alignment.
345 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
346 * otherwise, use fread().
347 * yytext_is_array - if true (i.e., %array directive), then declare
348 * yytext as a array instead of a character pointer. Nice and inefficient.
349 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
350 * "no more files".
351 * csize - size of character set for the scanner we're generating;
352 * 128 for 7-bit chars and 256 for 8-bit
353 * yymore_used - if true, yymore() is used in input rules
354 * reject - if true, generate back-up tables for REJECT macro
355 * real_reject - if true, scanner really uses REJECT (as opposed to just
356 * having "reject" set for variable trailing context)
357 * continued_action - true if this rule's action is to "fall through" to
358 * the next rule's action (i.e., the '|' action)
359 * in_rule - true if we're inside an individual rule, false if not.
360 * yymore_really_used - whether to treat yymore() as really used, regardless
361 * of what we think based on references to it in the user's actions.
362 * reject_really_used - same for REJECT
365 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
366 extern int interactive, caseins, lex_compat, do_yylineno;
367 extern int useecs, fulltbl, usemecs, fullspd;
368 extern int gen_line_dirs, performance_report, backing_up_report;
369 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
370 extern int csize;
371 extern int yymore_used, reject, real_reject, continued_action, in_rule;
373 extern int yymore_really_used, reject_really_used;
376 /* Variables used in the flex input routines:
377 * datapos - characters on current output line
378 * dataline - number of contiguous lines of data in current data
379 * statement. Used to generate readable -f output
380 * linenum - current input line number
381 * out_linenum - current output line number
382 * skelfile - the skeleton file
383 * skel - compiled-in skeleton array
384 * skel_ind - index into "skel" array, if skelfile is nil
385 * yyin - input file
386 * backing_up_file - file to summarize backing-up states to
387 * infilename - name of input file
388 * outfilename - name of output file
389 * did_outfilename - whether outfilename was explicitly set
390 * prefix - the prefix used for externally visible names ("yy" by default)
391 * yyclass - yyFlexLexer subclass to use for YY_DECL
392 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
393 * use_stdout - the -t flag
394 * input_files - array holding names of input files
395 * num_input_files - size of input_files array
396 * program_name - name with which program was invoked
398 * action_array - array to hold the rule actions
399 * action_size - size of action_array
400 * defs1_offset - index where the user's section 1 definitions start
401 * in action_array
402 * prolog_offset - index where the prolog starts in action_array
403 * action_offset - index where the non-prolog starts in action_array
404 * action_index - index where the next action should go, with respect
405 * to "action_array"
408 extern int datapos, dataline, linenum, out_linenum;
409 extern FILE *skelfile, *yyin, *backing_up_file;
410 extern const char *skel[];
411 extern int skel_ind;
412 extern char *infilename, *outfilename;
413 extern int did_outfilename;
414 extern char *prefix, *yyclass;
415 extern int do_stdinit, use_stdout;
416 extern char **input_files;
417 extern int num_input_files;
418 extern char *program_name;
420 extern char *action_array;
421 extern int action_size;
422 extern int defs1_offset, prolog_offset, action_offset, action_index;
425 /* Variables for stack of states having only one out-transition:
426 * onestate - state number
427 * onesym - transition symbol
428 * onenext - target state
429 * onedef - default base entry
430 * onesp - stack pointer
433 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
434 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
437 /* Variables for nfa machine data:
438 * current_mns - current maximum on number of NFA states
439 * num_rules - number of the last accepting state; also is number of
440 * rules created so far
441 * num_eof_rules - number of <<EOF>> rules
442 * default_rule - number of the default rule
443 * current_max_rules - current maximum number of rules
444 * lastnfa - last nfa state number created
445 * firstst - physically the first state of a fragment
446 * lastst - last physical state of fragment
447 * finalst - last logical state of fragment
448 * transchar - transition character
449 * trans1 - transition state
450 * trans2 - 2nd transition state for epsilons
451 * accptnum - accepting number
452 * assoc_rule - rule associated with this NFA state (or 0 if none)
453 * state_type - a STATE_xxx type identifying whether the state is part
454 * of a normal rule, the leading state in a trailing context
455 * rule (i.e., the state which marks the transition from
456 * recognizing the text-to-be-matched to the beginning of
457 * the trailing context), or a subsequent state in a trailing
458 * context rule
459 * rule_type - a RULE_xxx type identifying whether this a ho-hum
460 * normal rule or one which has variable head & trailing
461 * context
462 * rule_linenum - line number associated with rule
463 * rule_useful - true if we've determined that the rule can be matched
466 extern int current_mns, current_max_rules;
467 extern int num_rules, num_eof_rules, default_rule, lastnfa;
468 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
469 extern int *accptnum, *assoc_rule, *state_type;
470 extern int *rule_type, *rule_linenum, *rule_useful;
472 /* Different types of states; values are useful as masks, as well, for
473 * routines like check_trailing_context().
475 #define STATE_NORMAL 0x1
476 #define STATE_TRAILING_CONTEXT 0x2
478 /* Global holding current type of state we're making. */
480 extern int current_state_type;
482 /* Different types of rules. */
483 #define RULE_NORMAL 0
484 #define RULE_VARIABLE 1
486 /* True if the input rules include a rule with both variable-length head
487 * and trailing context, false otherwise.
489 extern int variable_trailing_context_rules;
492 /* Variables for protos:
493 * numtemps - number of templates created
494 * numprots - number of protos created
495 * protprev - backlink to a more-recently used proto
496 * protnext - forward link to a less-recently used proto
497 * prottbl - base/def table entry for proto
498 * protcomst - common state of proto
499 * firstprot - number of the most recently used proto
500 * lastprot - number of the least recently used proto
501 * protsave contains the entire state array for protos
504 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
505 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
508 /* Variables for managing equivalence classes:
509 * numecs - number of equivalence classes
510 * nextecm - forward link of Equivalence Class members
511 * ecgroup - class number or backward link of EC members
512 * nummecs - number of meta-equivalence classes (used to compress
513 * templates)
514 * tecfwd - forward link of meta-equivalence classes members
515 * tecbck - backward link of MEC's
518 /* Reserve enough room in the equivalence class arrays so that we
519 * can use the CSIZE'th element to hold equivalence class information
520 * for the NUL character. Later we'll move this information into
521 * the 0th element.
523 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
525 /* Meta-equivalence classes are indexed starting at 1, so it's possible
526 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
527 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
528 * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
530 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
533 /* Variables for start conditions:
534 * lastsc - last start condition created
535 * current_max_scs - current limit on number of start conditions
536 * scset - set of rules active in start condition
537 * scbol - set of rules active only at the beginning of line in a s.c.
538 * scxclu - true if start condition is exclusive
539 * sceof - true if start condition has EOF rule
540 * scname - start condition name
543 extern int lastsc, *scset, *scbol, *scxclu, *sceof;
544 extern int current_max_scs;
545 extern char **scname;
548 /* Variables for dfa machine data:
549 * current_max_dfa_size - current maximum number of NFA states in DFA
550 * current_max_xpairs - current maximum number of non-template xtion pairs
551 * current_max_template_xpairs - current maximum number of template pairs
552 * current_max_dfas - current maximum number DFA states
553 * lastdfa - last dfa state number created
554 * nxt - state to enter upon reading character
555 * chk - check value to see if "nxt" applies
556 * tnxt - internal nxt table for templates
557 * base - offset into "nxt" for given state
558 * def - where to go if "chk" disallows "nxt" entry
559 * nultrans - NUL transition for each state
560 * NUL_ec - equivalence class of the NUL character
561 * tblend - last "nxt/chk" table entry being used
562 * firstfree - first empty entry in "nxt/chk" table
563 * dss - nfa state set for each dfa
564 * dfasiz - size of nfa state set for each dfa
565 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
566 * number, if not
567 * accsiz - size of accepting set for each dfa state
568 * dhash - dfa state hash value
569 * numas - number of DFA accepting states created; note that this
570 * is not necessarily the same value as num_rules, which is the analogous
571 * value for the NFA
572 * numsnpairs - number of state/nextstate transition pairs
573 * jambase - position in base/def where the default jam table starts
574 * jamstate - state number corresponding to "jam" state
575 * end_of_buffer_state - end-of-buffer dfa state number
578 extern int current_max_dfa_size, current_max_xpairs;
579 extern int current_max_template_xpairs, current_max_dfas;
580 extern int lastdfa, *nxt, *chk, *tnxt;
581 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
582 extern union dfaacc_union
584 int *dfaacc_set;
585 int dfaacc_state;
586 } *dfaacc;
587 extern int *accsiz, *dhash, numas;
588 extern int numsnpairs, jambase, jamstate;
589 extern int end_of_buffer_state;
591 /* Variables for ccl information:
592 * lastccl - ccl index of the last created ccl
593 * current_maxccls - current limit on the maximum number of unique ccl's
594 * cclmap - maps a ccl index to its set pointer
595 * ccllen - gives the length of a ccl
596 * cclng - true for a given ccl if the ccl is negated
597 * cclreuse - counts how many times a ccl is re-used
598 * current_max_ccl_tbl_size - current limit on number of characters needed
599 * to represent the unique ccl's
600 * ccltbl - holds the characters in each ccl - indexed by cclmap
603 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
604 extern int current_maxccls, current_max_ccl_tbl_size;
605 extern Char *ccltbl;
608 /* Variables for miscellaneous information:
609 * nmstr - last NAME scanned by the scanner
610 * sectnum - section number currently being parsed
611 * nummt - number of empty nxt/chk table entries
612 * hshcol - number of hash collisions detected by snstods
613 * dfaeql - number of times a newly created dfa was equal to an old one
614 * numeps - number of epsilon NFA states created
615 * eps2 - number of epsilon states which have 2 out-transitions
616 * num_reallocs - number of times it was necessary to realloc() a group
617 * of arrays
618 * tmpuses - number of DFA states that chain to templates
619 * totnst - total number of NFA states used to make DFA states
620 * peakpairs - peak number of transition pairs we had to store internally
621 * numuniq - number of unique transitions
622 * numdup - number of duplicate transitions
623 * hshsave - number of hash collisions saved by checking number of states
624 * num_backing_up - number of DFA states requiring backing up
625 * bol_needed - whether scanner needs beginning-of-line recognition
628 extern char nmstr[MAXLINE];
629 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
630 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
631 extern int num_backing_up, bol_needed;
633 void *allocate_array PROTO((int, size_t));
634 void *reallocate_array PROTO((void*, int, size_t));
636 void *flex_alloc PROTO((size_t));
637 void *flex_realloc PROTO((void*, size_t));
638 void flex_free PROTO((void*));
640 #define allocate_integer_array(size) \
641 (int *) allocate_array( size, sizeof( int ) )
643 #define reallocate_integer_array(array,size) \
644 (int *) reallocate_array( (void *) array, size, sizeof( int ) )
646 #define allocate_int_ptr_array(size) \
647 (int **) allocate_array( size, sizeof( int * ) )
649 #define allocate_char_ptr_array(size) \
650 (char **) allocate_array( size, sizeof( char * ) )
652 #define allocate_dfaacc_union(size) \
653 (union dfaacc_union *) \
654 allocate_array( size, sizeof( union dfaacc_union ) )
656 #define reallocate_int_ptr_array(array,size) \
657 (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
659 #define reallocate_char_ptr_array(array,size) \
660 (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
662 #define reallocate_dfaacc_union(array, size) \
663 (union dfaacc_union *) \
664 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
666 #define allocate_character_array(size) \
667 (char *) allocate_array( size, sizeof( char ) )
669 #define reallocate_character_array(array,size) \
670 (char *) reallocate_array( (void *) array, size, sizeof( char ) )
672 #define allocate_Character_array(size) \
673 (Char *) allocate_array( size, sizeof( Char ) )
675 #define reallocate_Character_array(array,size) \
676 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
679 /* Used to communicate between scanner and parser. The type should really
680 * be YYSTYPE, but we can't easily get our hands on it.
682 extern int yylval;
685 /* External functions that are cross-referenced among the flex source files. */
688 /* from file ccl.c */
690 extern void ccladd PROTO((int, int)); /* add a single character to a ccl */
691 extern int cclinit PROTO((void)); /* make an empty ccl */
692 extern void cclnegate PROTO((int)); /* negate a ccl */
694 /* List the members of a set of characters in CCL form. */
695 extern void list_character_set PROTO((FILE*, int[]));
698 /* from file dfa.c */
700 /* Check a DFA state for backing up. */
701 extern void check_for_backing_up PROTO((int, int[]));
703 /* Check to see if NFA state set constitutes "dangerous" trailing context. */
704 extern void check_trailing_context PROTO((int*, int, int*, int));
706 /* Construct the epsilon closure of a set of ndfa states. */
707 extern int *epsclosure PROTO((int*, int*, int[], int*, int*));
709 /* Increase the maximum number of dfas. */
710 extern void increase_max_dfas PROTO((void));
712 extern void ntod PROTO((void)); /* convert a ndfa to a dfa */
714 /* Converts a set of ndfa states into a dfa state. */
715 extern int snstods PROTO((int[], int, int[], int, int, int*));
718 /* from file ecs.c */
720 /* Convert character classes to set of equivalence classes. */
721 extern void ccl2ecl PROTO((void));
723 /* Associate equivalence class numbers with class members. */
724 extern int cre8ecs PROTO((int[], int[], int));
726 /* Update equivalence classes based on character class transitions. */
727 extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
729 /* Create equivalence class for single character. */
730 extern void mkechar PROTO((int, int[], int[]));
733 /* from file gen.c */
735 extern void do_indent PROTO((void)); /* indent to the current level */
737 /* Generate the code to keep backing-up information. */
738 extern void gen_backing_up PROTO((void));
740 /* Generate the code to perform the backing up. */
741 extern void gen_bu_action PROTO((void));
743 /* Generate full speed compressed transition table. */
744 extern void genctbl PROTO((void));
746 /* Generate the code to find the action number. */
747 extern void gen_find_action PROTO((void));
749 extern void genftbl PROTO((void)); /* generate full transition table */
751 /* Generate the code to find the next compressed-table state. */
752 extern void gen_next_compressed_state PROTO((char*));
754 /* Generate the code to find the next match. */
755 extern void gen_next_match PROTO((void));
757 /* Generate the code to find the next state. */
758 extern void gen_next_state PROTO((int));
760 /* Generate the code to make a NUL transition. */
761 extern void gen_NUL_trans PROTO((void));
763 /* Generate the code to find the start state. */
764 extern void gen_start_state PROTO((void));
766 /* Generate data statements for the transition tables. */
767 extern void gentabs PROTO((void));
769 /* Write out a formatted string at the current indentation level. */
770 extern void indent_put2s PROTO((char[], char[]));
772 /* Write out a string + newline at the current indentation level. */
773 extern void indent_puts PROTO((char[]));
775 extern void make_tables PROTO((void)); /* generate transition tables */
778 /* from file main.c */
780 extern void check_options PROTO((void));
781 extern void flexend PROTO((int));
782 extern void usage PROTO((void));
785 /* from file misc.c */
787 /* Add a #define to the action file. */
788 extern void action_define PROTO(( char *defname, int value ));
790 /* Add the given text to the stored actions. */
791 extern void add_action PROTO(( char *new_text ));
793 /* True if a string is all lower case. */
794 extern int all_lower PROTO((char *));
796 /* True if a string is all upper case. */
797 extern int all_upper PROTO((char *));
799 /* Bubble sort an integer array. */
800 extern void bubble PROTO((int [], int));
802 /* Check a character to make sure it's in the expected range. */
803 extern void check_char PROTO((int c));
805 /* Replace upper-case letter to lower-case. */
806 extern Char clower PROTO((int));
808 /* Returns a dynamically allocated copy of a string. */
809 extern char *copy_string PROTO((const char *));
811 /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
812 extern Char *copy_unsigned_string PROTO((Char *));
814 /* Shell sort a character array. */
815 extern void cshell PROTO((Char [], int, int));
817 /* Finish up a block of data declarations. */
818 extern void dataend PROTO((void));
820 /* Flush generated data statements. */
821 extern void dataflush PROTO((void));
823 /* Report an error message and terminate. */
824 extern void flexerror PROTO((const char[]));
826 /* Report a fatal error message and terminate. */
827 extern void flexfatal PROTO((const char[]));
829 /* Convert a hexadecimal digit string to an integer value. */
830 extern int htoi PROTO((Char[]));
832 /* Report an error message formatted with one integer argument. */
833 extern void lerrif PROTO((const char[], int));
835 /* Report an error message formatted with one string argument. */
836 extern void lerrsf PROTO((const char[], const char[]));
838 /* Spit out a "#line" statement. */
839 extern void line_directive_out PROTO((FILE*, int));
841 /* Mark the current position in the action array as the end of the section 1
842 * user defs.
844 extern void mark_defs1 PROTO((void));
846 /* Mark the current position in the action array as the end of the prolog. */
847 extern void mark_prolog PROTO((void));
849 /* Generate a data statment for a two-dimensional array. */
850 extern void mk2data PROTO((int));
852 extern void mkdata PROTO((int)); /* generate a data statement */
854 /* Return the integer represented by a string of digits. */
855 extern int myctoi PROTO((char []));
857 /* Return character corresponding to escape sequence. */
858 extern Char myesc PROTO((Char[]));
860 /* Convert an octal digit string to an integer value. */
861 extern int otoi PROTO((Char [] ));
863 /* Output a (possibly-formatted) string to the generated scanner. */
864 extern void out PROTO((const char []));
865 extern void out_dec PROTO((const char [], int));
866 extern void out_dec2 PROTO((const char [], int, int));
867 extern void out_hex PROTO((const char [], unsigned int));
868 extern void out_line_count PROTO((const char []));
869 extern void out_str PROTO((const char [], const char []));
870 extern void out_str3
871 PROTO((const char [], const char [], const char [], const char []));
872 extern void out_str_dec PROTO((const char [], const char [], int));
873 extern void outc PROTO((int));
874 extern void outn PROTO((const char []));
876 /* Return a printable version of the given character, which might be
877 * 8-bit.
879 extern char *readable_form PROTO((int));
881 /* Write out one section of the skeleton file. */
882 extern void skelout PROTO((void));
884 /* Output a yy_trans_info structure. */
885 extern void transition_struct_out PROTO((int, int));
887 /* Only needed when using certain broken versions of bison to build parse.c. */
888 extern void *yy_flex_xmalloc PROTO(( int ));
890 /* Set a region of memory to 0. */
891 extern void zero_out PROTO((char *, size_t));
894 /* from file nfa.c */
896 /* Add an accepting state to a machine. */
897 extern void add_accept PROTO((int, int));
899 /* Make a given number of copies of a singleton machine. */
900 extern int copysingl PROTO((int, int));
902 /* Debugging routine to write out an nfa. */
903 extern void dumpnfa PROTO((int));
905 /* Finish up the processing for a rule. */
906 extern void finish_rule PROTO((int, int, int, int));
908 /* Connect two machines together. */
909 extern int link_machines PROTO((int, int));
911 /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
912 * not trailing context associated) state.
914 extern void mark_beginning_as_normal PROTO((int));
916 /* Make a machine that branches to two machines. */
917 extern int mkbranch PROTO((int, int));
919 extern int mkclos PROTO((int)); /* convert a machine into a closure */
920 extern int mkopt PROTO((int)); /* make a machine optional */
922 /* Make a machine that matches either one of two machines. */
923 extern int mkor PROTO((int, int));
925 /* Convert a machine into a positive closure. */
926 extern int mkposcl PROTO((int));
928 extern int mkrep PROTO((int, int, int)); /* make a replicated machine */
930 /* Create a state with a transition on a given symbol. */
931 extern int mkstate PROTO((int));
933 extern void new_rule PROTO((void)); /* initialize for a new rule */
936 /* from file parse.y */
938 /* Build the "<<EOF>>" action for the active start conditions. */
939 extern void build_eof_action PROTO((void));
941 /* Write out a message formatted with one string, pinpointing its location. */
942 extern void format_pinpoint_message PROTO((char[], char[]));
944 /* Write out a message, pinpointing its location. */
945 extern void pinpoint_message PROTO((char[]));
947 /* Write out a warning, pinpointing it at the given line. */
948 extern void line_warning PROTO(( char[], int ));
950 /* Write out a message, pinpointing it at the given line. */
951 extern void line_pinpoint PROTO(( char[], int ));
953 /* Report a formatted syntax error. */
954 extern void format_synerr PROTO((char [], char[]));
955 extern void synerr PROTO((char [])); /* report a syntax error */
956 extern void format_warn PROTO((char [], char[]));
957 extern void warn PROTO((char [])); /* report a warning */
958 extern void yyerror PROTO((char [])); /* report a parse error */
959 extern int yyparse PROTO((void)); /* the YACC parser */
962 /* from file scan.l */
964 /* The Flex-generated scanner for flex. */
965 extern int flexscan PROTO((void));
967 /* Open the given file (if NULL, stdin) for scanning. */
968 extern void set_input_file PROTO((char*));
970 /* Wrapup a file in the lexical analyzer. */
971 extern int yywrap PROTO((void));
974 /* from file sym.c */
976 /* Add symbol and definitions to symbol table. */
977 extern int addsym PROTO((char[], char*, int, hash_table, int));
979 /* Save the text of a character class. */
980 extern void cclinstal PROTO ((Char [], int));
982 /* Lookup the number associated with character class. */
983 extern int ccllookup PROTO((Char []));
985 /* Find symbol in symbol table. */
986 extern struct hash_entry *findsym PROTO((char[], hash_table, int ));
988 extern void ndinstal PROTO((char[], Char[])); /* install a name definition */
989 extern Char *ndlookup PROTO((char[])); /* lookup a name definition */
991 /* Increase maximum number of SC's. */
992 extern void scextend PROTO((void));
993 extern void scinstal PROTO((char[], int)); /* make a start condition */
995 /* Lookup the number associated with a start condition. */
996 extern int sclookup PROTO((char[]));
999 /* from file tblcmp.c */
1001 /* Build table entries for dfa state. */
1002 extern void bldtbl PROTO((int[], int, int, int, int));
1004 extern void cmptmps PROTO((void)); /* compress template table entries */
1005 extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */
1006 /* Finds a space in the table for a state to be placed. */
1007 extern int find_table_space PROTO((int*, int));
1008 extern void inittbl PROTO((void)); /* initialize transition tables */
1009 /* Make the default, "jam" table entries. */
1010 extern void mkdeftbl PROTO((void));
1012 /* Create table entries for a state (or state fragment) which has
1013 * only one out-transition.
1015 extern void mk1tbl PROTO((int, int, int, int));
1017 /* Place a state into full speed transition table. */
1018 extern void place_state PROTO((int*, int, int));
1020 /* Save states with only one out-transition to be processed later. */
1021 extern void stack1 PROTO((int, int, int, int));
1024 /* from file yylex.c */
1026 extern int yylex PROTO((void));