home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / flex704.lha / src.lha / flexdef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-22  |  28.3 KB  |  866 lines

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