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