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