6 /* machine-dependent definitions */
7 /* the following definitions are for the Tahoe */
8 /* they might have to be changed for other machines */
10 /* MAXCHAR is the largest unsigned character value */
11 /* MAXSHORT is the largest value of a C short */
12 /* MINSHORT is the most negative value of a C short */
13 /* MAXTABLE is the maximum table size */
14 /* BITS_PER_WORD is the number of bits in a C unsigned */
15 /* WORDSIZE computes the number of words needed to */
17 /* BIT returns the value of the n-th bit starting */
18 /* from r (0-indexed) */
19 /* SETBIT sets the n-th bit starting from r */
23 #define MAXSHORT 32767
24 #define MINSHORT -32768
25 #define BITS_PER_WORD 32
28 #define MAXCHAR UCHAR_MAX
29 #define MAXSHORT SHRT_MAX
30 #define MINSHORT SHRT_MIN
31 #define BITS_PER_WORD (INT_MAX == 32767 ? 16 : 32)
32 #define BITS_PER_BPW (INT_MAX == 32767 ? 4 : 5)
34 #define MAXTABLE 32500
35 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
36 #define BIT(r, n) ((((r)[(n)>>BITS_PER_BPW])>>((n)&(BITS_PER_WORD-1)))&1)
37 #define SETBIT(r, n) ((r)[(n)>>BITS_PER_BPW]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
42 #define NUL '\0' /* the null character */
43 #define NEWLINE '\n' /* line feed */
44 #define SP ' ' /* space */
45 #define BS '\b' /* backspace */
46 #define HT '\t' /* horizontal tab */
47 #define VT '\013' /* vertical tab */
48 #define CR '\r' /* carriage return */
49 #define FF '\f' /* form feed */
50 #define QUOTE '\'' /* single quote */
51 #define DOUBLE_QUOTE '\"' /* double quote */
52 #define BACKSLASH '\\' /* backslash */
55 /* defines for constructing filenames */
57 #define CODE_SUFFIX ".code.c"
58 #define DEFINES_SUFFIX ".tab.h"
59 #define OUTPUT_SUFFIX ".tab.c"
60 #define VERBOSE_SUFFIX ".output"
84 /* the undefined value */
86 #define UNDEFINED (-1)
95 /* character macros */
97 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
98 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
99 #define NUMERIC_VALUE(c) ((c) - '0')
104 #define ISTOKEN(s) ((s) < start_symbol)
105 #define ISVAR(s) ((s) >= start_symbol)
108 /* storage allocation macros */
110 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
111 #define FREE(x) (free((char*)(x)))
112 #define MALLOC(n) (malloc((unsigned)(n)))
113 #define NEW(t) ((t*)allocate(sizeof(t)))
114 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
115 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
118 /* the structure of a symbol table entry */
120 typedef struct bucket bucket
;
135 /* the structure of the LR(0) state machine */
137 typedef struct core core
;
143 short accessing_symbol
;
149 /* the structure used to record shifts */
151 typedef struct shifts shifts
;
161 /* the structure used to store reductions */
163 typedef struct reductions reductions
;
166 struct reductions
*next
;
173 /* the structure used to represent parser actions */
175 typedef struct action action
;
188 /* global variables */
195 extern char *symbol_prefix
;
203 extern char *banner
[];
204 extern char *tables
[];
205 extern char *header
[];
207 extern char *trailer
[];
209 extern char *action_file_name
;
210 extern char *code_file_name
;
211 extern char *defines_file_name
;
212 extern char *input_file_name
;
213 extern char *output_file_name
;
214 extern char *text_file_name
;
215 extern char *union_file_name
;
216 extern char *verbose_file_name
;
218 extern FILE *action_file
;
219 extern FILE *code_file
;
220 extern FILE *defines_file
;
221 extern FILE *input_file
;
222 extern FILE *output_file
;
223 extern FILE *text_file
;
224 extern FILE *union_file
;
225 extern FILE *verbose_file
;
234 extern char unionized
;
235 extern char line_format
[];
237 extern int start_symbol
;
238 extern char **symbol_name
;
239 extern short *symbol_value
;
240 extern short *symbol_prec
;
241 extern char *symbol_assoc
;
249 extern short **derives
;
250 extern char *nullable
;
252 extern bucket
*first_symbol
;
253 extern bucket
*last_symbol
;
256 extern core
*first_state
;
257 extern shifts
*first_shift
;
258 extern reductions
*first_reduction
;
259 extern short *accessing_symbol
;
260 extern core
**state_table
;
261 extern shifts
**shift_table
;
262 extern reductions
**reduction_table
;
264 extern short *LAruleno
;
265 extern short *lookaheads
;
266 extern short *goto_map
;
267 extern short *from_state
;
268 extern short *to_state
;
270 extern action
**parser
;
273 extern short *SRconflicts
;
274 extern short *RRconflicts
;
275 extern short *defred
;
276 extern short *rules_used
;
277 extern short nunused
;
278 extern short final_state
;
280 /* global functions */
282 extern char *allocate();
283 extern bucket
*lookup();
284 extern bucket
*make_bucket();
287 /* system variables */
292 /* system functions */
295 extern char *calloc();
296 extern char *malloc();
297 extern char *realloc();
298 extern char *strcpy();