mkfs: move directory entry manipulation
[minix.git] / external / bsd / byacc / dist / defs.h
blob262c26507b20367c1d1f0cfced184239340c8e10
1 /* $NetBSD: defs.h,v 1.5 2011/09/10 21:29:04 christos Exp $ */
3 #if HAVE_NBTOOL_CONFIG_H
4 #include "nbtool_config.h"
5 #endif
6 /* Id: defs.h,v 1.35 2011/09/07 08:55:03 tom Exp */
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
12 #include <stdlib.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <assert.h>
16 #include <ctype.h>
17 #include <stdio.h>
19 #define YYMAJOR 1
20 #define YYMINOR 9
22 #define CONCAT(first,second) first #second
23 #define CONCAT1(string,number) CONCAT(string, number)
24 #define CONCAT2(first,second) #first "." #second
26 #ifdef YYPATCH
27 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
28 #else
29 #define VSTRING(a,b) CONCAT2(a,b)
30 #endif
32 #define VERSION VSTRING(YYMAJOR, YYMINOR)
34 /* machine-dependent definitions */
35 /* the following definitions are for the Tahoe */
36 /* they might have to be changed for other machines */
38 /* MAXCHAR is the largest unsigned character value */
39 /* MAXSHORT is the largest value of a C short */
40 /* MINSHORT is the most negative value of a C short */
41 /* MAXTABLE is the maximum table size */
42 /* BITS_PER_WORD is the number of bits in a C unsigned */
43 /* WORDSIZE computes the number of words needed to */
44 /* store n bits */
45 /* BIT returns the value of the n-th bit starting */
46 /* from r (0-indexed) */
47 /* SETBIT sets the n-th bit starting from r */
49 #define MAXCHAR 255
50 #define MAXSHORT 32767
51 #define MINSHORT -32768
52 #define MAXTABLE 32500
53 #define BITS_PER_WORD 32
54 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
55 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
56 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
58 /* character names */
60 #define NUL '\0' /* the null character */
61 #define NEWLINE '\n' /* line feed */
62 #define SP ' ' /* space */
63 #define BS '\b' /* backspace */
64 #define HT '\t' /* horizontal tab */
65 #define VT '\013' /* vertical tab */
66 #define CR '\r' /* carriage return */
67 #define FF '\f' /* form feed */
68 #define QUOTE '\'' /* single quote */
69 #define DOUBLE_QUOTE '\"' /* double quote */
70 #define BACKSLASH '\\' /* backslash */
72 #define UCH(c) (unsigned char)(c)
74 /* defines for constructing filenames */
76 #if defined(VMS)
77 #define CODE_SUFFIX "_code.c"
78 #define DEFINES_SUFFIX "_tab.h"
79 #define EXTERNS_SUFFIX "_tab.i"
80 #define OUTPUT_SUFFIX "_tab.c"
81 #else
82 #define CODE_SUFFIX ".code.c"
83 #define DEFINES_SUFFIX ".tab.h"
84 #define EXTERNS_SUFFIX ".tab.i"
85 #define OUTPUT_SUFFIX ".tab.c"
86 #endif
87 #define VERBOSE_SUFFIX ".output"
88 #define GRAPH_SUFFIX ".dot"
90 /* keyword codes */
92 #define TOKEN 0
93 #define LEFT 1
94 #define RIGHT 2
95 #define NONASSOC 3
96 #define MARK 4
97 #define TEXT 5
98 #define TYPE 6
99 #define START 7
100 #define UNION 8
101 #define IDENT 9
102 #define EXPECT 10
103 #define EXPECT_RR 11
104 #define PURE_PARSER 12
105 #define PARSE_PARAM 13
106 #define LEX_PARAM 14
107 #define POSIX_YACC 15
109 /* symbol classes */
111 #define UNKNOWN 0
112 #define TERM 1
113 #define NONTERM 2
115 /* the undefined value */
117 #define UNDEFINED (-1)
119 /* action codes */
121 #define SHIFT 1
122 #define REDUCE 2
124 /* character macros */
126 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
127 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
128 #define NUMERIC_VALUE(c) ((c) - '0')
130 /* symbol macros */
132 #define ISTOKEN(s) ((s) < start_symbol)
133 #define ISVAR(s) ((s) >= start_symbol)
135 /* storage allocation macros */
137 #define CALLOC(k,n) (calloc((size_t)(k),(size_t)(n)))
138 #define FREE(x) (free((char*)(x)))
139 #define MALLOC(n) (malloc((size_t)(n)))
140 #define NEW(t) ((t*)allocate(sizeof(t)))
141 #define NEW2(n,t) ((t*)allocate(((size_t)(n)*sizeof(t))))
142 #define REALLOC(p,n) (realloc((char*)(p),(size_t)(n)))
144 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
146 #define NO_SPACE(p) if (p == 0) no_space(); assert(p != 0)
148 /* messages */
149 #define PLURAL(n) ((n) > 1 ? "s" : "")
151 typedef char Assoc_t;
152 typedef char Class_t;
153 typedef short Index_t;
154 typedef short Value_t;
156 /* the structure of a symbol table entry */
158 typedef struct bucket bucket;
159 struct bucket
161 struct bucket *link;
162 struct bucket *next;
163 char *name;
164 char *tag;
165 Value_t value;
166 Index_t index;
167 Value_t prec;
168 Class_t class;
169 Assoc_t assoc;
172 /* the structure of the LR(0) state machine */
174 typedef struct core core;
175 struct core
177 struct core *next;
178 struct core *link;
179 Value_t number;
180 Value_t accessing_symbol;
181 Value_t nitems;
182 Value_t items[1];
185 /* the structure used to record shifts */
187 typedef struct shifts shifts;
188 struct shifts
190 struct shifts *next;
191 Value_t number;
192 Value_t nshifts;
193 Value_t shift[1];
196 /* the structure used to store reductions */
198 typedef struct reductions reductions;
199 struct reductions
201 struct reductions *next;
202 Value_t number;
203 Value_t nreds;
204 Value_t rules[1];
207 /* the structure used to represent parser actions */
209 typedef struct action action;
210 struct action
212 struct action *next;
213 Value_t symbol;
214 Value_t number;
215 Value_t prec;
216 char action_code;
217 Assoc_t assoc;
218 char suppressed;
221 /* the structure used to store parse/lex parameters */
222 typedef struct param param;
223 struct param
225 struct param *next;
226 char *name; /* parameter name */
227 char *type; /* everything before parameter name */
228 char *type2; /* everything after parameter name */
231 /* global variables */
233 extern char dflag;
234 extern char gflag;
235 extern char iflag;
236 extern char lflag;
237 extern char rflag;
238 extern char tflag;
239 extern char vflag;
240 extern const char *symbol_prefix;
242 extern const char *myname;
243 extern char *cptr;
244 extern char *line;
245 extern int lineno;
246 extern int outline;
247 extern int exit_code;
248 extern int pure_parser;
250 extern const char *const banner[];
251 extern const char *const xdecls[];
252 extern const char *const tables[];
253 extern const char *const global_vars[];
254 extern const char *const impure_vars[];
255 extern const char *const hdr_defs[];
256 extern const char *const hdr_vars[];
257 extern const char *const body_1[];
258 extern const char *const body_vars[];
259 extern const char *const body_2[];
260 extern const char *const body_3[];
261 extern const char *const trailer[];
262 extern const char *const trailer_2[];
264 extern char *code_file_name;
265 extern char *input_file_name;
266 extern char *defines_file_name;
267 extern char *externs_file_name;
269 extern FILE *action_file;
270 extern FILE *code_file;
271 extern FILE *defines_file;
272 extern FILE *externs_file;
273 extern FILE *input_file;
274 extern FILE *output_file;
275 extern FILE *text_file;
276 extern FILE *union_file;
277 extern FILE *verbose_file;
278 extern FILE *graph_file;
280 extern int nitems;
281 extern int nrules;
282 extern int nsyms;
283 extern int ntokens;
284 extern int nvars;
285 extern int ntags;
287 extern char unionized;
288 extern char line_format[];
290 extern Value_t start_symbol;
291 extern char **symbol_name;
292 extern char **symbol_pname;
293 extern Value_t *symbol_value;
294 extern Value_t *symbol_prec;
295 extern char *symbol_assoc;
297 extern Value_t *ritem;
298 extern Value_t *rlhs;
299 extern Value_t *rrhs;
300 extern Value_t *rprec;
301 extern Assoc_t *rassoc;
303 extern Value_t **derives;
304 extern char *nullable;
306 extern bucket *first_symbol;
307 extern bucket *last_symbol;
309 extern int pure_parser;
310 extern int nstates;
311 extern core *first_state;
312 extern shifts *first_shift;
313 extern reductions *first_reduction;
314 extern Value_t *accessing_symbol;
315 extern core **state_table;
316 extern shifts **shift_table;
317 extern reductions **reduction_table;
318 extern unsigned *LA;
319 extern Value_t *LAruleno;
320 extern Value_t *lookaheads;
321 extern Value_t *goto_map;
322 extern Value_t *from_state;
323 extern Value_t *to_state;
325 extern action **parser;
326 extern int SRexpect;
327 extern int RRexpect;
328 extern int SRtotal;
329 extern int RRtotal;
330 extern Value_t *SRconflicts;
331 extern Value_t *RRconflicts;
332 extern Value_t *defred;
333 extern Value_t *rules_used;
334 extern Value_t nunused;
335 extern Value_t final_state;
337 extern Value_t *itemset;
338 extern Value_t *itemsetend;
339 extern unsigned *ruleset;
341 extern param *lex_param;
342 extern param *parse_param;
344 /* global functions */
346 extern bucket *lookup(const char *);
347 extern bucket *make_bucket(const char *);
349 #ifndef GCC_NORETURN
350 #define GCC_NORETURN /* nothing */
351 #endif
353 #ifndef GCC_UNUSED
354 #define GCC_UNUSED /* nothing */
355 #endif
357 /* closure.c */
358 extern void closure(Value_t * nucleus, int n);
359 extern void finalize_closure(void);
360 extern void set_first_derives(void);
362 /* error.c */
363 extern void default_action_warning(void);
364 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
365 extern void dollar_warning(int a_lineno, int i);
366 extern void fatal(const char *msg) GCC_NORETURN;
367 extern void illegal_character(char *c_cptr) GCC_NORETURN;
368 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
369 extern void missing_brace(void) GCC_NORETURN;
370 extern void no_grammar(void) GCC_NORETURN;
371 extern void no_space(void) GCC_NORETURN;
372 extern void open_error(const char *filename) GCC_NORETURN;
373 extern void over_unionized(char *u_cptr) GCC_NORETURN;
374 extern void prec_redeclared(void);
375 extern void reprec_warning(char *s);
376 extern void restarted_warning(void);
377 extern void retyped_warning(char *s);
378 extern void revalued_warning(char *s);
379 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
380 extern void terminal_lhs(int s_lineno) GCC_NORETURN;
381 extern void terminal_start(char *s) GCC_NORETURN;
382 extern void tokenized_start(char *s) GCC_NORETURN;
383 extern void undefined_goal(char *s) GCC_NORETURN;
384 extern void undefined_symbol_warning(char *s);
385 extern void unexpected_EOF(void) GCC_NORETURN;
386 extern void unknown_rhs(int i) GCC_NORETURN;
387 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
388 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) GCC_NORETURN;
389 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr) GCC_NORETURN;
390 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
391 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr) GCC_NORETURN;
392 extern void untyped_lhs(void) GCC_NORETURN;
393 extern void untyped_rhs(int i, char *s) GCC_NORETURN;
394 extern void used_reserved(char *s) GCC_NORETURN;
396 /* graph.c */
397 extern void graph(void);
399 /* lalr.c */
400 extern void create_symbol_table(void);
401 extern void free_symbol_table(void);
402 extern void free_symbols(void);
404 /* lalr.c */
405 extern void lalr(void);
407 /* lr0.c */
408 extern void lr0(void);
409 extern void show_cores(void);
410 extern void show_ritems(void);
411 extern void show_rrhs(void);
412 extern void show_shifts(void);
414 /* main.c */
415 extern void *allocate(size_t n);
416 extern void done(int k) GCC_NORETURN;
418 /* mkpar.c */
419 extern void free_parser(void);
420 extern void make_parser(void);
422 /* output.c */
423 extern void output(void);
425 /* reader.c */
426 extern void reader(void);
428 /* skeleton.c */
429 extern void write_section(FILE *fp, const char *const section[]);
431 /* verbose.c */
432 extern void verbose(void);
434 /* warshall.c */
435 extern void reflexive_transitive_closure(unsigned *R, int n);
437 #ifdef NO_LEAKS
438 extern void lr0_leaks(void);
439 extern void lalr_leaks(void);
440 extern void mkpar_leaks(void);
441 extern void output_leaks(void);
442 extern void reader_leaks(void);
443 #endif