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"
21 #define CONCAT(first,second) first #second
22 #define CONCAT1(string,number) CONCAT(string, number)
23 #define CONCAT2(first,second) #first "." #second
26 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
28 #define VSTRING(a,b) CONCAT2(a,b)
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 */
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 */
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)))
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 */
74 #define CODE_SUFFIX "_code.c"
75 #define DEFINES_SUFFIX "_tab.h"
76 #define OUTPUT_SUFFIX "_tab.c"
78 #define CODE_SUFFIX ".code.c"
79 #define DEFINES_SUFFIX ".tab.h"
80 #define OUTPUT_SUFFIX ".tab.c"
82 #define VERBOSE_SUFFIX ".output"
83 #define GRAPH_SUFFIX ".dot"
99 #define PURE_PARSER 12
100 #define PARSE_PARAM 13
109 /* the undefined value */
111 #define UNDEFINED (-1)
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')
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; }
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
;
164 /* the structure of the LR(0) state machine */
166 typedef struct core core
;
172 Value_t accessing_symbol
;
177 /* the structure used to record shifts */
179 typedef struct shifts shifts
;
188 typedef struct param param
;
195 /* the structure used to store reductions */
197 typedef struct reductions reductions
;
200 struct reductions
*next
;
206 /* the structure used to represent parser actions */
208 typedef struct action action
;
220 /* global variables */
228 extern const char *symbol_prefix
;
230 extern const char *myname
;
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
;
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
;
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
;
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
;
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 *);
330 #define GCC_NORETURN /* nothing */
334 #define GCC_UNUSED /* nothing */
338 extern void closure(Value_t
*nucleus
, int n
);
339 extern void finalize_closure(void);
340 extern void set_first_derives(void);
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
);
377 extern void graph(void);
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);
386 extern void lalr(void);
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);
396 extern char *allocate(unsigned n
);
397 extern void done(int k
) GCC_NORETURN
;
400 extern void free_parser(void);
401 extern void make_parser(void);
404 extern void output(void);
407 extern void reader(void);
410 extern void write_section(const char * const section
[], int);
413 extern void verbose(void);
416 extern void reflexive_transitive_closure(unsigned *R
, int n
);
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);