Imported Upstream version 20101124
[platform/upstream/byacc.git] / defs.h
1 /* $Id: defs.h,v 1.29 2010/11/24 15:13:25 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 *trailer[];
251
252 extern char *code_file_name;
253 extern char *input_file_name;
254
255 extern FILE *action_file;
256 extern FILE *code_file;
257 extern FILE *defines_file;
258 extern FILE *input_file;
259 extern FILE *output_file;
260 extern FILE *text_file;
261 extern FILE *union_file;
262 extern FILE *verbose_file;
263 extern FILE *graph_file;
264
265 extern int nitems;
266 extern int nrules;
267 extern int nsyms;
268 extern int ntokens;
269 extern int nvars;
270 extern int ntags;
271
272 extern char unionized;
273 extern char line_format[];
274
275 extern Value_t start_symbol;
276 extern char **symbol_name;
277 extern char **symbol_pname;
278 extern Value_t *symbol_value;
279 extern Value_t *symbol_prec;
280 extern char *symbol_assoc;
281
282 extern Value_t *ritem;
283 extern Value_t *rlhs;
284 extern Value_t *rrhs;
285 extern Value_t *rprec;
286 extern Assoc_t *rassoc;
287
288 extern Value_t **derives;
289 extern char *nullable;
290
291 extern bucket *first_symbol;
292 extern bucket *last_symbol;
293
294 extern int pure_parser;
295 extern int nstates;
296 extern core *first_state;
297 extern shifts *first_shift;
298 extern reductions *first_reduction;
299 extern Value_t *accessing_symbol;
300 extern core **state_table;
301 extern shifts **shift_table;
302 extern reductions **reduction_table;
303 extern unsigned *LA;
304 extern Value_t *LAruleno;
305 extern Value_t *lookaheads;
306 extern Value_t *goto_map;
307 extern Value_t *from_state;
308 extern Value_t *to_state;
309
310 extern action **parser;
311 extern int SRexpect;
312 extern int RRexpect;
313 extern int SRtotal;
314 extern int RRtotal;
315 extern Value_t *SRconflicts;
316 extern Value_t *RRconflicts;
317 extern Value_t *defred;
318 extern Value_t *rules_used;
319 extern Value_t nunused;
320 extern Value_t final_state;
321
322 extern Value_t *itemset;
323 extern Value_t *itemsetend;
324 extern unsigned *ruleset;
325
326 extern param *lex_param;
327 extern param *parse_param;
328
329 /* global functions */
330
331 extern bucket *lookup(const char *);
332 extern bucket *make_bucket(const char *);
333
334 #ifndef GCC_NORETURN
335 #define GCC_NORETURN            /* nothing */
336 #endif
337
338 #ifndef GCC_UNUSED
339 #define GCC_UNUSED              /* nothing */
340 #endif
341
342 /* closure.c */
343 extern void closure(Value_t * nucleus, int n);
344 extern void finalize_closure(void);
345 extern void set_first_derives(void);
346
347 /* error.c */
348 extern void default_action_warning(void);
349 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr);
350 extern void dollar_warning(int a_lineno, int i);
351 extern void fatal(const char *msg);
352 extern void illegal_character(char *c_cptr);
353 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr);
354 extern void no_grammar(void);
355 extern void no_space(void);
356 extern void open_error(const char *filename);
357 extern void over_unionized(char *u_cptr);
358 extern void prec_redeclared(void);
359 extern void reprec_warning(char *s);
360 extern void restarted_warning(void);
361 extern void retyped_warning(char *s);
362 extern void revalued_warning(char *s);
363 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
364 extern void terminal_lhs(int s_lineno);
365 extern void terminal_start(char *s);
366 extern void tokenized_start(char *s);
367 extern void undefined_goal(char *s);
368 extern void undefined_symbol_warning(char *s);
369 extern void unexpected_EOF(void);
370 extern void unknown_rhs(int i);
371 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr);
372 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr);
373 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr);
374 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr);
375 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr);
376 extern void untyped_lhs(void);
377 extern void untyped_rhs(int i, char *s);
378 extern void used_reserved(char *s);
379
380 /* graph.c */
381 extern void graph(void);
382
383 /* lalr.c */
384 extern void create_symbol_table(void);
385 extern void free_symbol_table(void);
386 extern void free_symbols(void);
387
388 /* lalr.c */
389 extern void lalr(void);
390
391 /* lr0.c */
392 extern void lr0(void);
393 extern void show_cores(void);
394 extern void show_ritems(void);
395 extern void show_rrhs(void);
396 extern void show_shifts(void);
397
398 /* main.c */
399 extern char *allocate(size_t n);
400 extern void done(int k) GCC_NORETURN;
401
402 /* mkpar.c */
403 extern void free_parser(void);
404 extern void make_parser(void);
405
406 /* output.c */
407 extern void output(void);
408
409 /* reader.c */
410 extern void reader(void);
411
412 /* skeleton.c */
413 extern void write_section(const char *section[]);
414
415 /* verbose.c */
416 extern void verbose(void);
417
418 /* warshall.c */
419 extern void reflexive_transitive_closure(unsigned *R, int n);
420
421 #ifdef NO_LEAKS
422 extern void lr0_leaks(void);
423 extern void lalr_leaks(void);
424 extern void mkpar_leaks(void);
425 extern void output_leaks(void);
426 extern void reader_leaks(void);
427 #endif