2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)defs.h 5.6 (Berkeley) 5/24/93
42 /* machine-dependent definitions */
43 /* the following definitions are for the Tahoe */
44 /* they might have to be changed for other machines */
46 /* MAXTABLE is the maximum table size */
47 /* BITS_PER_WORD is the number of bits in a C unsigned */
48 /* WORDSIZE computes the number of words needed to */
50 /* BIT returns the value of the n-th bit starting */
51 /* from r (0-indexed) */
52 /* SETBIT sets the n-th bit starting from r */
54 #define MAXTABLE 32500
55 #define BITS_PER_WORD 32
56 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
57 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
58 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
63 #define NUL '\0' /* the null character */
64 #define NEWLINE '\n' /* line feed */
65 #define SP ' ' /* space */
66 #define BS '\b' /* backspace */
67 #define HT '\t' /* horizontal tab */
68 #define VT '\013' /* vertical tab */
69 #define CR '\r' /* carriage return */
70 #define FF '\f' /* form feed */
71 #define QUOTE '\'' /* single quote */
72 #define DOUBLE_QUOTE '\"' /* double quote */
73 #define BACKSLASH '\\' /* backslash */
76 /* defines for constructing filenames */
78 #define CODE_SUFFIX ".code.c"
79 #define DEFINES_SUFFIX ".tab.h"
80 #define OUTPUT_SUFFIX ".tab.c"
81 #define VERBOSE_SUFFIX ".output"
106 /* the undefined value */
108 #define UNDEFINED (-1)
117 /* character macros */
119 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
120 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
121 #define NUMERIC_VALUE(c) ((c) - '0')
126 #define ISTOKEN(s) ((s) < start_symbol)
127 #define ISVAR(s) ((s) >= start_symbol)
130 /* storage allocation macros */
132 #define NEW(t) ((t*)allocate(sizeof(t)))
133 #define NEW2(n,t) ((t*)allocate((n)*sizeof(t)))
136 /* the structure of a symbol table entry */
138 typedef struct bucket bucket;
153 /* the structure of the LR(0) state machine */
155 typedef struct core core;
161 short accessing_symbol;
167 /* the structure used to record shifts */
169 typedef struct shifts shifts;
179 /* the structure used to store reductions */
181 typedef struct reductions reductions;
184 struct reductions *next;
191 /* the structure used to represent parser actions */
193 typedef struct action action;
206 /* global variables */
213 extern const char *symbol_prefix;
220 extern const char *banner[];
221 extern const char *tables[];
222 extern const char *header[];
223 extern const char *body[];
224 extern const char *trailer[];
226 extern char *action_file_name;
227 extern char *code_file_name;
228 extern char *defines_file_name;
229 extern const char *input_file_name;
230 extern char *output_file_name;
231 extern char *text_file_name;
232 extern char *union_file_name;
233 extern char *verbose_file_name;
235 extern FILE *action_file;
236 extern FILE *code_file;
237 extern FILE *defines_file;
238 extern FILE *input_file;
239 extern FILE *output_file;
240 extern FILE *text_file;
241 extern FILE *union_file;
242 extern FILE *verbose_file;
251 extern char unionized;
253 extern int start_symbol;
254 extern char **symbol_name;
255 extern short *symbol_value;
256 extern short *symbol_prec;
257 extern char *symbol_assoc;
265 extern short **derives;
266 extern char *nullable;
268 extern bucket *first_symbol;
269 extern bucket *last_symbol;
272 extern core *first_state;
273 extern shifts *first_shift;
274 extern reductions *first_reduction;
275 extern short *accessing_symbol;
276 extern core **state_table;
277 extern shifts **shift_table;
278 extern reductions **reduction_table;
280 extern short *LAruleno;
281 extern short *lookaheads;
282 extern short *goto_map;
283 extern short *from_state;
284 extern short *to_state;
286 extern action **parser;
290 extern short *SRconflicts;
291 extern short *RRconflicts;
292 extern short *defred;
293 extern short *rules_used;
294 extern short nunused;
295 extern short final_state;
297 /* global functions */
299 void *allocate(size_t);
300 void closure(short *, int);
301 void create_symbol_table(void);
302 void default_action_warning(void);
303 void dollar_error(int, char *, char *) __dead2;
304 void dollar_warning(int, int);
305 void done(int) __dead2;
306 void fatal(const char *msg) __dead2;
307 void finalize_closure(void);
308 void free_parser(void);
309 void free_symbols(void);
310 void free_symbol_table(void);
311 void illegal_character(char *) __dead2;
312 void illegal_tag(int, char *, char *) __dead2;
314 bucket *lookup(char *);
316 bucket *make_bucket(const char *);
317 void make_parser(void);
318 void no_grammar(void) __dead2;
319 void no_space(void) __dead2;
320 void open_error(const char *) __dead2;
322 void over_unionized(char *) __dead2;
323 void prec_redeclared(void);
325 void reflexive_transitive_closure(unsigned *, int);
326 void reprec_warning(char *);
327 void restarted_warning(void);
328 void retyped_warning(char *);
329 void revalued_warning(char *);
330 void set_first_derives(void);
331 void syntax_error(int, char *, char *) __dead2;
332 void terminal_lhs(int) __dead2;
333 void terminal_start(char *) __dead2;
334 void tokenized_start(char *) __dead2;
335 void undefined_goal(char *) __dead2;
336 void undefined_symbol_warning(char *);
337 void unexpected_EOF(void) __dead2;
338 void unknown_rhs(int) __dead2;
339 void unterminated_action(int, char *, char *) __dead2;
340 void unterminated_comment(int, char *, char *) __dead2;
341 void unterminated_string(int, char *, char *) __dead2;
342 void unterminated_text(int, char *, char *) __dead2;
343 void unterminated_union(int, char *, char *) __dead2;
344 void untyped_lhs(void) __dead2;
345 void untyped_rhs(int, char *) __dead2;
346 void used_reserved(char *) __dead2;
348 void write_section(const char **);