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