tag rc1
[mcs.git] / jay / defs.h
blobf3679864735109a25ade32aab48d6574282fe9f6
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
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.
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.
36 * @(#)defs.h 5.6 (Berkeley) 5/24/93
39 #include <assert.h>
40 #include <ctype.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <errno.h>
47 /* machine-dependent definitions */
48 /* the following definitions are for the Tahoe */
49 /* they might have to be changed for other machines */
51 /* MAXCHAR is the largest unsigned character value */
52 /* MAXSHORT is the largest value of a C short */
53 /* MINSHORT is the most negative value of a C short */
54 /* MAXTABLE is the maximum table size */
55 /* BITS_PER_WORD is the number of bits in a C unsigned */
56 /* WORDSIZE computes the number of words needed to */
57 /* store n bits */
58 /* BIT returns the value of the n-th bit starting */
59 /* from r (0-indexed) */
60 /* SETBIT sets the n-th bit starting from r */
62 #define MAXCHAR 255
63 #define MAXSHORT 32767
64 #define MINSHORT -32768
65 #define MAXTABLE 32500
66 #define BITS_PER_WORD 32
67 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
68 #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
69 #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
72 /* character names */
74 #define NUL '\0' /* the null character */
75 #define NEWLINE '\n' /* line feed */
76 #define SP ' ' /* space */
77 #define BS '\b' /* backspace */
78 #define HT '\t' /* horizontal tab */
79 #define VT '\013' /* vertical tab */
80 #define CR '\r' /* carriage return */
81 #define FF '\f' /* form feed */
82 #define QUOTE '\'' /* single quote */
83 #define DOUBLE_QUOTE '\"' /* double quote */
84 #define BACKSLASH '\\' /* backslash */
87 /* defines for constructing filenames */
89 #define CODE_SUFFIX ".code.c"
90 #define DEFINES_SUFFIX ".tab.h"
91 #define OUTPUT_SUFFIX ".tab.c"
92 #define VERBOSE_SUFFIX ".output"
95 /* keyword codes */
97 #define TOKEN 0
98 #define LEFT 1
99 #define RIGHT 2
100 #define NONASSOC 3
101 #define MARK 4
102 #define TEXT 5
103 #define TYPE 6
104 #define START 7
107 /* symbol classes */
109 #define UNKNOWN 0
110 #define TERM 1
111 #define NONTERM 2
114 /* the undefined value */
116 #define UNDEFINED (-1)
119 /* action codes */
121 #define SHIFT 1
122 #define REDUCE 2
125 /* character macros */
127 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
128 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
129 #define NUMERIC_VALUE(c) ((c) - '0')
132 /* symbol macros */
134 #define ISTOKEN(s) ((s) < start_symbol)
135 #define ISVAR(s) ((s) >= start_symbol)
138 /* storage allocation macros */
140 #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
141 #define FREE(x) (free((char*)(x)))
142 #define MALLOC(n) (malloc((unsigned)(n)))
143 #define NEW(t) ((t*)allocate(sizeof(t)))
144 #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
145 #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
148 /* the structure of a symbol table entry */
150 typedef struct bucket bucket;
151 struct bucket
153 struct bucket *link;
154 struct bucket *next;
155 char *name;
156 char *tag;
157 short value;
158 short index;
159 short prec;
160 char class;
161 char assoc;
165 /* the structure of the LR(0) state machine */
167 typedef struct core core;
168 struct core
170 struct core *next;
171 struct core *link;
172 short number;
173 short accessing_symbol;
174 short nitems;
175 short items[1];
179 /* the structure used to record shifts */
181 typedef struct shifts shifts;
182 struct shifts
184 struct shifts *next;
185 short number;
186 short nshifts;
187 short shift[1];
191 /* the structure used to store reductions */
193 typedef struct reductions reductions;
194 struct reductions
196 struct reductions *next;
197 short number;
198 short nreds;
199 short rules[1];
203 /* the structure used to represent parser actions */
205 typedef struct action action;
206 struct action
208 struct action *next;
209 short symbol;
210 short number;
211 short prec;
212 char action_code;
213 char assoc;
214 char suppressed;
218 /* global variables */
220 extern char tflag;
221 extern char vflag;
223 extern char *myname;
224 extern char *cptr;
225 extern char *line;
226 extern int lineno;
227 extern int outline;
229 extern char *action_file_name;
230 extern char *input_file_name;
231 extern char *prolog_file_name;
232 extern char *local_file_name;
233 extern char *verbose_file_name;
235 extern FILE *action_file;
236 extern FILE *input_file;
237 extern FILE *prolog_file;
238 extern FILE *local_file;
239 extern FILE *verbose_file;
241 extern int nitems;
242 extern int nrules;
243 extern int nsyms;
244 extern int ntokens;
245 extern int nvars;
246 extern int ntags;
248 extern char *line_format;
249 extern char *default_line_format;
251 extern int start_symbol;
252 extern char **symbol_name;
253 extern short *symbol_value;
254 extern short *symbol_prec;
255 extern char *symbol_assoc;
257 extern short *ritem;
258 extern short *rlhs;
259 extern short *rrhs;
260 extern short *rprec;
261 extern char *rassoc;
263 extern short **derives;
264 extern char *nullable;
266 extern bucket *first_symbol;
267 extern bucket *last_symbol;
269 extern int nstates;
270 extern core *first_state;
271 extern shifts *first_shift;
272 extern reductions *first_reduction;
273 extern short *accessing_symbol;
274 extern core **state_table;
275 extern shifts **shift_table;
276 extern reductions **reduction_table;
277 extern unsigned *LA;
278 extern short *LAruleno;
279 extern short *lookaheads;
280 extern short *goto_map;
281 extern short *from_state;
282 extern short *to_state;
284 extern action **parser;
285 extern int SRtotal;
286 extern int RRtotal;
287 extern short *SRconflicts;
288 extern short *RRconflicts;
289 extern short *defred;
290 extern short *rules_used;
291 extern short nunused;
292 extern short final_state;
294 /* global functions */
296 extern char *allocate();
297 extern bucket *lookup();
298 extern bucket *make_bucket();