home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 290_01 / flexdef.h < prev    next >
C/C++ Source or Header  |  1990-05-14  |  19KB  |  518 lines

  1. /*
  2. **    file:        flexdef.h
  3. **    purpose:    Definitions for flex.
  4.  *
  5.  * modification history
  6.  * --------------------
  7.  *     RA    30Dec89  .Added the prototypes for 'synerr' and
  8.  *              'yyerror' to this file. They were put in
  9.  *              the file 'parse.h' manually. However this
  10.  *              file gets generated by YACC/BISON when
  11.  *              'parse.y' gets processed and this wipes
  12.  *              out said prototypes CAUSING all sorts of
  13.  *              UGLY warning messages
  14.  *     DrH      Jan89    .port to Microsoft C v5.1 under MsDOS v3.x
  15.  * 02b kg, vp   30sep87  .added definitions for fast scanner; misc. cleanup
  16.  * 02a vp       27jun86  .translated into C/FTL
  17.  */
  18.  
  19. /*
  20.  * Copyright (c) 1987, the University of California
  21.  * 
  22.  * The United States Government has rights in this work pursuant to
  23.  * contract no. DE-AC03-76SF00098 between the United States Department of
  24.  * Energy and the University of California.
  25.  * 
  26.  * This program may be redistributed.  Enhancements and derivative works
  27.  * may be created provided the new works, if made available to the general
  28.  * public, are made available for use by anyone.
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>           /* should contain decls for memset(), malloc() */
  33. #include <ctype.h>            /* without dragging in memory.h & malloc.h (DrH) */
  34.  
  35. #define SV
  36. #ifdef SV
  37. #include <string.h>
  38. #define bzero(s, n) memset((char *)(s), '\0', (unsigned)(n))
  39. #else
  40. #include <strings.h>
  41. #endif
  42.  
  43. /* char *sprintf(); */  /* keep lint happy */ 
  44.  
  45.  
  46. /* maximum line length we'll have to deal with */
  47. #define MAXLINE BUFSIZ
  48.  
  49. /* maximum size of file name */
  50. #define FILENAMESIZE 1024
  51. /*
  52. #define min(x,y) (x < y ? x : y)
  53. #define max(x,y) (x > y ? x : y)
  54. */
  55. #define true 1
  56. #define false 0
  57.  
  58. /* skeleton file names truncated for MS-DOS conventions */
  59.  
  60. #ifndef DEFAULT_SKELETON_FILE
  61. #define DEFAULT_SKELETON_FILE "skeleton.c"
  62. #endif
  63.  
  64. #ifndef FAST_SKELETON_FILE
  65. #define FAST_SKELETON_FILE "fastskel.c"
  66. #endif
  67.  
  68. /* special nxt[] action number for the "at the end of the input buffer" state */
  69. /* note: -1 is already taken by YY_NEW_FILE */
  70. #define END_OF_BUFFER_ACTION -3
  71. /* action number for default action for fast scanners */
  72. #define DEFAULT_ACTION -2
  73.  
  74. /* special chk[] values marking the slots taking by end-of-buffer and action
  75.  * numbers
  76.  */
  77. #define EOB_POSITION -1
  78. #define ACTION_POSITION -2
  79.  
  80. /* number of data items per line for -f output */
  81. #define NUMDATAITEMS 10
  82.  
  83. /* number of lines of data in -f output before inserting a blank line for
  84.  * readability.
  85.  */
  86. #define NUMDATALINES 10
  87.  
  88. /* transition_struct_out() definitions */
  89. #define TRANS_STRUCT_PRINT_LENGTH 15
  90.  
  91. /* returns true if an nfa state has an epsilon out-transition slot
  92.  * that can be used.  This definition is currently not used.
  93.  */
  94. #define FREE_EPSILON(state) \
  95.     (transchar[state] == SYM_EPSILON && \
  96.      trans2[state] == NO_TRANSITION && \
  97.      finalst[state] != state)
  98.  
  99. /* returns true if an nfa state has an epsilon out-transition character
  100.  * and both slots are free
  101.  */
  102. #define SUPER_FREE_EPSILON(state) \
  103.     (transchar[state] == SYM_EPSILON && \
  104.      trans1[state] == NO_TRANSITION) \
  105.  
  106. /* maximum number of NFA states that can comprise a DFA state.  It's real
  107.  * big because if there's a lot of rules, the initial state will have a
  108.  * huge epsilon closure.
  109.  */
  110. #define INITIAL_MAX_DFA_SIZE 750
  111. #define MAX_DFA_SIZE_INCREMENT 750
  112.  
  113. /* array names to be used in generated machine.  They're short because
  114.  * we write out one data statement (which names the array) for each element
  115.  * in the array.
  116.  */
  117.  
  118. #define ALIST 'l'    /* points to list of rules accepted for a state */
  119. #define ACCEPT 'a'    /* list of rules accepted for a state */
  120. #define ECARRAY 'e'    /* maps input characters to equivalence classes */
  121. #define MATCHARRAY 'm'    /* maps equivalence classes to meta-equivalence classes */
  122. #define BASEARRAY 'b'    /* "base" array */
  123. #define DEFARRAY 'd'    /* "default" array */
  124. #define NEXTARRAY 'n'    /* "next" array */
  125. #define CHECKARRAY 'c'    /* "check" array */
  126.  
  127. /* NIL must be 0.  If not, its special meaning when making equivalence classes
  128.  * (it marks the representative of a given e.c.) will be unidentifiable
  129.  */
  130. #define NIL 0
  131.  
  132. #define JAM -1    /* to mark a missing DFA transition */
  133. #define NO_TRANSITION NIL
  134. #define UNIQUE -1    /* marks a symbol as an e.c. representative */
  135. #define INFINITY -1    /* for x{5,} constructions */
  136.  
  137. /* size of input alphabet - should be size of ASCII set */
  138. #define CSIZE 127
  139.  
  140. #define INITIAL_MAXCCLS 100    /* max number of unique character classes */
  141. #define MAXCCLS_INCREMENT 100
  142.  
  143. /* size of table holding members of character classes */
  144. #define INITIAL_MAX_CCL_TBL_SIZE 500
  145. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  146.  
  147. #define INITIAL_MNS 2000    /* default maximum number of nfa states */
  148. #define MNS_INCREMENT 1000    /* amount to bump above by if it's not enough */
  149.  
  150. #define INITIAL_MAX_DFAS 1000    /* default maximum number of dfa states */
  151. #define MAX_DFAS_INCREMENT 1000
  152.  
  153. #define JAMSTATE -32766    /* marks a reference to the state that always jams */
  154.  
  155. /* enough so that if it's subtracted from an NFA state number, the result
  156.  * is guaranteed to be negative
  157.  */
  158. #define MARKER_DIFFERENCE 32000
  159. #define MAXIMUM_MNS 31999
  160.  
  161. /* maximum number of nxt/chk pairs for non-templates */
  162. #define INITIAL_MAX_XPAIRS 2000
  163. #define MAX_XPAIRS_INCREMENT 2000
  164.  
  165. /* maximum number of nxt/chk pairs needed for templates */
  166. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  167. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  168.  
  169. #define SYM_EPSILON 0    /* to mark transitions on the symbol epsilon */
  170.  
  171. #define INITIAL_MAX_SCS 40    /* maximum number of start conditions */
  172. #define MAX_SCS_INCREMENT 40    /* amount to bump by if it's not enough */
  173.  
  174. #define ONE_STACK_SIZE 500    /* stack of states with only one out-transition */
  175. #define SAME_TRANS -1    /* transition is the same as "default" entry for state */
  176.  
  177. /* the following percentages are used to tune table compression:
  178.  
  179.  * the percentage the number of out-transitions a state must be of the
  180.  * number of equivalence classes in order to be considered for table
  181.  * compaction by using protos
  182.  */
  183. #define PROTO_SIZE_PERCENTAGE 15
  184.  
  185. /* the percentage the number of homogeneous out-transitions of a state
  186.  * must be of the number of total out-transitions of the state in order
  187.  * that the state's transition table is first compared with a potential 
  188.  * template of the most common out-transition instead of with the first
  189.  * proto in the proto queue
  190.  */
  191. #define CHECK_COM_PERCENTAGE 50
  192.  
  193. /* the percentage the number of differences between a state's transition
  194.  * table and the proto it was first compared with must be of the total
  195.  * number of out-transitions of the state in order to keep the first
  196.  * proto as a good match and not search any further
  197.  */
  198. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  199.  
  200. /* the percentage the number of differences between a state's transition
  201.  * table and the most similar proto must be of the state's total number
  202.  * of out-transitions to use the proto as an acceptable close match
  203.  */
  204. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  205.  
  206. /* the percentage the number of homogeneous out-transitions of a state
  207.  * must be of the number of total out-transitions of the state in order
  208.  * to consider making a template from the state
  209.  */
  210. #define TEMPLATE_SAME_PERCENTAGE 60
  211.  
  212. /* the percentage the number of differences between a state's transition
  213.  * table and the most similar proto must be of the state's total number
  214.  * of out-transitions to create a new proto from the state
  215.  */
  216. #define NEW_PROTO_DIFF_PERCENTAGE 20
  217.  
  218. /* the percentage the total number of out-transitions of a state must be
  219.  * of the number of equivalence classes in order to consider trying to
  220.  * fit the transition table into "holes" inside the nxt/chk table.
  221.  */
  222. #define INTERIOR_FIT_PERCENTAGE 15
  223.  
  224. /* size of region set aside to cache the complete transition table of
  225.  * protos on the proto queue to enable quick comparisons
  226.  */
  227. #define PROT_SAVE_SIZE 2000
  228.  
  229. #define MSP 50    /* maximum number of saved protos (protos on the proto queue) */
  230.  
  231. /* maximum number of out-transitions a state can have that we'll rummage
  232.  * around through the interior of the internal fast table looking for a
  233.  * spot for it
  234.  * MAX_XTIONS_FOR_FULL_INTERIOR_FIT is 32 chars long
  235.  */                         
  236. #define MAX_XTIONS_FOR_FULL_TABLE 4
  237.  
  238. /* number that, if used to subscript an array, has a good chance of producing
  239.  * an error; should be small enough to fit into a short
  240.  */
  241. #define BAD_SUBSCRIPT -32767
  242.  
  243. /* absolute value of largest number that can be stored in a short, with a
  244.  * bit of slop thrown in for general paranoia.
  245.  */
  246. #define MAX_SHORT 32766
  247.  
  248.  
  249. /* Declarations for global variables. */
  250.  
  251. /* variables for symbol tables:
  252.  * sctbl - start-condition symbol table
  253.  * ndtbl - name-definition symbol table
  254.  * ccltab - character class text symbol table
  255.  */
  256.  
  257. struct hash_entry
  258.     {
  259.     struct hash_entry *prev, *next;
  260.     char *name;
  261.     char *str_val;
  262.     int int_val;
  263.     } ;
  264.  
  265. typedef struct hash_entry *hash_table[];
  266.  
  267. #define NAME_TABLE_HASH_SIZE 101
  268. #define START_COND_HASH_SIZE 101
  269. #define CCL_HASH_SIZE 101
  270.  
  271. extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; 
  272. extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  273. extern struct hash_entry *ccltab[CCL_HASH_SIZE];
  274.  
  275.  
  276. /* variables for flags:
  277.  * printstats - if true (-v), dump statistics
  278.  * syntaxerror - true if a syntax error has been found
  279.  * eofseen - true if we've seen an eof in the input file
  280.  * ddebug - if true (-d), make a "debug" scanner
  281.  * trace - if true (-T), trace processing
  282.  * spprdflt - if true (-s), suppress the default rule
  283.  * interactive - if true (-I), generate an interactive scanner
  284.  * caseins - if true (-i), generate a case-insensitive scanner
  285.  * useecs - if true (-ce flag), use equivalence classes
  286.  * fulltbl - if true (-cf flag), don't compress the DFA state table
  287.  * usemecs - if true (-cm flag), use meta-equivalence classes
  288.  * reject - if true (-r flag), generate tables for REJECT macro
  289.  * fullspd - if true (-F flag), use Jacobson method of table representation
  290.  * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  291.  */
  292.  
  293. extern int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
  294. extern int interactive, caseins, useecs, fulltbl, usemecs, reject;
  295. extern int fullspd, gen_line_dirs;
  296.  
  297.  
  298. /* variables used in the flex input routines:
  299.  * datapos - characters on current output line
  300.  * dataline - number of contiguous lines of data in current data
  301.  *    statement.  Used to generate readable -f output
  302.  * skelfile - fd of the skeleton file
  303.  * yyin - input file
  304.  * temp_action_file - temporary file to hold actions
  305.  * action_file_name - name of the temporary file
  306.  * infilename - name of input file
  307.  * linenum - current input line number
  308.  */
  309.  
  310. extern int datapos, dataline, linenum;
  311. extern FILE *skelfile, *yyin, *temp_action_file;
  312. extern char *infilename;
  313. extern char *action_file_name;
  314.  
  315.  
  316. /* variables for stack of states having only one out-transition:
  317.  * onestate - state number
  318.  * onesym - transition symbol
  319.  * onenext - target state
  320.  * onedef - default base entry
  321.  * onesp - stack pointer
  322.  */
  323.  
  324. extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  325. extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  326.  
  327.  
  328. /* variables for nfa machine data:
  329.  * current_mns - current maximum on number of NFA states
  330.  * accnum - number of the last accepting state
  331.  * firstst - physically the first state of a fragment
  332.  * lastst - last physical state of fragment
  333.  * finalst - last logical state of fragment
  334.  * transchar - transition character
  335.  * trans1 - transition state
  336.  * trans2 - 2nd transition state for epsilons
  337.  * accptnum - accepting number
  338.  * lastnfa - last nfa state number created
  339.  */
  340.  
  341. extern int current_mns;
  342. extern int accnum, *firstst, *lastst, *finalst, *transchar;
  343. extern int *trans1, *trans2, *accptnum, lastnfa;
  344.  
  345.  
  346. /* variables for protos:
  347.  * numtemps - number of templates created
  348.  * numprots - number of protos created
  349.  * protprev - backlink to a more-recently used proto
  350.  * protnext - forward link to a less-recently used proto
  351.  * prottbl - base/def table entry for proto
  352.  * protcomst - common state of proto
  353.  * firstprot - number of the most recently used proto
  354.  * lastprot - number of the least recently used proto
  355.  * protsave contains the entire state array for protos
  356.  */
  357.  
  358. extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  359. extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  360.  
  361.  
  362. /* variables for managing equivalence classes:
  363.  * numecs - number of equivalence classes
  364.  * nextecm - forward link of Equivalence Class members
  365.  * ecgroup - class number or backward link of EC members
  366.  * nummecs - number of meta-equivalence classes (used to compress
  367.  *   templates)
  368.  * tecfwd - forward link of meta-equivalence classes members
  369.  * tecbck - backward link of MEC's
  370.  */
  371.  
  372. extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  373. extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  374.  
  375.  
  376. /* variables for start conditions:
  377.  * lastsc - last start condition created
  378.  * current_max_scs - current limit on number of start conditions
  379.  * scset - set of rules active in start condition
  380.  * scbol - set of rules active only at the beginning of line in a s.c.
  381.  * scxclu - true if start condition is exclusive
  382.  * actvsc - stack of active start conditions for the current rule
  383.  */
  384.  
  385. extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *actvsc;
  386.  
  387.  
  388. /* variables for dfa machine data:
  389.  * current_max_dfa_size - current maximum number of NFA states in DFA
  390.  * current_max_xpairs - current maximum number of non-template xtion pairs
  391.  * current_max_template_xpairs - current maximum number of template pairs
  392.  * current_max_dfas - current maximum number DFA states
  393.  * lastdfa - last dfa state number created
  394.  * nxt - state to enter upon reading character
  395.  * chk - check value to see if "nxt" applies
  396.  * tnxt - internal nxt table for templates
  397.  * base - offset into "nxt" for given state
  398.  * def - where to go if "chk" disallows "nxt" entry
  399.  * tblend - last "nxt/chk" table entry being used
  400.  * firstfree - first empty entry in "nxt/chk" table
  401.  * dss - nfa state set for each dfa
  402.  * dfasiz - size of nfa state set for each dfa
  403.  * dfaacc - accepting set for each dfa state (or accepting number, if
  404.  *    -r is not given)
  405.  * accsiz - size of accepting set for each dfa state
  406.  * dhash - dfa state hash value
  407.  * todo - queue of DFAs still to be processed
  408.  * todo_head - head of todo queue
  409.  * todo_next - next available entry on todo queue
  410.  * numas - number of DFA accepting states created; note that this
  411.  *    is not necessarily the same value as accnum, which is the analogous
  412.  *    value for the NFA
  413.  * numsnpairs - number of state/nextstate transition pairs
  414.  * jambase - position in base/def where the default jam table starts
  415.  * jamstate - state number corresponding to "jam" state
  416.  * end_of_buffer_state - end-of-buffer dfa state number
  417.  */
  418.  
  419. extern int current_max_dfa_size, current_max_xpairs;
  420. extern int current_max_template_xpairs, current_max_dfas;
  421. extern int lastdfa, lasttemp, *nxt, *chk, *tnxt;
  422. extern int *base, *def, tblend, firstfree, **dss, *dfasiz;
  423. extern union dfaacc_union
  424.     {
  425.     int *dfaacc_set;
  426.     long dfaacc_state;
  427.     } *dfaacc;
  428. extern int *accsiz, *dhash, *todo, todo_head, todo_next, numas;
  429. extern int numsnpairs, jambase, jamstate;
  430. extern int end_of_buffer_state;
  431.  
  432. /* variables for ccl information:
  433.  * lastccl - ccl index of the last created ccl
  434.  * current_maxccls - current limit on the maximum number of unique ccl's
  435.  * cclmap - maps a ccl index to its set pointer
  436.  * ccllen - gives the length of a ccl
  437.  * cclng - true for a given ccl if the ccl is negated
  438.  * cclreuse - counts how many times a ccl is re-used
  439.  * current_max_ccl_tbl_size - current limit on number of characters needed
  440.  *    to represent the unique ccl's
  441.  * ccltbl - holds the characters in each ccl - indexed by cclmap
  442.  */
  443.  
  444. extern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  445. extern int current_max_ccl_tbl_size;
  446. extern char *ccltbl;
  447.  
  448.  
  449. /* variables for miscellaneous information:
  450.  * starttime - real-time when we started
  451.  * endtime - real-time when we ended
  452.  * nmstr - last NAME scanned by the scanner
  453.  * sectnum - section number currently being parsed
  454.  * nummt - number of empty nxt/chk table entries
  455.  * hshcol - number of hash collisions detected by snstods
  456.  * dfaeql - number of times a newly created dfa was equal to an old one
  457.  * numeps - number of epsilon NFA states created
  458.  * eps2 - number of epsilon states which have 2 out-transitions
  459.  * num_reallocs - number of times it was necessary to realloc() a group
  460.  *          of arrays
  461.  * tmpuses - number of DFA states that chain to templates
  462.  * totnst - total number of NFA states used to make DFA states
  463.  * peakpairs - peak number of transition pairs we had to store internally
  464.  * numuniq - number of unique transitions
  465.  * numdup - number of duplicate transitions
  466.  * hshsave - number of hash collisions saved by checking number of states
  467.  */
  468.  
  469. extern char *starttime, *endtime, nmstr[MAXLINE];
  470. extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  471. extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  472.  
  473. char *allocate_array(), *reallocate_array();
  474.  
  475. #define allocate_integer_array(size) \
  476.     (int *) allocate_array( size, sizeof( int ) )
  477.  
  478. #define reallocate_integer_array(array,size) \
  479.     (int *) reallocate_array( (char *) array, size, sizeof( int ) )
  480. /*
  481.  
  482.   identifiers have been truncated: 
  483.   allocate_integer_pointer_array    --> allocate_intptr_array
  484.   reallocate_integer_pointer_array  --> reallocate_intptr_array
  485.   1/89 DrH
  486. */
  487.  
  488. #define allocate_intptr_array(size) \
  489.     (int **) allocate_array( size, sizeof( int * ) )
  490.  
  491. #define allocate_dfaacc_union(size) \
  492.     (union dfaacc_union *) \
  493.         allocate_array( size, sizeof( union dfaacc_union ) )
  494.  
  495. #define reallocate_intptr_array(array,size) \
  496.     (int **) reallocate_array( (char *) array, size, sizeof( int * ) )
  497.  
  498. #define reallocate_dfaacc_union(array, size) \
  499.     (union dfaacc_union *)  reallocate_array( (char *) array, size, sizeof( union dfaacc_union ) )
  500.  
  501. #define allocate_character_array(size) allocate_array( size, sizeof( char ) )
  502.  
  503. #define reallocate_character_array(array,size) \
  504.     reallocate_array( array, size, sizeof( char ) )
  505.  
  506.  
  507. /* used to communicate between scanner and parser.  The type should really
  508.  * be YYSTYPE, but we can't easily get our hands on it.
  509.  */
  510. extern int yylval;
  511. extern int yyparse( void) ;
  512. /*
  513. **    1989.12.30 - Roberto Artigas Jr - Added these here.
  514. **    Were located in 'parse.h'. See explanation above.
  515. */
  516. extern void synerr (char *) ;
  517. extern void yyerror (char *) ;
  518.