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"
6 /* Id: defs.h,v 1.35 2011/09/07 08:55:03 tom Exp */
22 #define CONCAT(first,second) first #second
23 #define CONCAT1(string,number) CONCAT(string, number)
24 #define CONCAT2(first,second) #first "." #second
27 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
29 #define VSTRING(a,b) CONCAT2(a,b)
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 */
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 */
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)))
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 */
77 #define CODE_SUFFIX "_code.c"
78 #define DEFINES_SUFFIX "_tab.h"
79 #define EXTERNS_SUFFIX "_tab.i"
80 #define OUTPUT_SUFFIX "_tab.c"
82 #define CODE_SUFFIX ".code.c"
83 #define DEFINES_SUFFIX ".tab.h"
84 #define EXTERNS_SUFFIX ".tab.i"
85 #define OUTPUT_SUFFIX ".tab.c"
87 #define VERBOSE_SUFFIX ".output"
88 #define GRAPH_SUFFIX ".dot"
104 #define PURE_PARSER 12
105 #define PARSE_PARAM 13
107 #define POSIX_YACC 15
115 /* the undefined value */
117 #define UNDEFINED (-1)
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')
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)
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
;
172 /* the structure of the LR(0) state machine */
174 typedef struct core core
;
180 Value_t accessing_symbol
;
185 /* the structure used to record shifts */
187 typedef struct shifts shifts
;
196 /* the structure used to store reductions */
198 typedef struct reductions reductions
;
201 struct reductions
*next
;
207 /* the structure used to represent parser actions */
209 typedef struct action action
;
221 /* the structure used to store parse/lex parameters */
222 typedef struct param param
;
226 char *name
; /* parameter name */
227 char *type
; /* everything before parameter name */
228 char *type2
; /* everything after parameter name */
231 /* global variables */
240 extern const char *symbol_prefix
;
242 extern const char *myname
;
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
;
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
;
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
;
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
;
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 *);
350 #define GCC_NORETURN /* nothing */
354 #define GCC_UNUSED /* nothing */
358 extern void closure(Value_t
* nucleus
, int n
);
359 extern void finalize_closure(void);
360 extern void set_first_derives(void);
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
;
397 extern void graph(void);
400 extern void create_symbol_table(void);
401 extern void free_symbol_table(void);
402 extern void free_symbols(void);
405 extern void lalr(void);
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);
415 extern void *allocate(size_t n
);
416 extern void done(int k
) GCC_NORETURN
;
419 extern void free_parser(void);
420 extern void make_parser(void);
423 extern void output(void);
426 extern void reader(void);
429 extern void write_section(FILE *fp
, const char *const section
[]);
432 extern void verbose(void);
435 extern void reflexive_transitive_closure(unsigned *R
, int n
);
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);