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