summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/yacc/common/dextern.h
blob: dfabe6574897e602ae9a44346eb8c0e180964550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */

#ifndef _DEXTERN_H
#define	_DEXTERN_H

#include <stdio.h>
#include <inttypes.h>
#include <ctype.h>
#include <memory.h>
#include <string.h>
#include <malloc.h>
#include <values.h>
#include <widec.h>
#include <unistd.h>
#include <stdlib.h>
#include <wctype.h>

#ifdef	__cplusplus
extern "C" {
#endif

	/*  MANIFEST CONSTANT DEFINITIONS */
#if u3b || u3b15 || u3b2 || vax || uts || sparc
#define	WORD32
#endif
#include <libintl.h>

	/* base of nonterminal internal numbers */

#define	NTBASE (10000000)

	/* internal codes for error and accept actions */

#define	ERRCODE  8190
#define	ACCEPTCODE 8191

	/* sizes and limits */

#define	ACTSIZE 4000
#define	MEMSIZE 2000
#define	PSTSIZE 1024
#define	NSTATES 1000
#define	NTERMS 127
#define	NPROD 300
#define	NNONTERM 600
#define	TEMPSIZE 800
#define	CNAMSZ 1000
#define	LSETSIZE 950
#define	WSETSIZE 850

#define	NAMESIZE 50
#define	NTYPES 1000

#define	NMBCHARSZ 100
#define	LKFACTOR 5

#ifdef WORD32
	/* bit packing macros (may be machine dependent) */
#define	BIT(a, i) ((a)[(i)>>5] & (1<<((i)&037)))
#define	SETBIT(a, i) ((a)[(i)>>5] |= (1<<((i)&037)))

	/* number of words needed to hold n+1 bits */
#define	NWORDS(n) (((n)+32)/32)

#else

	/* bit packing macros (may be machine dependent) */
#define	BIT(a, i) ((a)[(i)>>4] & (1<<((i)&017)))
#define	SETBIT(a, i) ((a)[(i)>>4] |= (1<<((i)&017)))

	/* number of words needed to hold n+1 bits */
#define	NWORDS(n) (((n)+16)/16)
#endif

	/*
	 * relationships which must hold:
	 * TBITSET ints must hold NTERMS+1 bits...
	 * WSETSIZE >= NNONTERM
	 * LSETSIZE >= NNONTERM
	 * TEMPSIZE >= NTERMS + NNONTERMs + 1
	 * TEMPSIZE >= NSTATES
	 */

	/* associativities */

#define	NOASC 0  /* no assoc. */
#define	LASC 1  /* left assoc. */
#define	RASC 2  /* right assoc. */
#define	BASC 3  /* binary assoc. */

	/* flags for state generation */

#define	DONE 0
#define	MUSTDO 1
#define	MUSTLOOKAHEAD 2

	/* flags for a rule having an action, and being reduced */

#define	ACTFLAG 04
#define	REDFLAG 010

	/* output parser flags */
#define	YYFLAG1 (-10000000)

	/* macros for getting associativity and precedence levels */

#define	ASSOC(i) ((i)&07)
#define	PLEVEL(i) (((i)>>4)&077)
#define	TYPE(i)  ((i>>10)&077)

	/* macros for setting associativity and precedence levels */

#define	SETASC(i, j) i |= j
#define	SETPLEV(i, j) i |= (j<<4)
#define	SETTYPE(i, j) i |= (j<<10)

	/* looping macros */

#define	TLOOP(i) for (i = 1; i <= ntokens; ++i)
#define	NTLOOP(i) for (i = 0; i <= nnonter; ++i)
#define	PLOOP(s, i) for (i = s; i < nprod; ++i)
#define	SLOOP(i) for (i = 0; i < nstate; ++i)
#define	WSBUMP(x) ++x
#define	WSLOOP(s, j) for (j = s; j < &wsets[cwp]; ++j)
#define	ITMLOOP(i, p, q) q = pstate[i+1]; for (p = pstate[i]; p < q; ++p)
#define	SETLOOP(i) for (i = 0; i < tbitset; ++i)

	/* I/O descriptors */

extern FILE *finput;		/* input file */
extern FILE *faction;		/* file for saving actions */
extern FILE *fdefine;		/* file for #defines */
extern FILE *ftable;		/* y.tab.c file */
extern FILE *ftemp;		/* tempfile to pass 2 */
extern FILE *fdebug;		/* tempfile for two debugging info arrays */
extern FILE *foutput;		/* y.output file */

	/* structure declarations */

typedef struct looksets {
	int *lset;
} LOOKSETS;

typedef struct item {
	int *pitem;
	LOOKSETS *look;
} ITEM;

typedef struct toksymb {
	wchar_t *name;
	int value;
} TOKSYMB;

typedef struct mbclit {
	wchar_t character;
	int tvalue; /* token issued for the character */
} MBCLIT;

typedef struct ntsymb {
	wchar_t *name;
	int tvalue;
} NTSYMB;

typedef struct wset {
	int *pitem;
	int flag;
	LOOKSETS ws;
} WSET;

	/* token information */

extern int ntokens;	/* number of tokens */
extern TOKSYMB *tokset;
extern int ntoksz;

	/*
	 * multibyte (c > 255) character literals are
	 * handled as though they were tokens except
	 * that it generates a separate mapping table.
	 */
extern int nmbchars;	/* number of mb literals */
extern MBCLIT *mbchars;
extern int nmbcharsz;

	/* nonterminal information */

extern int nnonter;	/* the number of nonterminals */
extern NTSYMB *nontrst;
extern int nnontersz;

	/* grammar rule information */

extern int nprod;	/* number of productions */
extern int **prdptr;	/* pointers to descriptions of productions */
extern int *levprd;	/* contains production levels to break conflicts */
extern wchar_t *had_act; /* set if reduction has associated action code */

	/* state information */

extern int nstate;		/* number of states */
extern ITEM **pstate;	/* pointers to the descriptions of the states */
extern int *tystate;	/* contains type information about the states */
extern int *defact;	/* the default action of the state */

extern int size;

	/* lookahead set information */

extern int TBITSET;
extern LOOKSETS *lkst;
extern int nolook;  /* flag to turn off lookahead computations */

	/* working set information */

extern WSET *wsets;

	/* storage for productions */

extern int *mem0;
extern int *mem;
extern int *tracemem;
extern int new_memsize;

	/* storage for action table */

extern int *amem;
extern int *memp;		/* next free action table position */
extern int *indgo;		/* index to the stored goto table */
extern int new_actsize;

	/* temporary vector, indexable by states, terms, or ntokens */

extern int *temp1;
extern int lineno; /* current line number */

	/* statistics collection variables */

extern int zzgoent;
extern int zzgobest;
extern int zzacent;
extern int zzexcp;
extern int zzrrconf;
extern int zzsrconf;

	/* define external functions */

extern void setup(int, char *[]);
extern void closure(int);
extern void output(void);
extern void aryfil(int *, int, int);
extern void error(char *, ...);
extern void warning(int, char *, ...);
extern void putitem(int *, LOOKSETS *);
extern void go2out(void);
extern void hideprod(void);
extern void callopt(void);
extern void warray(wchar_t *, int *, int);
extern wchar_t *symnam(int);
extern wchar_t *writem(int *);
extern void exp_mem(int);
extern void exp_act(int **);
extern int apack(int *, int);
extern int state(int);
extern void fprintf3(FILE *, const char *, const wchar_t *, const char *, ...);
extern void error3(const char *, const wchar_t *, const char *, ...);

extern wchar_t *wscpy(wchar_t *, const wchar_t *);
extern size_t wslen(const wchar_t *);
extern int wscmp(const wchar_t *, const wchar_t *);


	/* yaccpar location */

extern char *parser;

	/* default settings for a number of macros */

	/* name of yacc tempfiles */

#ifndef TEMPNAME
#define	TEMPNAME "yacc.tmp"
#endif

#ifndef ACTNAME
#define	ACTNAME "yacc.acts"
#endif

#ifndef DEBUGNAME
#define	DEBUGNAME "yacc.debug"
#endif

	/* command to clobber tempfiles after use */

#ifndef ZAPFILE
#define	ZAPFILE(x) (void)unlink(x)
#endif

#ifndef PARSER
#define	PARSER "/usr/share/lib/ccs/yaccpar"
#endif

/*
 * Lint is unable to properly handle formats with wide strings
 * (e.g. %ws) and misdiagnoses them as being malformed.
 * This macro is used to work around that, by substituting
 * a pointer to a null string when compiled by lint. This
 * trick works because lint is not able to evaluate the
 * variable.
 *
 * When lint is able to handle %ws, it would be appropriate
 * to come back through and remove the use of this macro.
 */
#if defined(__lint)
static const char *lint_ws_fmt = "";
#define	WSFMT(_fmt) lint_ws_fmt
#else
#define	WSFMT(_fmt) _fmt
#endif

#ifdef	__cplusplus
}
#endif

#endif /* _DEXTERN_H */