Get rid off conditionals for hpux, AIX, THINKC, TURBOC, MS_DOS, VMS.
[dragonfly.git] / usr.bin / lex / flexdef.h
CommitLineData
984263bc
MD
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 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.
27 */
28
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 $ */
6e8149e3 31/* $DragonFly: src/usr.bin/lex/flexdef.h,v 1.3 2005/02/20 17:34:11 asmodai Exp $ */
984263bc
MD
32
33#include <stdio.h>
34#include <ctype.h>
35
36#include "config.h"
37
984263bc
MD
38#ifdef HAVE_STRING_H
39#include <string.h>
40#else
41#include <strings.h>
42#endif
43
44#ifdef HAVE_SYS_TYPES_H
45#include <sys/types.h>
46#endif
47
48#ifdef HAVE_MALLOC_H
49#include <malloc.h>
50#endif
51
52#ifdef STDC_HEADERS
53#include <stdlib.h>
54#endif
55
56/* As an aid for the internationalization patch to flex, which
57 * is maintained outside this distribution for copyright reasons.
58 */
59#define _(String) (String)
60
61/* Always be prepared to generate an 8-bit scanner. */
62#define CSIZE 256
63#define Char unsigned char
64
65/* Size of input alphabet - should be size of ASCII set. */
66#ifndef DEFAULT_CSIZE
67#define DEFAULT_CSIZE 128
68#endif
69
70#ifndef PROTO
71#if __STDC__
72#define PROTO(proto) proto
73#else
74#define PROTO(proto) ()
75#endif
76#endif
77
984263bc
MD
78
79
80/* Maximum line length we'll have to deal with. */
81#define MAXLINE 2048
82
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
92
93
94/* ANSI C does not guarantee that isascii() is defined */
95#ifndef isascii
96#define isascii(c) ((c) <= 0177)
97#endif
98
99
100#define true 1
101#define false 0
102#define unspecified -1
103
104
105/* Special chk[] values marking the slots taking by end-of-buffer and action
106 * numbers.
107 */
108#define EOB_POSITION -1
109#define ACTION_POSITION -2
110
111/* Number of data items per line for -f output. */
112#define NUMDATAITEMS 10
113
114/* Number of lines of data in -f output before inserting a blank line for
115 * readability.
116 */
117#define NUMDATALINES 10
118
119/* transition_struct_out() definitions. */
120#define TRANS_STRUCT_PRINT_LENGTH 14
121
122/* Returns true if an nfa state has an epsilon out-transition slot
123 * that can be used. This definition is currently not used.
124 */
125#define FREE_EPSILON(state) \
126 (transchar[state] == SYM_EPSILON && \
127 trans2[state] == NO_TRANSITION && \
128 finalst[state] != state)
129
130/* Returns true if an nfa state has an epsilon out-transition character
131 * and both slots are free
132 */
133#define SUPER_FREE_EPSILON(state) \
134 (transchar[state] == SYM_EPSILON && \
135 trans1[state] == NO_TRANSITION) \
136
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.
140 */
141#define INITIAL_MAX_DFA_SIZE 750
142#define MAX_DFA_SIZE_INCREMENT 750
143
144
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.
151 */
152
153/* Mask to mark a trailing context accepting number. */
154#define YY_TRAILING_MASK 0x2000
155
156/* Mask to mark the accepting number of the "head" of a trailing context
157 * rule.
158 */
159#define YY_TRAILING_HEAD_MASK 0x4000
160
161/* Maximum number of rules, as outlined in the above note. */
162#define MAX_RULE (YY_TRAILING_MASK - 1)
163
164
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.
167 */
168#define NIL 0
169
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 */
174
175#define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
176#define MAX_CCLS_INCREMENT 100
177
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
181
182#define INITIAL_MAX_RULES 100 /* default maximum number of rules */
183#define MAX_RULES_INCREMENT 100
184
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 */
187
188#define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
189#define MAX_DFAS_INCREMENT 1000
190
191#define JAMSTATE -32766 /* marks a reference to the state that always jams */
192
193/* Maximum number of NFA states. */
194#define MAXIMUM_MNS 31999
195
196/* Enough so that if it's subtracted from an NFA state number, the result
197 * is guaranteed to be negative.
198 */
199#define MARKER_DIFFERENCE (MAXIMUM_MNS+2)
200
201/* Maximum number of nxt/chk pairs for non-templates. */
202#define INITIAL_MAX_XPAIRS 2000
203#define MAX_XPAIRS_INCREMENT 2000
204
205/* Maximum number of nxt/chk pairs needed for templates. */
206#define INITIAL_MAX_TEMPLATE_XPAIRS 2500
207#define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
208
209#define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
210
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 */
213
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 */
216
217/* The following percentages are used to tune table compression:
218
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.
222 */
223#define PROTO_SIZE_PERCENTAGE 15
224
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.
230 */
231#define CHECK_COM_PERCENTAGE 50
232
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.
237 */
238#define FIRST_MATCH_DIFF_PERCENTAGE 10
239
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.
243 */
244#define ACCEPTABLE_DIFF_PERCENTAGE 50
245
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.
249 */
250#define TEMPLATE_SAME_PERCENTAGE 60
251
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.
255 */
256#define NEW_PROTO_DIFF_PERCENTAGE 20
257
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.
261 */
262#define INTERIOR_FIT_PERCENTAGE 15
263
264/* Size of region set aside to cache the complete transition table of
265 * protos on the proto queue to enable quick comparisons.
266 */
267#define PROT_SAVE_SIZE 2000
268
269#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
270
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.
274 */
275#define MAX_XTIONS_FULL_INTERIOR_FIT 4
276
277/* Maximum number of rules which will be reported as being associated
278 * with a DFA state.
279 */
280#define MAX_ASSOC_RULES 100
281
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.
284 */
285#define BAD_SUBSCRIPT -32767
286
287/* Absolute value of largest number that can be stored in a short, with a
288 * bit of slop thrown in for general paranoia.
289 */
290#define MAX_SHORT 32700
291
292
293/* Declarations for global variables. */
294
295/* Variables for symbol tables:
296 * sctbl - start-condition symbol table
297 * ndtbl - name-definition symbol table
298 * ccltab - character class text symbol table
299 */
300
301struct hash_entry
302 {
303 struct hash_entry *prev, *next;
304 char *name;
305 char *str_val;
306 int int_val;
307 } ;
308
309typedef struct hash_entry **hash_table;
310
311#define NAME_TABLE_HASH_SIZE 101
312#define START_COND_HASH_SIZE 101
313#define CCL_HASH_SIZE 101
314
315extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
316extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
317extern struct hash_entry *ccltab[CCL_HASH_SIZE];
318
319
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
363 */
364
365extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
366extern int interactive, caseins, lex_compat, do_yylineno;
367extern int useecs, fulltbl, usemecs, fullspd;
368extern int gen_line_dirs, performance_report, backing_up_report;
369extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
370extern int csize;
371extern int yymore_used, reject, real_reject, continued_action, in_rule;
372
373extern int yymore_really_used, reject_really_used;
374
375
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
397 *
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"
406 */
407
408extern int datapos, dataline, linenum, out_linenum;
409extern FILE *skelfile, *yyin, *backing_up_file;
410extern const char *skel[];
411extern int skel_ind;
412extern char *infilename, *outfilename;
413extern int did_outfilename;
414extern char *prefix, *yyclass;
415extern int do_stdinit, use_stdout;
416extern char **input_files;
417extern int num_input_files;
418extern char *program_name;
419
420extern char *action_array;
421extern int action_size;
422extern int defs1_offset, prolog_offset, action_offset, action_index;
423
424
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
431 */
432
433extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
434extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
435
436
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
464 */
465
466extern int current_mns, current_max_rules;
467extern int num_rules, num_eof_rules, default_rule, lastnfa;
468extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
469extern int *accptnum, *assoc_rule, *state_type;
470extern int *rule_type, *rule_linenum, *rule_useful;
471
472/* Different types of states; values are useful as masks, as well, for
473 * routines like check_trailing_context().
474 */
475#define STATE_NORMAL 0x1
476#define STATE_TRAILING_CONTEXT 0x2
477
478/* Global holding current type of state we're making. */
479
480extern int current_state_type;
481
482/* Different types of rules. */
483#define RULE_NORMAL 0
484#define RULE_VARIABLE 1
485
486/* True if the input rules include a rule with both variable-length head
487 * and trailing context, false otherwise.
488 */
489extern int variable_trailing_context_rules;
490
491
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
502 */
503
504extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
505extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
506
507
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
516 */
517
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.
522 */
523extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
524
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.
529 */
530extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
531
532
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
541 */
542
543extern int lastsc, *scset, *scbol, *scxclu, *sceof;
544extern int current_max_scs;
545extern char **scname;
546
547
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
576 */
577
578extern int current_max_dfa_size, current_max_xpairs;
579extern int current_max_template_xpairs, current_max_dfas;
580extern int lastdfa, *nxt, *chk, *tnxt;
581extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
582extern union dfaacc_union
583 {
584 int *dfaacc_set;
585 int dfaacc_state;
586 } *dfaacc;
587extern int *accsiz, *dhash, numas;
588extern int numsnpairs, jambase, jamstate;
589extern int end_of_buffer_state;
590
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
601 */
602
603extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
604extern int current_maxccls, current_max_ccl_tbl_size;
605extern Char *ccltbl;
606
607
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
626 */
627
628extern char nmstr[MAXLINE];
629extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
630extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
631extern int num_backing_up, bol_needed;
632
633void *allocate_array PROTO((int, size_t));
634void *reallocate_array PROTO((void*, int, size_t));
635
636void *flex_alloc PROTO((size_t));
637void *flex_realloc PROTO((void*, size_t));
638void flex_free PROTO((void*));
639
640#define allocate_integer_array(size) \
641 (int *) allocate_array( size, sizeof( int ) )
642
643#define reallocate_integer_array(array,size) \
644 (int *) reallocate_array( (void *) array, size, sizeof( int ) )
645
646#define allocate_int_ptr_array(size) \
647 (int **) allocate_array( size, sizeof( int * ) )
648
649#define allocate_char_ptr_array(size) \
650 (char **) allocate_array( size, sizeof( char * ) )
651
652#define allocate_dfaacc_union(size) \
653 (union dfaacc_union *) \
654 allocate_array( size, sizeof( union dfaacc_union ) )
655
656#define reallocate_int_ptr_array(array,size) \
657 (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
658
659#define reallocate_char_ptr_array(array,size) \
660 (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
661
662#define reallocate_dfaacc_union(array, size) \
663 (union dfaacc_union *) \
664 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
665
666#define allocate_character_array(size) \
667 (char *) allocate_array( size, sizeof( char ) )
668
669#define reallocate_character_array(array,size) \
670 (char *) reallocate_array( (void *) array, size, sizeof( char ) )
671
672#define allocate_Character_array(size) \
673 (Char *) allocate_array( size, sizeof( Char ) )
674
675#define reallocate_Character_array(array,size) \
676 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
677
678
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.
681 */
682extern int yylval;
683
684
685/* External functions that are cross-referenced among the flex source files. */
686
687
688/* from file ccl.c */
689
690extern void ccladd PROTO((int, int)); /* add a single character to a ccl */
691extern int cclinit PROTO((void)); /* make an empty ccl */
692extern void cclnegate PROTO((int)); /* negate a ccl */
693
694/* List the members of a set of characters in CCL form. */
695extern void list_character_set PROTO((FILE*, int[]));
696
697
698/* from file dfa.c */
699
700/* Check a DFA state for backing up. */
701extern void check_for_backing_up PROTO((int, int[]));
702
703/* Check to see if NFA state set constitutes "dangerous" trailing context. */
704extern void check_trailing_context PROTO((int*, int, int*, int));
705
706/* Construct the epsilon closure of a set of ndfa states. */
707extern int *epsclosure PROTO((int*, int*, int[], int*, int*));
708
709/* Increase the maximum number of dfas. */
710extern void increase_max_dfas PROTO((void));
711
712extern void ntod PROTO((void)); /* convert a ndfa to a dfa */
713
714/* Converts a set of ndfa states into a dfa state. */
715extern int snstods PROTO((int[], int, int[], int, int, int*));
716
717
718/* from file ecs.c */
719
720/* Convert character classes to set of equivalence classes. */
721extern void ccl2ecl PROTO((void));
722
723/* Associate equivalence class numbers with class members. */
724extern int cre8ecs PROTO((int[], int[], int));
725
726/* Update equivalence classes based on character class transitions. */
727extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
728
729/* Create equivalence class for single character. */
730extern void mkechar PROTO((int, int[], int[]));
731
732
733/* from file gen.c */
734
735extern void do_indent PROTO((void)); /* indent to the current level */
736
737/* Generate the code to keep backing-up information. */
738extern void gen_backing_up PROTO((void));
739
740/* Generate the code to perform the backing up. */
741extern void gen_bu_action PROTO((void));
742
743/* Generate full speed compressed transition table. */
744extern void genctbl PROTO((void));
745
746/* Generate the code to find the action number. */
747extern void gen_find_action PROTO((void));
748
749extern void genftbl PROTO((void)); /* generate full transition table */
750
751/* Generate the code to find the next compressed-table state. */
752extern void gen_next_compressed_state PROTO((char*));
753
754/* Generate the code to find the next match. */
755extern void gen_next_match PROTO((void));
756
757/* Generate the code to find the next state. */
758extern void gen_next_state PROTO((int));
759
760/* Generate the code to make a NUL transition. */
761extern void gen_NUL_trans PROTO((void));
762
763/* Generate the code to find the start state. */
764extern void gen_start_state PROTO((void));
765
766/* Generate data statements for the transition tables. */
767extern void gentabs PROTO((void));
768
769/* Write out a formatted string at the current indentation level. */
770extern void indent_put2s PROTO((char[], char[]));
771
772/* Write out a string + newline at the current indentation level. */
773extern void indent_puts PROTO((char[]));
774
775extern void make_tables PROTO((void)); /* generate transition tables */
776
777
778/* from file main.c */
779
780extern void check_options PROTO((void));
781extern void flexend PROTO((int));
782extern void usage PROTO((void));
783
784
785/* from file misc.c */
786
787/* Add a #define to the action file. */
788extern void action_define PROTO(( char *defname, int value ));
789
790/* Add the given text to the stored actions. */
791extern void add_action PROTO(( char *new_text ));
792
793/* True if a string is all lower case. */
794extern int all_lower PROTO((register char *));
795
796/* True if a string is all upper case. */
797extern int all_upper PROTO((register char *));
798
799/* Bubble sort an integer array. */
800extern void bubble PROTO((int [], int));
801
802/* Check a character to make sure it's in the expected range. */
803extern void check_char PROTO((int c));
804
805/* Replace upper-case letter to lower-case. */
806extern Char clower PROTO((int));
807
808/* Returns a dynamically allocated copy of a string. */
809extern char *copy_string PROTO((register const char *));
810
811/* Returns a dynamically allocated copy of a (potentially) unsigned string. */
812extern Char *copy_unsigned_string PROTO((register Char *));
813
814/* Shell sort a character array. */
815extern void cshell PROTO((Char [], int, int));
816
817/* Finish up a block of data declarations. */
818extern void dataend PROTO((void));
819
820/* Flush generated data statements. */
821extern void dataflush PROTO((void));
822
823/* Report an error message and terminate. */
824extern void flexerror PROTO((const char[]));
825
826/* Report a fatal error message and terminate. */
827extern void flexfatal PROTO((const char[]));
828
829/* Convert a hexadecimal digit string to an integer value. */
830extern int htoi PROTO((Char[]));
831
832/* Report an error message formatted with one integer argument. */
833extern void lerrif PROTO((const char[], int));
834
835/* Report an error message formatted with one string argument. */
836extern void lerrsf PROTO((const char[], const char[]));
837
838/* Spit out a "#line" statement. */
839extern void line_directive_out PROTO((FILE*, int));
840
841/* Mark the current position in the action array as the end of the section 1
842 * user defs.
843 */
844extern void mark_defs1 PROTO((void));
845
846/* Mark the current position in the action array as the end of the prolog. */
847extern void mark_prolog PROTO((void));
848
849/* Generate a data statment for a two-dimensional array. */
850extern void mk2data PROTO((int));
851
852extern void mkdata PROTO((int)); /* generate a data statement */
853
854/* Return the integer represented by a string of digits. */
855extern int myctoi PROTO((char []));
856
857/* Return character corresponding to escape sequence. */
858extern Char myesc PROTO((Char[]));
859
860/* Convert an octal digit string to an integer value. */
861extern int otoi PROTO((Char [] ));
862
863/* Output a (possibly-formatted) string to the generated scanner. */
864extern void out PROTO((const char []));
865extern void out_dec PROTO((const char [], int));
866extern void out_dec2 PROTO((const char [], int, int));
867extern void out_hex PROTO((const char [], unsigned int));
868extern void out_line_count PROTO((const char []));
869extern void out_str PROTO((const char [], const char []));
870extern void out_str3
871 PROTO((const char [], const char [], const char [], const char []));
872extern void out_str_dec PROTO((const char [], const char [], int));
873extern void outc PROTO((int));
874extern void outn PROTO((const char []));
875
876/* Return a printable version of the given character, which might be
877 * 8-bit.
878 */
879extern char *readable_form PROTO((int));
880
881/* Write out one section of the skeleton file. */
882extern void skelout PROTO((void));
883
884/* Output a yy_trans_info structure. */
885extern void transition_struct_out PROTO((int, int));
886
887/* Only needed when using certain broken versions of bison to build parse.c. */
888extern void *yy_flex_xmalloc PROTO(( int ));
889
890/* Set a region of memory to 0. */
891extern void zero_out PROTO((char *, size_t));
892
893
894/* from file nfa.c */
895
896/* Add an accepting state to a machine. */
897extern void add_accept PROTO((int, int));
898
899/* Make a given number of copies of a singleton machine. */
900extern int copysingl PROTO((int, int));
901
902/* Debugging routine to write out an nfa. */
903extern void dumpnfa PROTO((int));
904
905/* Finish up the processing for a rule. */
906extern void finish_rule PROTO((int, int, int, int));
907
908/* Connect two machines together. */
909extern int link_machines PROTO((int, int));
910
911/* Mark each "beginning" state in a machine as being a "normal" (i.e.,
912 * not trailing context associated) state.
913 */
914extern void mark_beginning_as_normal PROTO((register int));
915
916/* Make a machine that branches to two machines. */
917extern int mkbranch PROTO((int, int));
918
919extern int mkclos PROTO((int)); /* convert a machine into a closure */
920extern int mkopt PROTO((int)); /* make a machine optional */
921
922/* Make a machine that matches either one of two machines. */
923extern int mkor PROTO((int, int));
924
925/* Convert a machine into a positive closure. */
926extern int mkposcl PROTO((int));
927
928extern int mkrep PROTO((int, int, int)); /* make a replicated machine */
929
930/* Create a state with a transition on a given symbol. */
931extern int mkstate PROTO((int));
932
933extern void new_rule PROTO((void)); /* initialize for a new rule */
934
935
936/* from file parse.y */
937
938/* Build the "<<EOF>>" action for the active start conditions. */
939extern void build_eof_action PROTO((void));
940
941/* Write out a message formatted with one string, pinpointing its location. */
942extern void format_pinpoint_message PROTO((char[], char[]));
943
944/* Write out a message, pinpointing its location. */
945extern void pinpoint_message PROTO((char[]));
946
947/* Write out a warning, pinpointing it at the given line. */
948extern void line_warning PROTO(( char[], int ));
949
950/* Write out a message, pinpointing it at the given line. */
951extern void line_pinpoint PROTO(( char[], int ));
952
953/* Report a formatted syntax error. */
954extern void format_synerr PROTO((char [], char[]));
955extern void synerr PROTO((char [])); /* report a syntax error */
956extern void format_warn PROTO((char [], char[]));
957extern void warn PROTO((char [])); /* report a warning */
958extern void yyerror PROTO((char [])); /* report a parse error */
959extern int yyparse PROTO((void)); /* the YACC parser */
960
961
962/* from file scan.l */
963
964/* The Flex-generated scanner for flex. */
965extern int flexscan PROTO((void));
966
967/* Open the given file (if NULL, stdin) for scanning. */
968extern void set_input_file PROTO((char*));
969
970/* Wrapup a file in the lexical analyzer. */
971extern int yywrap PROTO((void));
972
973
974/* from file sym.c */
975
976/* Add symbol and definitions to symbol table. */
977extern int addsym PROTO((register char[], char*, int, hash_table, int));
978
979/* Save the text of a character class. */
980extern void cclinstal PROTO ((Char [], int));
981
982/* Lookup the number associated with character class. */
983extern int ccllookup PROTO((Char []));
984
985/* Find symbol in symbol table. */
986extern struct hash_entry *findsym PROTO((register char[], hash_table, int ));
987
988extern void ndinstal PROTO((char[], Char[])); /* install a name definition */
989extern Char *ndlookup PROTO((char[])); /* lookup a name definition */
990
991/* Increase maximum number of SC's. */
992extern void scextend PROTO((void));
993extern void scinstal PROTO((char[], int)); /* make a start condition */
994
995/* Lookup the number associated with a start condition. */
996extern int sclookup PROTO((char[]));
997
998
999/* from file tblcmp.c */
1000
1001/* Build table entries for dfa state. */
1002extern void bldtbl PROTO((int[], int, int, int, int));
1003
1004extern void cmptmps PROTO((void)); /* compress template table entries */
1005extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */
1006/* Finds a space in the table for a state to be placed. */
1007extern int find_table_space PROTO((int*, int));
1008extern void inittbl PROTO((void)); /* initialize transition tables */
1009/* Make the default, "jam" table entries. */
1010extern void mkdeftbl PROTO((void));
1011
1012/* Create table entries for a state (or state fragment) which has
1013 * only one out-transition.
1014 */
1015extern void mk1tbl PROTO((int, int, int, int));
1016
1017/* Place a state into full speed transition table. */
1018extern void place_state PROTO((int*, int, int));
1019
1020/* Save states with only one out-transition to be processed later. */
1021extern void stack1 PROTO((int, int, int, int));
1022
1023
1024/* from file yylex.c */
1025
1026extern int yylex PROTO((void));