00001 /* flexdef - definitions file for flex */ 00002 00003 /*- 00004 * Copyright (c) 1990 The Regents of the University of California. 00005 * All rights reserved. 00006 * 00007 * This code is derived from software contributed to Berkeley by 00008 * Vern Paxson. 00009 * 00010 * The United States Government has rights in this work pursuant 00011 * to contract no. DE-AC03-76SF00098 between the United States 00012 * Department of Energy and the University of California. 00013 * 00014 * Redistribution and use in source and binary forms with or without 00015 * modification are permitted provided that: (1) source distributions retain 00016 * this entire copyright notice and comment, and (2) distributions including 00017 * binaries display the following acknowledgement: ``This product includes 00018 * software developed by the University of California, Berkeley and its 00019 * contributors'' in the documentation or other materials provided with the 00020 * distribution and in all advertising materials mentioning features or use 00021 * of this software. Neither the name of the University nor the names of 00022 * its contributors may be used to endorse or promote products derived from 00023 * this software without specific prior written permission. 00024 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 00025 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00026 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 */ 00028 00029 /* @(#) $Header$ (LBL) */ 00030 00031 #include <stdio.h> 00032 #include <ctype.h> 00033 00034 #include "config.h" 00035 00036 #ifdef __TURBOC__ 00037 #define HAVE_STRING_H 1 00038 #define MS_DOS 1 00039 #ifndef __STDC__ 00040 #define __STDC__ 1 00041 #endif 00042 #pragma warn -pro 00043 #pragma warn -rch 00044 #pragma warn -use 00045 #pragma warn -aus 00046 #pragma warn -par 00047 #pragma warn -pia 00048 #endif 00049 00050 #ifdef HAVE_STRING_H 00051 #include <string.h> 00052 #else 00053 #include <strings.h> 00054 #endif 00055 00056 #ifdef HAVE_SYS_TYPES_H 00057 #include <sys/types.h> 00058 #endif 00059 00060 #ifdef HAVE_MALLOC_H 00061 #include <malloc.h> 00062 #endif 00063 00064 #ifdef STDC_HEADERS 00065 #include <stdlib.h> 00066 #endif 00067 00068 /* As an aid for the internationalization patch to flex, which 00069 * is maintained outside this distribution for copyright reasons. 00070 */ 00071 #define _(String) (String) 00072 00073 /* Always be prepared to generate an 8-bit scanner. */ 00074 #define CSIZE 256 00075 #define Char unsigned char 00076 00077 /* Size of input alphabet - should be size of ASCII set. */ 00078 #ifndef DEFAULT_CSIZE 00079 #define DEFAULT_CSIZE 128 00080 #endif 00081 00082 #ifndef PROTO 00083 #if __STDC__ 00084 #define PROTO(proto) proto 00085 #else 00086 #define PROTO(proto) () 00087 #endif 00088 #endif 00089 00090 #ifdef VMS 00091 #ifndef __VMS_POSIX 00092 #define unlink remove 00093 #define SHORT_FILE_NAMES 00094 #endif 00095 #endif 00096 00097 #ifdef MS_DOS 00098 #define SHORT_FILE_NAMES 00099 #endif 00100 00101 00102 /* Maximum line length we'll have to deal with. */ 00103 #define MAXLINE 2048 00104 00105 #ifndef MIN 00106 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 00107 #endif 00108 #ifndef MAX 00109 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 00110 #endif 00111 #ifndef ABS 00112 #define ABS(x) ((x) < 0 ? -(x) : (x)) 00113 #endif 00114 00115 00116 /* ANSI C does not guarantee that isascii() is defined */ 00117 #ifndef isascii 00118 #define isascii(c) ((c) <= 0177) 00119 #endif 00120 00121 00122 #define true 1 00123 #define false 0 00124 #define unspecified -1 00125 00126 00127 /* Special chk[] values marking the slots taking by end-of-buffer and action 00128 * numbers. 00129 */ 00130 #define EOB_POSITION -1 00131 #define ACTION_POSITION -2 00132 00133 /* Number of data items per line for -f output. */ 00134 #define NUMDATAITEMS 10 00135 00136 /* Number of lines of data in -f output before inserting a blank line for 00137 * readability. 00138 */ 00139 #define NUMDATALINES 10 00140 00141 /* transition_struct_out() definitions. */ 00142 #define TRANS_STRUCT_PRINT_LENGTH 14 00143 00144 /* Returns true if an nfa state has an epsilon out-transition slot 00145 * that can be used. This definition is currently not used. 00146 */ 00147 #define FREE_EPSILON(state) \ 00148 (transchar[state] == SYM_EPSILON && \ 00149 trans2[state] == NO_TRANSITION && \ 00150 finalst[state] != state) 00151 00152 /* Returns true if an nfa state has an epsilon out-transition character 00153 * and both slots are free 00154 */ 00155 #define SUPER_FREE_EPSILON(state) \ 00156 (transchar[state] == SYM_EPSILON && \ 00157 trans1[state] == NO_TRANSITION) \ 00158 00159 /* Maximum number of NFA states that can comprise a DFA state. It's real 00160 * big because if there's a lot of rules, the initial state will have a 00161 * huge epsilon closure. 00162 */ 00163 #define INITIAL_MAX_DFA_SIZE 750 00164 #define MAX_DFA_SIZE_INCREMENT 750 00165 00166 00167 /* A note on the following masks. They are used to mark accepting numbers 00168 * as being special. As such, they implicitly limit the number of accepting 00169 * numbers (i.e., rules) because if there are too many rules the rule numbers 00170 * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 == 00171 * 8192) so unlikely to actually cause any problems. A check is made in 00172 * new_rule() to ensure that this limit is not reached. 00173 */ 00174 00175 /* Mask to mark a trailing context accepting number. */ 00176 #define YY_TRAILING_MASK 0x2000 00177 00178 /* Mask to mark the accepting number of the "head" of a trailing context 00179 * rule. 00180 */ 00181 #define YY_TRAILING_HEAD_MASK 0x4000 00182 00183 /* Maximum number of rules, as outlined in the above note. */ 00184 #define MAX_RULE (YY_TRAILING_MASK - 1) 00185 00186 00187 /* NIL must be 0. If not, its special meaning when making equivalence classes 00188 * (it marks the representative of a given e.c.) will be unidentifiable. 00189 */ 00190 #define NIL 0 00191 00192 #define JAM -1 /* to mark a missing DFA transition */ 00193 #define NO_TRANSITION NIL 00194 #define UNIQUE -1 /* marks a symbol as an e.c. representative */ 00195 #define INFINITY -1 /* for x{5,} constructions */ 00196 00197 #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ 00198 #define MAX_CCLS_INCREMENT 100 00199 00200 /* Size of table holding members of character classes. */ 00201 #define INITIAL_MAX_CCL_TBL_SIZE 500 00202 #define MAX_CCL_TBL_SIZE_INCREMENT 250 00203 00204 #define INITIAL_MAX_RULES 100 /* default maximum number of rules */ 00205 #define MAX_RULES_INCREMENT 100 00206 00207 #define INITIAL_MNS 2000 /* default maximum number of nfa states */ 00208 #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */ 00209 00210 #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ 00211 #define MAX_DFAS_INCREMENT 1000 00212 00213 #define JAMSTATE -32766 /* marks a reference to the state that always jams */ 00214 00215 /* Maximum number of NFA states. */ 00216 #define MAXIMUM_MNS 31999 00217 00218 /* Enough so that if it's subtracted from an NFA state number, the result 00219 * is guaranteed to be negative. 00220 */ 00221 #define MARKER_DIFFERENCE (MAXIMUM_MNS+2) 00222 00223 /* Maximum number of nxt/chk pairs for non-templates. */ 00224 #define INITIAL_MAX_XPAIRS 2000 00225 #define MAX_XPAIRS_INCREMENT 2000 00226 00227 /* Maximum number of nxt/chk pairs needed for templates. */ 00228 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500 00229 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500 00230 00231 #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */ 00232 00233 #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */ 00234 #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ 00235 00236 #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ 00237 #define SAME_TRANS -1 /* transition is the same as "default" entry for state */ 00238 00239 /* The following percentages are used to tune table compression: 00240 00241 * The percentage the number of out-transitions a state must be of the 00242 * number of equivalence classes in order to be considered for table 00243 * compaction by using protos. 00244 */ 00245 #define PROTO_SIZE_PERCENTAGE 15 00246 00247 /* The percentage the number of homogeneous out-transitions of a state 00248 * must be of the number of total out-transitions of the state in order 00249 * that the state's transition table is first compared with a potential 00250 * template of the most common out-transition instead of with the first 00251 * proto in the proto queue. 00252 */ 00253 #define CHECK_COM_PERCENTAGE 50 00254 00255 /* The percentage the number of differences between a state's transition 00256 * table and the proto it was first compared with must be of the total 00257 * number of out-transitions of the state in order to keep the first 00258 * proto as a good match and not search any further. 00259 */ 00260 #define FIRST_MATCH_DIFF_PERCENTAGE 10 00261 00262 /* The percentage the number of differences between a state's transition 00263 * table and the most similar proto must be of the state's total number 00264 * of out-transitions to use the proto as an acceptable close match. 00265 */ 00266 #define ACCEPTABLE_DIFF_PERCENTAGE 50 00267 00268 /* The percentage the number of homogeneous out-transitions of a state 00269 * must be of the number of total out-transitions of the state in order 00270 * to consider making a template from the state. 00271 */ 00272 #define TEMPLATE_SAME_PERCENTAGE 60 00273 00274 /* The percentage the number of differences between a state's transition 00275 * table and the most similar proto must be of the state's total number 00276 * of out-transitions to create a new proto from the state. 00277 */ 00278 #define NEW_PROTO_DIFF_PERCENTAGE 20 00279 00280 /* The percentage the total number of out-transitions of a state must be 00281 * of the number of equivalence classes in order to consider trying to 00282 * fit the transition table into "holes" inside the nxt/chk table. 00283 */ 00284 #define INTERIOR_FIT_PERCENTAGE 15 00285 00286 /* Size of region set aside to cache the complete transition table of 00287 * protos on the proto queue to enable quick comparisons. 00288 */ 00289 #define PROT_SAVE_SIZE 2000 00290 00291 #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ 00292 00293 /* Maximum number of out-transitions a state can have that we'll rummage 00294 * around through the interior of the internal fast table looking for a 00295 * spot for it. 00296 */ 00297 #define MAX_XTIONS_FULL_INTERIOR_FIT 4 00298 00299 /* Maximum number of rules which will be reported as being associated 00300 * with a DFA state. 00301 */ 00302 #define MAX_ASSOC_RULES 100 00303 00304 /* Number that, if used to subscript an array, has a good chance of producing 00305 * an error; should be small enough to fit into a short. 00306 */ 00307 #define BAD_SUBSCRIPT -32767 00308 00309 /* Absolute value of largest number that can be stored in a short, with a 00310 * bit of slop thrown in for general paranoia. 00311 */ 00312 #define MAX_SHORT 32700 00313 00314 00315 /* Declarations for global variables. */ 00316 00317 /* Variables for symbol tables: 00318 * sctbl - start-condition symbol table 00319 * ndtbl - name-definition symbol table 00320 * ccltab - character class text symbol table 00321 */ 00322 00323 struct hash_entry 00324 { 00325 struct hash_entry *prev, *next; 00326 char *name; 00327 char *str_val; 00328 int int_val; 00329 } ; 00330 00331 typedef struct hash_entry **hash_table; 00332 00333 #define NAME_TABLE_HASH_SIZE 101 00334 #define START_COND_HASH_SIZE 101 00335 #define CCL_HASH_SIZE 101 00336 00337 extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; 00338 extern struct hash_entry *sctbl[START_COND_HASH_SIZE]; 00339 extern struct hash_entry *ccltab[CCL_HASH_SIZE]; 00340 00341 00342 /* Variables for flags: 00343 * printstats - if true (-v), dump statistics 00344 * syntaxerror - true if a syntax error has been found 00345 * eofseen - true if we've seen an eof in the input file 00346 * ddebug - if true (-d), make a "debug" scanner 00347 * trace - if true (-T), trace processing 00348 * nowarn - if true (-w), do not generate warnings 00349 * spprdflt - if true (-s), suppress the default rule 00350 * interactive - if true (-I), generate an interactive scanner 00351 * caseins - if true (-i), generate a case-insensitive scanner 00352 * lex_compat - if true (-l), maximize compatibility with AT&T lex 00353 * do_yylineno - if true, generate code to maintain yylineno 00354 * useecs - if true (-Ce flag), use equivalence classes 00355 * fulltbl - if true (-Cf flag), don't compress the DFA state table 00356 * usemecs - if true (-Cm flag), use meta-equivalence classes 00357 * fullspd - if true (-F flag), use Jacobson method of table representation 00358 * gen_line_dirs - if true (i.e., no -L flag), generate #line directives 00359 * performance_report - if > 0 (i.e., -p flag), generate a report relating 00360 * to scanner performance; if > 1 (-p -p), report on minor performance 00361 * problems, too 00362 * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file 00363 * listing backing-up states 00364 * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class; 00365 * otherwise, a standard C scanner 00366 * long_align - if true (-Ca flag), favor long-word alignment. 00367 * use_read - if true (-f, -F, or -Cr) then use read() for scanner input; 00368 * otherwise, use fread(). 00369 * yytext_is_array - if true (i.e., %array directive), then declare 00370 * yytext as a array instead of a character pointer. Nice and inefficient. 00371 * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as 00372 * "no more files". 00373 * csize - size of character set for the scanner we're generating; 00374 * 128 for 7-bit chars and 256 for 8-bit 00375 * yymore_used - if true, yymore() is used in input rules 00376 * reject - if true, generate back-up tables for REJECT macro 00377 * real_reject - if true, scanner really uses REJECT (as opposed to just 00378 * having "reject" set for variable trailing context) 00379 * continued_action - true if this rule's action is to "fall through" to 00380 * the next rule's action (i.e., the '|' action) 00381 * in_rule - true if we're inside an individual rule, false if not. 00382 * yymore_really_used - whether to treat yymore() as really used, regardless 00383 * of what we think based on references to it in the user's actions. 00384 * reject_really_used - same for REJECT 00385 */ 00386 00387 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; 00388 extern int interactive, caseins, lex_compat, do_yylineno; 00389 extern int useecs, fulltbl, usemecs, fullspd; 00390 extern int gen_line_dirs, performance_report, backing_up_report; 00391 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap; 00392 extern int csize; 00393 extern int yymore_used, reject, real_reject, continued_action, in_rule; 00394 00395 extern int yymore_really_used, reject_really_used; 00396 00397 00398 /* Variables used in the flex input routines: 00399 * datapos - characters on current output line 00400 * dataline - number of contiguous lines of data in current data 00401 * statement. Used to generate readable -f output 00402 * linenum - current input line number 00403 * out_linenum - current output line number 00404 * skelfile - the skeleton file 00405 * skel - compiled-in skeleton array 00406 * skel_ind - index into "skel" array, if skelfile is nil 00407 * yyin - input file 00408 * backing_up_file - file to summarize backing-up states to 00409 * infilename - name of input file 00410 * outfilename - name of output file 00411 * did_outfilename - whether outfilename was explicitly set 00412 * prefix - the prefix used for externally visible names ("yy" by default) 00413 * yyclass - yyFlexLexer subclass to use for YY_DECL 00414 * do_stdinit - whether to initialize yyin/yyout to stdin/stdout 00415 * use_stdout - the -t flag 00416 * input_files - array holding names of input files 00417 * num_input_files - size of input_files array 00418 * program_name - name with which program was invoked 00419 * 00420 * action_array - array to hold the rule actions 00421 * action_size - size of action_array 00422 * defs1_offset - index where the user's section 1 definitions start 00423 * in action_array 00424 * prolog_offset - index where the prolog starts in action_array 00425 * action_offset - index where the non-prolog starts in action_array 00426 * action_index - index where the next action should go, with respect 00427 * to "action_array" 00428 */ 00429 00430 extern int datapos, dataline, linenum, out_linenum; 00431 extern FILE *skelfile, *yyin, *backing_up_file; 00432 extern const char *skel[]; 00433 extern int skel_ind; 00434 extern char *infilename, *outfilename; 00435 extern int did_outfilename; 00436 extern char *prefix, *yyclass; 00437 extern int do_stdinit, use_stdout; 00438 extern char **input_files; 00439 extern int num_input_files; 00440 extern char *program_name; 00441 00442 extern char *action_array; 00443 extern int action_size; 00444 extern int defs1_offset, prolog_offset, action_offset, action_index; 00445 00446 00447 /* Variables for stack of states having only one out-transition: 00448 * onestate - state number 00449 * onesym - transition symbol 00450 * onenext - target state 00451 * onedef - default base entry 00452 * onesp - stack pointer 00453 */ 00454 00455 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; 00456 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; 00457 00458 00459 /* Variables for nfa machine data: 00460 * current_mns - current maximum on number of NFA states 00461 * num_rules - number of the last accepting state; also is number of 00462 * rules created so far 00463 * num_eof_rules - number of <<EOF>> rules 00464 * default_rule - number of the default rule 00465 * current_max_rules - current maximum number of rules 00466 * lastnfa - last nfa state number created 00467 * firstst - physically the first state of a fragment 00468 * lastst - last physical state of fragment 00469 * finalst - last logical state of fragment 00470 * transchar - transition character 00471 * trans1 - transition state 00472 * trans2 - 2nd transition state for epsilons 00473 * accptnum - accepting number 00474 * assoc_rule - rule associated with this NFA state (or 0 if none) 00475 * state_type - a STATE_xxx type identifying whether the state is part 00476 * of a normal rule, the leading state in a trailing context 00477 * rule (i.e., the state which marks the transition from 00478 * recognizing the text-to-be-matched to the beginning of 00479 * the trailing context), or a subsequent state in a trailing 00480 * context rule 00481 * rule_type - a RULE_xxx type identifying whether this a ho-hum 00482 * normal rule or one which has variable head & trailing 00483 * context 00484 * rule_linenum - line number associated with rule 00485 * rule_useful - true if we've determined that the rule can be matched 00486 */ 00487 00488 extern int current_mns, current_max_rules; 00489 extern int num_rules, num_eof_rules, default_rule, lastnfa; 00490 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; 00491 extern int *accptnum, *assoc_rule, *state_type; 00492 extern int *rule_type, *rule_linenum, *rule_useful; 00493 00494 /* Different types of states; values are useful as masks, as well, for 00495 * routines like check_trailing_context(). 00496 */ 00497 #define STATE_NORMAL 0x1 00498 #define STATE_TRAILING_CONTEXT 0x2 00499 00500 /* Global holding current type of state we're making. */ 00501 00502 extern int current_state_type; 00503 00504 /* Different types of rules. */ 00505 #define RULE_NORMAL 0 00506 #define RULE_VARIABLE 1 00507 00508 /* True if the input rules include a rule with both variable-length head 00509 * and trailing context, false otherwise. 00510 */ 00511 extern int variable_trailing_context_rules; 00512 00513 00514 /* Variables for protos: 00515 * numtemps - number of templates created 00516 * numprots - number of protos created 00517 * protprev - backlink to a more-recently used proto 00518 * protnext - forward link to a less-recently used proto 00519 * prottbl - base/def table entry for proto 00520 * protcomst - common state of proto 00521 * firstprot - number of the most recently used proto 00522 * lastprot - number of the least recently used proto 00523 * protsave contains the entire state array for protos 00524 */ 00525 00526 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; 00527 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; 00528 00529 00530 /* Variables for managing equivalence classes: 00531 * numecs - number of equivalence classes 00532 * nextecm - forward link of Equivalence Class members 00533 * ecgroup - class number or backward link of EC members 00534 * nummecs - number of meta-equivalence classes (used to compress 00535 * templates) 00536 * tecfwd - forward link of meta-equivalence classes members 00537 * tecbck - backward link of MEC's 00538 */ 00539 00540 /* Reserve enough room in the equivalence class arrays so that we 00541 * can use the CSIZE'th element to hold equivalence class information 00542 * for the NUL character. Later we'll move this information into 00543 * the 0th element. 00544 */ 00545 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs; 00546 00547 /* Meta-equivalence classes are indexed starting at 1, so it's possible 00548 * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1 00549 * slots total (since the arrays are 0-based). nextecm[] and ecgroup[] 00550 * don't require the extra position since they're indexed from 1 .. CSIZE - 1. 00551 */ 00552 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1]; 00553 00554 00555 /* Variables for start conditions: 00556 * lastsc - last start condition created 00557 * current_max_scs - current limit on number of start conditions 00558 * scset - set of rules active in start condition 00559 * scbol - set of rules active only at the beginning of line in a s.c. 00560 * scxclu - true if start condition is exclusive 00561 * sceof - true if start condition has EOF rule 00562 * scname - start condition name 00563 */ 00564 00565 extern int lastsc, *scset, *scbol, *scxclu, *sceof; 00566 extern int current_max_scs; 00567 extern char **scname; 00568 00569 00570 /* Variables for dfa machine data: 00571 * current_max_dfa_size - current maximum number of NFA states in DFA 00572 * current_max_xpairs - current maximum number of non-template xtion pairs 00573 * current_max_template_xpairs - current maximum number of template pairs 00574 * current_max_dfas - current maximum number DFA states 00575 * lastdfa - last dfa state number created 00576 * nxt - state to enter upon reading character 00577 * chk - check value to see if "nxt" applies 00578 * tnxt - internal nxt table for templates 00579 * base - offset into "nxt" for given state 00580 * def - where to go if "chk" disallows "nxt" entry 00581 * nultrans - NUL transition for each state 00582 * NUL_ec - equivalence class of the NUL character 00583 * tblend - last "nxt/chk" table entry being used 00584 * firstfree - first empty entry in "nxt/chk" table 00585 * dss - nfa state set for each dfa 00586 * dfasiz - size of nfa state set for each dfa 00587 * dfaacc - accepting set for each dfa state (if using REJECT), or accepting 00588 * number, if not 00589 * accsiz - size of accepting set for each dfa state 00590 * dhash - dfa state hash value 00591 * numas - number of DFA accepting states created; note that this 00592 * is not necessarily the same value as num_rules, which is the analogous 00593 * value for the NFA 00594 * numsnpairs - number of state/nextstate transition pairs 00595 * jambase - position in base/def where the default jam table starts 00596 * jamstate - state number corresponding to "jam" state 00597 * end_of_buffer_state - end-of-buffer dfa state number 00598 */ 00599 00600 extern int current_max_dfa_size, current_max_xpairs; 00601 extern int current_max_template_xpairs, current_max_dfas; 00602 extern int lastdfa, *nxt, *chk, *tnxt; 00603 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; 00604 extern union dfaacc_union 00605 { 00606 int *dfaacc_set; 00607 int dfaacc_state; 00608 } *dfaacc; 00609 extern int *accsiz, *dhash, numas; 00610 extern int numsnpairs, jambase, jamstate; 00611 extern int end_of_buffer_state; 00612 00613 /* Variables for ccl information: 00614 * lastccl - ccl index of the last created ccl 00615 * current_maxccls - current limit on the maximum number of unique ccl's 00616 * cclmap - maps a ccl index to its set pointer 00617 * ccllen - gives the length of a ccl 00618 * cclng - true for a given ccl if the ccl is negated 00619 * cclreuse - counts how many times a ccl is re-used 00620 * current_max_ccl_tbl_size - current limit on number of characters needed 00621 * to represent the unique ccl's 00622 * ccltbl - holds the characters in each ccl - indexed by cclmap 00623 */ 00624 00625 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse; 00626 extern int current_maxccls, current_max_ccl_tbl_size; 00627 extern Char *ccltbl; 00628 00629 00630 /* Variables for miscellaneous information: 00631 * nmstr - last NAME scanned by the scanner 00632 * sectnum - section number currently being parsed 00633 * nummt - number of empty nxt/chk table entries 00634 * hshcol - number of hash collisions detected by snstods 00635 * dfaeql - number of times a newly created dfa was equal to an old one 00636 * numeps - number of epsilon NFA states created 00637 * eps2 - number of epsilon states which have 2 out-transitions 00638 * num_reallocs - number of times it was necessary to realloc() a group 00639 * of arrays 00640 * tmpuses - number of DFA states that chain to templates 00641 * totnst - total number of NFA states used to make DFA states 00642 * peakpairs - peak number of transition pairs we had to store internally 00643 * numuniq - number of unique transitions 00644 * numdup - number of duplicate transitions 00645 * hshsave - number of hash collisions saved by checking number of states 00646 * num_backing_up - number of DFA states requiring backing up 00647 * bol_needed - whether scanner needs beginning-of-line recognition 00648 */ 00649 00650 extern char nmstr[MAXLINE]; 00651 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; 00652 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; 00653 extern int num_backing_up, bol_needed; 00654 00655 void *allocate_array PROTO((int, size_t)); 00656 void *reallocate_array PROTO((void*, int, size_t)); 00657 00658 void *flex_alloc PROTO((size_t)); 00659 void *flex_realloc PROTO((void*, size_t)); 00660 void flex_free PROTO((void*)); 00661 00662 #define allocate_integer_array(size) \ 00663 (int *) allocate_array( size, sizeof( int ) ) 00664 00665 #define reallocate_integer_array(array,size) \ 00666 (int *) reallocate_array( (void *) array, size, sizeof( int ) ) 00667 00668 #define allocate_int_ptr_array(size) \ 00669 (int **) allocate_array( size, sizeof( int * ) ) 00670 00671 #define allocate_char_ptr_array(size) \ 00672 (char **) allocate_array( size, sizeof( char * ) ) 00673 00674 #define allocate_dfaacc_union(size) \ 00675 (union dfaacc_union *) \ 00676 allocate_array( size, sizeof( union dfaacc_union ) ) 00677 00678 #define reallocate_int_ptr_array(array,size) \ 00679 (int **) reallocate_array( (void *) array, size, sizeof( int * ) ) 00680 00681 #define reallocate_char_ptr_array(array,size) \ 00682 (char **) reallocate_array( (void *) array, size, sizeof( char * ) ) 00683 00684 #define reallocate_dfaacc_union(array, size) \ 00685 (union dfaacc_union *) \ 00686 reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) ) 00687 00688 #define allocate_character_array(size) \ 00689 (char *) allocate_array( size, sizeof( char ) ) 00690 00691 #define reallocate_character_array(array,size) \ 00692 (char *) reallocate_array( (void *) array, size, sizeof( char ) ) 00693 00694 #define allocate_Character_array(size) \ 00695 (Char *) allocate_array( size, sizeof( Char ) ) 00696 00697 #define reallocate_Character_array(array,size) \ 00698 (Char *) reallocate_array( (void *) array, size, sizeof( Char ) ) 00699 00700 00701 /* Used to communicate between scanner and parser. The type should really 00702 * be YYSTYPE, but we can't easily get our hands on it. 00703 */ 00704 extern int yylval; 00705 00706 00707 /* External functions that are cross-referenced among the flex source files. */ 00708 00709 00710 /* from file ccl.c */ 00711 00712 extern void ccladd PROTO((int, int)); /* add a single character to a ccl */ 00713 extern int cclinit PROTO((void)); /* make an empty ccl */ 00714 extern void cclnegate PROTO((int)); /* negate a ccl */ 00715 00716 /* List the members of a set of characters in CCL form. */ 00717 extern void list_character_set PROTO((FILE*, int[])); 00718 00719 00720 /* from file dfa.c */ 00721 00722 /* Check a DFA state for backing up. */ 00723 extern void check_for_backing_up PROTO((int, int[])); 00724 00725 /* Check to see if NFA state set constitutes "dangerous" trailing context. */ 00726 extern void check_trailing_context PROTO((int*, int, int*, int)); 00727 00728 /* Construct the epsilon closure of a set of ndfa states. */ 00729 extern int *epsclosure PROTO((int*, int*, int[], int*, int*)); 00730 00731 /* Increase the maximum number of dfas. */ 00732 extern void increase_max_dfas PROTO((void)); 00733 00734 extern void ntod PROTO((void)); /* convert a ndfa to a dfa */ 00735 00736 /* Converts a set of ndfa states into a dfa state. */ 00737 extern int snstods PROTO((int[], int, int[], int, int, int*)); 00738 00739 00740 /* from file ecs.c */ 00741 00742 /* Convert character classes to set of equivalence classes. */ 00743 extern void ccl2ecl PROTO((void)); 00744 00745 /* Associate equivalence class numbers with class members. */ 00746 extern int cre8ecs PROTO((int[], int[], int)); 00747 00748 /* Update equivalence classes based on character class transitions. */ 00749 extern void mkeccl PROTO((Char[], int, int[], int[], int, int)); 00750 00751 /* Create equivalence class for single character. */ 00752 extern void mkechar PROTO((int, int[], int[])); 00753 00754 00755 /* from file gen.c */ 00756 00757 extern void do_indent PROTO((void)); /* indent to the current level */ 00758 00759 /* Generate the code to keep backing-up information. */ 00760 extern void gen_backing_up PROTO((void)); 00761 00762 /* Generate the code to perform the backing up. */ 00763 extern void gen_bu_action PROTO((void)); 00764 00765 /* Generate full speed compressed transition table. */ 00766 extern void genctbl PROTO((void)); 00767 00768 /* Generate the code to find the action number. */ 00769 extern void gen_find_action PROTO((void)); 00770 00771 extern void genftbl PROTO((void)); /* generate full transition table */ 00772 00773 /* Generate the code to find the next compressed-table state. */ 00774 extern void gen_next_compressed_state PROTO((char*)); 00775 00776 /* Generate the code to find the next match. */ 00777 extern void gen_next_match PROTO((void)); 00778 00779 /* Generate the code to find the next state. */ 00780 extern void gen_next_state PROTO((int)); 00781 00782 /* Generate the code to make a NUL transition. */ 00783 extern void gen_NUL_trans PROTO((void)); 00784 00785 /* Generate the code to find the start state. */ 00786 extern void gen_start_state PROTO((void)); 00787 00788 /* Generate data statements for the transition tables. */ 00789 extern void gentabs PROTO((void)); 00790 00791 /* Write out a formatted string at the current indentation level. */ 00792 extern void indent_put2s PROTO((char[], char[])); 00793 00794 /* Write out a string + newline at the current indentation level. */ 00795 extern void indent_puts PROTO((char[])); 00796 00797 extern void make_tables PROTO((void)); /* generate transition tables */ 00798 00799 00800 /* from file main.c */ 00801 00802 extern void check_options PROTO((void)); 00803 extern void flexend PROTO((int)); 00804 extern void usage PROTO((void)); 00805 00806 00807 /* from file misc.c */ 00808 00809 /* Add a #define to the action file. */ 00810 extern void action_define PROTO(( char *defname, int value )); 00811 00812 /* Add the given text to the stored actions. */ 00813 extern void add_action PROTO(( char *new_text )); 00814 00815 /* True if a string is all lower case. */ 00816 extern int all_lower PROTO((register char *)); 00817 00818 /* True if a string is all upper case. */ 00819 extern int all_upper PROTO((register char *)); 00820 00821 /* Bubble sort an integer array. */ 00822 extern void bubble PROTO((int [], int)); 00823 00824 /* Check a character to make sure it's in the expected range. */ 00825 extern void check_char PROTO((int c)); 00826 00827 /* Replace upper-case letter to lower-case. */ 00828 extern Char clower PROTO((int)); 00829 00830 /* Returns a dynamically allocated copy of a string. */ 00831 extern char *copy_string PROTO((register const char *)); 00832 00833 /* Returns a dynamically allocated copy of a (potentially) unsigned string. */ 00834 extern Char *copy_unsigned_string PROTO((register Char *)); 00835 00836 /* Shell sort a character array. */ 00837 extern void cshell PROTO((Char [], int, int)); 00838 00839 /* Finish up a block of data declarations. */ 00840 extern void dataend PROTO((void)); 00841 00842 /* Flush generated data statements. */ 00843 extern void dataflush PROTO((void)); 00844 00845 /* Report an error message and terminate. */ 00846 extern void flexerror PROTO((const char[])); 00847 00848 /* Report a fatal error message and terminate. */ 00849 extern void flexfatal PROTO((const char[])); 00850 00851 /* Convert a hexadecimal digit string to an integer value. */ 00852 extern int htoi PROTO((Char[])); 00853 00854 /* Report an error message formatted with one integer argument. */ 00855 extern void lerrif PROTO((const char[], int)); 00856 00857 /* Report an error message formatted with one string argument. */ 00858 extern void lerrsf PROTO((const char[], const char[])); 00859 00860 /* Spit out a "#line" statement. */ 00861 extern void line_directive_out PROTO((FILE*, int)); 00862 00863 /* Mark the current position in the action array as the end of the section 1 00864 * user defs. 00865 */ 00866 extern void mark_defs1 PROTO((void)); 00867 00868 /* Mark the current position in the action array as the end of the prolog. */ 00869 extern void mark_prolog PROTO((void)); 00870 00871 /* Generate a data statment for a two-dimensional array. */ 00872 extern void mk2data PROTO((int)); 00873 00874 extern void mkdata PROTO((int)); /* generate a data statement */ 00875 00876 /* Return the integer represented by a string of digits. */ 00877 extern int myctoi PROTO((char [])); 00878 00879 /* Return character corresponding to escape sequence. */ 00880 extern Char myesc PROTO((Char[])); 00881 00882 /* Convert an octal digit string to an integer value. */ 00883 extern int otoi PROTO((Char [] )); 00884 00885 /* Output a (possibly-formatted) string to the generated scanner. */ 00886 extern void out PROTO((const char [])); 00887 extern void out_dec PROTO((const char [], int)); 00888 extern void out_dec2 PROTO((const char [], int, int)); 00889 extern void out_hex PROTO((const char [], unsigned int)); 00890 extern void out_line_count PROTO((const char [])); 00891 extern void out_str PROTO((const char [], const char [])); 00892 extern void out_str3 00893 PROTO((const char [], const char [], const char [], const char [])); 00894 extern void out_str_dec PROTO((const char [], const char [], int)); 00895 extern void outc PROTO((int)); 00896 extern void outn PROTO((const char [])); 00897 00898 /* Return a printable version of the given character, which might be 00899 * 8-bit. 00900 */ 00901 extern char *readable_form PROTO((int)); 00902 00903 /* Write out one section of the skeleton file. */ 00904 extern void skelout PROTO((void)); 00905 00906 /* Output a yy_trans_info structure. */ 00907 extern void transition_struct_out PROTO((int, int)); 00908 00909 /* Only needed when using certain broken versions of bison to build parse.c. */ 00910 extern void *yy_flex_xmalloc PROTO(( int )); 00911 00912 /* Set a region of memory to 0. */ 00913 extern void zero_out PROTO((char *, size_t)); 00914 00915 00916 /* from file nfa.c */ 00917 00918 /* Add an accepting state to a machine. */ 00919 extern void add_accept PROTO((int, int)); 00920 00921 /* Make a given number of copies of a singleton machine. */ 00922 extern int copysingl PROTO((int, int)); 00923 00924 /* Debugging routine to write out an nfa. */ 00925 extern void dumpnfa PROTO((int)); 00926 00927 /* Finish up the processing for a rule. */ 00928 extern void finish_rule PROTO((int, int, int, int)); 00929 00930 /* Connect two machines together. */ 00931 extern int link_machines PROTO((int, int)); 00932 00933 /* Mark each "beginning" state in a machine as being a "normal" (i.e., 00934 * not trailing context associated) state. 00935 */ 00936 extern void mark_beginning_as_normal PROTO((register int)); 00937 00938 /* Make a machine that branches to two machines. */ 00939 extern int mkbranch PROTO((int, int)); 00940 00941 extern int mkclos PROTO((int)); /* convert a machine into a closure */ 00942 extern int mkopt PROTO((int)); /* make a machine optional */ 00943 00944 /* Make a machine that matches either one of two machines. */ 00945 extern int mkor PROTO((int, int)); 00946 00947 /* Convert a machine into a positive closure. */ 00948 extern int mkposcl PROTO((int)); 00949 00950 extern int mkrep PROTO((int, int, int)); /* make a replicated machine */ 00951 00952 /* Create a state with a transition on a given symbol. */ 00953 extern int mkstate PROTO((int)); 00954 00955 extern void new_rule PROTO((void)); /* initialize for a new rule */ 00956 00957 00958 /* from file parse.y */ 00959 00960 /* Build the "<<EOF>>" action for the active start conditions. */ 00961 extern void build_eof_action PROTO((void)); 00962 00963 /* Write out a message formatted with one string, pinpointing its location. */ 00964 extern void format_pinpoint_message PROTO((char[], char[])); 00965 00966 /* Write out a message, pinpointing its location. */ 00967 extern void pinpoint_message PROTO((char[])); 00968 00969 /* Write out a warning, pinpointing it at the given line. */ 00970 extern void line_warning PROTO(( char[], int )); 00971 00972 /* Write out a message, pinpointing it at the given line. */ 00973 extern void line_pinpoint PROTO(( char[], int )); 00974 00975 /* Report a formatted syntax error. */ 00976 extern void format_synerr PROTO((char [], char[])); 00977 extern void synerr PROTO((char [])); /* report a syntax error */ 00978 extern void format_warn PROTO((char [], char[])); 00979 extern void warn PROTO((char [])); /* report a warning */ 00980 extern void yyerror PROTO((char [])); /* report a parse error */ 00981 extern int yyparse PROTO((void)); /* the YACC parser */ 00982 00983 00984 /* from file scan.l */ 00985 00986 /* The Flex-generated scanner for flex. */ 00987 extern int flexscan PROTO((void)); 00988 00989 /* Open the given file (if NULL, stdin) for scanning. */ 00990 extern void set_input_file PROTO((char*)); 00991 00992 /* Wrapup a file in the lexical analyzer. */ 00993 extern int yywrap PROTO((void)); 00994 00995 00996 /* from file sym.c */ 00997 00998 /* Add symbol and definitions to symbol table. */ 00999 extern int addsym PROTO((register char[], char*, int, hash_table, int)); 01000 01001 /* Save the text of a character class. */ 01002 extern void cclinstal PROTO ((Char [], int)); 01003 01004 /* Lookup the number associated with character class. */ 01005 extern int ccllookup PROTO((Char [])); 01006 01007 /* Find symbol in symbol table. */ 01008 extern struct hash_entry *findsym PROTO((register char[], hash_table, int )); 01009 01010 extern void ndinstal PROTO((char[], Char[])); /* install a name definition */ 01011 extern Char *ndlookup PROTO((char[])); /* lookup a name definition */ 01012 01013 /* Increase maximum number of SC's. */ 01014 extern void scextend PROTO((void)); 01015 extern void scinstal PROTO((char[], int)); /* make a start condition */ 01016 01017 /* Lookup the number associated with a start condition. */ 01018 extern int sclookup PROTO((char[])); 01019 01020 01021 /* from file tblcmp.c */ 01022 01023 /* Build table entries for dfa state. */ 01024 extern void bldtbl PROTO((int[], int, int, int, int)); 01025 01026 extern void cmptmps PROTO((void)); /* compress template table entries */ 01027 extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */ 01028 /* Finds a space in the table for a state to be placed. */ 01029 extern int find_table_space PROTO((int*, int)); 01030 extern void inittbl PROTO((void)); /* initialize transition tables */ 01031 /* Make the default, "jam" table entries. */ 01032 extern void mkdeftbl PROTO((void)); 01033 01034 /* Create table entries for a state (or state fragment) which has 01035 * only one out-transition. 01036 */ 01037 extern void mk1tbl PROTO((int, int, int, int)); 01038 01039 /* Place a state into full speed transition table. */ 01040 extern void place_state PROTO((int*, int, int)); 01041 01042 /* Save states with only one out-transition to be processed later. */ 01043 extern void stack1 PROTO((int, int, int, int)); 01044 01045 01046 /* from file yylex.c */ 01047 01048 extern int yylex PROTO((void));
1.5.8