1 /* $Id: defs.h,v 1.20 2009/10/27 10:47:43 tom Exp $ */
17 #define CONCAT(first,second) first #second
18 #define CONCAT1(string,number) CONCAT(string, number)
19 #define CONCAT2(first,second) #first "." #second
22 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
24 #define VSTRING(a,b) CONCAT2(a,b)
27 #define VERSION VSTRING(YYMAJOR, YYMINOR)
29 /* machine-dependent definitions */
30 /* the following definitions are for the Tahoe */
31 /* they might have to be changed for other machines */
33 /* MAXCHAR is the largest unsigned character value */
34 /* MAXSHORT is the largest value of a C short */
35 /* MINSHORT is the most negative value of a C short */
36 /* MAXTABLE is the maximum table size */
37 /* BITS_PER_WORD is the number of bits in a C unsigned */
38 /* WORDSIZE computes the number of words needed to */
40 /* BIT returns the value of the n-th bit starting */
41 /* from r (0-indexed) */
42 /* SETBIT sets the n-th bit starting from r */
45 #define MAXSHORT 32767
46 #define MINSHORT -32768
47 #define MAXTABLE 32500
48 #define BITS_PER_WORD 32
49 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
50 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
51 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
55 #define NUL '\0' /* the null character */
56 #define NEWLINE '\n' /* line feed */
57 #define SP ' ' /* space */
58 #define BS '\b' /* backspace */
59 #define HT '\t' /* horizontal tab */
60 #define VT '\013' /* vertical tab */
61 #define CR '\r' /* carriage return */
62 #define FF '\f' /* form feed */
63 #define QUOTE '\'' /* single quote */
64 #define DOUBLE_QUOTE '\"' /* double quote */
65 #define BACKSLASH '\\' /* backslash */
67 /* defines for constructing filenames */
70 #define CODE_SUFFIX "_code.c"
71 #define DEFINES_SUFFIX "_tab.h"
72 #define OUTPUT_SUFFIX "_tab.c"
74 #define CODE_SUFFIX ".code.c"
75 #define DEFINES_SUFFIX ".tab.h"
76 #define OUTPUT_SUFFIX ".tab.c"
78 #define VERBOSE_SUFFIX ".output"
79 #define GRAPH_SUFFIX ".dot"
102 /* the undefined value */
104 #define UNDEFINED (-1)
111 /* character macros */
113 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
114 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
115 #define NUMERIC_VALUE(c) ((c) - '0')
119 #define ISTOKEN(s) ((s) < start_symbol)
120 #define ISVAR(s) ((s) >= start_symbol)
122 /* storage allocation macros */
124 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
125 #define FREE(x) (free((char*)(x)))
126 #define MALLOC(n) (malloc((unsigned)(n)))
127 #define NEW(t) ((t*)allocate(sizeof(t)))
128 #define NEW2(n,t) ((t*)allocate(((unsigned)(n)*sizeof(t))))
129 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
131 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
134 #define PLURAL(n) ((n) > 1 ? "s" : "")
136 typedef char Assoc_t;
137 typedef char Class_t;
138 typedef short Index_t;
139 typedef short Value_t;
141 /* the structure of a symbol table entry */
143 typedef struct bucket bucket;
157 /* the structure of the LR(0) state machine */
159 typedef struct core core;
165 Value_t accessing_symbol;
170 /* the structure used to record shifts */
172 typedef struct shifts shifts;
181 /* the structure used to store reductions */
183 typedef struct reductions reductions;
186 struct reductions *next;
192 /* the structure used to represent parser actions */
194 typedef struct action action;
206 /* global variables */
214 extern const char *symbol_prefix;
216 extern const char *myname;
221 extern int exit_code;
223 extern const char *banner[];
224 extern const char *tables[];
225 extern const char *header[];
226 extern const char *body[];
227 extern const char *trailer[];
229 extern char *code_file_name;
230 extern char *defines_file_name;
231 extern char *input_file_name;
232 extern char *output_file_name;
233 extern char *verbose_file_name;
234 extern char *graph_file_name;
236 extern FILE *action_file;
237 extern FILE *code_file;
238 extern FILE *defines_file;
239 extern FILE *input_file;
240 extern FILE *output_file;
241 extern FILE *text_file;
242 extern FILE *union_file;
243 extern FILE *verbose_file;
244 extern FILE *graph_file;
253 extern char unionized;
254 extern char line_format[];
256 extern Value_t start_symbol;
257 extern char **symbol_name;
258 extern char **symbol_pname;
259 extern Value_t *symbol_value;
260 extern Value_t *symbol_prec;
261 extern char *symbol_assoc;
263 extern Value_t *ritem;
264 extern Value_t *rlhs;
265 extern Value_t *rrhs;
266 extern Value_t *rprec;
267 extern Assoc_t *rassoc;
269 extern Value_t **derives;
270 extern char *nullable;
272 extern bucket *first_symbol;
273 extern bucket *last_symbol;
276 extern core *first_state;
277 extern shifts *first_shift;
278 extern reductions *first_reduction;
279 extern Value_t *accessing_symbol;
280 extern core **state_table;
281 extern shifts **shift_table;
282 extern reductions **reduction_table;
284 extern Value_t *LAruleno;
285 extern Value_t *lookaheads;
286 extern Value_t *goto_map;
287 extern Value_t *from_state;
288 extern Value_t *to_state;
290 extern action **parser;
295 extern Value_t *SRconflicts;
296 extern Value_t *RRconflicts;
297 extern Value_t *defred;
298 extern Value_t *rules_used;
299 extern Value_t nunused;
300 extern Value_t final_state;
302 extern Value_t *itemset;
303 extern Value_t *itemsetend;
304 extern unsigned *ruleset;
306 /* global functions */
308 extern bucket *lookup(const char *);
309 extern bucket *make_bucket(const char *);
312 #define GCC_NORETURN /* nothing */
316 #define GCC_UNUSED /* nothing */
320 extern void closure(Value_t *nucleus, int n);
321 extern void finalize_closure(void);
322 extern void set_first_derives(void);
325 extern void default_action_warning(void);
326 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr);
327 extern void dollar_warning(int a_lineno, int i);
328 extern void fatal(const char *msg);
329 extern void illegal_character(char *c_cptr);
330 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr);
331 extern void no_grammar(void);
332 extern void no_space(void);
333 extern void open_error(const char *filename);
334 extern void over_unionized(char *u_cptr);
335 extern void prec_redeclared(void);
336 extern void print_pos(char *st_line, char *st_cptr);
337 extern void reprec_warning(char *s);
338 extern void restarted_warning(void);
339 extern void retyped_warning(char *s);
340 extern void revalued_warning(char *s);
341 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
342 extern void terminal_lhs(int s_lineno);
343 extern void terminal_start(char *s);
344 extern void tokenized_start(char *s);
345 extern void undefined_goal(char *s);
346 extern void undefined_symbol_warning(char *s);
347 extern void unexpected_EOF(void);
348 extern void unknown_rhs(int i);
349 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr);
350 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr);
351 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr);
352 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr);
353 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr);
354 extern void untyped_lhs(void);
355 extern void untyped_rhs(int i, char *s);
356 extern void used_reserved(char *s);
359 extern void graph(void);
362 extern int hash(const char *name);
363 extern void create_symbol_table(void);
364 extern void free_symbol_table(void);
365 extern void free_symbols(void);
368 extern void lalr(void);
371 extern void lr0(void);
372 extern void show_cores(void);
373 extern void show_ritems(void);
374 extern void show_rrhs(void);
375 extern void show_shifts(void);
378 extern char *allocate(unsigned n);
379 extern void done(int k) GCC_NORETURN;
382 extern void free_parser(void);
383 extern void make_parser(void);
386 extern void output(void);
389 extern void reader(void);
392 extern void write_section(const char *section[]);
395 extern void verbose(void);
398 extern void reflexive_transitive_closure(unsigned *R, int n);
401 extern void lr0_leaks(void);
402 extern void lalr_leaks(void);
403 extern void mkpar_leaks(void);
404 extern void output_leaks(void);
405 extern void reader_leaks(void);