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