Home | History | Annotate | Download | only in dlg
      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.33
     24  * Will Cohen
     25  * With mods by Terence Parr; AHPCRC, University of Minnesota
     26  * 1989-2001
     27  */
     28 
     29 /* MR1 Move pcctscfg.h to top of file 					*/
     30 
     31 #include "pcctscfg.h"
     32 
     33 /* turn off warnings for unreferenced labels */
     34 
     35 #ifdef _MSC_VER
     36 #pragma warning(disable:4102)
     37 #endif
     38 
     39 #include "set.h"
     40 
     41 #define TRUE	1
     42 #define FALSE	0
     43 
     44 /***** output related stuff *******************/
     45 #define IN	input_stream
     46 #define OUT	output_stream
     47 
     48 #define MAX_MODES	50	/* number of %%names allowed */
     49 #define MAX_ON_LINE	10
     50 
     51 #define NFA_MIN		64	/* minimum nfa_array size */
     52 #define DFA_MIN		64	/* minimum dfa_array size */
     53 
     54 #define DEFAULT_CLASSNAME "DLGLexer"
     55 
     56 /* these macros allow the size of the character set to be easily changed */
     57 /* NOTE: do NOT change MIN_CHAR since EOF is the lowest char, -1 */
     58 #define MIN_CHAR (-1)	/* lowest possible character possible on input */
     59 #define MAX_CHAR 255	/* highest possible character possible on input */
     60 #define CHAR_RANGE (1+(MAX_CHAR) - (MIN_CHAR))
     61 
     62 /* indicates that the not an "array" reference */
     63 #define NIL_INDEX 0
     64 
     65 /* size of hash table used to find dfa_states quickly */
     66 #define HASH_SIZE 211
     67 
     68 #define nfa_node struct _nfa_node
     69 nfa_node {
     70 	int		node_no;
     71 	int		nfa_set;
     72 	int		accept;	/* what case to use */
     73 	nfa_node	*trans[2];
     74 	set		label;	/* one arc always labelled with epsilon */
     75 };
     76 
     77 #define dfa_node struct _dfa_node
     78 dfa_node {
     79 	int		node_no;
     80 	int		dfa_set;
     81 	int		alternatives;	/* used for interactive mode */
     82 					/* are more characters needed */
     83 	int		done;
     84 	set		nfa_states;
     85 	int		trans[1];/* size of transition table depends on
     86 				  * number of classes required for automata.
     87 				  */
     88 
     89 
     90 };
     91 
     92 /******** macros for accessing the NFA and DFA nodes ****/
     93 #define NFA(x)	(nfa_array[x])
     94 #define DFA(x)	(dfa_array[x])
     95 #define DFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
     96 #define NFA_NO(x) ( (x) ? (x)->node_no : NIL_INDEX)
     97 
     98 /******** wrapper for memory checking ***/
     99 /*#define malloc(x)	dlg_malloc((x),__FILE__,__LINE__)*/
    100 
    101 /*#define calloc(x,y)	dlg_calloc((x),(y),__FILE__,__LINE__)*/
    102 
    103 /******** antlr attributes *************/
    104 typedef struct {
    105 	unsigned char letter;
    106 	nfa_node *l,*r;
    107 	set label;
    108 	} Attrib;
    109 
    110 #define zzcr_attr(attr, token, text) {					\
    111 	(attr)->letter = text[0]; (attr)->l = NULL;			\
    112 	(attr)->r = NULL; (attr)->label = empty;			\
    113 }
    114 #define zzd_attr(a)	set_free((a)->label);
    115 
    116 /******************** Variable ******************************/
    117 extern char	program[];	/* tells what program this is */
    118 extern char	version[];	/* tells what version this is */
    119 extern char	*file_str[];	/* file names being used */
    120 extern int	err_found;	/* flag to indicate error occured */
    121 extern int	action_no;	/* last action function printed */
    122 extern int	func_action;	/* should actions be turned into functions?*/
    123 extern set	used_chars;	/* used to label trans. arcs */
    124 extern set	used_classes;	/* classes or chars used to label trans. arcs */
    125 extern int	class_no;	/* number of classes used */
    126 extern set	class_sets[];	/* shows char. in each class */
    127 extern set	normal_chars;	/* mask off unused portion of set */
    128 extern int	comp_level;	/* what compression level to use */
    129 extern int	interactive;	/* interactive scanner (avoid lookahead)*/
    130 extern int	mode_counter;	/* keeps track of the number of %%name */
    131 extern int	dfa_basep[];	/* start of each group of dfa */
    132 extern int	dfa_class_nop[];/* number of transistion arcs in */
    133 				/* each dfa in each mode */
    134 extern int	nfa_allocated;
    135 extern int	dfa_allocated;
    136 extern nfa_node	**nfa_array;	/* start of nfa "array" */
    137 extern dfa_node	**dfa_array;	/* start of dfa "array" */
    138 extern int	operation_no;	/* unique number for each operation */
    139 extern FILE	*input_stream;	/* where description read from */
    140 extern FILE	*output_stream; /* where to put the output */
    141 extern FILE	*mode_stream;	/* where to put the mode output */
    142 extern FILE	*class_stream;
    143 extern char	*mode_file;	/* name of file for mode output */
    144 extern int	gen_ansi;	/* produce ansi compatible code */
    145 extern int	case_insensitive;/* ignore case of input spec. */
    146 extern int	warn_ambig;	/* show if regular expressions ambiguous */
    147 extern int	gen_cpp;
    148 extern char *cl_file_str;
    149 extern int	firstLexMember;	/* MR1 */
    150 extern char *OutputDirectory;
    151 extern char	*class_name;
    152 
    153 /******************** Functions ******************************/
    154 #ifdef __USE_PROTOS
    155 extern char 	*dlg_malloc(int, char *, int); /* wrapper malloc */
    156 extern char 	*dlg_calloc(int, int, char *, int); /* wrapper calloc */
    157 extern int	reach(unsigned *, register int, unsigned *);
    158 extern set	closure(set *, unsigned *);
    159 extern dfa_node *new_dfa_node(set);
    160 extern nfa_node *new_nfa_node(void);
    161 extern dfa_node *dfastate(set);
    162 extern dfa_node **nfa_to_dfa(nfa_node *);
    163 extern void	internal_error(char *, char *, int);    /* MR9 23-Sep-97 */
    164 extern FILE	*read_stream(char *);	/* opens file for reading */
    165 extern FILE	*write_stream(char *);	/* opens file for writing */
    166 extern void	make_nfa_model_node(void);
    167 extern void	make_dfa_model_node(int);
    168 extern char *ClassName(char *);
    169 extern char *OutMetaName(char *);
    170 extern void error(char*, int);
    171 extern void warning(char*, int);
    172 extern void p_head(void);
    173 extern void p_class_hdr(void);
    174 extern void p_includes(void);
    175 extern void p_tables(void);
    176 extern void p_tail(void);					/* MR1 */
    177 extern void p_class_def1(void);				/* MR1 */
    178 extern void new_automaton_mode(void);			/* MR1 */
    179 extern int  relabel(nfa_node *,int);			/* MR1 */
    180 extern void p_shift_table(int);				/* MR1 */
    181 extern void p_bshift_table(void);				/* MR1 */
    182 extern void p_class_table(void);				/* MR1 */
    183 extern void p_mode_def(char *,int);			/* MR1 */
    184 extern void init(void);					/* MR1 */
    185 extern void p_class_def2(void);				/* MR1 */
    186 extern void clear_hash(void);				/* MR1 */
    187 extern void p_alternative_table(void);			/* MR1 */
    188 extern void p_node_table(void);				/* MR1 */
    189 extern void p_dfa_table(void);				/* MR1 */
    190 extern void p_accept_table(void);				/* MR1 */
    191 extern void p_action_table(void);				/* MR1 */
    192 extern void p_base_table(void);				/* MR1 */
    193 extern void p_single_node(int,int);			/* MR1 */
    194 extern char * minsize(int);				/* MR1 */
    195 extern void close1(nfa_node *,int,set *);		/* MR1 */
    196 extern void partition(nfa_node *,int);			/* MR1 */
    197 extern void intersect_nfa_labels(nfa_node *,set *);	/* MR1 */
    198 extern void r_intersect(nfa_node *,set *);		/* MR1 */
    199 extern void label_node(nfa_node *);			/* MR1 */
    200 extern void label_with_classes(nfa_node *);		/* MR1 */
    201 
    202 #else
    203 extern char *dlg_malloc();	/* wrapper malloc */
    204 extern char *dlg_calloc();	/* wrapper calloc */
    205 extern int	reach();
    206 extern set	closure();
    207 extern dfa_node *new_dfa_node();
    208 extern nfa_node *new_nfa_node();
    209 extern dfa_node *dfastate();
    210 extern dfa_node **nfa_to_dfa();
    211 extern void	internal_error();   /* MR9 23-Sep-97 */
    212 extern FILE	*read_stream();		/* opens file for reading */
    213 extern FILE	*write_stream();	/* opens file for writing */
    214 extern void	make_nfa_model_node();
    215 extern void	make_dfa_model_node();
    216 extern char *ClassName();
    217 extern char *OutMetaName();
    218 extern void error();
    219 extern void warning();
    220 extern void p_head();                   /* MR9 */
    221 extern void p_class_hdr();              /* MR9 */
    222 extern void p_includes();               /* MR9 */
    223 extern void p_tables();                 /* MR9 */
    224 extern void p_tail();					/* MR1 */
    225 extern void p_class_def1();				/* MR1 */
    226 extern void new_automaton_mode();			/* MR1 */
    227 extern int  relabel();					/* MR1 */
    228 extern void p_shift_table();				/* MR1 */
    229 extern void p_bshift_table();				/* MR1 */
    230 extern void p_class_table();				/* MR1 */
    231 extern void p_mode_def();				/* MR1 */
    232 extern void init();					/* MR1 */
    233 extern void p_class_def2();				/* MR1 */
    234 extern void clear_hash();				/* MR1 */
    235 extern void p_alternative_table();			/* MR1 */
    236 extern void p_node_table();				/* MR1 */
    237 extern void p_dfa_table();				/* MR1 */
    238 extern void p_accept_table();				/* MR1 */
    239 extern void p_action_table();				/* MR1 */
    240 extern void p_base_table();				/* MR1 */
    241 extern void p_single_node();				/* MR1 */
    242 extern char * minsize();				/* MR1 */
    243 extern void close1();					/* MR1 */
    244 extern void partition();				/* MR1 */
    245 extern void intersect_nfa_labels();			/* MR1 */
    246 extern void r_intersect();				/* MR1 */
    247 extern void label_node();				/* MR1 */
    248 extern void label_with_classes();			/* MR1 */
    249 
    250 #endif
    251