xref: /illumos-gate/usr/src/cmd/sgs/yacc/common/dextern.h (revision caeaa75185132c7efab72ba0c9e7256bae1b9b95)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
28 
29 #ifndef _DEXTERN_H
30 #define	_DEXTERN_H
31 
32 #include <stdio.h>
33 #include <inttypes.h>
34 #include <ctype.h>
35 #include <memory.h>
36 #include <string.h>
37 #include <malloc.h>
38 #include <values.h>
39 #include <widec.h>
40 #include <unistd.h>
41 #include <stdlib.h>
42 #include <wctype.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 	/*  MANIFEST CONSTANT DEFINITIONS */
49 #if u3b || u3b15 || u3b2 || vax || uts || sparc
50 #define	WORD32
51 #endif
52 #include <libintl.h>
53 
54 	/* base of nonterminal internal numbers */
55 
56 #define	NTBASE (10000000)
57 
58 	/* internal codes for error and accept actions */
59 
60 #define	ERRCODE  8190
61 #define	ACCEPTCODE 8191
62 
63 	/* sizes and limits */
64 
65 #define	ACTSIZE 4000
66 #define	MEMSIZE 2000
67 #define	PSTSIZE 1024
68 #define	NSTATES 1000
69 #define	NTERMS 127
70 #define	NPROD 300
71 #define	NNONTERM 600
72 #define	TEMPSIZE 800
73 #define	CNAMSZ 1000
74 #define	LSETSIZE 950
75 #define	WSETSIZE 850
76 
77 #define	NAMESIZE 50
78 #define	NTYPES 1000
79 
80 #define	NMBCHARSZ 100
81 #define	LKFACTOR 5
82 
83 #ifdef WORD32
84 	/* bit packing macros (may be machine dependent) */
85 #define	BIT(a, i) ((a)[(i)>>5] & (1<<((i)&037)))
86 #define	SETBIT(a, i) ((a)[(i)>>5] |= (1<<((i)&037)))
87 
88 	/* number of words needed to hold n+1 bits */
89 #define	NWORDS(n) (((n)+32)/32)
90 
91 #else
92 
93 	/* bit packing macros (may be machine dependent) */
94 #define	BIT(a, i) ((a)[(i)>>4] & (1<<((i)&017)))
95 #define	SETBIT(a, i) ((a)[(i)>>4] |= (1<<((i)&017)))
96 
97 	/* number of words needed to hold n+1 bits */
98 #define	NWORDS(n) (((n)+16)/16)
99 #endif
100 
101 	/*
102 	 * relationships which must hold:
103 	 * TBITSET ints must hold NTERMS+1 bits...
104 	 * WSETSIZE >= NNONTERM
105 	 * LSETSIZE >= NNONTERM
106 	 * TEMPSIZE >= NTERMS + NNONTERMs + 1
107 	 * TEMPSIZE >= NSTATES
108 	 */
109 
110 	/* associativities */
111 
112 #define	NOASC 0  /* no assoc. */
113 #define	LASC 1  /* left assoc. */
114 #define	RASC 2  /* right assoc. */
115 #define	BASC 3  /* binary assoc. */
116 
117 	/* flags for state generation */
118 
119 #define	DONE 0
120 #define	MUSTDO 1
121 #define	MUSTLOOKAHEAD 2
122 
123 	/* flags for a rule having an action, and being reduced */
124 
125 #define	ACTFLAG 04
126 #define	REDFLAG 010
127 
128 	/* output parser flags */
129 #define	YYFLAG1 (-10000000)
130 
131 	/* macros for getting associativity and precedence levels */
132 
133 #define	ASSOC(i) ((i)&07)
134 #define	PLEVEL(i) (((i)>>4)&077)
135 #define	TYPE(i)  ((i>>10)&077)
136 
137 	/* macros for setting associativity and precedence levels */
138 
139 #define	SETASC(i, j) i |= j
140 #define	SETPLEV(i, j) i |= (j<<4)
141 #define	SETTYPE(i, j) i |= (j<<10)
142 
143 	/* looping macros */
144 
145 #define	TLOOP(i) for (i = 1; i <= ntokens; ++i)
146 #define	NTLOOP(i) for (i = 0; i <= nnonter; ++i)
147 #define	PLOOP(s, i) for (i = s; i < nprod; ++i)
148 #define	SLOOP(i) for (i = 0; i < nstate; ++i)
149 #define	WSBUMP(x) ++x
150 #define	WSLOOP(s, j) for (j = s; j < &wsets[cwp]; ++j)
151 #define	ITMLOOP(i, p, q) q = pstate[i+1]; for (p = pstate[i]; p < q; ++p)
152 #define	SETLOOP(i) for (i = 0; i < tbitset; ++i)
153 
154 	/* I/O descriptors */
155 
156 extern FILE *finput;		/* input file */
157 extern FILE *faction;		/* file for saving actions */
158 extern FILE *fdefine;		/* file for #defines */
159 extern FILE *ftable;		/* y.tab.c file */
160 extern FILE *ftemp;		/* tempfile to pass 2 */
161 extern FILE *fdebug;		/* tempfile for two debugging info arrays */
162 extern FILE *foutput;		/* y.output file */
163 
164 	/* structure declarations */
165 
166 typedef struct looksets {
167 	int *lset;
168 } LOOKSETS;
169 
170 typedef struct item {
171 	int *pitem;
172 	LOOKSETS *look;
173 } ITEM;
174 
175 typedef struct toksymb {
176 	wchar_t *name;
177 	int value;
178 } TOKSYMB;
179 
180 typedef struct mbclit {
181 	wchar_t character;
182 	int tvalue; /* token issued for the character */
183 } MBCLIT;
184 
185 typedef struct ntsymb {
186 	wchar_t *name;
187 	int tvalue;
188 } NTSYMB;
189 
190 typedef struct wset {
191 	int *pitem;
192 	int flag;
193 	LOOKSETS ws;
194 } WSET;
195 
196 	/* token information */
197 
198 extern int ntokens;	/* number of tokens */
199 extern TOKSYMB *tokset;
200 extern int ntoksz;
201 
202 	/*
203 	 * multibyte (c > 255) character literals are
204 	 * handled as though they were tokens except
205 	 * that it generates a separate mapping table.
206 	 */
207 extern int nmbchars;	/* number of mb literals */
208 extern MBCLIT *mbchars;
209 extern int nmbcharsz;
210 
211 	/* nonterminal information */
212 
213 extern int nnonter;	/* the number of nonterminals */
214 extern NTSYMB *nontrst;
215 extern int nnontersz;
216 
217 	/* grammar rule information */
218 
219 extern int nprod;	/* number of productions */
220 extern int **prdptr;	/* pointers to descriptions of productions */
221 extern int *levprd;	/* contains production levels to break conflicts */
222 extern wchar_t *had_act; /* set if reduction has associated action code */
223 
224 	/* state information */
225 
226 extern int nstate;		/* number of states */
227 extern ITEM **pstate;	/* pointers to the descriptions of the states */
228 extern int *tystate;	/* contains type information about the states */
229 extern int *defact;	/* the default action of the state */
230 
231 extern int size;
232 
233 	/* lookahead set information */
234 
235 extern int TBITSET;
236 extern LOOKSETS *lkst;
237 extern int nolook;  /* flag to turn off lookahead computations */
238 
239 	/* working set information */
240 
241 extern WSET *wsets;
242 
243 	/* storage for productions */
244 
245 extern int *mem0;
246 extern int *mem;
247 extern int *tracemem;
248 extern int new_memsize;
249 
250 	/* storage for action table */
251 
252 extern int *amem;
253 extern int *memp;		/* next free action table position */
254 extern int *indgo;		/* index to the stored goto table */
255 extern int new_actsize;
256 
257 	/* temporary vector, indexable by states, terms, or ntokens */
258 
259 extern int *temp1;
260 extern int lineno; /* current line number */
261 
262 	/* statistics collection variables */
263 
264 extern int zzgoent;
265 extern int zzgobest;
266 extern int zzacent;
267 extern int zzexcp;
268 extern int zzrrconf;
269 extern int zzsrconf;
270 
271 	/* define external functions */
272 
273 extern void setup(int, char *[]);
274 extern void closure(int);
275 extern void output(void);
276 extern void aryfil(int *, int, int);
277 extern void error(char *, ...);
278 extern void warning(int, char *, ...);
279 extern void putitem(int *, LOOKSETS *);
280 extern void go2out(void);
281 extern void hideprod(void);
282 extern void callopt(void);
283 extern void warray(wchar_t *, int *, int);
284 extern wchar_t *symnam(int);
285 extern wchar_t *writem(int *);
286 extern void exp_mem(int);
287 extern void exp_act(int **);
288 extern int apack(int *, int);
289 extern int state(int);
290 extern void fprintf3(FILE *, const char *, const wchar_t *, const char *, ...);
291 extern void error3(const char *, const wchar_t *, const char *, ...);
292 
293 extern wchar_t *wscpy(wchar_t *, const wchar_t *);
294 extern size_t wslen(const wchar_t *);
295 extern int wscmp(const wchar_t *, const wchar_t *);
296 
297 
298 	/* yaccpar location */
299 
300 extern char *parser;
301 
302 	/* default settings for a number of macros */
303 
304 	/* name of yacc tempfiles */
305 
306 #ifndef TEMPNAME
307 #define	TEMPNAME "yacc.tmp"
308 #endif
309 
310 #ifndef ACTNAME
311 #define	ACTNAME "yacc.acts"
312 #endif
313 
314 #ifndef DEBUGNAME
315 #define	DEBUGNAME "yacc.debug"
316 #endif
317 
318 	/* command to clobber tempfiles after use */
319 
320 #ifndef ZAPFILE
321 #define	ZAPFILE(x) (void)unlink(x)
322 #endif
323 
324 #ifndef PARSER
325 #define	PARSER "/usr/share/lib/ccs/yaccpar"
326 #endif
327 
328 #ifdef	__cplusplus
329 }
330 #endif
331 
332 #endif /* _DEXTERN_H */
333