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"
6 /* Id: defs.h,v 1.37 2012/05/26 15:23:00 tom Exp */
19 #if defined(__cplusplus) /* __cplusplus, etc. */
26 #define CONCAT(first,second) first #second
27 #define CONCAT1(string,number) CONCAT(string, number)
28 #define CONCAT2(first,second) #first "." #second
31 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
33 #define VSTRING(a,b) CONCAT2(a,b)
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 */
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 */
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)))
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 */
81 #define CODE_SUFFIX "_code.c"
82 #define DEFINES_SUFFIX "_tab.h"
83 #define EXTERNS_SUFFIX "_tab.i"
84 #define OUTPUT_SUFFIX "_tab.c"
86 #define CODE_SUFFIX ".code.c"
87 #define DEFINES_SUFFIX ".tab.h"
88 #define EXTERNS_SUFFIX ".tab.i"
89 #define OUTPUT_SUFFIX ".tab.c"
91 #define VERBOSE_SUFFIX ".output"
92 #define GRAPH_SUFFIX ".dot"
108 #define PURE_PARSER 12
109 #define PARSE_PARAM 13
111 #define POSIX_YACC 15
119 /* the undefined value */
121 #define UNDEFINED (-1)
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')
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)
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
;
178 /* the structure of the LR(0) state machine */
180 typedef struct core core
;
186 Value_t accessing_symbol
;
191 /* the structure used to record shifts */
193 typedef struct shifts shifts
;
202 /* the structure used to store reductions */
204 typedef struct reductions reductions
;
207 struct reductions
*next
;
213 /* the structure used to represent parser actions */
215 typedef struct action action
;
227 /* the structure used to store parse/lex parameters */
228 typedef struct param param
;
232 char *name
; /* parameter name */
233 char *type
; /* everything before parameter name */
234 char *type2
; /* everything after parameter name */
237 /* global variables */
247 extern const char *symbol_prefix
;
249 extern const char *myname
;
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
;
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
;
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
;
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
;
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 *);
357 #define GCC_NORETURN __dead2
358 #elif defined(__dead)
359 #define GCC_NORETURN __dead
361 #define GCC_NORETURN /* nothing */
366 #if defined(__unused)
367 #define GCC_UNUSED __unused
369 #define GCC_UNUSED /* nothing */
374 extern void closure(Value_t
* nucleus
, int n
);
375 extern void finalize_closure(void);
376 extern void set_first_derives(void);
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
;
413 extern void graph(void);
416 extern void create_symbol_table(void);
417 extern void free_symbol_table(void);
418 extern void free_symbols(void);
421 extern void lalr(void);
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);
431 extern void *allocate(size_t n
);
432 extern void done(int k
) GCC_NORETURN
;
435 extern void free_parser(void);
436 extern void make_parser(void);
439 extern void output(void);
442 extern void reader(void);
445 extern void write_section(FILE * fp
, const char *const section
[]);
448 extern void verbose(void);
451 extern void reflexive_transitive_closure(unsigned *R
, int n
);
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);