home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts.zip / pccts / dlg / dlg.h < prev    next >
C/C++ Source or Header  |  1994-03-31  |  6KB  |  176 lines

  1. /* dlg header file
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * DLG 1.20
  24.  * Will Cohen
  25.  * With mods by Terence Parr; AHPCRC, University of Minnesota
  26.  * 1989-1994
  27.  */
  28. #include "set.h"
  29.  
  30. #define TRUE    1
  31. #define FALSE    0
  32.  
  33. /***** output related stuff *******************/
  34. #define IN    input_stream
  35. #define OUT    output_stream
  36.  
  37. #define MAX_MODES    50    /* number of %%names allowed */
  38. #define MAX_ON_LINE    10
  39.  
  40. #define NFA_MIN        64    /* minimum nfa_array size */
  41. #define DFA_MIN        64    /* minimum dfa_array size */
  42.  
  43. #define DirectorySymbol    "/"
  44.  
  45. #define DEFAULT_CLASSNAME "DLGLexer"
  46.  
  47. /* these macros allow the size of the character set to be easily changed */
  48. /* NOTE: do NOT change MIN_CHAR since EOF is the lowest char, -1 */
  49. #define MIN_CHAR (-1)    /* lowest possible character possible on input */
  50. #define MAX_CHAR 255    /* highest possible character possible on input */
  51. #define CHAR_RANGE (1+(MAX_CHAR) - (MIN_CHAR))
  52.  
  53. /* indicates that the not an "array" reference */
  54. #define NIL_INDEX 0
  55.  
  56. /* size of hash table used to find dfa_states quickly */
  57. #define HASH_SIZE 211
  58.  
  59. #define nfa_node struct _nfa_node
  60. nfa_node {
  61.     int        node_no;
  62.     int        nfa_set;
  63.     int        accept;    /* what case to use */
  64.     nfa_node    *trans[2];
  65.     set        label;    /* one arc always labelled with epsilon */
  66. };
  67.  
  68. #define dfa_node struct _dfa_node
  69. dfa_node {
  70.     int        node_no;
  71.     int        dfa_set;
  72.     int        alternatives;    /* used for interactive mode */
  73.                     /* are more characters needed */
  74.     int        done;
  75.     set        nfa_states;
  76.     int        trans[1];/* size of transition table depends on
  77.                   * number of classes required for automata.
  78.                   */
  79.  
  80.  
  81. };
  82.  
  83. /******** macros for accessing the NFA and DFA nodes ****/
  84. #define NFA(x)    (nfa_array[x])
  85. #define DFA(x)    (dfa_array[x])
  86. #define DFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
  87. #define NFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
  88.  
  89. /******** wrapper for memory checking ***/
  90. /*#define malloc(x)    dlg_malloc((x),__FILE__,__LINE__)*/
  91.  
  92. /*#define calloc(x,y)    dlg_calloc((x),(y),__FILE__,__LINE__)*/
  93.  
  94. /******** antlr attributes *************/
  95. typedef struct {
  96.     char letter;
  97.     nfa_node *l,*r;
  98.     set label;
  99.     } Attrib;
  100.  
  101. #define zzcr_attr(attr, token, text) {                    \
  102.     (attr)->letter = text[0]; (attr)->l = NULL;            \
  103.     (attr)->r = NULL; (attr)->label = empty;            \
  104. }
  105. #define zzd_attr(a)    set_free((a)->label);
  106.  
  107. /******************** Variable ******************************/
  108. extern char    program[];    /* tells what program this is */
  109. extern char    version[];    /* tells what version this is */
  110. extern char    *file_str[];    /* file names being used */
  111. extern int    err_found;    /* flag to indicate error occured */
  112. extern int    action_no;    /* last action function printed */
  113. extern int    func_action;    /* should actions be turned into functions?*/
  114. extern set    used_chars;    /* used to label trans. arcs */
  115. extern set    used_classes;    /* classes or chars used to label trans. arcs */
  116. extern int    class_no;    /* number of classes used */
  117. extern set    class[];    /* shows char. in each class */
  118. extern set    normal_chars;    /* mask off unused portion of set */
  119. extern int    comp_level;    /* what compression level to use */
  120. extern int    interactive;    /* interactive scanner (avoid lookahead)*/
  121. extern int    mode_counter;    /* keeps track of the number of %%name */
  122. extern int    dfa_basep[];    /* start of each group of dfa */
  123. extern int    dfa_class_nop[];/* number of transistion arcs in */
  124.                 /* each dfa in each mode */
  125. extern int    nfa_allocated;
  126. extern int    dfa_allocated;
  127. extern nfa_node    **nfa_array;    /* start of nfa "array" */
  128. extern dfa_node    **dfa_array;    /* start of dfa "array" */
  129. extern int    operation_no;    /* unique number for each operation */
  130. extern FILE    *input_stream;    /* where description read from */
  131. extern FILE    *output_stream; /* where to put the output */
  132. extern FILE    *mode_stream;    /* where to put the mode output */
  133. extern FILE    *class_stream;
  134. extern char    *mode_file;    /* name of file for mode output */
  135. extern int    gen_ansi;    /* produce ansi compatible code */
  136. extern int    case_insensitive;/* ignore case of input spec. */
  137. extern int    warn_ambig;    /* show if regular expressions ambigious */
  138. extern int    gen_cpp;
  139. extern char *cl_file_str;
  140. extern char *outdir;
  141.  
  142. /******************** Functions ******************************/
  143. #ifdef __STDC__
  144. extern char     *dlg_malloc(int, char *, int); /* wrapper malloc */
  145. extern char     *dlg_calloc(int, int, char *, int); /* wrapper calloc */
  146. extern int    reach(unsigned *, register int, unsigned *);
  147. extern set    closure(set *, unsigned *);
  148. extern dfa_node *new_dfa_node(set);
  149. extern nfa_node *new_nfa_node(void);
  150. extern dfa_node *dfastate(set);
  151. extern dfa_node **nfa_to_dfa(nfa_node *);
  152. extern        internal_error(char *, char *, int);
  153. extern FILE    *read_stream(char *);    /* opens file for reading */
  154. extern FILE    *write_stream(char *);    /* opens file for writing */
  155. extern void    make_nfa_model_node(void);
  156. extern void    make_dfa_model_node(int);
  157. extern char *ClassName(char *);
  158. extern char *OutMetaName(char *);
  159. #else
  160. extern char *dlg_malloc();    /* wrapper malloc */
  161. extern char *dlg_calloc();    /* wrapper calloc */
  162. extern int    reach();
  163. extern set    closure();
  164. extern dfa_node *new_dfa_node();
  165. extern nfa_node *new_nfa_node();
  166. extern dfa_node *dfastate();
  167. extern dfa_node **nfa_to_dfa();
  168. extern        internal_error();
  169. extern FILE    *read_stream();        /* opens file for reading */
  170. extern FILE    *write_stream();    /* opens file for writing */
  171. extern void    make_nfa_model_node();
  172. extern void    make_dfa_model_node();
  173. extern char *ClassName();
  174. extern char *OutMetaName();
  175. #endif
  176.