1 /* $Id: defs.h,v 1.51 2014/10/02 22:38:13 tom Exp $ */
15 #if defined(__cplusplus) /* __cplusplus, etc. */
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: */
36 /* MAXCHAR is the largest unsigned character value */
37 /* MAXTABLE is the maximum table size */
38 /* YYINT is the smallest C integer type that can be */
39 /* used to address a table of size MAXTABLE */
40 /* MAXYYINT is the largest value of a YYINT */
41 /* MINYYINT is the most negative value of a YYINT */
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 */
49 #define MAXCHAR UCHAR_MAX
51 #define MAXTABLE 32500
53 #if MAXTABLE <= SHRT_MAX
55 #define MAXYYINT SHRT_MAX
56 #define MINYYINT SHRT_MIN
57 #elif MAXTABLE <= INT_MAX
59 #define MAXYYINT INT_MAX
60 #define MINYYINT INT_MIN
62 #error "MAXTABLE is too large for this machine architecture!"
65 #define BITS_PER_WORD ((int) sizeof (unsigned) * CHAR_BIT)
66 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
67 #define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)&(BITS_PER_WORD-1)))&1)
68 #define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
72 #define NUL '\0' /* the null character */
73 #define NEWLINE '\n' /* line feed */
74 #define SP ' ' /* space */
75 #define BS '\b' /* backspace */
76 #define HT '\t' /* horizontal tab */
77 #define VT '\013' /* vertical tab */
78 #define CR '\r' /* carriage return */
79 #define FF '\f' /* form feed */
80 #define QUOTE '\'' /* single quote */
81 #define DOUBLE_QUOTE '\"' /* double quote */
82 #define BACKSLASH '\\' /* backslash */
84 #define UCH(c) (unsigned char)(c)
86 /* defines for constructing filenames */
89 #define CODE_SUFFIX "_code.c"
90 #define DEFINES_SUFFIX "_tab.h"
91 #define EXTERNS_SUFFIX "_tab.i"
92 #define OUTPUT_SUFFIX "_tab.c"
94 #define CODE_SUFFIX ".code.c"
95 #define DEFINES_SUFFIX ".tab.h"
96 #define EXTERNS_SUFFIX ".tab.i"
97 #define OUTPUT_SUFFIX ".tab.c"
99 #define VERBOSE_SUFFIX ".output"
100 #define GRAPH_SUFFIX ".dot"
116 #define PURE_PARSER 12
117 #define PARSE_PARAM 13
119 #define POSIX_YACC 15
120 #define TOKEN_TABLE 16
122 #if defined(YYBTYACC)
124 #define DESTRUCTOR 18
135 /* the undefined value */
137 #define UNDEFINED (-1)
144 /* character macros */
146 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
147 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
148 #define NUMERIC_VALUE(c) ((c) - '0')
152 #define ISTOKEN(s) ((s) < start_symbol)
153 #define ISVAR(s) ((s) >= start_symbol)
155 /* storage allocation macros */
157 #define CALLOC(k,n) (calloc((size_t)(k),(size_t)(n)))
158 #define FREE(x) (free((char*)(x)))
159 #define MALLOC(n) (malloc((size_t)(n)))
160 #define TCMALLOC(t,n) ((t*) calloc((size_t)(n), sizeof(t)))
161 #define TMALLOC(t,n) ((t*) malloc((size_t)(n) * sizeof(t)))
162 #define NEW(t) ((t*)allocate(sizeof(t)))
163 #define NEW2(n,t) ((t*)allocate(((size_t)(n)*sizeof(t))))
164 #define REALLOC(p,n) (realloc((char*)(p),(size_t)(n)))
165 #define TREALLOC(t,p,n) ((t*)realloc((char*)(p), (size_t)(n) * sizeof(t)))
167 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
169 #define NO_SPACE(p) if (p == 0) no_space(); assert(p != 0)
172 #define PLURAL(n) ((n) > 1 ? "s" : "")
175 * Features which depend indirectly on the btyacc configuration, but are not
178 #if defined(YYBTYACC)
179 #define USE_HEADER_GUARDS 1
181 #define USE_HEADER_GUARDS 0
184 typedef char Assoc_t
;
185 typedef char Class_t
;
186 typedef YYINT Index_t
;
187 typedef YYINT Value_t
;
189 /* the structure of a symbol table entry */
191 typedef struct bucket bucket
;
198 #if defined(YYBTYACC)
211 /* the structure of the LR(0) state machine */
213 typedef struct core core
;
219 Value_t accessing_symbol
;
224 /* the structure used to record shifts */
226 typedef struct shifts shifts
;
235 /* the structure used to store reductions */
237 typedef struct reductions reductions
;
240 struct reductions
*next
;
246 /* the structure used to represent parser actions */
248 typedef struct action action
;
260 /* the structure used to store parse/lex parameters */
261 typedef struct param param
;
265 char *name
; /* parameter name */
266 char *type
; /* everything before parameter name */
267 char *type2
; /* everything after parameter name */
270 /* global variables */
280 extern const char *symbol_prefix
;
282 extern const char *myname
;
287 extern int exit_code
;
288 extern int pure_parser
;
289 extern int token_table
;
290 #if defined(YYBTYACC)
291 extern int locations
;
292 extern int backtrack
;
293 extern int destructor
;
296 extern const char *const banner
[];
297 extern const char *const xdecls
[];
298 extern const char *const tables
[];
299 extern const char *const global_vars
[];
300 extern const char *const impure_vars
[];
301 extern const char *const hdr_defs
[];
302 extern const char *const hdr_vars
[];
303 extern const char *const body_1
[];
304 extern const char *const body_vars
[];
305 extern const char *const body_2
[];
306 extern const char *const trailer
[];
308 extern char *code_file_name
;
309 extern char *input_file_name
;
310 extern char *defines_file_name
;
311 extern char *externs_file_name
;
313 extern FILE *action_file
;
314 extern FILE *code_file
;
315 extern FILE *defines_file
;
316 extern FILE *externs_file
;
317 extern FILE *input_file
;
318 extern FILE *output_file
;
319 extern FILE *text_file
;
320 extern FILE *union_file
;
321 extern FILE *verbose_file
;
322 extern FILE *graph_file
;
324 extern Value_t nitems
;
325 extern Value_t nrules
;
326 extern Value_t nsyms
;
327 extern Value_t ntokens
;
328 extern Value_t nvars
;
331 extern char unionized
;
332 extern char line_format
[];
334 extern Value_t start_symbol
;
335 extern char **symbol_name
;
336 extern char **symbol_pname
;
337 extern Value_t
*symbol_value
;
338 extern Value_t
*symbol_prec
;
339 extern char *symbol_assoc
;
341 #if defined(YYBTYACC)
342 extern Value_t
*symbol_pval
;
343 extern char **symbol_destructor
;
344 extern char **symbol_type_tag
;
347 extern Value_t
*ritem
;
348 extern Value_t
*rlhs
;
349 extern Value_t
*rrhs
;
350 extern Value_t
*rprec
;
351 extern Assoc_t
*rassoc
;
353 extern Value_t
**derives
;
354 extern char *nullable
;
356 extern bucket
*first_symbol
;
357 extern bucket
*last_symbol
;
360 extern core
*first_state
;
361 extern shifts
*first_shift
;
362 extern reductions
*first_reduction
;
363 extern Value_t
*accessing_symbol
;
364 extern core
**state_table
;
365 extern shifts
**shift_table
;
366 extern reductions
**reduction_table
;
368 extern Value_t
*LAruleno
;
369 extern Value_t
*lookaheads
;
370 extern Value_t
*goto_base
;
371 extern Value_t
*goto_map
;
372 extern Value_t
*from_state
;
373 extern Value_t
*to_state
;
375 extern action
**parser
;
380 extern Value_t
*SRconflicts
;
381 extern Value_t
*RRconflicts
;
382 extern Value_t
*defred
;
383 extern Value_t
*rules_used
;
384 extern Value_t nunused
;
385 extern Value_t final_state
;
387 extern Value_t
*itemset
;
388 extern Value_t
*itemsetend
;
389 extern unsigned *ruleset
;
391 extern param
*lex_param
;
392 extern param
*parse_param
;
394 /* global functions */
398 #define GCC_NORETURN __dead2
399 #elif defined(__dead)
400 #define GCC_NORETURN __dead
402 #define GCC_NORETURN /* nothing */
407 #if defined(__unused)
408 #define GCC_UNUSED __unused
410 #define GCC_UNUSED /* nothing */
414 #ifndef GCC_PRINTFLIKE
415 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
419 extern void closure(Value_t
* nucleus
, int n
);
420 extern void finalize_closure(void);
421 extern void set_first_derives(void);
424 extern void arg_number_disagree_warning(int a_lineno
, char *a_name
);
425 extern void arg_type_disagree_warning(int a_lineno
, int i
, char *a_name
);
426 extern void at_error(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
427 extern void at_warning(int a_lineno
, int i
);
428 extern void bad_formals(void) GCC_NORETURN
;
429 extern void default_action_warning(void);
430 extern void destructor_redeclared_warning(int a_lineno
, char *a_line
, char *a_cptr
);
431 extern void dollar_error(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
432 extern void dollar_warning(int a_lineno
, int i
);
433 extern void fatal(const char *msg
) GCC_NORETURN
;
434 extern void illegal_character(char *c_cptr
) GCC_NORETURN
;
435 extern void illegal_tag(int t_lineno
, char *t_line
, char *t_cptr
) GCC_NORETURN
;
436 extern void missing_brace(void) GCC_NORETURN
;
437 extern void no_grammar(void) GCC_NORETURN
;
438 extern void no_space(void) GCC_NORETURN
;
439 extern void open_error(const char *filename
) GCC_NORETURN
;
440 extern void over_unionized(char *u_cptr
) GCC_NORETURN
;
441 extern void prec_redeclared(void);
442 extern void reprec_warning(char *s
);
443 extern void restarted_warning(void);
444 extern void retyped_warning(char *s
);
445 extern void revalued_warning(char *s
);
446 extern void start_requires_args(char *a_name
);
447 extern void syntax_error(int st_lineno
, char *st_line
, char *st_cptr
) GCC_NORETURN
;
448 extern void terminal_lhs(int s_lineno
) GCC_NORETURN
;
449 extern void terminal_start(char *s
) GCC_NORETURN
;
450 extern void tokenized_start(char *s
) GCC_NORETURN
;
451 extern void undefined_goal(char *s
) GCC_NORETURN
;
452 extern void undefined_symbol_warning(char *s
);
453 extern void unexpected_EOF(void) GCC_NORETURN
;
454 extern void unknown_arg_warning(int d_lineno
, const char *dlr_opt
, const char *d_arg
, const char *d_line
, const char *d_cptr
);
455 extern void unknown_rhs(int i
) GCC_NORETURN
;
456 extern void unsupported_flag_warning(const char *flag
, const char *details
);
457 extern void unterminated_action(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
458 extern void unterminated_comment(int c_lineno
, char *c_line
, char *c_cptr
) GCC_NORETURN
;
459 extern void unterminated_string(int s_lineno
, char *s_line
, char *s_cptr
) GCC_NORETURN
;
460 extern void unterminated_text(int t_lineno
, char *t_line
, char *t_cptr
) GCC_NORETURN
;
461 extern void unterminated_union(int u_lineno
, char *u_line
, char *u_cptr
) GCC_NORETURN
;
462 extern void untyped_arg_warning(int a_lineno
, const char *dlr_opt
, const char *a_name
);
463 extern void untyped_lhs(void) GCC_NORETURN
;
464 extern void untyped_rhs(int i
, char *s
) GCC_NORETURN
;
465 extern void used_reserved(char *s
) GCC_NORETURN
;
466 extern void unterminated_arglist(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
467 extern void wrong_number_args_warning(const char *which
, const char *a_name
);
468 extern void wrong_type_for_arg_warning(int i
, char *a_name
);
471 extern void graph(void);
474 extern void lalr(void);
477 extern void lr0(void);
478 extern void show_cores(void);
479 extern void show_ritems(void);
480 extern void show_rrhs(void);
481 extern void show_shifts(void);
484 extern void *allocate(size_t n
);
485 extern void done(int k
) GCC_NORETURN
;
488 extern void free_parser(void);
489 extern void make_parser(void);
494 char *base
, *ptr
, *end
;
497 extern void msprintf(struct mstring
*, const char *, ...) GCC_PRINTFLIKE(2,3);
498 extern int mputchar(struct mstring
*, int);
499 extern struct mstring
*msnew(void);
500 extern char *msdone(struct mstring
*);
501 extern int strnscmp(const char *, const char *);
502 extern unsigned int strnshash(const char *);
504 #define mputc(m, ch) (((m)->ptr == (m)->end) \
506 : (*(m)->ptr++ = (char) (ch)))
509 extern void output(void);
512 extern void reader(void);
514 /* skeleton.c (generated by skel2c) */
515 extern void write_section(FILE * fp
, const char *const section
[]);
518 extern bucket
*make_bucket(const char *);
519 extern bucket
*lookup(const char *);
520 extern void create_symbol_table(void);
521 extern void free_symbol_table(void);
522 extern void free_symbols(void);
525 extern void verbose(void);
528 extern void reflexive_transitive_closure(unsigned *R
, int n
);
532 extern void print_closure(int n
);
533 extern void print_EFF(void);
534 extern void print_first_derives(void);
536 extern void print_derives(void);
540 extern void lr0_leaks(void);
541 extern void lalr_leaks(void);
542 extern void mkpar_leaks(void);
543 extern void output_leaks(void);
544 extern void mstring_leaks(void);
545 extern void reader_leaks(void);