Commit | Line | Data |
---|---|---|
86041518 WJ |
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 | |
6 | * Vern Paxson of Lawrence Berkeley Laboratory. | |
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 | * | |
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. | |
27 | * | |
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 | ||
41 | #ifndef lint | |
42 | char copyright[] = | |
43 | "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ | |
44 | All rights reserved.\n"; | |
45 | #endif /* not lint */ | |
46 | ||
47 | #ifndef lint | |
48 | static char sccsid[] = "@(#)main.c 5.3 (Berkeley) 6/18/90"; | |
49 | #endif /* not lint */ | |
50 | ||
51 | /* flex - tool to generate fast lexical analyzers */ | |
52 | ||
53 | #include "flexdef.h" | |
54 | #include "pathnames.h" | |
55 | ||
56 | static char flex_version[] = "2.3"; | |
57 | ||
58 | ||
59 | /* declare functions that have forward references */ | |
60 | ||
61 | void flexinit PROTO((int, char**)); | |
62 | void readin PROTO(()); | |
63 | void set_up_initial_allocations PROTO(()); | |
64 | ||
65 | ||
66 | /* these globals are all defined and commented in flexdef.h */ | |
67 | int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt; | |
68 | int interactive, caseins, useecs, fulltbl, usemecs; | |
69 | int fullspd, gen_line_dirs, performance_report, backtrack_report, csize; | |
70 | int yymore_used, reject, real_reject, continued_action; | |
71 | int yymore_really_used, reject_really_used; | |
72 | int datapos, dataline, linenum; | |
73 | FILE *skelfile = NULL; | |
74 | char *infilename = NULL; | |
75 | int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; | |
76 | int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; | |
77 | int current_mns, num_rules, current_max_rules, lastnfa; | |
78 | int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; | |
79 | int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum; | |
80 | int current_state_type; | |
81 | int variable_trailing_context_rules; | |
82 | int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; | |
83 | int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; | |
84 | int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1]; | |
85 | int tecbck[CSIZE + 1]; | |
86 | int *xlation = (int *) 0; | |
87 | int num_xlations; | |
88 | int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc; | |
89 | char **scname; | |
90 | int current_max_dfa_size, current_max_xpairs; | |
91 | int current_max_template_xpairs, current_max_dfas; | |
92 | int lastdfa, *nxt, *chk, *tnxt; | |
93 | int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; | |
94 | union dfaacc_union *dfaacc; | |
95 | int *accsiz, *dhash, numas; | |
96 | int numsnpairs, jambase, jamstate; | |
97 | int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse; | |
98 | int current_max_ccl_tbl_size; | |
99 | Char *ccltbl; | |
100 | char *starttime, *endtime, nmstr[MAXLINE]; | |
101 | int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; | |
102 | int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; | |
103 | int num_backtracking, bol_needed; | |
104 | FILE *temp_action_file; | |
105 | FILE *backtrack_file; | |
106 | int end_of_buffer_state; | |
107 | char *action_file_name = NULL; | |
108 | char **input_files; | |
109 | int num_input_files; | |
110 | char *program_name; | |
111 | ||
112 | #ifndef SHORT_FILE_NAMES | |
113 | static char *outfile = "lex.yy.c"; | |
114 | #else | |
115 | static char *outfile = "lexyy.c"; | |
116 | #endif | |
117 | static int outfile_created = 0; | |
118 | static int use_stdout; | |
119 | static char *skelname = NULL; | |
120 | ||
121 | ||
122 | int main( argc, argv ) | |
123 | int argc; | |
124 | char **argv; | |
125 | ||
126 | { | |
127 | flexinit( argc, argv ); | |
128 | ||
129 | readin(); | |
130 | ||
131 | if ( syntaxerror ) | |
132 | flexend( 1 ); | |
133 | ||
134 | if ( yymore_really_used == REALLY_USED ) | |
135 | yymore_used = true; | |
136 | else if ( yymore_really_used == REALLY_NOT_USED ) | |
137 | yymore_used = false; | |
138 | ||
139 | if ( reject_really_used == REALLY_USED ) | |
140 | reject = true; | |
141 | else if ( reject_really_used == REALLY_NOT_USED ) | |
142 | reject = false; | |
143 | ||
144 | if ( performance_report ) | |
145 | { | |
146 | if ( interactive ) | |
147 | fprintf( stderr, | |
148 | "-I (interactive) entails a minor performance penalty\n" ); | |
149 | ||
150 | if ( yymore_used ) | |
151 | fprintf( stderr, "yymore() entails a minor performance penalty\n" ); | |
152 | ||
153 | if ( reject ) | |
154 | fprintf( stderr, "REJECT entails a large performance penalty\n" ); | |
155 | ||
156 | if ( variable_trailing_context_rules ) | |
157 | fprintf( stderr, | |
158 | "Variable trailing context rules entail a large performance penalty\n" ); | |
159 | } | |
160 | ||
161 | if ( reject ) | |
162 | real_reject = true; | |
163 | ||
164 | if ( variable_trailing_context_rules ) | |
165 | reject = true; | |
166 | ||
167 | if ( (fulltbl || fullspd) && reject ) | |
168 | { | |
169 | if ( real_reject ) | |
170 | flexerror( "REJECT cannot be used with -f or -F" ); | |
171 | else | |
172 | flexerror( | |
173 | "variable trailing context rules cannot be used with -f or -F" ); | |
174 | } | |
175 | ||
176 | ntod(); | |
177 | ||
178 | /* generate the C state transition tables from the DFA */ | |
179 | make_tables(); | |
180 | ||
181 | /* note, flexend does not return. It exits with its argument as status. */ | |
182 | ||
183 | flexend( 0 ); | |
184 | ||
185 | /*NOTREACHED*/ | |
186 | } | |
187 | ||
188 | ||
189 | /* flexend - terminate flex | |
190 | * | |
191 | * synopsis | |
192 | * int status; | |
193 | * flexend( status ); | |
194 | * | |
195 | * status is exit status. | |
196 | * | |
197 | * note | |
198 | * This routine does not return. | |
199 | */ | |
200 | ||
201 | void flexend( status ) | |
202 | int status; | |
203 | ||
204 | { | |
205 | int tblsiz; | |
206 | char *flex_gettime(); | |
207 | ||
208 | if ( skelfile != NULL ) | |
209 | { | |
210 | if ( ferror( skelfile ) ) | |
211 | flexfatal( "error occurred when writing skeleton file" ); | |
212 | ||
213 | else if ( fclose( skelfile ) ) | |
214 | flexfatal( "error occurred when closing skeleton file" ); | |
215 | } | |
216 | ||
217 | if ( temp_action_file ) | |
218 | { | |
219 | if ( ferror( temp_action_file ) ) | |
220 | flexfatal( "error occurred when writing temporary action file" ); | |
221 | ||
222 | else if ( fclose( temp_action_file ) ) | |
223 | flexfatal( "error occurred when closing temporary action file" ); | |
224 | ||
225 | else if ( unlink( action_file_name ) ) | |
226 | flexfatal( "error occurred when deleting temporary action file" ); | |
227 | } | |
228 | ||
229 | if ( status != 0 && outfile_created ) | |
230 | { | |
231 | if ( ferror( stdout ) ) | |
232 | flexfatal( "error occurred when writing output file" ); | |
233 | ||
234 | else if ( fclose( stdout ) ) | |
235 | flexfatal( "error occurred when closing output file" ); | |
236 | ||
237 | else if ( unlink( outfile ) ) | |
238 | flexfatal( "error occurred when deleting output file" ); | |
239 | } | |
240 | ||
241 | if ( backtrack_report && backtrack_file ) | |
242 | { | |
243 | if ( num_backtracking == 0 ) | |
244 | fprintf( backtrack_file, "No backtracking.\n" ); | |
245 | else if ( fullspd || fulltbl ) | |
246 | fprintf( backtrack_file, | |
247 | "%d backtracking (non-accepting) states.\n", | |
248 | num_backtracking ); | |
249 | else | |
250 | fprintf( backtrack_file, "Compressed tables always backtrack.\n" ); | |
251 | ||
252 | if ( ferror( backtrack_file ) ) | |
253 | flexfatal( "error occurred when writing backtracking file" ); | |
254 | ||
255 | else if ( fclose( backtrack_file ) ) | |
256 | flexfatal( "error occurred when closing backtracking file" ); | |
257 | } | |
258 | ||
259 | if ( printstats ) | |
260 | { | |
261 | endtime = flex_gettime(); | |
262 | ||
263 | fprintf( stderr, "%s version %s usage statistics:\n", program_name, | |
264 | flex_version ); | |
265 | fprintf( stderr, " started at %s, finished at %s\n", | |
266 | starttime, endtime ); | |
267 | ||
268 | fprintf( stderr, " scanner options: -" ); | |
269 | ||
270 | if ( backtrack_report ) | |
271 | putc( 'b', stderr ); | |
272 | if ( ddebug ) | |
273 | putc( 'd', stderr ); | |
274 | if ( interactive ) | |
275 | putc( 'I', stderr ); | |
276 | if ( caseins ) | |
277 | putc( 'i', stderr ); | |
278 | if ( ! gen_line_dirs ) | |
279 | putc( 'L', stderr ); | |
280 | if ( performance_report ) | |
281 | putc( 'p', stderr ); | |
282 | if ( spprdflt ) | |
283 | putc( 's', stderr ); | |
284 | if ( use_stdout ) | |
285 | putc( 't', stderr ); | |
286 | if ( trace ) | |
287 | putc( 'T', stderr ); | |
288 | if ( printstats ) | |
289 | putc( 'v', stderr ); /* always true! */ | |
290 | if ( csize == 256 ) | |
291 | putc( '8', stderr ); | |
292 | ||
293 | fprintf( stderr, " -C" ); | |
294 | ||
295 | if ( fulltbl ) | |
296 | putc( 'f', stderr ); | |
297 | if ( fullspd ) | |
298 | putc( 'F', stderr ); | |
299 | if ( useecs ) | |
300 | putc( 'e', stderr ); | |
301 | if ( usemecs ) | |
302 | putc( 'm', stderr ); | |
303 | ||
304 | if ( strcmp( skelname, _PATH_SKELETONFILE ) ) | |
305 | fprintf( stderr, " -S%s", skelname ); | |
306 | ||
307 | putc( '\n', stderr ); | |
308 | ||
309 | fprintf( stderr, " %d/%d NFA states\n", lastnfa, current_mns ); | |
310 | fprintf( stderr, " %d/%d DFA states (%d words)\n", lastdfa, | |
311 | current_max_dfas, totnst ); | |
312 | fprintf( stderr, | |
313 | " %d rules\n", num_rules - 1 /* - 1 for def. rule */ ); | |
314 | ||
315 | if ( num_backtracking == 0 ) | |
316 | fprintf( stderr, " No backtracking\n" ); | |
317 | else if ( fullspd || fulltbl ) | |
318 | fprintf( stderr, " %d backtracking (non-accepting) states\n", | |
319 | num_backtracking ); | |
320 | else | |
321 | fprintf( stderr, " compressed tables always backtrack\n" ); | |
322 | ||
323 | if ( bol_needed ) | |
324 | fprintf( stderr, " Beginning-of-line patterns used\n" ); | |
325 | ||
326 | fprintf( stderr, " %d/%d start conditions\n", lastsc, | |
327 | current_max_scs ); | |
328 | fprintf( stderr, " %d epsilon states, %d double epsilon states\n", | |
329 | numeps, eps2 ); | |
330 | ||
331 | if ( lastccl == 0 ) | |
332 | fprintf( stderr, " no character classes\n" ); | |
333 | else | |
334 | fprintf( stderr, | |
335 | " %d/%d character classes needed %d/%d words of storage, %d reused\n", | |
336 | lastccl, current_maxccls, | |
337 | cclmap[lastccl] + ccllen[lastccl], | |
338 | current_max_ccl_tbl_size, cclreuse ); | |
339 | ||
340 | fprintf( stderr, " %d state/nextstate pairs created\n", numsnpairs ); | |
341 | fprintf( stderr, " %d/%d unique/duplicate transitions\n", | |
342 | numuniq, numdup ); | |
343 | ||
344 | if ( fulltbl ) | |
345 | { | |
346 | tblsiz = lastdfa * numecs; | |
347 | fprintf( stderr, " %d table entries\n", tblsiz ); | |
348 | } | |
349 | ||
350 | else | |
351 | { | |
352 | tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend; | |
353 | ||
354 | fprintf( stderr, " %d/%d base-def entries created\n", | |
355 | lastdfa + numtemps, current_max_dfas ); | |
356 | fprintf( stderr, " %d/%d (peak %d) nxt-chk entries created\n", | |
357 | tblend, current_max_xpairs, peakpairs ); | |
358 | fprintf( stderr, | |
359 | " %d/%d (peak %d) template nxt-chk entries created\n", | |
360 | numtemps * nummecs, current_max_template_xpairs, | |
361 | numtemps * numecs ); | |
362 | fprintf( stderr, " %d empty table entries\n", nummt ); | |
363 | fprintf( stderr, " %d protos created\n", numprots ); | |
364 | fprintf( stderr, " %d templates created, %d uses\n", | |
365 | numtemps, tmpuses ); | |
366 | } | |
367 | ||
368 | if ( useecs ) | |
369 | { | |
370 | tblsiz = tblsiz + csize; | |
371 | fprintf( stderr, " %d/%d equivalence classes created\n", | |
372 | numecs, csize ); | |
373 | } | |
374 | ||
375 | if ( usemecs ) | |
376 | { | |
377 | tblsiz = tblsiz + numecs; | |
378 | fprintf( stderr, " %d/%d meta-equivalence classes created\n", | |
379 | nummecs, csize ); | |
380 | } | |
381 | ||
382 | fprintf( stderr, " %d (%d saved) hash collisions, %d DFAs equal\n", | |
383 | hshcol, hshsave, dfaeql ); | |
384 | fprintf( stderr, " %d sets of reallocations needed\n", num_reallocs ); | |
385 | fprintf( stderr, " %d total table entries needed\n", tblsiz ); | |
386 | } | |
387 | ||
388 | #ifndef VMS | |
389 | exit( status ); | |
390 | #else | |
391 | exit( status + 1 ); | |
392 | #endif | |
393 | } | |
394 | ||
395 | ||
396 | /* flexinit - initialize flex | |
397 | * | |
398 | * synopsis | |
399 | * int argc; | |
400 | * char **argv; | |
401 | * flexinit( argc, argv ); | |
402 | */ | |
403 | ||
404 | void flexinit( argc, argv ) | |
405 | int argc; | |
406 | char **argv; | |
407 | ||
408 | { | |
409 | int i, sawcmpflag; | |
410 | char *arg, *flex_gettime(), *mktemp(); | |
411 | ||
412 | printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; | |
413 | backtrack_report = performance_report = ddebug = fulltbl = fullspd = false; | |
414 | yymore_used = continued_action = reject = false; | |
415 | yymore_really_used = reject_really_used = false; | |
416 | gen_line_dirs = usemecs = useecs = true; | |
417 | ||
418 | sawcmpflag = false; | |
419 | use_stdout = false; | |
420 | ||
421 | csize = DEFAULT_CSIZE; | |
422 | ||
423 | program_name = argv[0]; | |
424 | ||
425 | /* read flags */ | |
426 | for ( --argc, ++argv; argc ; --argc, ++argv ) | |
427 | { | |
428 | if ( argv[0][0] != '-' || argv[0][1] == '\0' ) | |
429 | break; | |
430 | ||
431 | arg = argv[0]; | |
432 | ||
433 | for ( i = 1; arg[i] != '\0'; ++i ) | |
434 | switch ( arg[i] ) | |
435 | { | |
436 | case 'b': | |
437 | backtrack_report = true; | |
438 | break; | |
439 | ||
440 | case 'c': | |
441 | fprintf( stderr, | |
442 | "%s: Assuming use of deprecated -c flag is really intended to be -C\n", | |
443 | program_name ); | |
444 | ||
445 | /* fall through */ | |
446 | ||
447 | case 'C': | |
448 | if ( i != 1 ) | |
449 | flexerror( "-C flag must be given separately" ); | |
450 | ||
451 | if ( ! sawcmpflag ) | |
452 | { | |
453 | useecs = false; | |
454 | usemecs = false; | |
455 | fulltbl = false; | |
456 | sawcmpflag = true; | |
457 | } | |
458 | ||
459 | for ( ++i; arg[i] != '\0'; ++i ) | |
460 | switch ( arg[i] ) | |
461 | { | |
462 | case 'e': | |
463 | useecs = true; | |
464 | break; | |
465 | ||
466 | case 'F': | |
467 | fullspd = true; | |
468 | break; | |
469 | ||
470 | case 'f': | |
471 | fulltbl = true; | |
472 | break; | |
473 | ||
474 | case 'm': | |
475 | usemecs = true; | |
476 | break; | |
477 | ||
478 | default: | |
479 | lerrif( "unknown -C option '%c'", | |
480 | (int) arg[i] ); | |
481 | break; | |
482 | } | |
483 | ||
484 | goto get_next_arg; | |
485 | ||
486 | case 'd': | |
487 | ddebug = true; | |
488 | break; | |
489 | ||
490 | case 'f': | |
491 | useecs = usemecs = false; | |
492 | fulltbl = true; | |
493 | break; | |
494 | ||
495 | case 'F': | |
496 | useecs = usemecs = false; | |
497 | fullspd = true; | |
498 | break; | |
499 | ||
500 | case 'I': | |
501 | interactive = true; | |
502 | break; | |
503 | ||
504 | case 'i': | |
505 | caseins = true; | |
506 | break; | |
507 | ||
508 | case 'L': | |
509 | gen_line_dirs = false; | |
510 | break; | |
511 | ||
512 | case 'n': | |
513 | /* stupid do-nothing deprecated option */ | |
514 | break; | |
515 | ||
516 | case 'p': | |
517 | performance_report = true; | |
518 | break; | |
519 | ||
520 | case 'S': | |
521 | if ( i != 1 ) | |
522 | flexerror( "-S flag must be given separately" ); | |
523 | ||
524 | skelname = arg + i + 1; | |
525 | goto get_next_arg; | |
526 | ||
527 | case 's': | |
528 | spprdflt = true; | |
529 | break; | |
530 | ||
531 | case 't': | |
532 | use_stdout = true; | |
533 | break; | |
534 | ||
535 | case 'T': | |
536 | trace = true; | |
537 | break; | |
538 | ||
539 | case 'v': | |
540 | printstats = true; | |
541 | break; | |
542 | ||
543 | case '8': | |
544 | csize = CSIZE; | |
545 | break; | |
546 | ||
547 | default: | |
548 | lerrif( "unknown flag '%c'", (int) arg[i] ); | |
549 | break; | |
550 | } | |
551 | ||
552 | get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */ | |
553 | ; | |
554 | } | |
555 | ||
556 | if ( (fulltbl || fullspd) && usemecs ) | |
557 | flexerror( "full table and -Cm don't make sense together" ); | |
558 | ||
559 | if ( (fulltbl || fullspd) && interactive ) | |
560 | flexerror( "full table and -I are (currently) incompatible" ); | |
561 | ||
562 | if ( fulltbl && fullspd ) | |
563 | flexerror( "full table and -F are mutually exclusive" ); | |
564 | ||
565 | if ( ! skelname ) | |
566 | { | |
567 | static char skeleton_name_storage[400]; | |
568 | ||
569 | skelname = skeleton_name_storage; | |
570 | (void) strcpy( skelname, _PATH_SKELETONFILE ); | |
571 | } | |
572 | ||
573 | if ( ! use_stdout ) | |
574 | { | |
575 | FILE *prev_stdout = freopen( outfile, "w", stdout ); | |
576 | ||
577 | if ( prev_stdout == NULL ) | |
578 | lerrsf( "could not create %s", outfile ); | |
579 | ||
580 | outfile_created = 1; | |
581 | } | |
582 | ||
583 | num_input_files = argc; | |
584 | input_files = argv; | |
585 | set_input_file( num_input_files > 0 ? input_files[0] : NULL ); | |
586 | ||
587 | if ( backtrack_report ) | |
588 | { | |
589 | #ifndef SHORT_FILE_NAMES | |
590 | backtrack_file = fopen( "lex.backtrack", "w" ); | |
591 | #else | |
592 | backtrack_file = fopen( "lex.bck", "w" ); | |
593 | #endif | |
594 | ||
595 | if ( backtrack_file == NULL ) | |
596 | flexerror( "could not create lex.backtrack" ); | |
597 | } | |
598 | ||
599 | else | |
600 | backtrack_file = NULL; | |
601 | ||
602 | ||
603 | lastccl = 0; | |
604 | lastsc = 0; | |
605 | ||
606 | /* initialize the statistics */ | |
607 | starttime = flex_gettime(); | |
608 | ||
609 | if ( (skelfile = fopen( skelname, "r" )) == NULL ) | |
610 | lerrsf( "can't open skeleton file %s", skelname ); | |
611 | ||
612 | #ifdef SYS_V | |
613 | action_file_name = tmpnam( NULL ); | |
614 | #endif | |
615 | ||
616 | if ( action_file_name == NULL ) | |
617 | { | |
618 | static char temp_action_file_name[32]; | |
619 | ||
620 | #ifndef SHORT_FILE_NAMES | |
621 | (void) strcpy( temp_action_file_name, "/tmp/flexXXXXXX" ); | |
622 | #else | |
623 | (void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" ); | |
624 | #endif | |
625 | (void) mktemp( temp_action_file_name ); | |
626 | ||
627 | action_file_name = temp_action_file_name; | |
628 | } | |
629 | ||
630 | if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL ) | |
631 | lerrsf( "can't open temporary action file %s", action_file_name ); | |
632 | ||
633 | lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0; | |
634 | numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; | |
635 | numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; | |
636 | num_backtracking = onesp = numprots = 0; | |
637 | variable_trailing_context_rules = bol_needed = false; | |
638 | ||
639 | linenum = sectnum = 1; | |
640 | firstprot = NIL; | |
641 | ||
642 | /* used in mkprot() so that the first proto goes in slot 1 | |
643 | * of the proto queue | |
644 | */ | |
645 | lastprot = 1; | |
646 | ||
647 | if ( useecs ) | |
648 | { /* set up doubly-linked equivalence classes */ | |
649 | /* We loop all the way up to csize, since ecgroup[csize] is the | |
650 | * position used for NUL characters | |
651 | */ | |
652 | ecgroup[1] = NIL; | |
653 | ||
654 | for ( i = 2; i <= csize; ++i ) | |
655 | { | |
656 | ecgroup[i] = i - 1; | |
657 | nextecm[i - 1] = i; | |
658 | } | |
659 | ||
660 | nextecm[csize] = NIL; | |
661 | } | |
662 | ||
663 | else | |
664 | { /* put everything in its own equivalence class */ | |
665 | for ( i = 1; i <= csize; ++i ) | |
666 | { | |
667 | ecgroup[i] = i; | |
668 | nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ | |
669 | } | |
670 | } | |
671 | ||
672 | set_up_initial_allocations(); | |
673 | } | |
674 | ||
675 | ||
676 | /* readin - read in the rules section of the input file(s) | |
677 | * | |
678 | * synopsis | |
679 | * readin(); | |
680 | */ | |
681 | ||
682 | void readin() | |
683 | ||
684 | { | |
685 | skelout(); | |
686 | ||
687 | if ( ddebug ) | |
688 | puts( "#define FLEX_DEBUG" ); | |
689 | ||
690 | if ( csize == 256 ) | |
691 | puts( "#define YY_CHAR unsigned char" ); | |
692 | else | |
693 | puts( "#define YY_CHAR char" ); | |
694 | ||
695 | line_directive_out( stdout ); | |
696 | ||
697 | if ( yyparse() ) | |
698 | { | |
699 | pinpoint_message( "fatal parse error" ); | |
700 | flexend( 1 ); | |
701 | } | |
702 | ||
703 | if ( xlation ) | |
704 | { | |
705 | numecs = ecs_from_xlation( ecgroup ); | |
706 | useecs = true; | |
707 | } | |
708 | ||
709 | else if ( useecs ) | |
710 | numecs = cre8ecs( nextecm, ecgroup, csize ); | |
711 | ||
712 | else | |
713 | numecs = csize; | |
714 | ||
715 | /* now map the equivalence class for NUL to its expected place */ | |
716 | ecgroup[0] = ecgroup[csize]; | |
717 | NUL_ec = abs( ecgroup[0] ); | |
718 | ||
719 | if ( useecs ) | |
720 | ccl2ecl(); | |
721 | } | |
722 | ||
723 | ||
724 | ||
725 | /* set_up_initial_allocations - allocate memory for internal tables */ | |
726 | ||
727 | void set_up_initial_allocations() | |
728 | ||
729 | { | |
730 | current_mns = INITIAL_MNS; | |
731 | firstst = allocate_integer_array( current_mns ); | |
732 | lastst = allocate_integer_array( current_mns ); | |
733 | finalst = allocate_integer_array( current_mns ); | |
734 | transchar = allocate_integer_array( current_mns ); | |
735 | trans1 = allocate_integer_array( current_mns ); | |
736 | trans2 = allocate_integer_array( current_mns ); | |
737 | accptnum = allocate_integer_array( current_mns ); | |
738 | assoc_rule = allocate_integer_array( current_mns ); | |
739 | state_type = allocate_integer_array( current_mns ); | |
740 | ||
741 | current_max_rules = INITIAL_MAX_RULES; | |
742 | rule_type = allocate_integer_array( current_max_rules ); | |
743 | rule_linenum = allocate_integer_array( current_max_rules ); | |
744 | ||
745 | current_max_scs = INITIAL_MAX_SCS; | |
746 | scset = allocate_integer_array( current_max_scs ); | |
747 | scbol = allocate_integer_array( current_max_scs ); | |
748 | scxclu = allocate_integer_array( current_max_scs ); | |
749 | sceof = allocate_integer_array( current_max_scs ); | |
750 | scname = allocate_char_ptr_array( current_max_scs ); | |
751 | actvsc = allocate_integer_array( current_max_scs ); | |
752 | ||
753 | current_maxccls = INITIAL_MAX_CCLS; | |
754 | cclmap = allocate_integer_array( current_maxccls ); | |
755 | ccllen = allocate_integer_array( current_maxccls ); | |
756 | cclng = allocate_integer_array( current_maxccls ); | |
757 | ||
758 | current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE; | |
759 | ccltbl = allocate_character_array( current_max_ccl_tbl_size ); | |
760 | ||
761 | current_max_dfa_size = INITIAL_MAX_DFA_SIZE; | |
762 | ||
763 | current_max_xpairs = INITIAL_MAX_XPAIRS; | |
764 | nxt = allocate_integer_array( current_max_xpairs ); | |
765 | chk = allocate_integer_array( current_max_xpairs ); | |
766 | ||
767 | current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS; | |
768 | tnxt = allocate_integer_array( current_max_template_xpairs ); | |
769 | ||
770 | current_max_dfas = INITIAL_MAX_DFAS; | |
771 | base = allocate_integer_array( current_max_dfas ); | |
772 | def = allocate_integer_array( current_max_dfas ); | |
773 | dfasiz = allocate_integer_array( current_max_dfas ); | |
774 | accsiz = allocate_integer_array( current_max_dfas ); | |
775 | dhash = allocate_integer_array( current_max_dfas ); | |
776 | dss = allocate_int_ptr_array( current_max_dfas ); | |
777 | dfaacc = allocate_dfaacc_union( current_max_dfas ); | |
778 | ||
779 | nultrans = (int *) 0; | |
780 | } |