Annotation of src/usr.bin/yacc/defs.h, Revision 1.1.1.1
1.1 deraadt 1: /* $Id: defs.h,v 1.4 1994/12/24 16:57:28 cgd Exp $ */
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
69:
70:
71: /* symbol classes */
72:
73: #define UNKNOWN 0
74: #define TERM 1
75: #define NONTERM 2
76:
77:
78: /* the undefined value */
79:
80: #define UNDEFINED (-1)
81:
82:
83: /* action codes */
84:
85: #define SHIFT 1
86: #define REDUCE 2
87:
88:
89: /* character macros */
90:
91: #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
92: #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
93: #define NUMERIC_VALUE(c) ((c) - '0')
94:
95:
96: /* symbol macros */
97:
98: #define ISTOKEN(s) ((s) < start_symbol)
99: #define ISVAR(s) ((s) >= start_symbol)
100:
101:
102: /* storage allocation macros */
103:
104: #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
105: #define FREE(x) (free((char*)(x)))
106: #define MALLOC(n) (malloc((unsigned)(n)))
107: #define NEW(t) ((t*)allocate(sizeof(t)))
108: #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
109: #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
110:
111:
112: /* the structure of a symbol table entry */
113:
114: typedef struct bucket bucket;
115: struct bucket
116: {
117: struct bucket *link;
118: struct bucket *next;
119: char *name;
120: char *tag;
121: short value;
122: short index;
123: short prec;
124: char class;
125: char assoc;
126: };
127:
128:
129: /* the structure of the LR(0) state machine */
130:
131: typedef struct core core;
132: struct core
133: {
134: struct core *next;
135: struct core *link;
136: short number;
137: short accessing_symbol;
138: short nitems;
139: short items[1];
140: };
141:
142:
143: /* the structure used to record shifts */
144:
145: typedef struct shifts shifts;
146: struct shifts
147: {
148: struct shifts *next;
149: short number;
150: short nshifts;
151: short shift[1];
152: };
153:
154:
155: /* the structure used to store reductions */
156:
157: typedef struct reductions reductions;
158: struct reductions
159: {
160: struct reductions *next;
161: short number;
162: short nreds;
163: short rules[1];
164: };
165:
166:
167: /* the structure used to represent parser actions */
168:
169: typedef struct action action;
170: struct action
171: {
172: struct action *next;
173: short symbol;
174: short number;
175: short prec;
176: char action_code;
177: char assoc;
178: char suppressed;
179: };
180:
181:
182: /* global variables */
183:
184: extern char dflag;
185: extern char lflag;
186: extern char rflag;
187: extern char tflag;
188: extern char vflag;
189: extern char *symbol_prefix;
190:
191: extern char *myname;
192: extern char *cptr;
193: extern char *line;
194: extern int lineno;
195: extern int outline;
196:
197: extern char *banner[];
198: extern char *tables[];
199: extern char *header[];
200: extern char *body[];
201: extern char *trailer[];
202:
203: extern char *action_file_name;
204: extern char *code_file_name;
205: extern char *defines_file_name;
206: extern char *input_file_name;
207: extern char *output_file_name;
208: extern char *text_file_name;
209: extern char *union_file_name;
210: extern char *verbose_file_name;
211:
212: extern FILE *action_file;
213: extern FILE *code_file;
214: extern FILE *defines_file;
215: extern FILE *input_file;
216: extern FILE *output_file;
217: extern FILE *text_file;
218: extern FILE *union_file;
219: extern FILE *verbose_file;
220:
221: extern int nitems;
222: extern int nrules;
223: extern int nsyms;
224: extern int ntokens;
225: extern int nvars;
226: extern int ntags;
227:
228: extern char unionized;
229: extern char line_format[];
230:
231: extern int start_symbol;
232: extern char **symbol_name;
233: extern short *symbol_value;
234: extern short *symbol_prec;
235: extern char *symbol_assoc;
236:
237: extern short *ritem;
238: extern short *rlhs;
239: extern short *rrhs;
240: extern short *rprec;
241: extern char *rassoc;
242:
243: extern short **derives;
244: extern char *nullable;
245:
246: extern bucket *first_symbol;
247: extern bucket *last_symbol;
248:
249: extern int nstates;
250: extern core *first_state;
251: extern shifts *first_shift;
252: extern reductions *first_reduction;
253: extern short *accessing_symbol;
254: extern core **state_table;
255: extern shifts **shift_table;
256: extern reductions **reduction_table;
257: extern unsigned *LA;
258: extern short *LAruleno;
259: extern short *lookaheads;
260: extern short *goto_map;
261: extern short *from_state;
262: extern short *to_state;
263:
264: extern action **parser;
265: extern int SRtotal;
266: extern int RRtotal;
267: extern short *SRconflicts;
268: extern short *RRconflicts;
269: extern short *defred;
270: extern short *rules_used;
271: extern short nunused;
272: extern short final_state;
273:
274: /* global functions */
275:
276: extern char *allocate();
277: extern bucket *lookup();
278: extern bucket *make_bucket();
279:
280:
281: /* system variables */
282:
283: extern int errno;
284:
285:
286: /* system functions */
287:
288: extern void free();
289: extern char *calloc();
290: extern char *malloc();
291: extern char *realloc();
292: extern char *strcpy();