Imported Upstream version 20100216
[platform/upstream/byacc.git] / defs.h
1 /* $Id: defs.h,v 1.23 2010/02/17 00:48: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 /* defines for constructing filenames */
68
69 #if defined(VMS)
70 #define CODE_SUFFIX     "_code.c"
71 #define DEFINES_SUFFIX  "_tab.h"
72 #define OUTPUT_SUFFIX   "_tab.c"
73 #else
74 #define CODE_SUFFIX     ".code.c"
75 #define DEFINES_SUFFIX  ".tab.h"
76 #define OUTPUT_SUFFIX   ".tab.c"
77 #endif
78 #define VERBOSE_SUFFIX  ".output"
79 #define GRAPH_SUFFIX    ".dot"
80
81 /* keyword codes */
82
83 #define TOKEN 0
84 #define LEFT 1
85 #define RIGHT 2
86 #define NONASSOC 3
87 #define MARK 4
88 #define TEXT 5
89 #define TYPE 6
90 #define START 7
91 #define UNION 8
92 #define IDENT 9
93 #define EXPECT 10
94 #define EXPECT_RR 11
95 #define PURE_PARSER 12
96
97 /*  symbol classes  */
98
99 #define UNKNOWN 0
100 #define TERM 1
101 #define NONTERM 2
102
103 /*  the undefined value  */
104
105 #define UNDEFINED (-1)
106
107 /*  action codes  */
108
109 #define SHIFT 1
110 #define REDUCE 2
111
112 /*  character macros  */
113
114 #define IS_IDENT(c)     (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
115 #define IS_OCTAL(c)     ((c) >= '0' && (c) <= '7')
116 #define NUMERIC_VALUE(c)        ((c) - '0')
117
118 /*  symbol macros  */
119
120 #define ISTOKEN(s)      ((s) < start_symbol)
121 #define ISVAR(s)        ((s) >= start_symbol)
122
123 /*  storage allocation macros  */
124
125 #define CALLOC(k,n)     (calloc((unsigned)(k),(unsigned)(n)))
126 #define FREE(x)         (free((char*)(x)))
127 #define MALLOC(n)       (malloc((unsigned)(n)))
128 #define NEW(t)          ((t*)allocate(sizeof(t)))
129 #define NEW2(n,t)       ((t*)allocate(((unsigned)(n)*sizeof(t))))
130 #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
131
132 #define DO_FREE(x)      if (x) { FREE(x); x = 0; }
133
134 /* messages */
135 #define PLURAL(n) ((n) > 1 ? "s" : "")
136
137 typedef char Assoc_t;
138 typedef char Class_t;
139 typedef short Index_t;
140 typedef short Value_t;
141
142 /*  the structure of a symbol table entry  */
143
144 typedef struct bucket bucket;
145 struct bucket
146 {
147     struct bucket *link;
148     struct bucket *next;
149     char *name;
150     char *tag;
151     Value_t value;
152     Index_t index;
153     Value_t prec;
154     Class_t class;
155     Assoc_t assoc;
156 };
157
158 /*  the structure of the LR(0) state machine  */
159
160 typedef struct core core;
161 struct core
162 {
163     struct core *next;
164     struct core *link;
165     Value_t number;
166     Value_t accessing_symbol;
167     Value_t nitems;
168     Value_t items[1];
169 };
170
171 /*  the structure used to record shifts  */
172
173 typedef struct shifts shifts;
174 struct shifts
175 {
176     struct shifts *next;
177     Value_t number;
178     Value_t nshifts;
179     Value_t shift[1];
180 };
181
182 /*  the structure used to store reductions  */
183
184 typedef struct reductions reductions;
185 struct reductions
186 {
187     struct reductions *next;
188     Value_t number;
189     Value_t nreds;
190     Value_t rules[1];
191 };
192
193 /*  the structure used to represent parser actions  */
194
195 typedef struct action action;
196 struct action
197 {
198     struct action *next;
199     Value_t symbol;
200     Value_t number;
201     Value_t prec;
202     char action_code;
203     Assoc_t assoc;
204     char suppressed;
205 };
206
207 /* global variables */
208
209 extern char dflag;
210 extern char gflag;
211 extern char lflag;
212 extern char rflag;
213 extern char tflag;
214 extern char vflag;
215 extern const char *symbol_prefix;
216
217 extern const char *myname;
218 extern char *cptr;
219 extern char *line;
220 extern int lineno;
221 extern int outline;
222 extern int exit_code;
223
224 extern const char *banner[];
225 extern const char *xdecls[];
226 extern const char *tables[];
227 extern const char *hdr_defs[];
228 extern const char *hdr_vars[];
229 extern const char *body_1[];
230 extern const char *body_vars[];
231 extern const char *body_2[];
232 extern const char *trailer[];
233
234 extern char *code_file_name;
235 extern char *defines_file_name;
236 extern char *input_file_name;
237 extern char *output_file_name;
238 extern char *verbose_file_name;
239 extern char *graph_file_name;
240
241 extern FILE *action_file;
242 extern FILE *code_file;
243 extern FILE *defines_file;
244 extern FILE *input_file;
245 extern FILE *output_file;
246 extern FILE *text_file;
247 extern FILE *union_file;
248 extern FILE *verbose_file;
249 extern FILE *graph_file;
250
251 extern int nitems;
252 extern int nrules;
253 extern int nsyms;
254 extern int ntokens;
255 extern int nvars;
256 extern int ntags;
257
258 extern char unionized;
259 extern char line_format[];
260
261 extern Value_t start_symbol;
262 extern char **symbol_name;
263 extern char **symbol_pname;
264 extern Value_t *symbol_value;
265 extern Value_t *symbol_prec;
266 extern char *symbol_assoc;
267
268 extern Value_t *ritem;
269 extern Value_t *rlhs;
270 extern Value_t *rrhs;
271 extern Value_t *rprec;
272 extern Assoc_t *rassoc;
273
274 extern Value_t **derives;
275 extern char *nullable;
276
277 extern bucket *first_symbol;
278 extern bucket *last_symbol;
279
280 extern int pure_parser;
281 extern int nstates;
282 extern core *first_state;
283 extern shifts *first_shift;
284 extern reductions *first_reduction;
285 extern Value_t *accessing_symbol;
286 extern core **state_table;
287 extern shifts **shift_table;
288 extern reductions **reduction_table;
289 extern unsigned *LA;
290 extern Value_t *LAruleno;
291 extern Value_t *lookaheads;
292 extern Value_t *goto_map;
293 extern Value_t *from_state;
294 extern Value_t *to_state;
295
296 extern action **parser;
297 extern int SRexpect;
298 extern int RRexpect;
299 extern int SRtotal;
300 extern int RRtotal;
301 extern Value_t *SRconflicts;
302 extern Value_t *RRconflicts;
303 extern Value_t *defred;
304 extern Value_t *rules_used;
305 extern Value_t nunused;
306 extern Value_t final_state;
307
308 extern Value_t *itemset;
309 extern Value_t *itemsetend;
310 extern unsigned *ruleset;
311
312 /* global functions */
313
314 extern bucket *lookup(const char *);
315 extern bucket *make_bucket(const char *);
316
317 #ifndef GCC_NORETURN
318 #define GCC_NORETURN            /* nothing */
319 #endif
320
321 #ifndef GCC_UNUSED
322 #define GCC_UNUSED              /* nothing */
323 #endif
324
325 /* closure.c */
326 extern void closure(Value_t *nucleus, int n);
327 extern void finalize_closure(void);
328 extern void set_first_derives(void);
329
330 /* error.c */
331 extern void default_action_warning(void);
332 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr);
333 extern void dollar_warning(int a_lineno, int i);
334 extern void fatal(const char *msg);
335 extern void illegal_character(char *c_cptr);
336 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr);
337 extern void no_grammar(void);
338 extern void no_space(void);
339 extern void open_error(const char *filename);
340 extern void over_unionized(char *u_cptr);
341 extern void prec_redeclared(void);
342 extern void print_pos(char *st_line, char *st_cptr);
343 extern void reprec_warning(char *s);
344 extern void restarted_warning(void);
345 extern void retyped_warning(char *s);
346 extern void revalued_warning(char *s);
347 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
348 extern void terminal_lhs(int s_lineno);
349 extern void terminal_start(char *s);
350 extern void tokenized_start(char *s);
351 extern void undefined_goal(char *s);
352 extern void undefined_symbol_warning(char *s);
353 extern void unexpected_EOF(void);
354 extern void unknown_rhs(int i);
355 extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr);
356 extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr);
357 extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr);
358 extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr);
359 extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr);
360 extern void untyped_lhs(void);
361 extern void untyped_rhs(int i, char *s);
362 extern void used_reserved(char *s);
363
364 /* graph.c */
365 extern void graph(void);
366
367 /* lalr.c */
368 extern int hash(const char *name);
369 extern void create_symbol_table(void);
370 extern void free_symbol_table(void);
371 extern void free_symbols(void);
372
373 /* lalr.c */
374 extern void lalr(void);
375
376 /* lr0.c */
377 extern void lr0(void);
378 extern void show_cores(void);
379 extern void show_ritems(void);
380 extern void show_rrhs(void);
381 extern void show_shifts(void);
382
383 /* main.c */
384 extern char *allocate(unsigned n);
385 extern void done(int k) GCC_NORETURN;
386
387 /* mkpar.c */
388 extern void free_parser(void);
389 extern void make_parser(void);
390
391 /* output.c */
392 extern void output(void);
393
394 /* reader.c */
395 extern void reader(void);
396
397 /* skeleton.c */
398 extern void write_section(const char *section[]);
399
400 /* verbose.c */
401 extern void verbose(void);
402
403 /* warshall.c */
404 extern void reflexive_transitive_closure(unsigned *R, int n);
405
406 #ifdef NO_LEAKS
407 extern void lr0_leaks(void);
408 extern void lalr_leaks(void);
409 extern void mkpar_leaks(void);
410 extern void output_leaks(void);
411 extern void reader_leaks(void);
412 #endif