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 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)defs.h 5.6 (Berkeley) 5/24/93
37 * $FreeBSD: src/usr.bin/yacc/defs.h,v 1.8.2.1 2001/10/05 03:00:19 obrien Exp $
38 * $DragonFly: src/usr.bin/yacc/defs.h,v 1.5 2005/01/05 15:26:05 joerg Exp $
47 /* machine-dependent definitions */
48 /* the following definitions are for the Tahoe */
49 /* they might have to be changed for other machines */
51 /* MAXCHAR is the largest unsigned character value */
52 /* MAXSHORT is the largest value of a C short */
53 /* MINSHORT is the most negative value of a C short */
54 /* MAXTABLE is the maximum table size */
55 /* BITS_PER_WORD is the number of bits in a C unsigned */
56 /* WORDSIZE computes the number of words needed to */
58 /* BIT returns the value of the n-th bit starting */
59 /* from r (0-indexed) */
60 /* SETBIT sets the n-th bit starting from r */
63 #define MAXSHORT 32767
64 #define MINSHORT -32768
65 #define MAXTABLE 32500
66 #define BITS_PER_WORD 32
67 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
68 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
69 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
74 #define NUL '\0' /* the null character */
75 #define NEWLINE '\n' /* line feed */
76 #define SP ' ' /* space */
77 #define BS '\b' /* backspace */
78 #define HT '\t' /* horizontal tab */
79 #define VT '\013' /* vertical tab */
80 #define CR '\r' /* carriage return */
81 #define FF '\f' /* form feed */
82 #define QUOTE '\'' /* single quote */
83 #define DOUBLE_QUOTE '\"' /* double quote */
84 #define BACKSLASH '\\' /* backslash */
87 /* defines for constructing filenames */
89 #define CODE_SUFFIX ".code.c"
90 #define DEFINES_SUFFIX ".tab.h"
91 #define OUTPUT_SUFFIX ".tab.c"
92 #define VERBOSE_SUFFIX ".output"
117 /* the undefined value */
119 #define UNDEFINED (-1)
128 /* character macros */
130 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
131 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
132 #define NUMERIC_VALUE(c) ((c) - '0')
137 #define ISTOKEN(s) ((s) < start_symbol)
138 #define ISVAR(s) ((s) >= start_symbol)
141 /* storage allocation macros */
143 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
144 #define FREE(x) (free((char*)(x)))
145 #define MALLOC(n) (malloc((unsigned)(n)))
146 #define NEW(t) ((t*)allocate(sizeof(t)))
147 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
148 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
151 /* the structure of a symbol table entry */
153 typedef struct bucket bucket
;
168 /* the structure of the LR(0) state machine */
170 typedef struct core core
;
176 short accessing_symbol
;
182 /* the structure used to record shifts */
184 typedef struct shifts shifts
;
194 /* the structure used to store reductions */
196 typedef struct reductions reductions
;
199 struct reductions
*next
;
206 /* the structure used to represent parser actions */
208 typedef struct action action
;
221 /* global variables */
228 extern const char *symbol_prefix
;
230 extern const char *cptr
;
235 extern const char *banner
[];
236 extern const char *tables
[];
237 extern const char *header
[];
238 extern const char *body
[];
239 extern const char *trailer
[];
241 extern char *action_file_name
;
242 extern char *code_file_name
;
243 extern char *defines_file_name
;
244 extern const char *input_file_name
;
245 extern char *output_file_name
;
246 extern char *text_file_name
;
247 extern char *union_file_name
;
248 extern char *verbose_file_name
;
250 extern FILE *action_file
;
251 extern FILE *code_file
;
252 extern FILE *defines_file
;
253 extern FILE *input_file
;
254 extern FILE *output_file
;
255 extern FILE *text_file
;
256 extern FILE *union_file
;
257 extern FILE *verbose_file
;
266 extern char unionized
;
268 extern int start_symbol
;
269 extern char **symbol_name
;
270 extern short *symbol_value
;
271 extern short *symbol_prec
;
272 extern char *symbol_assoc
;
280 extern short **derives
;
281 extern char *nullable
;
283 extern bucket
*first_symbol
;
284 extern bucket
*last_symbol
;
287 extern core
*first_state
;
288 extern shifts
*first_shift
;
289 extern reductions
*first_reduction
;
290 extern short *accessing_symbol
;
291 extern core
**state_table
;
292 extern shifts
**shift_table
;
293 extern reductions
**reduction_table
;
295 extern short *LAruleno
;
296 extern short *lookaheads
;
297 extern short *goto_map
;
298 extern short *from_state
;
299 extern short *to_state
;
301 extern action
**parser
;
305 extern short *SRconflicts
;
306 extern short *RRconflicts
;
307 extern short *defred
;
308 extern short *rules_used
;
309 extern short nunused
;
310 extern short final_state
;
312 /* global functions */
314 char *allocate(unsigned);
315 void closure(short *, int);
316 void create_symbol_table(void);
317 void default_action_warning(void);
318 void dollar_error(int, const char *, const char *);
319 void dollar_warning(int, int);
320 void fatal(const char *msg
);
321 void finalize_closure(void);
322 void free_parser(void);
323 void free_symbols(void);
324 void free_symbol_table(void);
325 void illegal_character(const char *);
326 void illegal_tag(int, const char *, const char *);
328 bucket
*lookup(char *);
330 bucket
*make_bucket(const char *);
331 void make_parser(void);
332 void no_grammar(void);
334 void open_error(const char *);
336 void over_unionized(const char *);
337 void prec_redeclared(void);
339 void reflexive_transitive_closure(unsigned *, int);
340 void reprec_warning(const char *);
341 void restarted_warning(void);
342 void retyped_warning(const char *);
343 void revalued_warning(const char *);
344 void set_first_derives(void);
345 void syntax_error(int, const char *, const char *);
346 void terminal_lhs(int);
347 void terminal_start(const char *);
348 void tokenized_start(const char *);
349 void undefined_goal(const char *);
350 void undefined_symbol_warning(const char *);
351 void unexpected_EOF(void);
352 void unknown_rhs(int);
353 void unterminated_action(int, const char *, const char *);
354 void unterminated_comment(int, const char *, const char *);
355 void unterminated_string(int, const char *, const char *);
356 void unterminated_text(int, const char *, const char *);
357 void unterminated_union(int, const char *, const char *);
358 void untyped_lhs(void);
359 void untyped_rhs(int, const char *);
360 void used_reserved(const char *);
362 void write_section(const char **);