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