]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.bin/yacc/defs.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.bin / yacc / defs.h
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Robert Paul Corbett.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 4. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *      @(#)defs.h      5.6 (Berkeley) 5/24/93
33  * $FreeBSD$
34  */
35
36 #include <assert.h>
37 #include <ctype.h>
38 #include <err.h>
39 #include <stdio.h>
40
41
42 /*  machine-dependent definitions                       */
43 /*  the following definitions are for the Tahoe         */
44 /*  they might have to be changed for other machines    */
45
46 /*  MAXTABLE is the maximum table size                  */
47 /*  BITS_PER_WORD is the number of bits in a C unsigned */
48 /*  WORDSIZE computes the number of words needed to     */
49 /*      store n bits                                    */
50 /*  BIT returns the value of the n-th bit starting      */
51 /*      from r (0-indexed)                              */
52 /*  SETBIT sets the n-th bit starting from r            */
53
54 #define MAXTABLE        32500
55 #define BITS_PER_WORD   32
56 #define WORDSIZE(n)     (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
57 #define BIT(r, n)       ((((r)[(n)>>5])>>((n)&31))&1)
58 #define SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
59
60
61 /*  character names  */
62
63 #define NUL             '\0'    /*  the null character  */
64 #define NEWLINE         '\n'    /*  line feed  */
65 #define SP              ' '     /*  space  */
66 #define BS              '\b'    /*  backspace  */
67 #define HT              '\t'    /*  horizontal tab  */
68 #define VT              '\013'  /*  vertical tab  */
69 #define CR              '\r'    /*  carriage return  */
70 #define FF              '\f'    /*  form feed  */
71 #define QUOTE           '\''    /*  single quote  */
72 #define DOUBLE_QUOTE    '\"'    /*  double quote  */
73 #define BACKSLASH       '\\'    /*  backslash  */
74
75
76 /* defines for constructing filenames */
77
78 #define CODE_SUFFIX     ".code.c"
79 #define DEFINES_SUFFIX  ".tab.h"
80 #define OUTPUT_SUFFIX   ".tab.c"
81 #define VERBOSE_SUFFIX  ".output"
82
83
84 /* keyword codes */
85
86 #define TOKEN 0
87 #define LEFT 1
88 #define RIGHT 2
89 #define NONASSOC 3
90 #define MARK 4
91 #define TEXT 5
92 #define TYPE 6
93 #define START 7
94 #define UNION 8
95 #define IDENT 9
96 #define EXPECT 10
97
98
99 /*  symbol classes  */
100
101 #define UNKNOWN 0
102 #define TERM 1
103 #define NONTERM 2
104
105
106 /*  the undefined value  */
107
108 #define UNDEFINED (-1)
109
110
111 /*  action codes  */
112
113 #define SHIFT 1
114 #define REDUCE 2
115
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
124 /*  symbol macros  */
125
126 #define ISTOKEN(s)      ((s) < start_symbol)
127 #define ISVAR(s)        ((s) >= start_symbol)
128
129
130 /*  storage allocation macros  */
131
132 #define NEW(t)          ((t*)allocate(sizeof(t)))
133 #define NEW2(n,t)       ((t*)allocate((n)*sizeof(t)))
134
135
136 /*  the structure of a symbol table entry  */
137
138 typedef struct bucket bucket;
139 struct bucket
140 {
141     struct bucket *link;
142     struct bucket *next;
143     char *name;
144     char *tag;
145     short value;
146     short index;
147     short prec;
148     char class;
149     char assoc;
150 };
151
152
153 /*  the structure of the LR(0) state machine  */
154
155 typedef struct core core;
156 struct core
157 {
158     struct core *next;
159     struct core *link;
160     short number;
161     short accessing_symbol;
162     short nitems;
163     short items[1];
164 };
165
166
167 /*  the structure used to record shifts  */
168
169 typedef struct shifts shifts;
170 struct shifts
171 {
172     struct shifts *next;
173     short number;
174     short nshifts;
175     short shift[1];
176 };
177
178
179 /*  the structure used to store reductions  */
180
181 typedef struct reductions reductions;
182 struct reductions
183 {
184     struct reductions *next;
185     short number;
186     short nreds;
187     short rules[1];
188 };
189
190
191 /*  the structure used to represent parser actions  */
192
193 typedef struct action action;
194 struct action
195 {
196     struct action *next;
197     short symbol;
198     short number;
199     short prec;
200     char action_code;
201     char assoc;
202     char suppressed;
203 };
204
205
206 /* global variables */
207
208 extern char dflag;
209 extern char lflag;
210 extern char rflag;
211 extern char tflag;
212 extern char vflag;
213 extern const char *symbol_prefix;
214
215 extern char *cptr;
216 extern char *line;
217 extern int lineno;
218 extern int outline;
219
220 extern const char *banner[];
221 extern const char *tables[];
222 extern const char *header[];
223 extern const char *body[];
224 extern const char *trailer[];
225
226 extern char *action_file_name;
227 extern char *code_file_name;
228 extern char *defines_file_name;
229 extern const char *input_file_name;
230 extern char *output_file_name;
231 extern char *text_file_name;
232 extern char *union_file_name;
233 extern char *verbose_file_name;
234
235 extern FILE *action_file;
236 extern FILE *code_file;
237 extern FILE *defines_file;
238 extern FILE *input_file;
239 extern FILE *output_file;
240 extern FILE *text_file;
241 extern FILE *union_file;
242 extern FILE *verbose_file;
243
244 extern int nitems;
245 extern int nrules;
246 extern int nsyms;
247 extern int ntokens;
248 extern int nvars;
249 extern int ntags;
250
251 extern char unionized;
252
253 extern int   start_symbol;
254 extern char  **symbol_name;
255 extern short *symbol_value;
256 extern short *symbol_prec;
257 extern char  *symbol_assoc;
258
259 extern short *ritem;
260 extern short *rlhs;
261 extern short *rrhs;
262 extern short *rprec;
263 extern char  *rassoc;
264
265 extern short **derives;
266 extern char *nullable;
267
268 extern bucket *first_symbol;
269 extern bucket *last_symbol;
270
271 extern int nstates;
272 extern core *first_state;
273 extern shifts *first_shift;
274 extern reductions *first_reduction;
275 extern short *accessing_symbol;
276 extern core **state_table;
277 extern shifts **shift_table;
278 extern reductions **reduction_table;
279 extern unsigned *LA;
280 extern short *LAruleno;
281 extern short *lookaheads;
282 extern short *goto_map;
283 extern short *from_state;
284 extern short *to_state;
285
286 extern action **parser;
287 extern int SRexpect;
288 extern int SRtotal;
289 extern int RRtotal;
290 extern short *SRconflicts;
291 extern short *RRconflicts;
292 extern short *defred;
293 extern short *rules_used;
294 extern short nunused;
295 extern short final_state;
296
297 /* global functions */
298
299 void *allocate(size_t);
300 void closure(short *, int);
301 void create_symbol_table(void);
302 void default_action_warning(void);
303 void dollar_error(int, char *, char *) __dead2;
304 void dollar_warning(int, int);
305 void done(int) __dead2;
306 void fatal(const char *msg) __dead2;
307 void finalize_closure(void);
308 void free_parser(void);
309 void free_symbols(void);
310 void free_symbol_table(void);
311 void illegal_character(char *) __dead2;
312 void illegal_tag(int, char *, char *) __dead2;
313 void lalr(void);
314 bucket *lookup(char *);
315 void lr0(void);
316 bucket *make_bucket(const char *);
317 void make_parser(void);
318 void no_grammar(void) __dead2;
319 void no_space(void) __dead2;
320 void open_error(const char *) __dead2;
321 void output(void);
322 void over_unionized(char *) __dead2;
323 void prec_redeclared(void);
324 void reader(void);
325 void reflexive_transitive_closure(unsigned *, int);
326 void reprec_warning(char *);
327 void restarted_warning(void);
328 void retyped_warning(char *);
329 void revalued_warning(char *);
330 void set_first_derives(void);
331 void syntax_error(int, char *, char *) __dead2;
332 void terminal_lhs(int) __dead2;
333 void terminal_start(char *) __dead2;
334 void tokenized_start(char *) __dead2;
335 void undefined_goal(char *) __dead2;
336 void undefined_symbol_warning(char *);
337 void unexpected_EOF(void) __dead2;
338 void unknown_rhs(int) __dead2;
339 void unterminated_action(int, char *, char *) __dead2;
340 void unterminated_comment(int, char *, char *) __dead2;
341 void unterminated_string(int, char *, char *) __dead2;
342 void unterminated_text(int, char *, char *) __dead2;
343 void unterminated_union(int, char *, char *) __dead2;
344 void untyped_lhs(void) __dead2;
345 void untyped_rhs(int, char *) __dead2;
346 void used_reserved(char *) __dead2;
347 void verbose(void);
348 void write_section(const char **);