1 /* $NetBSD: defs.h,v 1.16 2007/12/15 22:01:25 perry Exp $ */
4 * Copyright (c) 1989 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)defs.h 5.6 (Berkeley) 5/24/93
37 #if HAVE_NBTOOL_CONFIG_H
38 #include "nbtool_config.h"
48 /* machine-dependent definitions */
49 /* the following definitions are for the Tahoe */
50 /* they might have to be changed for other machines */
52 /* MAXCHAR is the largest unsigned character value */
53 /* MAXSHORT is the largest value of a C short */
54 /* MINSHORT is the most negative value of a C short */
55 /* MAXTABLE is the maximum table size */
56 /* BITS_PER_WORD is the number of bits in a C unsigned */
57 /* WORDSIZE computes the number of words needed to */
59 /* BIT returns the value of the n-th bit starting */
60 /* from r (0-indexed) */
61 /* SETBIT sets the n-th bit starting from r */
64 #define MAXSHORT 32767
65 #define MINSHORT -32768
66 #define MAXTABLE 32500
67 #define BITS_PER_WORD 32
68 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1)/BITS_PER_WORD))
69 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31)&1))
70 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
75 #define NUL '\0' /* the null character */
76 #define NEWLINE '\n' /* line feed */
77 #define SP ' ' /* space */
78 #define BS '\b' /* backspace */
79 #define HT '\t' /* horizontal tab */
80 #define VT '\013' /* vertical tab */
81 #define CR '\r' /* carriage return */
82 #define FF '\f' /* form feed */
83 #define QUOTE '\'' /* single quote */
84 #define DOUBLE_QUOTE '\"' /* double quote */
85 #define BACKSLASH '\\' /* backslash */
88 /* defines for constructing filenames */
90 #define CODE_SUFFIX ".code.c"
91 #define DEFINES_SUFFIX ".tab.h"
92 #define OUTPUT_SUFFIX ".tab.c"
93 #define VERBOSE_SUFFIX ".output"
118 /* the undefined value */
120 #define UNDEFINED (-1)
129 /* character macros */
131 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
132 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
133 #define NUMERIC_VALUE(c) ((c) - '0')
138 #define ISTOKEN(s) ((s) < start_symbol)
139 #define ISVAR(s) ((s) >= start_symbol)
142 /* storage allocation macros */
144 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
145 #define FREE(x) (free((char*)(x)))
146 #define MALLOC(n) (malloc((unsigned)(n)))
147 #define NEW(t) ((t*)allocate(sizeof(t)))
148 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
149 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
152 /* the structure of a symbol table entry */
154 typedef struct bucket bucket
;
169 /* the structure of the LR(0) state machine */
171 typedef struct core core
;
177 short accessing_symbol
;
183 /* the structure used to record shifts */
185 typedef struct shifts shifts
;
195 /* the structure used to store reductions */
197 typedef struct reductions reductions
;
200 struct reductions
*next
;
207 /* the structure used to represent parser actions */
209 typedef struct action action
;
222 /* global variables */
229 extern const char *symbol_prefix
;
231 extern const char *myname
;
237 extern const char * const banner
[];
238 extern const char * const tables
[];
239 extern const char * const header
[];
240 extern const char * const body
[];
241 extern const char * const trailer
[];
243 extern char *action_file_name
;
244 extern char *code_file_name
;
245 extern char *defines_file_name
;
246 extern const char *input_file_name
;
247 extern char *output_file_name
;
248 extern char *text_file_name
;
249 extern char *union_file_name
;
250 extern char *verbose_file_name
;
252 extern FILE *action_file
;
253 extern FILE *code_file
;
254 extern FILE *defines_file
;
255 extern FILE *input_file
;
256 extern FILE *output_file
;
257 extern FILE *text_file
;
258 extern FILE *union_file
;
259 extern FILE *verbose_file
;
268 extern char unionized
;
270 extern int start_symbol
;
271 extern char **symbol_name
;
272 extern short *symbol_value
;
273 extern short *symbol_prec
;
274 extern char *symbol_assoc
;
282 extern short **derives
;
283 extern char *nullable
;
285 extern bucket
*first_symbol
;
286 extern bucket
*last_symbol
;
289 extern core
*first_state
;
290 extern shifts
*first_shift
;
291 extern reductions
*first_reduction
;
292 extern short *accessing_symbol
;
293 extern core
**state_table
;
294 extern shifts
**shift_table
;
295 extern reductions
**reduction_table
;
297 extern short *LAruleno
;
298 extern short *lookaheads
;
299 extern short *goto_map
;
300 extern short *from_state
;
301 extern short *to_state
;
303 extern action
**parser
;
306 extern short *SRconflicts
;
307 extern short *RRconflicts
;
308 extern short *defred
;
309 extern short *rules_used
;
310 extern short nunused
;
311 extern short final_state
;
313 /* global functions */
315 extern char *allocate(unsigned);
316 extern bucket
*lookup(char *);
317 extern bucket
*make_bucket(const char *);
319 extern void set_first_derives(void);
320 extern void closure(short *, int);
321 extern void finalize_closure(void);
323 extern __dead
void fatal(const char *);
325 extern void reflexive_transitive_closure(unsigned *, int);
326 extern __dead
void done(int);
328 extern __dead
void no_space(void);
329 extern __dead
void open_error(const char *);
330 extern __dead
void unexpected_EOF(void);
331 extern void print_pos(char *, char *);
332 extern __dead
void syntax_error(int, char *, char *);
333 extern __dead
void unterminated_comment(int, char *, char *);
334 extern __dead
void unterminated_string(int, char *, char *);
335 extern __dead
void unterminated_text(int, char *, char *);
336 extern __dead
void unterminated_union(int, char *, char *);
337 extern __dead
void over_unionized(char *);
338 extern void illegal_tag(int, char *, char *);
339 extern void illegal_character(char *);
340 extern void used_reserved(char *);
341 extern void tokenized_start(char *);
342 extern void retyped_warning(char *);
343 extern void reprec_warning(char *);
344 extern void revalued_warning(char *);
345 extern __dead
void terminal_start(char *);
346 extern void restarted_warning(void);
347 extern __dead
void no_grammar(void);
348 extern __dead
void terminal_lhs(int);
349 extern void prec_redeclared(void);
350 extern __dead
void unterminated_action(int, char *, char *);
351 extern void dollar_warning(int, int);
352 extern __dead
void dollar_error(int, char *, char *);
353 extern __dead
void untyped_lhs(void);
354 extern __dead
void untyped_rhs(int, char *);
355 extern __dead
void unknown_rhs(int);
356 extern void default_action_warning(void);
357 extern __dead
void undefined_goal(char *);
358 extern void undefined_symbol_warning(char *);
360 extern void lalr(void);
362 extern void reader(void);
363 extern void lr0(void);
364 extern void make_parser(void);
365 extern void verbose(void);
366 extern void output(void);
367 extern void free_parser(void);
368 extern void write_section(const char * const []);
370 extern void create_symbol_table(void);
371 extern void free_symbol_table(void);
372 extern void free_symbols(void);