Commit | Line | Data |
---|---|---|
1c15e888 C |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
af359dea | 6 | * Vern Paxson of Lawrence Berkeley Laboratory. |
1c15e888 C |
7 | * |
8 | * The United States Government has rights in this work pursuant | |
9 | * to contract no. DE-AC03-76SF00098 between the United States | |
10 | * Department of Energy and the University of California. | |
11 | * | |
af359dea C |
12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
15 | * 1. Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions and the following disclaimer. | |
17 | * 2. Redistributions in binary form must reproduce the above copyright | |
18 | * notice, this list of conditions and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * 3. All advertising materials mentioning features or use of this software | |
21 | * must display the following acknowledgement: | |
22 | * This product includes software developed by the University of | |
23 | * California, Berkeley and its contributors. | |
24 | * 4. Neither the name of the University nor the names of its contributors | |
25 | * may be used to endorse or promote products derived from this software | |
26 | * without specific prior written permission. | |
1c15e888 | 27 | * |
af359dea C |
28 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
38 | * SUCH DAMAGE. | |
39 | * | |
40 | * @(#)flexdef.h 5.4 (Berkeley) 2/14/91 | |
1c15e888 C |
41 | */ |
42 | ||
43 | /* flexdef - definitions file for flex */ | |
44 | ||
45 | #ifndef FILE | |
46 | #include <stdio.h> | |
47 | #endif | |
48 | ||
49 | /* always be prepared to generate an 8-bit scanner */ | |
50 | #define FLEX_8_BIT_CHARS | |
51 | ||
52 | #ifdef FLEX_8_BIT_CHARS | |
53 | #define CSIZE 256 | |
54 | #define Char unsigned char | |
55 | #else | |
56 | #define Char char | |
57 | #define CSIZE 128 | |
58 | #endif | |
59 | ||
60 | /* size of input alphabet - should be size of ASCII set */ | |
61 | #ifndef DEFAULT_CSIZE | |
62 | #define DEFAULT_CSIZE 128 | |
63 | #endif | |
64 | ||
65 | #ifndef PROTO | |
66 | #ifdef __STDC__ | |
67 | #define PROTO(proto) proto | |
68 | #else | |
69 | #define PROTO(proto) () | |
70 | #endif | |
71 | #endif | |
72 | ||
73 | #include <string.h> | |
74 | ||
75 | #ifdef AMIGA | |
76 | #define bzero(s, n) setmem((char *)(s), n, '\0') | |
77 | #ifndef abs | |
78 | #define abs(x) ((x) < 0 ? -(x) : (x)) | |
79 | #endif | |
80 | #else | |
81 | #define bzero(s, n) (void) memset((char *)(s), '\0', n) | |
82 | #endif | |
83 | ||
84 | #ifdef VMS | |
85 | #define unlink delete | |
86 | #define SHORT_FILE_NAMES | |
87 | #endif | |
88 | ||
1c15e888 C |
89 | /* maximum line length we'll have to deal with */ |
90 | #define MAXLINE BUFSIZ | |
91 | ||
92 | /* maximum size of file name */ | |
93 | #define FILENAMESIZE 1024 | |
94 | ||
95 | #ifndef min | |
96 | #define min(x,y) ((x) < (y) ? (x) : (y)) | |
97 | #endif | |
98 | #ifndef max | |
99 | #define max(x,y) ((x) > (y) ? (x) : (y)) | |
100 | #endif | |
101 | ||
102 | #ifdef MS_DOS | |
103 | #ifndef abs | |
104 | #define abs(x) ((x) < 0 ? -(x) : (x)) | |
105 | #endif | |
106 | #define SHORT_FILE_NAMES | |
107 | #endif | |
108 | ||
109 | #define true 1 | |
110 | #define false 0 | |
111 | ||
112 | ||
113 | /* special chk[] values marking the slots taking by end-of-buffer and action | |
114 | * numbers | |
115 | */ | |
116 | #define EOB_POSITION -1 | |
117 | #define ACTION_POSITION -2 | |
118 | ||
119 | /* number of data items per line for -f output */ | |
120 | #define NUMDATAITEMS 10 | |
121 | ||
122 | /* number of lines of data in -f output before inserting a blank line for | |
123 | * readability. | |
124 | */ | |
125 | #define NUMDATALINES 10 | |
126 | ||
127 | /* transition_struct_out() definitions */ | |
128 | #define TRANS_STRUCT_PRINT_LENGTH 15 | |
129 | ||
130 | /* returns true if an nfa state has an epsilon out-transition slot | |
131 | * that can be used. This definition is currently not used. | |
132 | */ | |
133 | #define FREE_EPSILON(state) \ | |
134 | (transchar[state] == SYM_EPSILON && \ | |
135 | trans2[state] == NO_TRANSITION && \ | |
136 | finalst[state] != state) | |
137 | ||
138 | /* returns true if an nfa state has an epsilon out-transition character | |
139 | * and both slots are free | |
140 | */ | |
141 | #define SUPER_FREE_EPSILON(state) \ | |
142 | (transchar[state] == SYM_EPSILON && \ | |
143 | trans1[state] == NO_TRANSITION) \ | |
144 | ||
145 | /* maximum number of NFA states that can comprise a DFA state. It's real | |
146 | * big because if there's a lot of rules, the initial state will have a | |
147 | * huge epsilon closure. | |
148 | */ | |
149 | #define INITIAL_MAX_DFA_SIZE 750 | |
150 | #define MAX_DFA_SIZE_INCREMENT 750 | |
151 | ||
152 | ||
153 | /* a note on the following masks. They are used to mark accepting numbers | |
154 | * as being special. As such, they implicitly limit the number of accepting | |
155 | * numbers (i.e., rules) because if there are too many rules the rule numbers | |
156 | * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 == | |
157 | * 8192) so unlikely to actually cause any problems. A check is made in | |
158 | * new_rule() to ensure that this limit is not reached. | |
159 | */ | |
160 | ||
161 | /* mask to mark a trailing context accepting number */ | |
162 | #define YY_TRAILING_MASK 0x2000 | |
163 | ||
164 | /* mask to mark the accepting number of the "head" of a trailing context rule */ | |
165 | #define YY_TRAILING_HEAD_MASK 0x4000 | |
166 | ||
167 | /* maximum number of rules, as outlined in the above note */ | |
168 | #define MAX_RULE (YY_TRAILING_MASK - 1) | |
169 | ||
170 | ||
171 | /* NIL must be 0. If not, its special meaning when making equivalence classes | |
172 | * (it marks the representative of a given e.c.) will be unidentifiable | |
173 | */ | |
174 | #define NIL 0 | |
175 | ||
176 | #define JAM -1 /* to mark a missing DFA transition */ | |
177 | #define NO_TRANSITION NIL | |
178 | #define UNIQUE -1 /* marks a symbol as an e.c. representative */ | |
179 | #define INFINITY -1 /* for x{5,} constructions */ | |
180 | ||
181 | #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ | |
182 | #define MAX_CCLS_INCREMENT 100 | |
183 | ||
184 | /* size of table holding members of character classes */ | |
185 | #define INITIAL_MAX_CCL_TBL_SIZE 500 | |
186 | #define MAX_CCL_TBL_SIZE_INCREMENT 250 | |
187 | ||
188 | #define INITIAL_MAX_RULES 100 /* default maximum number of rules */ | |
189 | #define MAX_RULES_INCREMENT 100 | |
190 | ||
191 | #define INITIAL_MNS 2000 /* default maximum number of nfa states */ | |
192 | #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */ | |
193 | ||
194 | #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ | |
195 | #define MAX_DFAS_INCREMENT 1000 | |
196 | ||
197 | #define JAMSTATE -32766 /* marks a reference to the state that always jams */ | |
198 | ||
199 | /* enough so that if it's subtracted from an NFA state number, the result | |
200 | * is guaranteed to be negative | |
201 | */ | |
202 | #define MARKER_DIFFERENCE 32000 | |
203 | #define MAXIMUM_MNS 31999 | |
204 | ||
205 | /* maximum number of nxt/chk pairs for non-templates */ | |
206 | #define INITIAL_MAX_XPAIRS 2000 | |
207 | #define MAX_XPAIRS_INCREMENT 2000 | |
208 | ||
209 | /* maximum number of nxt/chk pairs needed for templates */ | |
210 | #define INITIAL_MAX_TEMPLATE_XPAIRS 2500 | |
211 | #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500 | |
212 | ||
213 | #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */ | |
214 | ||
215 | #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */ | |
216 | #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ | |
217 | ||
218 | #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ | |
219 | #define SAME_TRANS -1 /* transition is the same as "default" entry for state */ | |
220 | ||
221 | /* the following percentages are used to tune table compression: | |
222 | ||
223 | * the percentage the number of out-transitions a state must be of the | |
224 | * number of equivalence classes in order to be considered for table | |
225 | * compaction by using protos | |
226 | */ | |
227 | #define PROTO_SIZE_PERCENTAGE 15 | |
228 | ||
229 | /* the percentage the number of homogeneous out-transitions of a state | |
230 | * must be of the number of total out-transitions of the state in order | |
231 | * that the state's transition table is first compared with a potential | |
232 | * template of the most common out-transition instead of with the first | |
233 | * proto in the proto queue | |
234 | */ | |
235 | #define CHECK_COM_PERCENTAGE 50 | |
236 | ||
237 | /* the percentage the number of differences between a state's transition | |
238 | * table and the proto it was first compared with must be of the total | |
239 | * number of out-transitions of the state in order to keep the first | |
240 | * proto as a good match and not search any further | |
241 | */ | |
242 | #define FIRST_MATCH_DIFF_PERCENTAGE 10 | |
243 | ||
244 | /* the percentage the number of differences between a state's transition | |
245 | * table and the most similar proto must be of the state's total number | |
246 | * of out-transitions to use the proto as an acceptable close match | |
247 | */ | |
248 | #define ACCEPTABLE_DIFF_PERCENTAGE 50 | |
249 | ||
250 | /* the percentage the number of homogeneous out-transitions of a state | |
251 | * must be of the number of total out-transitions of the state in order | |
252 | * to consider making a template from the state | |
253 | */ | |
254 | #define TEMPLATE_SAME_PERCENTAGE 60 | |
255 | ||
256 | /* the percentage the number of differences between a state's transition | |
257 | * table and the most similar proto must be of the state's total number | |
258 | * of out-transitions to create a new proto from the state | |
259 | */ | |
260 | #define NEW_PROTO_DIFF_PERCENTAGE 20 | |
261 | ||
262 | /* the percentage the total number of out-transitions of a state must be | |
263 | * of the number of equivalence classes in order to consider trying to | |
264 | * fit the transition table into "holes" inside the nxt/chk table. | |
265 | */ | |
266 | #define INTERIOR_FIT_PERCENTAGE 15 | |
267 | ||
268 | /* size of region set aside to cache the complete transition table of | |
269 | * protos on the proto queue to enable quick comparisons | |
270 | */ | |
271 | #define PROT_SAVE_SIZE 2000 | |
272 | ||
273 | #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ | |
274 | ||
275 | /* maximum number of out-transitions a state can have that we'll rummage | |
276 | * around through the interior of the internal fast table looking for a | |
277 | * spot for it | |
278 | */ | |
279 | #define MAX_XTIONS_FULL_INTERIOR_FIT 4 | |
280 | ||
281 | /* maximum number of rules which will be reported as being associated | |
282 | * with a DFA state | |
283 | */ | |
284 | #define MAX_ASSOC_RULES 100 | |
285 | ||
286 | /* number that, if used to subscript an array, has a good chance of producing | |
287 | * an error; should be small enough to fit into a short | |
288 | */ | |
289 | #define BAD_SUBSCRIPT -32767 | |
290 | ||
291 | /* absolute value of largest number that can be stored in a short, with a | |
292 | * bit of slop thrown in for general paranoia. | |
293 | */ | |
294 | #define MAX_SHORT 32766 | |
295 | ||
296 | ||
297 | /* Declarations for global variables. */ | |
298 | ||
299 | /* variables for symbol tables: | |
300 | * sctbl - start-condition symbol table | |
301 | * ndtbl - name-definition symbol table | |
302 | * ccltab - character class text symbol table | |
303 | */ | |
304 | ||
305 | struct hash_entry | |
306 | { | |
307 | struct hash_entry *prev, *next; | |
308 | char *name; | |
309 | char *str_val; | |
310 | int int_val; | |
311 | } ; | |
312 | ||
313 | typedef struct hash_entry *hash_table[]; | |
314 | ||
315 | #define NAME_TABLE_HASH_SIZE 101 | |
316 | #define START_COND_HASH_SIZE 101 | |
317 | #define CCL_HASH_SIZE 101 | |
318 | ||
319 | extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; | |
320 | extern struct hash_entry *sctbl[START_COND_HASH_SIZE]; | |
321 | extern struct hash_entry *ccltab[CCL_HASH_SIZE]; | |
322 | ||
323 | ||
324 | /* variables for flags: | |
325 | * printstats - if true (-v), dump statistics | |
326 | * syntaxerror - true if a syntax error has been found | |
327 | * eofseen - true if we've seen an eof in the input file | |
328 | * ddebug - if true (-d), make a "debug" scanner | |
329 | * trace - if true (-T), trace processing | |
330 | * spprdflt - if true (-s), suppress the default rule | |
331 | * interactive - if true (-I), generate an interactive scanner | |
332 | * caseins - if true (-i), generate a case-insensitive scanner | |
333 | * useecs - if true (-Ce flag), use equivalence classes | |
334 | * fulltbl - if true (-Cf flag), don't compress the DFA state table | |
335 | * usemecs - if true (-Cm flag), use meta-equivalence classes | |
336 | * fullspd - if true (-F flag), use Jacobson method of table representation | |
337 | * gen_line_dirs - if true (i.e., no -L flag), generate #line directives | |
338 | * performance_report - if true (i.e., -p flag), generate a report relating | |
339 | * to scanner performance | |
340 | * backtrack_report - if true (i.e., -b flag), generate "lex.backtrack" file | |
341 | * listing backtracking states | |
342 | * csize - size of character set for the scanner we're generating; | |
343 | * 128 for 7-bit chars and 256 for 8-bit | |
344 | * yymore_used - if true, yymore() is used in input rules | |
345 | * reject - if true, generate backtracking tables for REJECT macro | |
346 | * real_reject - if true, scanner really uses REJECT (as opposed to just | |
347 | * having "reject" set for variable trailing context) | |
348 | * continued_action - true if this rule's action is to "fall through" to | |
349 | * the next rule's action (i.e., the '|' action) | |
350 | * yymore_really_used - has a REALLY_xxx value indicating whether a | |
351 | * %used or %notused was used with yymore() | |
352 | * reject_really_used - same for REJECT | |
353 | */ | |
354 | ||
355 | extern int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt; | |
356 | extern int interactive, caseins, useecs, fulltbl, usemecs; | |
357 | extern int fullspd, gen_line_dirs, performance_report, backtrack_report, csize; | |
358 | extern int yymore_used, reject, real_reject, continued_action; | |
359 | ||
360 | #define REALLY_NOT_DETERMINED 0 | |
361 | #define REALLY_USED 1 | |
362 | #define REALLY_NOT_USED 2 | |
363 | extern int yymore_really_used, reject_really_used; | |
364 | ||
365 | ||
366 | /* variables used in the flex input routines: | |
367 | * datapos - characters on current output line | |
368 | * dataline - number of contiguous lines of data in current data | |
369 | * statement. Used to generate readable -f output | |
370 | * linenum - current input line number | |
371 | * skelfile - the skeleton file | |
372 | * yyin - input file | |
373 | * temp_action_file - temporary file to hold actions | |
374 | * backtrack_file - file to summarize backtracking states to | |
375 | * infilename - name of input file | |
376 | * action_file_name - name of the temporary file | |
377 | * input_files - array holding names of input files | |
378 | * num_input_files - size of input_files array | |
379 | * program_name - name with which program was invoked | |
380 | */ | |
381 | ||
382 | extern int datapos, dataline, linenum; | |
383 | extern FILE *skelfile, *yyin, *temp_action_file, *backtrack_file; | |
384 | extern char *infilename; | |
385 | extern char *action_file_name; | |
386 | extern char **input_files; | |
387 | extern int num_input_files; | |
388 | extern char *program_name; | |
389 | ||
390 | ||
391 | /* variables for stack of states having only one out-transition: | |
392 | * onestate - state number | |
393 | * onesym - transition symbol | |
394 | * onenext - target state | |
395 | * onedef - default base entry | |
396 | * onesp - stack pointer | |
397 | */ | |
398 | ||
399 | extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; | |
400 | extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; | |
401 | ||
402 | ||
403 | /* variables for nfa machine data: | |
404 | * current_mns - current maximum on number of NFA states | |
405 | * num_rules - number of the last accepting state; also is number of | |
406 | * rules created so far | |
407 | * current_max_rules - current maximum number of rules | |
408 | * lastnfa - last nfa state number created | |
409 | * firstst - physically the first state of a fragment | |
410 | * lastst - last physical state of fragment | |
411 | * finalst - last logical state of fragment | |
412 | * transchar - transition character | |
413 | * trans1 - transition state | |
414 | * trans2 - 2nd transition state for epsilons | |
415 | * accptnum - accepting number | |
416 | * assoc_rule - rule associated with this NFA state (or 0 if none) | |
417 | * state_type - a STATE_xxx type identifying whether the state is part | |
418 | * of a normal rule, the leading state in a trailing context | |
419 | * rule (i.e., the state which marks the transition from | |
420 | * recognizing the text-to-be-matched to the beginning of | |
421 | * the trailing context), or a subsequent state in a trailing | |
422 | * context rule | |
423 | * rule_type - a RULE_xxx type identifying whether this a a ho-hum | |
424 | * normal rule or one which has variable head & trailing | |
425 | * context | |
426 | * rule_linenum - line number associated with rule | |
427 | */ | |
428 | ||
429 | extern int current_mns, num_rules, current_max_rules, lastnfa; | |
430 | extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; | |
431 | extern int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum; | |
432 | ||
433 | /* different types of states; values are useful as masks, as well, for | |
434 | * routines like check_trailing_context() | |
435 | */ | |
436 | #define STATE_NORMAL 0x1 | |
437 | #define STATE_TRAILING_CONTEXT 0x2 | |
438 | ||
439 | /* global holding current type of state we're making */ | |
440 | ||
441 | extern int current_state_type; | |
442 | ||
443 | /* different types of rules */ | |
444 | #define RULE_NORMAL 0 | |
445 | #define RULE_VARIABLE 1 | |
446 | ||
447 | /* true if the input rules include a rule with both variable-length head | |
448 | * and trailing context, false otherwise | |
449 | */ | |
450 | extern int variable_trailing_context_rules; | |
451 | ||
452 | ||
453 | /* variables for protos: | |
454 | * numtemps - number of templates created | |
455 | * numprots - number of protos created | |
456 | * protprev - backlink to a more-recently used proto | |
457 | * protnext - forward link to a less-recently used proto | |
458 | * prottbl - base/def table entry for proto | |
459 | * protcomst - common state of proto | |
460 | * firstprot - number of the most recently used proto | |
461 | * lastprot - number of the least recently used proto | |
462 | * protsave contains the entire state array for protos | |
463 | */ | |
464 | ||
465 | extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; | |
466 | extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; | |
467 | ||
468 | ||
469 | /* variables for managing equivalence classes: | |
470 | * numecs - number of equivalence classes | |
471 | * nextecm - forward link of Equivalence Class members | |
472 | * ecgroup - class number or backward link of EC members | |
473 | * nummecs - number of meta-equivalence classes (used to compress | |
474 | * templates) | |
475 | * tecfwd - forward link of meta-equivalence classes members | |
476 | * tecbck - backward link of MEC's | |
477 | * xlation - maps character codes to their translations, or nil if no %t table | |
478 | * num_xlations - number of different xlation values | |
479 | */ | |
480 | ||
481 | /* reserve enough room in the equivalence class arrays so that we | |
482 | * can use the CSIZE'th element to hold equivalence class information | |
483 | * for the NUL character. Later we'll move this information into | |
484 | * the 0th element. | |
485 | */ | |
486 | extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs; | |
487 | ||
488 | /* meta-equivalence classes are indexed starting at 1, so it's possible | |
489 | * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1 | |
490 | * slots total (since the arrays are 0-based). nextecm[] and ecgroup[] | |
491 | * don't require the extra position since they're indexed from 1 .. CSIZE - 1. | |
492 | */ | |
493 | extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1]; | |
494 | ||
495 | extern int *xlation; | |
496 | extern int num_xlations; | |
497 | ||
498 | ||
499 | /* variables for start conditions: | |
500 | * lastsc - last start condition created | |
501 | * current_max_scs - current limit on number of start conditions | |
502 | * scset - set of rules active in start condition | |
503 | * scbol - set of rules active only at the beginning of line in a s.c. | |
504 | * scxclu - true if start condition is exclusive | |
505 | * sceof - true if start condition has EOF rule | |
506 | * scname - start condition name | |
507 | * actvsc - stack of active start conditions for the current rule | |
508 | */ | |
509 | ||
510 | extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc; | |
511 | extern char **scname; | |
512 | ||
513 | ||
514 | /* variables for dfa machine data: | |
515 | * current_max_dfa_size - current maximum number of NFA states in DFA | |
516 | * current_max_xpairs - current maximum number of non-template xtion pairs | |
517 | * current_max_template_xpairs - current maximum number of template pairs | |
518 | * current_max_dfas - current maximum number DFA states | |
519 | * lastdfa - last dfa state number created | |
520 | * nxt - state to enter upon reading character | |
521 | * chk - check value to see if "nxt" applies | |
522 | * tnxt - internal nxt table for templates | |
523 | * base - offset into "nxt" for given state | |
524 | * def - where to go if "chk" disallows "nxt" entry | |
525 | * nultrans - NUL transition for each state | |
526 | * NUL_ec - equivalence class of the NUL character | |
527 | * tblend - last "nxt/chk" table entry being used | |
528 | * firstfree - first empty entry in "nxt/chk" table | |
529 | * dss - nfa state set for each dfa | |
530 | * dfasiz - size of nfa state set for each dfa | |
531 | * dfaacc - accepting set for each dfa state (or accepting number, if | |
532 | * -r is not given) | |
533 | * accsiz - size of accepting set for each dfa state | |
534 | * dhash - dfa state hash value | |
535 | * numas - number of DFA accepting states created; note that this | |
536 | * is not necessarily the same value as num_rules, which is the analogous | |
537 | * value for the NFA | |
538 | * numsnpairs - number of state/nextstate transition pairs | |
539 | * jambase - position in base/def where the default jam table starts | |
540 | * jamstate - state number corresponding to "jam" state | |
541 | * end_of_buffer_state - end-of-buffer dfa state number | |
542 | */ | |
543 | ||
544 | extern int current_max_dfa_size, current_max_xpairs; | |
545 | extern int current_max_template_xpairs, current_max_dfas; | |
546 | extern int lastdfa, lasttemp, *nxt, *chk, *tnxt; | |
547 | extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; | |
548 | extern union dfaacc_union | |
549 | { | |
550 | int *dfaacc_set; | |
551 | int dfaacc_state; | |
552 | } *dfaacc; | |
553 | extern int *accsiz, *dhash, numas; | |
554 | extern int numsnpairs, jambase, jamstate; | |
555 | extern int end_of_buffer_state; | |
556 | ||
557 | /* variables for ccl information: | |
558 | * lastccl - ccl index of the last created ccl | |
559 | * current_maxccls - current limit on the maximum number of unique ccl's | |
560 | * cclmap - maps a ccl index to its set pointer | |
561 | * ccllen - gives the length of a ccl | |
562 | * cclng - true for a given ccl if the ccl is negated | |
563 | * cclreuse - counts how many times a ccl is re-used | |
564 | * current_max_ccl_tbl_size - current limit on number of characters needed | |
565 | * to represent the unique ccl's | |
566 | * ccltbl - holds the characters in each ccl - indexed by cclmap | |
567 | */ | |
568 | ||
569 | extern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse; | |
570 | extern int current_max_ccl_tbl_size; | |
571 | extern Char *ccltbl; | |
572 | ||
573 | ||
574 | /* variables for miscellaneous information: | |
575 | * starttime - real-time when we started | |
576 | * endtime - real-time when we ended | |
577 | * nmstr - last NAME scanned by the scanner | |
578 | * sectnum - section number currently being parsed | |
579 | * nummt - number of empty nxt/chk table entries | |
580 | * hshcol - number of hash collisions detected by snstods | |
581 | * dfaeql - number of times a newly created dfa was equal to an old one | |
582 | * numeps - number of epsilon NFA states created | |
583 | * eps2 - number of epsilon states which have 2 out-transitions | |
584 | * num_reallocs - number of times it was necessary to realloc() a group | |
585 | * of arrays | |
586 | * tmpuses - number of DFA states that chain to templates | |
587 | * totnst - total number of NFA states used to make DFA states | |
588 | * peakpairs - peak number of transition pairs we had to store internally | |
589 | * numuniq - number of unique transitions | |
590 | * numdup - number of duplicate transitions | |
591 | * hshsave - number of hash collisions saved by checking number of states | |
592 | * num_backtracking - number of DFA states requiring back-tracking | |
593 | * bol_needed - whether scanner needs beginning-of-line recognition | |
594 | */ | |
595 | ||
596 | extern char *starttime, *endtime, nmstr[MAXLINE]; | |
597 | extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; | |
598 | extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; | |
599 | extern int num_backtracking, bol_needed; | |
600 | ||
601 | void *allocate_array(), *reallocate_array(); | |
602 | ||
603 | #define allocate_integer_array(size) \ | |
604 | (int *) allocate_array( size, sizeof( int ) ) | |
605 | ||
606 | #define reallocate_integer_array(array,size) \ | |
607 | (int *) reallocate_array( (void *) array, size, sizeof( int ) ) | |
608 | ||
609 | #define allocate_int_ptr_array(size) \ | |
610 | (int **) allocate_array( size, sizeof( int * ) ) | |
611 | ||
612 | #define allocate_char_ptr_array(size) \ | |
613 | (char **) allocate_array( size, sizeof( char * ) ) | |
614 | ||
615 | #define allocate_dfaacc_union(size) \ | |
616 | (union dfaacc_union *) \ | |
617 | allocate_array( size, sizeof( union dfaacc_union ) ) | |
618 | ||
619 | #define reallocate_int_ptr_array(array,size) \ | |
620 | (int **) reallocate_array( (void *) array, size, sizeof( int * ) ) | |
621 | ||
622 | #define reallocate_char_ptr_array(array,size) \ | |
623 | (char **) reallocate_array( (void *) array, size, sizeof( char * ) ) | |
624 | ||
625 | #define reallocate_dfaacc_union(array, size) \ | |
626 | (union dfaacc_union *) \ | |
627 | reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) ) | |
628 | ||
629 | #define allocate_character_array(size) \ | |
630 | (Char *) allocate_array( size, sizeof( Char ) ) | |
631 | ||
632 | #define reallocate_character_array(array,size) \ | |
633 | (Char *) reallocate_array( (void *) array, size, sizeof( Char ) ) | |
634 | ||
635 | ||
636 | /* used to communicate between scanner and parser. The type should really | |
637 | * be YYSTYPE, but we can't easily get our hands on it. | |
638 | */ | |
639 | extern int yylval; | |
640 | ||
641 | ||
642 | /* external functions that are cross-referenced among the flex source files */ | |
643 | ||
644 | ||
645 | /* from file ccl.c */ | |
646 | ||
647 | extern void ccladd PROTO((int, int)); /* Add a single character to a ccl */ | |
648 | extern int cclinit PROTO(()); /* make an empty ccl */ | |
649 | extern void cclnegate PROTO((int)); /* negate a ccl */ | |
650 | ||
651 | /* list the members of a set of characters in CCL form */ | |
652 | extern void list_character_set PROTO((FILE*, int[])); | |
653 | ||
654 | ||
655 | /* from file dfa.c */ | |
656 | ||
657 | /* increase the maximum number of dfas */ | |
658 | extern void increase_max_dfas PROTO(()); | |
659 | ||
660 | extern void ntod PROTO(()); /* convert a ndfa to a dfa */ | |
661 | ||
662 | ||
663 | /* from file ecs.c */ | |
664 | ||
665 | /* convert character classes to set of equivalence classes */ | |
666 | extern void ccl2ecl PROTO(()); | |
667 | ||
668 | /* associate equivalence class numbers with class members */ | |
669 | extern int cre8ecs PROTO((int[], int[], int)); | |
670 | ||
671 | /* associate equivalence class numbers using %t table */ | |
672 | extern int ecs_from_xlation PROTO((int[])); | |
673 | ||
674 | /* update equivalence classes based on character class transitions */ | |
675 | extern void mkeccl PROTO((Char[], int, int[], int[], int, int)); | |
676 | ||
677 | /* create equivalence class for single character */ | |
678 | extern void mkechar PROTO((int, int[], int[])); | |
679 | ||
680 | ||
681 | /* from file gen.c */ | |
682 | ||
683 | extern void make_tables PROTO(()); /* generate transition tables */ | |
684 | ||
685 | ||
686 | /* from file main.c */ | |
687 | ||
688 | extern void flexend PROTO((int)); | |
689 | ||
690 | ||
691 | /* from file misc.c */ | |
692 | ||
693 | /* write out the actions from the temporary file to lex.yy.c */ | |
694 | extern void action_out PROTO(()); | |
695 | ||
696 | /* true if a string is all lower case */ | |
697 | extern int all_lower PROTO((register Char *)); | |
698 | ||
699 | /* true if a string is all upper case */ | |
700 | extern int all_upper PROTO((register Char *)); | |
701 | ||
702 | /* bubble sort an integer array */ | |
703 | extern void bubble PROTO((int [], int)); | |
704 | ||
705 | /* shell sort a character array */ | |
706 | extern void cshell PROTO((Char [], int, int)); | |
707 | ||
708 | extern void dataend PROTO(()); /* finish up a block of data declarations */ | |
709 | ||
710 | /* report an error message and terminate */ | |
711 | extern void flexerror PROTO((char[])); | |
712 | ||
713 | /* report a fatal error message and terminate */ | |
714 | extern void flexfatal PROTO((char[])); | |
715 | ||
716 | /* report an error message formatted with one integer argument */ | |
717 | extern void lerrif PROTO((char[], int)); | |
718 | ||
719 | /* report an error message formatted with one string argument */ | |
720 | extern void lerrsf PROTO((char[], char[])); | |
721 | ||
722 | /* spit out a "# line" statement */ | |
723 | extern void line_directive_out PROTO((FILE*)); | |
724 | ||
725 | /* generate a data statment for a two-dimensional array */ | |
726 | extern void mk2data PROTO((int)); | |
727 | ||
728 | extern void mkdata PROTO((int)); /* generate a data statement */ | |
729 | ||
730 | /* return the integer represented by a string of digits */ | |
731 | extern int myctoi PROTO((Char [])); | |
732 | ||
733 | /* write out one section of the skeleton file */ | |
734 | extern void skelout PROTO(()); | |
735 | ||
736 | /* output a yy_trans_info structure */ | |
737 | extern void transition_struct_out PROTO((int, int)); | |
738 | ||
739 | ||
740 | /* from file nfa.c */ | |
741 | ||
742 | /* add an accepting state to a machine */ | |
743 | extern void add_accept PROTO((int, int)); | |
744 | ||
745 | /* make a given number of copies of a singleton machine */ | |
746 | extern int copysingl PROTO((int, int)); | |
747 | ||
748 | /* debugging routine to write out an nfa */ | |
749 | extern void dumpnfa PROTO((int)); | |
750 | ||
751 | /* finish up the processing for a rule */ | |
752 | extern void finish_rule PROTO((int, int, int, int)); | |
753 | ||
754 | /* connect two machines together */ | |
755 | extern int link_machines PROTO((int, int)); | |
756 | ||
757 | /* mark each "beginning" state in a machine as being a "normal" (i.e., | |
758 | * not trailing context associated) state | |
759 | */ | |
760 | extern void mark_beginning_as_normal PROTO((register int)); | |
761 | ||
762 | /* make a machine that branches to two machines */ | |
763 | extern int mkbranch PROTO((int, int)); | |
764 | ||
765 | extern int mkclos PROTO((int)); /* convert a machine into a closure */ | |
766 | extern int mkopt PROTO((int)); /* make a machine optional */ | |
767 | ||
768 | /* make a machine that matches either one of two machines */ | |
769 | extern int mkor PROTO((int, int)); | |
770 | ||
771 | /* convert a machine into a positive closure */ | |
772 | extern int mkposcl PROTO((int)); | |
773 | ||
774 | extern int mkrep PROTO((int, int, int)); /* make a replicated machine */ | |
775 | ||
776 | /* create a state with a transition on a given symbol */ | |
777 | extern int mkstate PROTO((int)); | |
778 | ||
779 | extern void new_rule PROTO(()); /* initialize for a new rule */ | |
780 | ||
781 | ||
782 | /* from file parse.y */ | |
783 | ||
784 | /* write out a message formatted with one string, pinpointing its location */ | |
785 | extern void format_pinpoint_message PROTO((char[], char[])); | |
786 | ||
787 | /* write out a message, pinpointing its location */ | |
788 | extern void pinpoint_message PROTO((char[])); | |
789 | ||
790 | extern void synerr PROTO((char [])); /* report a syntax error */ | |
791 | extern int yyparse PROTO(()); /* the YACC parser */ | |
792 | ||
793 | ||
794 | /* from file scan.l */ | |
795 | ||
796 | extern int flexscan PROTO(()); /* the Flex-generated scanner for flex */ | |
797 | ||
798 | /* open the given file (if NULL, stdin) for scanning */ | |
799 | extern void set_input_file PROTO((char*)); | |
800 | ||
801 | extern int yywrap PROTO(()); /* wrapup a file in the lexical analyzer */ | |
802 | ||
803 | ||
804 | /* from file sym.c */ | |
805 | ||
806 | /* save the text of a character class */ | |
807 | extern void cclinstal PROTO ((Char [], int)); | |
808 | ||
809 | /* lookup the number associated with character class */ | |
810 | extern int ccllookup PROTO((Char [])); | |
811 | ||
812 | extern void ndinstal PROTO((char[], Char[])); /* install a name definition */ | |
813 | extern void scinstal PROTO((char[], int)); /* make a start condition */ | |
814 | ||
815 | /* lookup the number associated with a start condition */ | |
816 | extern int sclookup PROTO((char[])); | |
817 | ||
818 | ||
819 | /* from file tblcmp.c */ | |
820 | ||
821 | /* build table entries for dfa state */ | |
822 | extern void bldtbl PROTO((int[], int, int, int, int)); | |
823 | ||
824 | extern void cmptmps PROTO(()); /* compress template table entries */ | |
825 | extern void inittbl PROTO(()); /* initialize transition tables */ | |
826 | extern void mkdeftbl PROTO(()); /* make the default, "jam" table entries */ | |
827 | ||
828 | /* create table entries for a state (or state fragment) which has | |
829 | * only one out-transition */ | |
830 | extern void mk1tbl PROTO((int, int, int, int)); | |
831 | ||
832 | /* place a state into full speed transition table */ | |
833 | extern void place_state PROTO((int*, int, int)); | |
834 | ||
835 | /* save states with only one out-transition to be processed later */ | |
836 | extern void stack1 PROTO((int, int, int, int)); | |
837 | ||
838 | ||
839 | /* from file yylex.c */ | |
840 | ||
841 | extern int yylex PROTO(()); | |
842 | ||
843 | ||
844 | /* The Unix kernel calls used here */ | |
845 | ||
846 | extern int read PROTO((int, char*, int)); | |
847 | extern int unlink PROTO((char*)); | |
848 | extern int write PROTO((int, char*, int)); |