Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / byacc / dist / defs.h
blob3f103405bb386a6f44ad004af3589dc447244f32
1 /* Id: defs.h,v 1.20 2009/10/27 10:47:43 tom Exp */
3 #if HAVE_NBTOOL_CONFIG_H
4 #include "nbtool_config.h"
5 #endif
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
11 #include <stdlib.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <assert.h>
15 #include <ctype.h>
16 #include <stdio.h>
18 #define YYMAJOR 1
19 #define YYMINOR 9
21 #define CONCAT(first,second) first #second
22 #define CONCAT1(string,number) CONCAT(string, number)
23 #define CONCAT2(first,second) #first "." #second
25 #ifdef YYPATCH
26 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
27 #else
28 #define VSTRING(a,b) CONCAT2(a,b)
29 #endif
31 #define VERSION VSTRING(YYMAJOR, YYMINOR)
33 /* machine-dependent definitions */
34 /* the following definitions are for the Tahoe */
35 /* they might have to be changed for other machines */
37 /* MAXCHAR is the largest unsigned character value */
38 /* MAXSHORT is the largest value of a C short */
39 /* MINSHORT is the most negative value of a C short */
40 /* MAXTABLE is the maximum table size */
41 /* BITS_PER_WORD is the number of bits in a C unsigned */
42 /* WORDSIZE computes the number of words needed to */
43 /* store n bits */
44 /* BIT returns the value of the n-th bit starting */
45 /* from r (0-indexed) */
46 /* SETBIT sets the n-th bit starting from r */
48 #define MAXCHAR 255
49 #define MAXSHORT 32767
50 #define MINSHORT -32768
51 #define MAXTABLE 32500
52 #define BITS_PER_WORD 32
53 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
54 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
55 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
57 /* character names */
59 #define NUL '\0' /* the null character */
60 #define NEWLINE '\n' /* line feed */
61 #define SP ' ' /* space */
62 #define BS '\b' /* backspace */
63 #define HT '\t' /* horizontal tab */
64 #define VT '\013' /* vertical tab */
65 #define CR '\r' /* carriage return */
66 #define FF '\f' /* form feed */
67 #define QUOTE '\'' /* single quote */
68 #define DOUBLE_QUOTE '\"' /* double quote */
69 #define BACKSLASH '\\' /* backslash */
71 /* defines for constructing filenames */
73 #if defined(VMS)
74 #define CODE_SUFFIX "_code.c"
75 #define DEFINES_SUFFIX "_tab.h"
76 #define OUTPUT_SUFFIX "_tab.c"
77 #else
78 #define CODE_SUFFIX ".code.c"
79 #define DEFINES_SUFFIX ".tab.h"
80 #define OUTPUT_SUFFIX ".tab.c"
81 #endif
82 #define VERBOSE_SUFFIX ".output"
83 #define GRAPH_SUFFIX ".dot"
85 /* keyword codes */
87 #define TOKEN 0
88 #define LEFT 1
89 #define RIGHT 2
90 #define NONASSOC 3
91 #define MARK 4
92 #define TEXT 5
93 #define TYPE 6
94 #define START 7
95 #define UNION 8
96 #define IDENT 9
97 #define EXPECT 10
98 #define EXPECT_RR 11
99 #define PURE_PARSER 12
100 #define PARSE_PARAM 13
101 #define LEX_PARAM 14
103 /* symbol classes */
105 #define UNKNOWN 0
106 #define TERM 1
107 #define NONTERM 2
109 /* the undefined value */
111 #define UNDEFINED (-1)
113 /* action codes */
115 #define SHIFT 1
116 #define REDUCE 2
118 /* character macros */
120 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
121 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
122 #define NUMERIC_VALUE(c) ((c) - '0')
124 /* symbol macros */
126 #define ISTOKEN(s) ((s) < start_symbol)
127 #define ISVAR(s) ((s) >= start_symbol)
129 /* storage allocation macros */
131 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
132 #define FREE(x) (free((char*)(x)))
133 #define MALLOC(n) (malloc((unsigned)(n)))
134 #define NEW(t) ((t*)allocate(sizeof(t)))
135 #define NEW2(n,t) ((t*)allocate(((unsigned)(n)*sizeof(t))))
136 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
138 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
140 /* messages */
141 #define PLURAL(n) ((n) > 1 ? "s" : "")
143 typedef char Assoc_t;
144 typedef char Class_t;
145 typedef short Index_t;
146 typedef short Value_t;
148 /* the structure of a symbol table entry */
150 typedef struct bucket bucket;
151 struct bucket
153 struct bucket *link;
154 struct bucket *next;
155 char *name;
156 char *tag;
157 Value_t value;
158 Index_t index;
159 Value_t prec;
160 Class_t class;
161 Assoc_t assoc;
164 /* the structure of the LR(0) state machine */
166 typedef struct core core;
167 struct core
169 struct core *next;
170 struct core *link;
171 Value_t number;
172 Value_t accessing_symbol;
173 Value_t nitems;
174 Value_t items[1];
177 /* the structure used to record shifts */
179 typedef struct shifts shifts;
180 struct shifts
182 struct shifts *next;
183 Value_t number;
184 Value_t nshifts;
185 Value_t shift[1];
188 typedef struct param param;
189 struct param {
190 struct param *next;
191 char *name;
192 char *type;
195 /* the structure used to store reductions */
197 typedef struct reductions reductions;
198 struct reductions
200 struct reductions *next;
201 Value_t number;
202 Value_t nreds;
203 Value_t rules[1];
206 /* the structure used to represent parser actions */
208 typedef struct action action;
209 struct action
211 struct action *next;
212 Value_t symbol;
213 Value_t number;
214 Value_t prec;
215 char action_code;
216 Assoc_t assoc;
217 char suppressed;
220 /* global variables */
222 extern char dflag;
223 extern char gflag;
224 extern char lflag;
225 extern char rflag;
226 extern char tflag;
227 extern char vflag;
228 extern const char *symbol_prefix;
230 extern const char *myname;
231 extern char *cptr;
232 extern char *line;
233 extern int lineno;
234 extern int outline;
235 extern int exit_code;
236 extern int pure_parser;
238 extern const char * const banner[];
239 extern const char * const tables[];
240 extern const char * const header[];
241 extern const char * const body[];
242 extern const char * const trailer[];
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 *verbose_file_name;
249 extern char *graph_file_name;
251 extern FILE *action_file;
252 extern FILE *code_file;
253 extern FILE *defines_file;
254 extern FILE *input_file;
255 extern FILE *output_file;
256 extern FILE *text_file;
257 extern FILE *union_file;
258 extern FILE *verbose_file;
259 extern FILE *graph_file;
261 extern int nitems;
262 extern int nrules;
263 extern int nsyms;
264 extern int ntokens;
265 extern int nvars;
266 extern int ntags;
268 extern char unionized;
269 extern char line_format[];
271 extern Value_t start_symbol;
272 extern char **symbol_name;
273 extern char **symbol_pname;
274 extern Value_t *symbol_value;
275 extern Value_t *symbol_prec;
276 extern char *symbol_assoc;
278 extern Value_t *ritem;
279 extern Value_t *rlhs;
280 extern Value_t *rrhs;
281 extern Value_t *rprec;
282 extern Assoc_t *rassoc;
284 extern Value_t **derives;
285 extern char *nullable;
287 extern bucket *first_symbol;
288 extern bucket *last_symbol;
290 extern int nstates;
291 extern core *first_state;
292 extern shifts *first_shift;
293 extern reductions *first_reduction;
294 extern Value_t *accessing_symbol;
295 extern core **state_table;
296 extern shifts **shift_table;
297 extern reductions **reduction_table;
298 extern unsigned *LA;
299 extern Value_t *LAruleno;
300 extern Value_t *lookaheads;
301 extern Value_t *goto_map;
302 extern Value_t *from_state;
303 extern Value_t *to_state;
305 extern action **parser;
306 extern int SRexpect;
307 extern int RRexpect;
308 extern int SRtotal;
309 extern int RRtotal;
310 extern Value_t *SRconflicts;
311 extern Value_t *RRconflicts;
312 extern Value_t *defred;
313 extern Value_t *rules_used;
314 extern Value_t nunused;
315 extern Value_t final_state;
317 extern Value_t *itemset;
318 extern Value_t *itemsetend;
319 extern unsigned *ruleset;
321 extern param *lex_param;
322 extern param *parse_param;
324 /* global functions */
326 extern bucket *lookup(const char *);
327 extern bucket *make_bucket(const char *);
329 #ifndef GCC_NORETURN
330 #define GCC_NORETURN /* nothing */
331 #endif
333 #ifndef GCC_UNUSED
334 #define GCC_UNUSED /* nothing */
335 #endif
337 /* closure.c */
338 extern void closure(Value_t *nucleus, int n);
339 extern void finalize_closure(void);
340 extern void set_first_derives(void);
342 /* error.c */
343 extern void default_action_warning(void);
344 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr);
345 extern void dollar_warning(int a_lineno, int i);
346 extern void fatal(const char *msg);
347 extern void illegal_character(char *c_cptr);
348 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr);
349 extern void no_grammar(void);
350 extern void no_space(void);
351 extern void open_error(const char *filename);
352 extern void over_unionized(char *u_cptr);
353 extern void prec_redeclared(void);
354 extern void print_pos(char *st_line, char *st_cptr);
355 extern void reprec_warning(char *s);
356 extern void restarted_warning(void);
357 extern void retyped_warning(char *s);
358 extern void revalued_warning(char *s);
359 extern __dead void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
360 extern void terminal_lhs(int s_lineno);
361 extern void terminal_start(char *s);
362 extern void tokenized_start(char *s);
363 extern void undefined_goal(char *s);
364 extern void undefined_symbol_warning(char *s);
365 extern void unexpected_EOF(void);
366 extern void unknown_rhs(int i);
367 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr);
368 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr);
369 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr);
370 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr);
371 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr);
372 extern void untyped_lhs(void);
373 extern void untyped_rhs(int i, char *s);
374 extern void used_reserved(char *s);
376 /* graph.c */
377 extern void graph(void);
379 /* lalr.c */
380 extern int hash(const char *name);
381 extern void create_symbol_table(void);
382 extern void free_symbol_table(void);
383 extern void free_symbols(void);
385 /* lalr.c */
386 extern void lalr(void);
388 /* lr0.c */
389 extern void lr0(void);
390 extern void show_cores(void);
391 extern void show_ritems(void);
392 extern void show_rrhs(void);
393 extern void show_shifts(void);
395 /* main.c */
396 extern char *allocate(unsigned n);
397 extern void done(int k) GCC_NORETURN;
399 /* mkpar.c */
400 extern void free_parser(void);
401 extern void make_parser(void);
403 /* output.c */
404 extern void output(void);
406 /* reader.c */
407 extern void reader(void);
409 /* skeleton.c */
410 extern void write_section(const char * const section[], int);
412 /* verbose.c */
413 extern void verbose(void);
415 /* warshall.c */
416 extern void reflexive_transitive_closure(unsigned *R, int n);
418 #ifdef NO_LEAKS
419 extern void lr0_leaks(void);
420 extern void lalr_leaks(void);
421 extern void mkpar_leaks(void);
422 extern void output_leaks(void);
423 extern void reader_leaks(void);
424 #endif