10 /* machine-dependent definitions */
11 /* the following definitions are for the Tahoe */
12 /* they might have to be changed for other machines */
14 /* MAXCHAR is the largest unsigned character value */
15 /* MAXSHORT is the largest value of a C short */
16 /* MINSHORT is the most negative value of a C short */
17 /* MAXTABLE is the maximum table size */
18 /* BITS_PER_WORD is the number of bits in a C unsigned */
19 /* WORDSIZE computes the number of words needed to */
21 /* BIT returns the value of the n-th bit starting */
22 /* from r (0-indexed) */
23 /* SETBIT sets the n-th bit starting from r */
27 #define MAXSHORT 32767
28 #define MINSHORT -32768
29 #define BITS_PER_WORD 16
30 #define BITS_PER_BPW 4
33 #define MAXCHAR UCHAR_MAX
34 #define MAXSHORT SHRT_MAX
35 #define MINSHORT SHRT_MIN
36 #define BITS_PER_WORD (INT_MAX == 32767 ? 16 : 32)
37 #define BITS_PER_BPW (INT_MAX == 32767 ? 4 : 5)
39 #define MAXTABLE 32500
40 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
41 #define BIT(r, n) ((((r)[(n)>>BITS_PER_BPW])>>((n)&(BITS_PER_WORD-1)))&1)
42 #define SETBIT(r, n) ((r)[(n)>>BITS_PER_BPW]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
47 #define NUL '\0' /* the null character */
48 #define NEWLINE '\n' /* line feed */
49 #define SP ' ' /* space */
50 #define BS '\b' /* backspace */
51 #define HT '\t' /* horizontal tab */
52 #define VT '\013' /* vertical tab */
53 #define CR '\r' /* carriage return */
54 #define FF '\f' /* form feed */
55 #define QUOTE '\'' /* single quote */
56 #define DOUBLE_QUOTE '\"' /* double quote */
57 #define BACKSLASH '\\' /* backslash */
60 /* defines for constructing filenames */
62 #define CODE_SUFFIX ".code.c"
63 #define DEFINES_SUFFIX ".tab.h"
64 #define OUTPUT_SUFFIX ".tab.c"
65 #define VERBOSE_SUFFIX ".output"
89 /* the undefined value */
91 #define UNDEFINED (-1)
100 /* character macros */
102 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
103 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
104 #define NUMERIC_VALUE(c) ((c) - '0')
109 #define ISTOKEN(s) ((s) < start_symbol)
110 #define ISVAR(s) ((s) >= start_symbol)
113 /* storage allocation macros */
115 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
116 #define FREE(x) (free((char*)(x)))
117 #define MALLOC(n) (malloc((unsigned)(n)))
118 #define NEW(t) ((t*)allocate(sizeof(t)))
119 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
120 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
123 /* the structure of a symbol table entry */
125 typedef struct bucket bucket
;
140 /* the structure of the LR(0) state machine */
142 typedef struct core core
;
148 short accessing_symbol
;
154 /* the structure used to record shifts */
156 typedef struct shifts shifts
;
166 /* the structure used to store reductions */
168 typedef struct reductions reductions
;
171 struct reductions
*next
;
178 /* the structure used to represent parser actions */
180 typedef struct action action
;
193 /* global variables */
200 extern char *symbol_prefix
;
208 extern char *banner
[];
209 extern char *tables
[];
210 extern char *header
[];
212 extern char *trailer
[];
214 extern char *action_file_name
;
215 extern char *code_file_name
;
216 extern char *defines_file_name
;
217 extern char *input_file_name
;
218 extern char *output_file_name
;
219 extern char *text_file_name
;
220 extern char *union_file_name
;
221 extern char *verbose_file_name
;
223 extern FILE *action_file
;
224 extern FILE *code_file
;
225 extern FILE *defines_file
;
226 extern FILE *input_file
;
227 extern FILE *output_file
;
228 extern FILE *text_file
;
229 extern FILE *union_file
;
230 extern FILE *verbose_file
;
239 extern char unionized
;
240 extern char line_format
[];
242 extern int start_symbol
;
243 extern char **symbol_name
;
244 extern short *symbol_value
;
245 extern short *symbol_prec
;
246 extern char *symbol_assoc
;
254 extern short **derives
;
255 extern char *nullable
;
257 extern bucket
*first_symbol
;
258 extern bucket
*last_symbol
;
261 extern core
*first_state
;
262 extern shifts
*first_shift
;
263 extern reductions
*first_reduction
;
264 extern short *accessing_symbol
;
265 extern core
**state_table
;
266 extern shifts
**shift_table
;
267 extern reductions
**reduction_table
;
269 extern short *LAruleno
;
270 extern short *lookaheads
;
271 extern short *goto_map
;
272 extern short *from_state
;
273 extern short *to_state
;
275 extern action
**parser
;
278 extern short *SRconflicts
;
279 extern short *RRconflicts
;
280 extern short *defred
;
281 extern short *rules_used
;
282 extern short nunused
;
283 extern short final_state
;
285 /* global functions */
287 extern char *allocate();
288 extern bucket
*lookup();
289 extern bucket
*make_bucket();
292 /* system variables */
297 /* system functions */
300 extern char *calloc();
301 extern char *malloc();
302 extern char *realloc();
303 extern char *strcpy();