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