source: trunk/minix/commands/byacc/defs.h@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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