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