1 /* $OpenBSD: defs.h,v 1.18 2014/12/02 15:56:22 millert Exp $ */
2 /* $NetBSD: defs.h,v 1.6 1996/03/19 03:21:30 jtc Exp $ */
5 * Copyright (c) 1989 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)defs.h 5.6 (Berkeley) 5/24/93
44 /* machine-dependent definitions */
45 /* the following definitions are for the Tahoe */
46 /* they might have to be changed for other machines */
48 /* MAXCHAR is the largest unsigned character value */
49 /* MAXSHORT is the largest value of a C short */
50 /* MINSHORT is the most negative value of a C short */
51 /* MAXTABLE is the maximum table size */
52 /* BITS_PER_WORD is the number of bits in a C unsigned */
53 /* WORDSIZE computes the number of words needed to */
55 /* BIT returns the value of the n-th bit starting */
56 /* from r (0-indexed) */
57 /* SETBIT sets the n-th bit starting from r */
60 #define MAXSHORT 32767
61 #define MINSHORT -32768
62 #define MAXTABLE 32500
63 #define BITS_PER_WORD 32
64 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
65 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
66 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
71 #define NUL '\0' /* the null character */
72 #define NEWLINE '\n' /* line feed */
73 #define SP ' ' /* space */
74 #define BS '\b' /* backspace */
75 #define HT '\t' /* horizontal tab */
76 #define VT '\013' /* vertical tab */
77 #define CR '\r' /* carriage return */
78 #define FF '\f' /* form feed */
79 #define QUOTE '\'' /* single quote */
80 #define DOUBLE_QUOTE '\"' /* double quote */
81 #define BACKSLASH '\\' /* backslash */
84 /* defines for constructing filenames */
86 #define CODE_SUFFIX ".code.c"
87 #define DEFINES_SUFFIX ".tab.h"
88 #define OUTPUT_SUFFIX ".tab.c"
89 #define VERBOSE_SUFFIX ".output"
114 /* the undefined value */
116 #define UNDEFINED (-1)
125 /* character macros */
127 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
128 #define NUMERIC_VALUE(c) ((c) - '0')
133 #define ISTOKEN(s) ((s) < start_symbol)
134 #define ISVAR(s) ((s) >= start_symbol)
137 /* storage allocation macros */
139 #define NEW(t) ((t*)allocate(sizeof(t)))
140 #define NEW2(n,t) ((t*)allocate((n)*sizeof(t)))
143 /* the structure of a symbol table entry */
145 typedef struct bucket bucket
;
159 /* the structure of the LR(0) state machine */
161 typedef struct core core
;
166 short accessing_symbol
;
172 /* the structure used to record shifts */
174 typedef struct shifts shifts
;
183 /* the structure used to store reductions */
185 typedef struct reductions reductions
;
187 struct reductions
*next
;
194 /* the structure used to represent parser actions */
196 typedef struct action action
;
208 /* global variables */
215 extern char *symbol_prefix
;
222 extern char *banner
[];
223 extern char *tables
[];
224 extern char *header
[];
226 extern char *trailer
[];
228 extern char *action_file_name
;
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 *text_file_name
;
234 extern char *union_file_name
;
235 extern char *verbose_file_name
;
237 extern FILE *action_file
;
238 extern FILE *code_file
;
239 extern FILE *defines_file
;
240 extern FILE *input_file
;
241 extern FILE *output_file
;
242 extern FILE *text_file
;
243 extern FILE *union_file
;
244 extern FILE *verbose_file
;
253 extern char unionized
;
254 extern char line_format
[];
256 extern int start_symbol
;
257 extern char **symbol_name
;
258 extern short *symbol_value
;
259 extern short *symbol_prec
;
260 extern char *symbol_assoc
;
268 extern short **derives
;
269 extern char *nullable
;
271 extern bucket
*first_symbol
;
272 extern bucket
*last_symbol
;
275 extern core
*first_state
;
276 extern shifts
*first_shift
;
277 extern reductions
*first_reduction
;
278 extern short *accessing_symbol
;
279 extern core
**state_table
;
280 extern shifts
**shift_table
;
281 extern reductions
**reduction_table
;
283 extern short *LAruleno
;
284 extern short *lookaheads
;
285 extern short *goto_map
;
286 extern short *from_state
;
287 extern short *to_state
;
289 extern action
**parser
;
293 extern short *SRconflicts
;
294 extern short *RRconflicts
;
295 extern short *defred
;
296 extern short *rules_used
;
297 extern short nunused
;
298 extern short final_state
;
300 /* global functions */
302 extern void *allocate(size_t);
303 extern bucket
*lookup(char *);
304 extern bucket
*make_bucket(char *);
305 extern void set_first_derives(void);
306 extern void closure(short *, int);
307 extern void finalize_closure(void);
309 extern __dead
void fatal(char *);
311 extern void reflexive_transitive_closure(unsigned *, int);
312 extern __dead
void done(int);
314 extern __dead
void no_space(void);
315 extern __dead
void open_error(char *);
316 extern __dead
void open_write_error(char *);
317 extern __dead
void unexpected_EOF(void);
318 extern void print_pos(char *, char *);
319 extern __dead
void syntax_error(int, char *, char *);
320 extern __dead
void unterminated_comment(int, char *, char *);
321 extern __dead
void unterminated_string(int, char *, char *);
322 extern __dead
void unterminated_text(int, char *, char *);
323 extern __dead
void unterminated_union(int, char *, char *);
324 extern __dead
void over_unionized(char *);
325 extern __dead
void illegal_tag(int, char *, char *);
326 extern __dead
void illegal_character(char *);
327 extern __dead
void used_reserved(char *);
328 extern __dead
void tokenized_start(char *);
329 extern void retyped_warning(char *);
330 extern void reprec_warning(char *);
331 extern void revalued_warning(char *);
332 extern __dead
void terminal_start(char *);
333 extern void restarted_warning(void);
334 extern __dead
void no_grammar(void);
335 extern __dead
void terminal_lhs(int);
336 extern void prec_redeclared(void);
337 extern __dead
void unterminated_action(int, char *, char *);
338 extern void dollar_warning(int, int);
339 extern __dead
void dollar_error(int, char *, char *);
340 extern __dead
void untyped_lhs(void);
341 extern __dead
void untyped_rhs(int, char *);
342 extern __dead
void unknown_rhs(int);
343 extern void default_action_warning(void);
344 extern __dead
void undefined_goal(char *);
345 extern void undefined_symbol_warning(char *);
347 extern void lalr(void);
349 extern void reader(void);
350 extern void lr0(void);
351 extern void free_nullable(void);
352 extern void free_derives(void);
353 extern void make_parser(void);
354 extern void verbose(void);
355 extern void output(void);
356 extern void free_parser(void);
357 extern void write_section(char *[]);
359 extern void create_symbol_table(void);
360 extern void free_symbol_table(void);
361 extern void free_symbols(void);
364 /* system variables */
366 extern char *__progname
;