Annotation of src/usr.bin/yacc/defs.h, Revision 1.2
1.2 ! etheisen 1: /* $Id: defs.h,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $ */
1.1 deraadt 2:
3: #include <assert.h>
4: #include <ctype.h>
5: #include <stdio.h>
6: #include <string.h>
7:
8:
9: /* machine-dependent definitions */
10: /* the following definitions are for the Tahoe */
11: /* they might have to be changed for other machines */
12:
13: /* MAXCHAR is the largest unsigned character value */
14: /* MAXSHORT is the largest value of a C short */
15: /* MINSHORT is the most negative value of a C short */
16: /* MAXTABLE is the maximum table size */
17: /* BITS_PER_WORD is the number of bits in a C unsigned */
18: /* WORDSIZE computes the number of words needed to */
19: /* store n bits */
20: /* BIT returns the value of the n-th bit starting */
21: /* from r (0-indexed) */
22: /* SETBIT sets the n-th bit starting from r */
23:
24: #define MAXCHAR 255
25: #define MAXSHORT 32767
26: #define MINSHORT -32768
27: #define MAXTABLE 32500
28: #define BITS_PER_WORD 32
29: #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
30: #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
31: #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
32:
33:
34: /* character names */
35:
36: #define NUL '\0' /* the null character */
37: #define NEWLINE '\n' /* line feed */
38: #define SP ' ' /* space */
39: #define BS '\b' /* backspace */
40: #define HT '\t' /* horizontal tab */
41: #define VT '\013' /* vertical tab */
42: #define CR '\r' /* carriage return */
43: #define FF '\f' /* form feed */
44: #define QUOTE '\'' /* single quote */
45: #define DOUBLE_QUOTE '\"' /* double quote */
46: #define BACKSLASH '\\' /* backslash */
47:
48:
49: /* defines for constructing filenames */
50:
51: #define CODE_SUFFIX ".code.c"
52: #define DEFINES_SUFFIX ".tab.h"
53: #define OUTPUT_SUFFIX ".tab.c"
54: #define VERBOSE_SUFFIX ".output"
55:
56:
57: /* keyword codes */
58:
59: #define TOKEN 0
60: #define LEFT 1
61: #define RIGHT 2
62: #define NONASSOC 3
63: #define MARK 4
64: #define TEXT 5
65: #define TYPE 6
66: #define START 7
67: #define UNION 8
68: #define IDENT 9
1.2 ! etheisen 69: #define EXPECT 10
1.1 deraadt 70:
71:
72: /* symbol classes */
73:
74: #define UNKNOWN 0
75: #define TERM 1
76: #define NONTERM 2
77:
78:
79: /* the undefined value */
80:
81: #define UNDEFINED (-1)
82:
83:
84: /* action codes */
85:
86: #define SHIFT 1
87: #define REDUCE 2
88:
89:
90: /* character macros */
91:
92: #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
93: #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
94: #define NUMERIC_VALUE(c) ((c) - '0')
95:
96:
97: /* symbol macros */
98:
99: #define ISTOKEN(s) ((s) < start_symbol)
100: #define ISVAR(s) ((s) >= start_symbol)
101:
102:
103: /* storage allocation macros */
104:
105: #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
106: #define FREE(x) (free((char*)(x)))
107: #define MALLOC(n) (malloc((unsigned)(n)))
108: #define NEW(t) ((t*)allocate(sizeof(t)))
109: #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
110: #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
111:
112:
113: /* the structure of a symbol table entry */
114:
115: typedef struct bucket bucket;
116: struct bucket
117: {
118: struct bucket *link;
119: struct bucket *next;
120: char *name;
121: char *tag;
122: short value;
123: short index;
124: short prec;
125: char class;
126: char assoc;
127: };
128:
129:
130: /* the structure of the LR(0) state machine */
131:
132: typedef struct core core;
133: struct core
134: {
135: struct core *next;
136: struct core *link;
137: short number;
138: short accessing_symbol;
139: short nitems;
140: short items[1];
141: };
142:
143:
144: /* the structure used to record shifts */
145:
146: typedef struct shifts shifts;
147: struct shifts
148: {
149: struct shifts *next;
150: short number;
151: short nshifts;
152: short shift[1];
153: };
154:
155:
156: /* the structure used to store reductions */
157:
158: typedef struct reductions reductions;
159: struct reductions
160: {
161: struct reductions *next;
162: short number;
163: short nreds;
164: short rules[1];
165: };
166:
167:
168: /* the structure used to represent parser actions */
169:
170: typedef struct action action;
171: struct action
172: {
173: struct action *next;
174: short symbol;
175: short number;
176: short prec;
177: char action_code;
178: char assoc;
179: char suppressed;
180: };
181:
182:
183: /* global variables */
184:
185: extern char dflag;
186: extern char lflag;
187: extern char rflag;
188: extern char tflag;
189: extern char vflag;
190: extern char *symbol_prefix;
191:
192: extern char *myname;
193: extern char *cptr;
194: extern char *line;
195: extern int lineno;
196: extern int outline;
197:
198: extern char *banner[];
199: extern char *tables[];
200: extern char *header[];
201: extern char *body[];
202: extern char *trailer[];
203:
204: extern char *action_file_name;
205: extern char *code_file_name;
206: extern char *defines_file_name;
207: extern char *input_file_name;
208: extern char *output_file_name;
209: extern char *text_file_name;
210: extern char *union_file_name;
211: extern char *verbose_file_name;
212:
213: extern FILE *action_file;
214: extern FILE *code_file;
215: extern FILE *defines_file;
216: extern FILE *input_file;
217: extern FILE *output_file;
218: extern FILE *text_file;
219: extern FILE *union_file;
220: extern FILE *verbose_file;
221:
222: extern int nitems;
223: extern int nrules;
224: extern int nsyms;
225: extern int ntokens;
226: extern int nvars;
227: extern int ntags;
228:
229: extern char unionized;
230: extern char line_format[];
231:
232: extern int start_symbol;
233: extern char **symbol_name;
234: extern short *symbol_value;
235: extern short *symbol_prec;
236: extern char *symbol_assoc;
237:
238: extern short *ritem;
239: extern short *rlhs;
240: extern short *rrhs;
241: extern short *rprec;
242: extern char *rassoc;
243:
244: extern short **derives;
245: extern char *nullable;
246:
247: extern bucket *first_symbol;
248: extern bucket *last_symbol;
249:
250: extern int nstates;
251: extern core *first_state;
252: extern shifts *first_shift;
253: extern reductions *first_reduction;
254: extern short *accessing_symbol;
255: extern core **state_table;
256: extern shifts **shift_table;
257: extern reductions **reduction_table;
258: extern unsigned *LA;
259: extern short *LAruleno;
260: extern short *lookaheads;
261: extern short *goto_map;
262: extern short *from_state;
263: extern short *to_state;
264:
265: extern action **parser;
266: extern int SRtotal;
1.2 ! etheisen 267: extern int SRexpect;
1.1 deraadt 268: extern int RRtotal;
269: extern short *SRconflicts;
270: extern short *RRconflicts;
271: extern short *defred;
272: extern short *rules_used;
273: extern short nunused;
274: extern short final_state;
275:
276: /* global functions */
277:
278: extern char *allocate();
279: extern bucket *lookup();
280: extern bucket *make_bucket();
281:
282:
283: /* system variables */
284:
285: extern int errno;
286:
287:
288: /* system functions */
289:
290: extern void free();
291: extern char *calloc();
292: extern char *malloc();
293: extern char *realloc();
294: extern char *strcpy();