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