xref: /minix/external/bsd/byacc/dist/defs.h (revision 0a6a1f1d)
1 /*	$NetBSD: defs.h,v 1.9 2015/01/04 01:34:20 christos Exp $	*/
2 
3 #if HAVE_NBTOOL_CONFIG_H
4 #include "nbtool_config.h"
5 #endif
6 /* Id: defs.h,v 1.51 2014/10/02 22:38:13 tom Exp  */
7 
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11 
12 #include <limits.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <errno.h>
16 #include <assert.h>
17 #include <ctype.h>
18 #include <stdio.h>
19 
20 #if defined(__cplusplus)	/* __cplusplus, etc. */
21 #define class myClass
22 #endif
23 
24 #define YYMAJOR 1
25 #define YYMINOR 9
26 
27 #define CONCAT(first,second)    first #second
28 #define CONCAT1(string,number)  CONCAT(string, number)
29 #define CONCAT2(first,second)   #first "." #second
30 
31 #ifdef YYPATCH
32 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
33 #else
34 #define VSTRING(a,b) CONCAT2(a,b)
35 #endif
36 
37 #define VERSION VSTRING(YYMAJOR, YYMINOR)
38 
39 /*  machine-dependent definitions:			*/
40 
41 /*  MAXCHAR is the largest unsigned character value	*/
42 /*  MAXTABLE is the maximum table size			*/
43 /*  YYINT is the smallest C integer type that can be	*/
44 /*	used to address a table of size MAXTABLE	*/
45 /*  MAXYYINT is the largest value of a YYINT		*/
46 /*  MINYYINT is the most negative value of a YYINT	*/
47 /*  BITS_PER_WORD is the number of bits in a C unsigned	*/
48 /*  WORDSIZE computes the number of words needed to	*/
49 /*	store n bits					*/
50 /*  BIT returns the value of the n-th bit starting	*/
51 /*	from r (0-indexed)				*/
52 /*  SETBIT sets the n-th bit starting from r		*/
53 
54 #define	MAXCHAR		UCHAR_MAX
55 #ifndef MAXTABLE
56 #define MAXTABLE	32500
57 #endif
58 #if MAXTABLE <= SHRT_MAX
59 #define YYINT		short
60 #define MAXYYINT	SHRT_MAX
61 #define MINYYINT	SHRT_MIN
62 #elif MAXTABLE <= INT_MAX
63 #define YYINT		int
64 #define MAXYYINT	INT_MAX
65 #define MINYYINT	INT_MIN
66 #else
67 #error "MAXTABLE is too large for this machine architecture!"
68 #endif
69 
70 #define BITS_PER_WORD	((int) sizeof (unsigned) * CHAR_BIT)
71 #define WORDSIZE(n)	(((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
72 #define BIT(r, n)	((((r)[(n)/BITS_PER_WORD])>>((n)&(BITS_PER_WORD-1)))&1)
73 #define SETBIT(r, n)	((r)[(n)/BITS_PER_WORD]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
74 
75 /*  character names  */
76 
77 #define	NUL		'\0'	/*  the null character  */
78 #define	NEWLINE		'\n'	/*  line feed  */
79 #define	SP		' '	/*  space  */
80 #define	BS		'\b'	/*  backspace  */
81 #define	HT		'\t'	/*  horizontal tab  */
82 #define	VT		'\013'	/*  vertical tab  */
83 #define	CR		'\r'	/*  carriage return  */
84 #define	FF		'\f'	/*  form feed  */
85 #define	QUOTE		'\''	/*  single quote  */
86 #define	DOUBLE_QUOTE	'\"'	/*  double quote  */
87 #define	BACKSLASH	'\\'	/*  backslash  */
88 
89 #define UCH(c)          (unsigned char)(c)
90 
91 /* defines for constructing filenames */
92 
93 #if defined(VMS)
94 #define CODE_SUFFIX	"_code.c"
95 #define	DEFINES_SUFFIX	"_tab.h"
96 #define	EXTERNS_SUFFIX	"_tab.i"
97 #define	OUTPUT_SUFFIX	"_tab.c"
98 #else
99 #define CODE_SUFFIX	".code.c"
100 #define	DEFINES_SUFFIX	".tab.h"
101 #define	EXTERNS_SUFFIX	".tab.i"
102 #define	OUTPUT_SUFFIX	".tab.c"
103 #endif
104 #define	VERBOSE_SUFFIX	".output"
105 #define GRAPH_SUFFIX    ".dot"
106 
107 /* keyword codes */
108 
109 #define TOKEN 0
110 #define LEFT 1
111 #define RIGHT 2
112 #define NONASSOC 3
113 #define MARK 4
114 #define TEXT 5
115 #define TYPE 6
116 #define START 7
117 #define UNION 8
118 #define IDENT 9
119 #define EXPECT 10
120 #define EXPECT_RR 11
121 #define PURE_PARSER 12
122 #define PARSE_PARAM 13
123 #define LEX_PARAM 14
124 #define POSIX_YACC 15
125 #define TOKEN_TABLE 16
126 #define ERROR_VERBOSE 17
127 #define XXXDEBUG 18
128 
129 #if defined(YYBTYACC)
130 #define LOCATIONS 19
131 #define DESTRUCTOR 20
132 #define INITIAL_ACTION 21
133 #endif
134 
135 /*  symbol classes  */
136 
137 #define UNKNOWN 0
138 #define TERM 1
139 #define NONTERM 2
140 #define ACTION 3
141 #define ARGUMENT 4
142 
143 /*  the undefined value  */
144 
145 #define UNDEFINED (-1)
146 
147 /*  action codes  */
148 
149 #define SHIFT 1
150 #define REDUCE 2
151 
152 /*  character macros  */
153 
154 #define IS_IDENT(c)	(isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
155 #define	IS_OCTAL(c)	((c) >= '0' && (c) <= '7')
156 #define	NUMERIC_VALUE(c)	((c) - '0')
157 
158 /*  symbol macros  */
159 
160 #define ISTOKEN(s)	((s) < start_symbol)
161 #define ISVAR(s)	((s) >= start_symbol)
162 
163 /*  storage allocation macros  */
164 
165 #define CALLOC(k,n)	(calloc((size_t)(k),(size_t)(n)))
166 #define	FREE(x)		(free((char*)(x)))
167 #define MALLOC(n)	(malloc((size_t)(n)))
168 #define TCMALLOC(t,n)	((t*) calloc((size_t)(n), sizeof(t)))
169 #define TMALLOC(t,n)	((t*) malloc((size_t)(n) * sizeof(t)))
170 #define	NEW(t)		((t*)allocate(sizeof(t)))
171 #define	NEW2(n,t)	((t*)allocate(((size_t)(n)*sizeof(t))))
172 #define REALLOC(p,n)	(realloc((char*)(p),(size_t)(n)))
173 #define TREALLOC(t,p,n)	((t*)realloc((char*)(p), (size_t)(n) * sizeof(t)))
174 
175 #define DO_FREE(x)	if (x) { FREE(x); x = 0; }
176 
177 #define NO_SPACE(p)	if (p == 0) no_space(); assert(p != 0)
178 
179 /* messages */
180 #define PLURAL(n) ((n) > 1 ? "s" : "")
181 
182 /*
183  * Features which depend indirectly on the btyacc configuration, but are not
184  * essential.
185  */
186 #if defined(YYBTYACC)
187 #define USE_HEADER_GUARDS 1
188 #else
189 #define USE_HEADER_GUARDS 0
190 #endif
191 
192 typedef char Assoc_t;
193 typedef char Class_t;
194 typedef YYINT Index_t;
195 typedef YYINT Value_t;
196 
197 /*  the structure of a symbol table entry  */
198 
199 typedef struct bucket bucket;
200 struct bucket
201 {
202     struct bucket *link;
203     struct bucket *next;
204     char *name;
205     char *tag;
206 #if defined(YYBTYACC)
207     char **argnames;
208     char **argtags;
209     int  args;
210     char *destructor;
211 #endif
212     Value_t value;
213     Index_t index;
214     Value_t prec;
215     Class_t class;
216     Assoc_t assoc;
217 };
218 
219 /*  the structure of the LR(0) state machine  */
220 
221 typedef struct core core;
222 struct core
223 {
224     struct core *next;
225     struct core *link;
226     Value_t number;
227     Value_t accessing_symbol;
228     Value_t nitems;
229     Value_t items[1];
230 };
231 
232 /*  the structure used to record shifts  */
233 
234 typedef struct shifts shifts;
235 struct shifts
236 {
237     struct shifts *next;
238     Value_t number;
239     Value_t nshifts;
240     Value_t shift[1];
241 };
242 
243 /*  the structure used to store reductions  */
244 
245 typedef struct reductions reductions;
246 struct reductions
247 {
248     struct reductions *next;
249     Value_t number;
250     Value_t nreds;
251     Value_t rules[1];
252 };
253 
254 /*  the structure used to represent parser actions  */
255 
256 typedef struct action action;
257 struct action
258 {
259     struct action *next;
260     Value_t symbol;
261     Value_t number;
262     Value_t prec;
263     char action_code;
264     Assoc_t assoc;
265     char suppressed;
266 };
267 
268 /*  the structure used to store parse/lex parameters  */
269 typedef struct param param;
270 struct param
271 {
272     struct param *next;
273     char *name;		/* parameter name */
274     char *type;		/* everything before parameter name */
275     char *type2;	/* everything after parameter name */
276 };
277 
278 /* global variables */
279 
280 extern char dflag;
281 extern char gflag;
282 extern char iflag;
283 extern char lflag;
284 extern char rflag;
285 extern char sflag;
286 extern char tflag;
287 extern char vflag;
288 extern const char *symbol_prefix;
289 
290 extern const char *myname;
291 extern char *cptr;
292 extern char *line;
293 extern int lineno;
294 extern int outline;
295 extern int exit_code;
296 extern int pure_parser;
297 extern int token_table;
298 extern int error_verbose;
299 #if defined(YYBTYACC)
300 extern int locations;
301 extern int backtrack;
302 extern int destructor;
303 extern char *initial_action;
304 #endif
305 
306 extern const char *const banner[];
307 extern const char *const xdecls[];
308 extern const char *const tables[];
309 extern const char *const global_vars[];
310 extern const char *const impure_vars[];
311 extern const char *const hdr_defs[];
312 extern const char *const hdr_vars[];
313 extern const char *const body_1[];
314 extern const char *const body_vars[];
315 extern const char *const body_2[];
316 extern const char *const body_3[];
317 extern const char *const trailer[];
318 
319 extern char *code_file_name;
320 extern char *input_file_name;
321 extern char *defines_file_name;
322 extern char *externs_file_name;
323 
324 extern FILE *action_file;
325 extern FILE *code_file;
326 extern FILE *defines_file;
327 extern FILE *externs_file;
328 extern FILE *input_file;
329 extern FILE *output_file;
330 extern FILE *text_file;
331 extern FILE *union_file;
332 extern FILE *verbose_file;
333 extern FILE *graph_file;
334 
335 extern Value_t nitems;
336 extern Value_t nrules;
337 extern Value_t nsyms;
338 extern Value_t ntokens;
339 extern Value_t nvars;
340 extern int ntags;
341 
342 extern char unionized;
343 extern char line_format[];
344 
345 extern Value_t start_symbol;
346 extern char **symbol_name;
347 extern char **symbol_pname;
348 extern Value_t *symbol_value;
349 extern Value_t *symbol_prec;
350 extern char *symbol_assoc;
351 
352 #if defined(YYBTYACC)
353 extern Value_t *symbol_pval;
354 extern char **symbol_destructor;
355 extern char **symbol_type_tag;
356 #endif
357 
358 extern Value_t *ritem;
359 extern Value_t *rlhs;
360 extern Value_t *rrhs;
361 extern Value_t *rprec;
362 extern Assoc_t *rassoc;
363 
364 extern Value_t **derives;
365 extern char *nullable;
366 
367 extern bucket *first_symbol;
368 extern bucket *last_symbol;
369 
370 extern int nstates;
371 extern core *first_state;
372 extern shifts *first_shift;
373 extern reductions *first_reduction;
374 extern Value_t *accessing_symbol;
375 extern core **state_table;
376 extern shifts **shift_table;
377 extern reductions **reduction_table;
378 extern unsigned *LA;
379 extern Value_t *LAruleno;
380 extern Value_t *lookaheads;
381 extern Value_t *goto_base;
382 extern Value_t *goto_map;
383 extern Value_t *from_state;
384 extern Value_t *to_state;
385 
386 extern action **parser;
387 extern int SRexpect;
388 extern int RRexpect;
389 extern int SRtotal;
390 extern int RRtotal;
391 extern Value_t *SRconflicts;
392 extern Value_t *RRconflicts;
393 extern Value_t *defred;
394 extern Value_t *rules_used;
395 extern Value_t nunused;
396 extern Value_t final_state;
397 
398 extern Value_t *itemset;
399 extern Value_t *itemsetend;
400 extern unsigned *ruleset;
401 
402 extern param *lex_param;
403 extern param *parse_param;
404 
405 /* global functions */
406 
407 #ifndef GCC_NORETURN
408 #if defined(__dead2)
409 #define GCC_NORETURN		__dead2
410 #elif defined(__dead)
411 #define GCC_NORETURN		__dead
412 #else
413 #define GCC_NORETURN		/* nothing */
414 #endif
415 #endif
416 
417 #ifndef GCC_UNUSED
418 #if defined(__unused)
419 #define GCC_UNUSED		__unused
420 #else
421 #define GCC_UNUSED		/* nothing */
422 #endif
423 #endif
424 
425 #ifndef GCC_PRINTFLIKE
426 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
427 #endif
428 
429 /* closure.c */
430 extern void closure(Value_t * nucleus, int n);
431 extern void finalize_closure(void);
432 extern void set_first_derives(void);
433 
434 /* error.c */
435 extern void arg_number_disagree_warning(int a_lineno, char *a_name);
436 extern void arg_type_disagree_warning(int a_lineno, int i, char *a_name);
437 extern void at_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
438 extern void at_warning(int a_lineno, int i);
439 extern void bad_formals(void) GCC_NORETURN;
440 extern void default_action_warning(void);
441 struct ainfo {
442 	int a_lineno;
443 	char *a_line;
444 	char *a_cptr;
445 };
446 extern void destructor_redeclared_warning(const struct ainfo *);
447 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
448 extern void dollar_warning(int a_lineno, int i);
449 extern void fatal(const char *msg) GCC_NORETURN;
450 extern void illegal_character(char *c_cptr) GCC_NORETURN;
451 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
452 extern void missing_brace(void) GCC_NORETURN;
453 extern void no_grammar(void) GCC_NORETURN;
454 extern void no_space(void) GCC_NORETURN;
455 extern void open_error(const char *filename) GCC_NORETURN;
456 extern void over_unionized(char *u_cptr) GCC_NORETURN;
457 extern void prec_redeclared(void);
458 extern void reprec_warning(char *s);
459 extern void restarted_warning(void);
460 extern void retyped_warning(char *s);
461 extern void revalued_warning(char *s);
462 extern void start_requires_args(char *a_name);
463 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
464 extern void terminal_lhs(int s_lineno) GCC_NORETURN;
465 extern void terminal_start(char *s) GCC_NORETURN;
466 extern void tokenized_start(char *s) GCC_NORETURN;
467 extern void undefined_goal(char *s) GCC_NORETURN;
468 extern void undefined_symbol_warning(char *s);
469 extern void unexpected_EOF(void) GCC_NORETURN;
470 extern void unknown_arg_warning(int d_lineno, const char *dlr_opt, const char *d_arg, const char *d_line, const char *d_cptr);
471 extern void unknown_rhs(int i) GCC_NORETURN;
472 extern void unsupported_flag_warning(const char *flag, const char *details);
473 extern void unterminated_action(const struct ainfo *);
474 extern void unterminated_comment(const struct ainfo *) GCC_NORETURN;
475 extern void unterminated_string(const struct ainfo *) GCC_NORETURN;
476 extern void unterminated_text(const struct ainfo *) GCC_NORETURN;
477 extern void unterminated_union(const struct ainfo *) GCC_NORETURN;
478 extern void untyped_arg_warning(int a_lineno, const char *dlr_opt, const char *a_name);
479 extern void untyped_lhs(void) GCC_NORETURN;
480 extern void untyped_rhs(int i, char *s) GCC_NORETURN;
481 extern void used_reserved(char *s) GCC_NORETURN;
482 extern void unterminated_arglist(const struct ainfo *) GCC_NORETURN;
483 extern void wrong_number_args_warning(const char *which, const char *a_name);
484 extern void wrong_type_for_arg_warning(int i, char *a_name);
485 
486 /* graph.c */
487 extern void graph(void);
488 
489 /* lalr.c */
490 extern void lalr(void);
491 
492 /* lr0.c */
493 extern void lr0(void);
494 extern void show_cores(void);
495 extern void show_ritems(void);
496 extern void show_rrhs(void);
497 extern void show_shifts(void);
498 
499 /* main.c */
500 extern void *allocate(size_t n);
501 extern void done(int k) GCC_NORETURN;
502 
503 /* mkpar.c */
504 extern void free_parser(void);
505 extern void make_parser(void);
506 
507 /* mstring.c */
508 struct mstring
509 {
510     char *base, *ptr, *end;
511 };
512 
513 extern void msprintf(struct mstring *, const char *, ...) GCC_PRINTFLIKE(2,3);
514 extern int mputchar(struct mstring *, int);
515 extern struct mstring *msnew(void);
516 extern char *msdone(struct mstring *);
517 extern int strnscmp(const char *, const char *);
518 extern unsigned int strnshash(const char *);
519 
520 #define mputc(m, ch)	(((m)->ptr == (m)->end) \
521 			 ? mputchar(m,ch) \
522 			 : (*(m)->ptr++ = (char) (ch)))
523 
524 /* output.c */
525 extern void output(void);
526 
527 /* reader.c */
528 extern void reader(void);
529 
530 /* skeleton.c (generated by skel2c) */
531 extern void write_section(FILE * fp, const char *const section[]);
532 
533 /* symtab.c */
534 extern bucket *make_bucket(const char *);
535 extern bucket *lookup(const char *);
536 extern void create_symbol_table(void);
537 extern void free_symbol_table(void);
538 extern void free_symbols(void);
539 
540 /* verbose.c */
541 extern void verbose(void);
542 
543 /* warshall.c */
544 extern void reflexive_transitive_closure(unsigned *R, int n);
545 
546 #ifdef DEBUG
547     /* closure.c */
548 extern void print_closure(int n);
549 extern void print_EFF(void);
550 extern void print_first_derives(void);
551     /* lr0.c */
552 extern void print_derives(void);
553 #endif
554 
555 #ifdef NO_LEAKS
556 extern void lr0_leaks(void);
557 extern void lalr_leaks(void);
558 extern void mkpar_leaks(void);
559 extern void output_leaks(void);
560 extern void mstring_leaks(void);
561 extern void reader_leaks(void);
562 #endif
563