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