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