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