tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / defs.h
blob3bae439e7d7e026aeb486b5e2c65abd54ba9ce9c
1 /* $NetBSD: defs.h,v 1.6 2013/04/06 14:52:24 christos Exp $ */
3 #if HAVE_NBTOOL_CONFIG_H
4 #include "nbtool_config.h"
5 #endif
6 /* Id: defs.h,v 1.37 2012/05/26 15:23:00 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 #if defined(__cplusplus) /* __cplusplus, etc. */
20 #define class myClass
21 #endif
23 #define YYMAJOR 1
24 #define YYMINOR 9
26 #define CONCAT(first,second) first #second
27 #define CONCAT1(string,number) CONCAT(string, number)
28 #define CONCAT2(first,second) #first "." #second
30 #ifdef YYPATCH
31 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
32 #else
33 #define VSTRING(a,b) CONCAT2(a,b)
34 #endif
36 #define VERSION VSTRING(YYMAJOR, YYMINOR)
38 /* machine-dependent definitions */
39 /* the following definitions are for the Tahoe */
40 /* they might have to be changed for other machines */
42 /* MAXCHAR is the largest unsigned character value */
43 /* MAXSHORT is the largest value of a C short */
44 /* MINSHORT is the most negative value of a C short */
45 /* MAXTABLE is the maximum table size */
46 /* BITS_PER_WORD is the number of bits in a C unsigned */
47 /* WORDSIZE computes the number of words needed to */
48 /* store n bits */
49 /* BIT returns the value of the n-th bit starting */
50 /* from r (0-indexed) */
51 /* SETBIT sets the n-th bit starting from r */
53 #define MAXCHAR 255
54 #define MAXSHORT 32767
55 #define MINSHORT -32768
56 #define MAXTABLE 32500
57 #define BITS_PER_WORD 32
58 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
59 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
60 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
62 /* character names */
64 #define NUL '\0' /* the null character */
65 #define NEWLINE '\n' /* line feed */
66 #define SP ' ' /* space */
67 #define BS '\b' /* backspace */
68 #define HT '\t' /* horizontal tab */
69 #define VT '\013' /* vertical tab */
70 #define CR '\r' /* carriage return */
71 #define FF '\f' /* form feed */
72 #define QUOTE '\'' /* single quote */
73 #define DOUBLE_QUOTE '\"' /* double quote */
74 #define BACKSLASH '\\' /* backslash */
76 #define UCH(c) (unsigned char)(c)
78 /* defines for constructing filenames */
80 #if defined(VMS)
81 #define CODE_SUFFIX "_code.c"
82 #define DEFINES_SUFFIX "_tab.h"
83 #define EXTERNS_SUFFIX "_tab.i"
84 #define OUTPUT_SUFFIX "_tab.c"
85 #else
86 #define CODE_SUFFIX ".code.c"
87 #define DEFINES_SUFFIX ".tab.h"
88 #define EXTERNS_SUFFIX ".tab.i"
89 #define OUTPUT_SUFFIX ".tab.c"
90 #endif
91 #define VERBOSE_SUFFIX ".output"
92 #define GRAPH_SUFFIX ".dot"
94 /* keyword codes */
96 #define TOKEN 0
97 #define LEFT 1
98 #define RIGHT 2
99 #define NONASSOC 3
100 #define MARK 4
101 #define TEXT 5
102 #define TYPE 6
103 #define START 7
104 #define UNION 8
105 #define IDENT 9
106 #define EXPECT 10
107 #define EXPECT_RR 11
108 #define PURE_PARSER 12
109 #define PARSE_PARAM 13
110 #define LEX_PARAM 14
111 #define POSIX_YACC 15
113 /* symbol classes */
115 #define UNKNOWN 0
116 #define TERM 1
117 #define NONTERM 2
119 /* the undefined value */
121 #define UNDEFINED (-1)
123 /* action codes */
125 #define SHIFT 1
126 #define REDUCE 2
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')
134 /* symbol macros */
136 #define ISTOKEN(s) ((s) < start_symbol)
137 #define ISVAR(s) ((s) >= start_symbol)
139 /* storage allocation macros */
141 #define CALLOC(k,n) (calloc((size_t)(k),(size_t)(n)))
142 #define FREE(x) (free((char*)(x)))
143 #define MALLOC(n) (malloc((size_t)(n)))
144 #define TMALLOC(t,n) ((t*) malloc((size_t)(n) * sizeof(t)))
145 #define NEW(t) ((t*)allocate(sizeof(t)))
146 #define NEW2(n,t) ((t*)allocate(((size_t)(n)*sizeof(t))))
147 #define REALLOC(p,n) (realloc((char*)(p),(size_t)(n)))
148 #define TREALLOC(t,p,n) ((t*)realloc((char*)(p), (size_t)(n) * sizeof(t)))
150 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
152 #define NO_SPACE(p) if (p == 0) no_space(); assert(p != 0)
154 /* messages */
155 #define PLURAL(n) ((n) > 1 ? "s" : "")
157 typedef char Assoc_t;
158 typedef char Class_t;
159 typedef short Index_t;
160 typedef short Value_t;
162 /* the structure of a symbol table entry */
164 typedef struct bucket bucket;
165 struct bucket
167 struct bucket *link;
168 struct bucket *next;
169 char *name;
170 char *tag;
171 Value_t value;
172 Index_t index;
173 Value_t prec;
174 Class_t class;
175 Assoc_t assoc;
178 /* the structure of the LR(0) state machine */
180 typedef struct core core;
181 struct core
183 struct core *next;
184 struct core *link;
185 Value_t number;
186 Value_t accessing_symbol;
187 Value_t nitems;
188 Value_t items[1];
191 /* the structure used to record shifts */
193 typedef struct shifts shifts;
194 struct shifts
196 struct shifts *next;
197 Value_t number;
198 Value_t nshifts;
199 Value_t shift[1];
202 /* the structure used to store reductions */
204 typedef struct reductions reductions;
205 struct reductions
207 struct reductions *next;
208 Value_t number;
209 Value_t nreds;
210 Value_t rules[1];
213 /* the structure used to represent parser actions */
215 typedef struct action action;
216 struct action
218 struct action *next;
219 Value_t symbol;
220 Value_t number;
221 Value_t prec;
222 char action_code;
223 Assoc_t assoc;
224 char suppressed;
227 /* the structure used to store parse/lex parameters */
228 typedef struct param param;
229 struct param
231 struct param *next;
232 char *name; /* parameter name */
233 char *type; /* everything before parameter name */
234 char *type2; /* everything after parameter name */
237 /* global variables */
239 extern char dflag;
240 extern char gflag;
241 extern char iflag;
242 extern char lflag;
243 extern char rflag;
244 extern char sflag;
245 extern char tflag;
246 extern char vflag;
247 extern const char *symbol_prefix;
249 extern const char *myname;
250 extern char *cptr;
251 extern char *line;
252 extern int lineno;
253 extern int outline;
254 extern int exit_code;
255 extern int pure_parser;
257 extern const char *const banner[];
258 extern const char *const xdecls[];
259 extern const char *const tables[];
260 extern const char *const global_vars[];
261 extern const char *const impure_vars[];
262 extern const char *const hdr_defs[];
263 extern const char *const hdr_vars[];
264 extern const char *const body_1[];
265 extern const char *const body_vars[];
266 extern const char *const body_2[];
267 extern const char *const body_3[];
268 extern const char *const trailer[];
269 extern const char *const trailer_2[];
271 extern char *code_file_name;
272 extern char *input_file_name;
273 extern char *defines_file_name;
274 extern char *externs_file_name;
276 extern FILE *action_file;
277 extern FILE *code_file;
278 extern FILE *defines_file;
279 extern FILE *externs_file;
280 extern FILE *input_file;
281 extern FILE *output_file;
282 extern FILE *text_file;
283 extern FILE *union_file;
284 extern FILE *verbose_file;
285 extern FILE *graph_file;
287 extern int nitems;
288 extern int nrules;
289 extern int nsyms;
290 extern int ntokens;
291 extern int nvars;
292 extern int ntags;
294 extern char unionized;
295 extern char line_format[];
297 extern Value_t start_symbol;
298 extern char **symbol_name;
299 extern char **symbol_pname;
300 extern Value_t *symbol_value;
301 extern Value_t *symbol_prec;
302 extern char *symbol_assoc;
304 extern Value_t *ritem;
305 extern Value_t *rlhs;
306 extern Value_t *rrhs;
307 extern Value_t *rprec;
308 extern Assoc_t *rassoc;
310 extern Value_t **derives;
311 extern char *nullable;
313 extern bucket *first_symbol;
314 extern bucket *last_symbol;
316 extern int nstates;
317 extern core *first_state;
318 extern shifts *first_shift;
319 extern reductions *first_reduction;
320 extern Value_t *accessing_symbol;
321 extern core **state_table;
322 extern shifts **shift_table;
323 extern reductions **reduction_table;
324 extern unsigned *LA;
325 extern Value_t *LAruleno;
326 extern Value_t *lookaheads;
327 extern Value_t *goto_map;
328 extern Value_t *from_state;
329 extern Value_t *to_state;
331 extern action **parser;
332 extern int SRexpect;
333 extern int RRexpect;
334 extern int SRtotal;
335 extern int RRtotal;
336 extern Value_t *SRconflicts;
337 extern Value_t *RRconflicts;
338 extern Value_t *defred;
339 extern Value_t *rules_used;
340 extern Value_t nunused;
341 extern Value_t final_state;
343 extern Value_t *itemset;
344 extern Value_t *itemsetend;
345 extern unsigned *ruleset;
347 extern param *lex_param;
348 extern param *parse_param;
350 /* global functions */
352 extern bucket *lookup(const char *);
353 extern bucket *make_bucket(const char *);
355 #ifndef GCC_NORETURN
356 #if defined(__dead2)
357 #define GCC_NORETURN __dead2
358 #elif defined(__dead)
359 #define GCC_NORETURN __dead
360 #else
361 #define GCC_NORETURN /* nothing */
362 #endif
363 #endif
365 #ifndef GCC_UNUSED
366 #if defined(__unused)
367 #define GCC_UNUSED __unused
368 #else
369 #define GCC_UNUSED /* nothing */
370 #endif
371 #endif
373 /* closure.c */
374 extern void closure(Value_t * nucleus, int n);
375 extern void finalize_closure(void);
376 extern void set_first_derives(void);
378 /* error.c */
379 extern void default_action_warning(void);
380 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
381 extern void dollar_warning(int a_lineno, int i);
382 extern void fatal(const char *msg) GCC_NORETURN;
383 extern void illegal_character(char *c_cptr) GCC_NORETURN;
384 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
385 extern void missing_brace(void) GCC_NORETURN;
386 extern void no_grammar(void) GCC_NORETURN;
387 extern void no_space(void) GCC_NORETURN;
388 extern void open_error(const char *filename) GCC_NORETURN;
389 extern void over_unionized(char *u_cptr) GCC_NORETURN;
390 extern void prec_redeclared(void);
391 extern void reprec_warning(char *s);
392 extern void restarted_warning(void);
393 extern void retyped_warning(char *s);
394 extern void revalued_warning(char *s);
395 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
396 extern void terminal_lhs(int s_lineno) GCC_NORETURN;
397 extern void terminal_start(char *s) GCC_NORETURN;
398 extern void tokenized_start(char *s) GCC_NORETURN;
399 extern void undefined_goal(char *s) GCC_NORETURN;
400 extern void undefined_symbol_warning(char *s);
401 extern void unexpected_EOF(void) GCC_NORETURN;
402 extern void unknown_rhs(int i) GCC_NORETURN;
403 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
404 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) GCC_NORETURN;
405 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr) GCC_NORETURN;
406 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
407 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr) GCC_NORETURN;
408 extern void untyped_lhs(void) GCC_NORETURN;
409 extern void untyped_rhs(int i, char *s) GCC_NORETURN;
410 extern void used_reserved(char *s) GCC_NORETURN;
412 /* graph.c */
413 extern void graph(void);
415 /* lalr.c */
416 extern void create_symbol_table(void);
417 extern void free_symbol_table(void);
418 extern void free_symbols(void);
420 /* lalr.c */
421 extern void lalr(void);
423 /* lr0.c */
424 extern void lr0(void);
425 extern void show_cores(void);
426 extern void show_ritems(void);
427 extern void show_rrhs(void);
428 extern void show_shifts(void);
430 /* main.c */
431 extern void *allocate(size_t n);
432 extern void done(int k) GCC_NORETURN;
434 /* mkpar.c */
435 extern void free_parser(void);
436 extern void make_parser(void);
438 /* output.c */
439 extern void output(void);
441 /* reader.c */
442 extern void reader(void);
444 /* skeleton.c */
445 extern void write_section(FILE * fp, const char *const section[]);
447 /* verbose.c */
448 extern void verbose(void);
450 /* warshall.c */
451 extern void reflexive_transitive_closure(unsigned *R, int n);
453 #ifdef NO_LEAKS
454 extern void lr0_leaks(void);
455 extern void lalr_leaks(void);
456 extern void mkpar_leaks(void);
457 extern void output_leaks(void);
458 extern void reader_leaks(void);
459 #endif