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