* reordered a little bit
[mascara-docs.git] / i86 / elks / elkscmd / byacc / defs.h
bloba24bc2886e91372e0e19ef156ceb7a66b9a7cc3d
1 #if ASSERT
2 #include <assert.h>
3 #else
4 #define assert(_a_)
5 #endif
6 #include <ctype.h>
7 #include <stdio.h>
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 */
20 /* store n bits */
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 */
25 #if !__STDC__
26 #define MAXCHAR 255
27 #define MAXSHORT 32767
28 #define MINSHORT -32768
29 #define BITS_PER_WORD 16
30 #define BITS_PER_BPW 4
31 #else
32 #include <limits.h>
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)
38 #endif
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))))
45 /* character names */
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"
68 /* keyword codes */
70 #define TOKEN 0
71 #define LEFT 1
72 #define RIGHT 2
73 #define NONASSOC 3
74 #define MARK 4
75 #define TEXT 5
76 #define TYPE 6
77 #define START 7
78 #define UNION 8
79 #define IDENT 9
82 /* symbol classes */
84 #define UNKNOWN 0
85 #define TERM 1
86 #define NONTERM 2
89 /* the undefined value */
91 #define UNDEFINED (-1)
94 /* action codes */
96 #define SHIFT 1
97 #define REDUCE 2
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')
107 /* symbol macros */
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;
126 struct bucket
128 struct bucket *link;
129 struct bucket *next;
130 char *name;
131 char *tag;
132 short value;
133 short index;
134 short prec;
135 char class;
136 char assoc;
140 /* the structure of the LR(0) state machine */
142 typedef struct core core;
143 struct core
145 struct core *next;
146 struct core *link;
147 short number;
148 short accessing_symbol;
149 short nitems;
150 short items[1];
154 /* the structure used to record shifts */
156 typedef struct shifts shifts;
157 struct shifts
159 struct shifts *next;
160 short number;
161 short nshifts;
162 short shift[1];
166 /* the structure used to store reductions */
168 typedef struct reductions reductions;
169 struct reductions
171 struct reductions *next;
172 short number;
173 short nreds;
174 short rules[1];
178 /* the structure used to represent parser actions */
180 typedef struct action action;
181 struct action
183 struct action *next;
184 short symbol;
185 short number;
186 short prec;
187 char action_code;
188 char assoc;
189 char suppressed;
193 /* global variables */
195 extern char dflag;
196 extern char lflag;
197 extern char rflag;
198 extern char tflag;
199 extern char vflag;
200 extern char *symbol_prefix;
202 extern char *myname;
203 extern char *cptr;
204 extern char *line;
205 extern int lineno;
206 extern int outline;
208 extern char *banner[];
209 extern char *tables[];
210 extern char *header[];
211 extern char *body[];
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;
232 extern int nitems;
233 extern int nrules;
234 extern int nsyms;
235 extern int ntokens;
236 extern int nvars;
237 extern int ntags;
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;
248 extern short *ritem;
249 extern short *rlhs;
250 extern short *rrhs;
251 extern short *rprec;
252 extern char *rassoc;
254 extern short **derives;
255 extern char *nullable;
257 extern bucket *first_symbol;
258 extern bucket *last_symbol;
260 extern int nstates;
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;
268 extern unsigned *LA;
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;
276 extern int SRtotal;
277 extern int RRtotal;
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 */
294 extern int errno;
297 /* system functions */
299 extern void free();
300 extern char *calloc();
301 extern char *malloc();
302 extern char *realloc();
303 extern char *strcpy();