[BACK]Return to flexdef.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / lex

Annotation of src/usr.bin/lex/flexdef.h, Revision 1.2

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