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