xref: /illumos-gate/usr/src/cmd/sgs/yacc/common/y2.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include "dextern"
33*7c478bd9Sstevel@tonic-gate #include "sgs.h"
34*7c478bd9Sstevel@tonic-gate #define	IDENTIFIER 257
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #define	MARK 258
37*7c478bd9Sstevel@tonic-gate #define	TERM 259
38*7c478bd9Sstevel@tonic-gate #define	LEFT 260
39*7c478bd9Sstevel@tonic-gate #define	RIGHT 261
40*7c478bd9Sstevel@tonic-gate #define	BINARY 262
41*7c478bd9Sstevel@tonic-gate #define	PREC 263
42*7c478bd9Sstevel@tonic-gate #define	LCURLY 264
43*7c478bd9Sstevel@tonic-gate #define	C_IDENTIFIER 265  /* name followed by colon */
44*7c478bd9Sstevel@tonic-gate #define	NUMBER 266
45*7c478bd9Sstevel@tonic-gate #define	START 267
46*7c478bd9Sstevel@tonic-gate #define	TYPEDEF 268
47*7c478bd9Sstevel@tonic-gate #define	TYPENAME 269
48*7c478bd9Sstevel@tonic-gate #define	UNION 270
49*7c478bd9Sstevel@tonic-gate #define	ENDFILE 0
50*7c478bd9Sstevel@tonic-gate #define	LHS_TEXT_LEN		80	/* length of lhstext */
51*7c478bd9Sstevel@tonic-gate #define	RHS_TEXT_LEN		640	/* length of rhstext */
52*7c478bd9Sstevel@tonic-gate 	/* communication variables between various I/O routines */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #define	v_FLAG	0x01
55*7c478bd9Sstevel@tonic-gate #define	d_FLAG	0x02
56*7c478bd9Sstevel@tonic-gate #define	DEFAULT_PREFIX	"y"
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate char *infile;				/* input file name 		*/
59*7c478bd9Sstevel@tonic-gate static int numbval;			/* value of an input number 	*/
60*7c478bd9Sstevel@tonic-gate static int toksize = NAMESIZE;
61*7c478bd9Sstevel@tonic-gate static wchar_t *tokname;	/* input token name		*/
62*7c478bd9Sstevel@tonic-gate char *parser = NULL;		/* location of common parser 	*/
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate static void finact(void);
65*7c478bd9Sstevel@tonic-gate static wchar_t *cstash(wchar_t *);
66*7c478bd9Sstevel@tonic-gate static void defout(void);
67*7c478bd9Sstevel@tonic-gate static void cpyunion(void);
68*7c478bd9Sstevel@tonic-gate static void cpycode(void);
69*7c478bd9Sstevel@tonic-gate static void cpyact(int);
70*7c478bd9Sstevel@tonic-gate static void lhsfill(wchar_t *);
71*7c478bd9Sstevel@tonic-gate static void rhsfill(wchar_t *);
72*7c478bd9Sstevel@tonic-gate static void lrprnt(void);
73*7c478bd9Sstevel@tonic-gate static void beg_debug(void);
74*7c478bd9Sstevel@tonic-gate static void end_toks(void);
75*7c478bd9Sstevel@tonic-gate static void end_debug(void);
76*7c478bd9Sstevel@tonic-gate static void exp_tokname(void);
77*7c478bd9Sstevel@tonic-gate static void exp_prod(void);
78*7c478bd9Sstevel@tonic-gate static void exp_ntok(void);
79*7c478bd9Sstevel@tonic-gate static void exp_nonterm(void);
80*7c478bd9Sstevel@tonic-gate static int defin(int, wchar_t *);
81*7c478bd9Sstevel@tonic-gate static int gettok(void);
82*7c478bd9Sstevel@tonic-gate static int chfind(int, wchar_t *);
83*7c478bd9Sstevel@tonic-gate static int skipcom(void);
84*7c478bd9Sstevel@tonic-gate static int findchtok(int);
85*7c478bd9Sstevel@tonic-gate static void put_prefix_define(char *);
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /* storage of names */
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate  * initial block to place token and
92*7c478bd9Sstevel@tonic-gate  * nonterminal names are stored
93*7c478bd9Sstevel@tonic-gate  * points to initial block - more space
94*7c478bd9Sstevel@tonic-gate  * is allocated as needed.
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate static wchar_t cnamesblk0[CNAMSZ];
97*7c478bd9Sstevel@tonic-gate static wchar_t *cnames = cnamesblk0;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /* place where next name is to be put in */
100*7c478bd9Sstevel@tonic-gate static wchar_t *cnamp = cnamesblk0;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /* number of defined symbols output */
103*7c478bd9Sstevel@tonic-gate static int ndefout = 3;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	/* storage of types */
106*7c478bd9Sstevel@tonic-gate static int defunion = 0;	/* union of types defined? */
107*7c478bd9Sstevel@tonic-gate static int ntypes = 0;		/* number of types defined */
108*7c478bd9Sstevel@tonic-gate static wchar_t *typeset[NTYPES]; /* pointers to type tags */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	/* symbol tables for tokens and nonterminals */
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate int ntokens = 0;
113*7c478bd9Sstevel@tonic-gate int ntoksz = NTERMS;
114*7c478bd9Sstevel@tonic-gate TOKSYMB *tokset;
115*7c478bd9Sstevel@tonic-gate int *toklev;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate int nnonter = -1;
118*7c478bd9Sstevel@tonic-gate NTSYMB *nontrst;
119*7c478bd9Sstevel@tonic-gate int nnontersz = NNONTERM;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate static int start;	/* start symbol */
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	/* assigned token type values */
124*7c478bd9Sstevel@tonic-gate static int extval = 0;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	/* input and output file descriptors */
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate FILE *finput;		/* yacc input file */
129*7c478bd9Sstevel@tonic-gate FILE *faction;		/* file for saving actions */
130*7c478bd9Sstevel@tonic-gate FILE *fdefine;		/* file for # defines */
131*7c478bd9Sstevel@tonic-gate FILE *ftable;		/* y.tab.c file */
132*7c478bd9Sstevel@tonic-gate FILE *ftemp;		/* tempfile to pass 2 */
133*7c478bd9Sstevel@tonic-gate FILE *fdebug;		/* where the strings for debugging are stored */
134*7c478bd9Sstevel@tonic-gate FILE *foutput;		/* y.output file */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	/* output string */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate static wchar_t *lhstext;
139*7c478bd9Sstevel@tonic-gate static wchar_t *rhstext;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	/* storage for grammar rules */
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate int *mem0; /* production storage */
144*7c478bd9Sstevel@tonic-gate int *mem;
145*7c478bd9Sstevel@tonic-gate int *tracemem;
146*7c478bd9Sstevel@tonic-gate extern int *optimmem;
147*7c478bd9Sstevel@tonic-gate int new_memsize = MEMSIZE;
148*7c478bd9Sstevel@tonic-gate int nprod = 1;	/* number of productions */
149*7c478bd9Sstevel@tonic-gate int nprodsz = NPROD;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate int **prdptr;
152*7c478bd9Sstevel@tonic-gate int *levprd;
153*7c478bd9Sstevel@tonic-gate wchar_t *had_act;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate /* flag for generating the # line's default is yes */
156*7c478bd9Sstevel@tonic-gate int gen_lines = 1;
157*7c478bd9Sstevel@tonic-gate int act_lines = 0;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate /* flag for whether to include runtime debugging */
160*7c478bd9Sstevel@tonic-gate static int gen_testing = 0;
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate /* flag for version stamping--default turned off */
163*7c478bd9Sstevel@tonic-gate static char *v_stmp = "n";
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate #ifndef NOLIBW	/* No wchar_t, no multibyte char handling! */
166*7c478bd9Sstevel@tonic-gate int nmbchars = 0;	/* number of mb literals in mbchars */
167*7c478bd9Sstevel@tonic-gate MBCLIT *mbchars = (MBCLIT *) 0; /* array of mb literals */
168*7c478bd9Sstevel@tonic-gate int nmbcharsz = 0; /* allocated space for mbchars */
169*7c478bd9Sstevel@tonic-gate #endif /* !NOLIBW */
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate void
172*7c478bd9Sstevel@tonic-gate setup(argc, argv)
173*7c478bd9Sstevel@tonic-gate int argc;
174*7c478bd9Sstevel@tonic-gate char *argv[];
175*7c478bd9Sstevel@tonic-gate {	int ii, i, j, lev, t, ty;
176*7c478bd9Sstevel@tonic-gate 		/* ty is the sequencial number of token name in tokset */
177*7c478bd9Sstevel@tonic-gate 	int c;
178*7c478bd9Sstevel@tonic-gate 	int *p;
179*7c478bd9Sstevel@tonic-gate 	char *cp;
180*7c478bd9Sstevel@tonic-gate 	wchar_t actname[8];
181*7c478bd9Sstevel@tonic-gate 	unsigned int options = 0;
182*7c478bd9Sstevel@tonic-gate 	char *file_prefix = DEFAULT_PREFIX;
183*7c478bd9Sstevel@tonic-gate 	char *sym_prefix = "";
184*7c478bd9Sstevel@tonic-gate #define	F_NAME_LENGTH	128
185*7c478bd9Sstevel@tonic-gate 	char	fname[F_NAME_LENGTH+1];
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 	extern char	*optarg;
188*7c478bd9Sstevel@tonic-gate 	extern int	optind;
189*7c478bd9Sstevel@tonic-gate 	extern 		getopt();
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	foutput = NULL;
192*7c478bd9Sstevel@tonic-gate 	fdefine = NULL;
193*7c478bd9Sstevel@tonic-gate 	i = 1;
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	tokname = (wchar_t *)malloc(sizeof (wchar_t) * toksize);
196*7c478bd9Sstevel@tonic-gate 	tokset = (TOKSYMB *)malloc(sizeof (TOKSYMB) * ntoksz);
197*7c478bd9Sstevel@tonic-gate 	toklev = (int *)malloc(sizeof (int) * ntoksz);
198*7c478bd9Sstevel@tonic-gate 	nontrst = (NTSYMB *)malloc(sizeof (NTSYMB) * nnontersz);
199*7c478bd9Sstevel@tonic-gate 	mem0 = (int *)malloc(sizeof (int) * new_memsize);
200*7c478bd9Sstevel@tonic-gate 	prdptr = (int **)malloc(sizeof (int *) * (nprodsz+2));
201*7c478bd9Sstevel@tonic-gate 	levprd = (int *)malloc(sizeof (int) * (nprodsz+2));
202*7c478bd9Sstevel@tonic-gate 	had_act = (wchar_t *)calloc((nprodsz + 2), sizeof (wchar_t));
203*7c478bd9Sstevel@tonic-gate 	lhstext = (wchar_t *)malloc(sizeof (wchar_t) * LHS_TEXT_LEN);
204*7c478bd9Sstevel@tonic-gate 	rhstext = (wchar_t *)malloc(sizeof (wchar_t) * RHS_TEXT_LEN);
205*7c478bd9Sstevel@tonic-gate 	aryfil(toklev, ntoksz, 0);
206*7c478bd9Sstevel@tonic-gate 	aryfil(levprd, nprodsz, 0);
207*7c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < ntoksz; ++ii)
208*7c478bd9Sstevel@tonic-gate 		tokset[ii].value = 0;
209*7c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < nnontersz; ++ii)
210*7c478bd9Sstevel@tonic-gate 		nontrst[ii].tvalue = 0;
211*7c478bd9Sstevel@tonic-gate 	aryfil(mem0, new_memsize, 0);
212*7c478bd9Sstevel@tonic-gate 	mem = mem0;
213*7c478bd9Sstevel@tonic-gate 	tracemem = mem0;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "vVdltp:Q:Y:P:b:")) != EOF)
216*7c478bd9Sstevel@tonic-gate 		switch (c) {
217*7c478bd9Sstevel@tonic-gate 		case 'v':
218*7c478bd9Sstevel@tonic-gate 			options |= v_FLAG;
219*7c478bd9Sstevel@tonic-gate 			break;
220*7c478bd9Sstevel@tonic-gate 		case 'V':
221*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "yacc: %s %s\n",
222*7c478bd9Sstevel@tonic-gate 			    (const char *)SGU_PKG,
223*7c478bd9Sstevel@tonic-gate 			    (const char *)SGU_REL);
224*7c478bd9Sstevel@tonic-gate 			break;
225*7c478bd9Sstevel@tonic-gate 		case 'Q':
226*7c478bd9Sstevel@tonic-gate 			v_stmp = optarg;
227*7c478bd9Sstevel@tonic-gate 			if (*v_stmp != 'y' && *v_stmp != 'n')
228*7c478bd9Sstevel@tonic-gate /*
229*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
230*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
231*7c478bd9Sstevel@tonic-gate  *	Do not translate -Q and [y/n].
232*7c478bd9Sstevel@tonic-gate  */
233*7c478bd9Sstevel@tonic-gate 				error(gettext(
234*7c478bd9Sstevel@tonic-gate 			"yacc: -Q should be followed by [y/n]"));
235*7c478bd9Sstevel@tonic-gate 			break;
236*7c478bd9Sstevel@tonic-gate 		case 'd':
237*7c478bd9Sstevel@tonic-gate 			options |= d_FLAG;
238*7c478bd9Sstevel@tonic-gate 			break;
239*7c478bd9Sstevel@tonic-gate 		case 'l':
240*7c478bd9Sstevel@tonic-gate 			gen_lines = 0;	/* don't gen #lines */
241*7c478bd9Sstevel@tonic-gate 			break;
242*7c478bd9Sstevel@tonic-gate 		case 't':
243*7c478bd9Sstevel@tonic-gate 			gen_testing = 1;	/* set YYDEBUG on */
244*7c478bd9Sstevel@tonic-gate 			break;
245*7c478bd9Sstevel@tonic-gate 		case 'Y':
246*7c478bd9Sstevel@tonic-gate 			cp = (char *)malloc(strlen(optarg)+
247*7c478bd9Sstevel@tonic-gate 				sizeof ("/yaccpar") + 1);
248*7c478bd9Sstevel@tonic-gate 			cp = strcpy(cp, optarg);
249*7c478bd9Sstevel@tonic-gate 			parser = strcat(cp, "/yaccpar");
250*7c478bd9Sstevel@tonic-gate 			break;
251*7c478bd9Sstevel@tonic-gate 		case 'P':
252*7c478bd9Sstevel@tonic-gate 			parser = optarg;
253*7c478bd9Sstevel@tonic-gate 			break;
254*7c478bd9Sstevel@tonic-gate 		case 'p':
255*7c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "yy") != 0)
256*7c478bd9Sstevel@tonic-gate 				sym_prefix = optarg;
257*7c478bd9Sstevel@tonic-gate 			else
258*7c478bd9Sstevel@tonic-gate 				sym_prefix = "";
259*7c478bd9Sstevel@tonic-gate 			break;
260*7c478bd9Sstevel@tonic-gate 		case 'b':
261*7c478bd9Sstevel@tonic-gate 			file_prefix = optarg;
262*7c478bd9Sstevel@tonic-gate 			break;
263*7c478bd9Sstevel@tonic-gate 		case '?':
264*7c478bd9Sstevel@tonic-gate 		default:
265*7c478bd9Sstevel@tonic-gate /*
266*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
267*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
268*7c478bd9Sstevel@tonic-gate  *	This is a usage message. The translate should be
269*7c478bd9Sstevel@tonic-gate  *	consistent with man page translation.
270*7c478bd9Sstevel@tonic-gate  */
271*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
272*7c478bd9Sstevel@tonic-gate "Usage: yacc [-vVdltY] [-Q(y/n)] [-b file_prefix] [-p sym_prefix]"
273*7c478bd9Sstevel@tonic-gate " [-P parser] file\n"));
274*7c478bd9Sstevel@tonic-gate 			exit(1);
275*7c478bd9Sstevel@tonic-gate 		}
276*7c478bd9Sstevel@tonic-gate 	/*
277*7c478bd9Sstevel@tonic-gate 	 * Open y.output if -v is specified
278*7c478bd9Sstevel@tonic-gate 	 */
279*7c478bd9Sstevel@tonic-gate 	if (options & v_FLAG) {
280*7c478bd9Sstevel@tonic-gate 		strncpy(fname,
281*7c478bd9Sstevel@tonic-gate 			file_prefix,
282*7c478bd9Sstevel@tonic-gate 			F_NAME_LENGTH-strlen(".output"));
283*7c478bd9Sstevel@tonic-gate 		strcat(fname, ".output");
284*7c478bd9Sstevel@tonic-gate 		foutput = fopen(fname, "w");
285*7c478bd9Sstevel@tonic-gate 		if (foutput == NULL)
286*7c478bd9Sstevel@tonic-gate 			error(gettext(
287*7c478bd9Sstevel@tonic-gate 			"cannot open y.output"));
288*7c478bd9Sstevel@tonic-gate 	}
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	/*
291*7c478bd9Sstevel@tonic-gate 	 * Open y.tab.h if -d is specified
292*7c478bd9Sstevel@tonic-gate 	 */
293*7c478bd9Sstevel@tonic-gate 	if (options & d_FLAG) {
294*7c478bd9Sstevel@tonic-gate 		strncpy(fname,
295*7c478bd9Sstevel@tonic-gate 			file_prefix,
296*7c478bd9Sstevel@tonic-gate 			F_NAME_LENGTH-strlen(".tab.h"));
297*7c478bd9Sstevel@tonic-gate 		strcat(fname, ".tab.h");
298*7c478bd9Sstevel@tonic-gate 		fdefine = fopen(fname, "w");
299*7c478bd9Sstevel@tonic-gate 		if (fdefine == NULL)
300*7c478bd9Sstevel@tonic-gate 			error(gettext(
301*7c478bd9Sstevel@tonic-gate 			"cannot open y.tab.h"));
302*7c478bd9Sstevel@tonic-gate 	}
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	fdebug = fopen(DEBUGNAME, "w");
305*7c478bd9Sstevel@tonic-gate 	if (fdebug == NULL)
306*7c478bd9Sstevel@tonic-gate /*
307*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
308*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
309*7c478bd9Sstevel@tonic-gate  *	Do not translate yacc.debug.
310*7c478bd9Sstevel@tonic-gate  */
311*7c478bd9Sstevel@tonic-gate 		error(gettext(
312*7c478bd9Sstevel@tonic-gate 		"cannot open yacc.debug"));
313*7c478bd9Sstevel@tonic-gate 	/*
314*7c478bd9Sstevel@tonic-gate 	 * Open y.tab.c
315*7c478bd9Sstevel@tonic-gate 	 */
316*7c478bd9Sstevel@tonic-gate 	strncpy(fname,
317*7c478bd9Sstevel@tonic-gate 		file_prefix,
318*7c478bd9Sstevel@tonic-gate 		F_NAME_LENGTH-strlen(".tab.c"));
319*7c478bd9Sstevel@tonic-gate 	strcat(fname, ".tab.c");
320*7c478bd9Sstevel@tonic-gate 	ftable = fopen(fname, "w");
321*7c478bd9Sstevel@tonic-gate 	if (ftable == NULL)
322*7c478bd9Sstevel@tonic-gate 		error(gettext(
323*7c478bd9Sstevel@tonic-gate 		"cannot open %s"), fname);
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate 	ftemp = fopen(TEMPNAME, "w");
326*7c478bd9Sstevel@tonic-gate 	faction = fopen(ACTNAME, "w");
327*7c478bd9Sstevel@tonic-gate 	if (ftemp == NULL || faction == NULL)
328*7c478bd9Sstevel@tonic-gate /*
329*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
330*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
331*7c478bd9Sstevel@tonic-gate  *	The message means: "Could not open a temporary file."
332*7c478bd9Sstevel@tonic-gate  */
333*7c478bd9Sstevel@tonic-gate 		error(gettext(
334*7c478bd9Sstevel@tonic-gate 		"cannot open temp file"));
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	if ((finput = fopen(infile = argv[optind], "r")) == NULL)
337*7c478bd9Sstevel@tonic-gate /*
338*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
339*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
340*7c478bd9Sstevel@tonic-gate  */
341*7c478bd9Sstevel@tonic-gate 		error(gettext(
342*7c478bd9Sstevel@tonic-gate 		"cannot open input file"));
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	lineno = 1;
345*7c478bd9Sstevel@tonic-gate 	cnamp = cnames;
346*7c478bd9Sstevel@tonic-gate 	(void) defin(0, L"$end");
347*7c478bd9Sstevel@tonic-gate 	extval = 0400;
348*7c478bd9Sstevel@tonic-gate 	(void) defin(0, L"error");
349*7c478bd9Sstevel@tonic-gate 	(void) defin(1, L"$accept");
350*7c478bd9Sstevel@tonic-gate 	mem = mem0;
351*7c478bd9Sstevel@tonic-gate 	lev = 0;
352*7c478bd9Sstevel@tonic-gate 	ty = 0;
353*7c478bd9Sstevel@tonic-gate 	i = 0;
354*7c478bd9Sstevel@tonic-gate 	beg_debug();	/* initialize fdebug file */
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate 	/*
357*7c478bd9Sstevel@tonic-gate 	 * sorry -- no yacc parser here.....
358*7c478bd9Sstevel@tonic-gate 	 *	we must bootstrap somehow...
359*7c478bd9Sstevel@tonic-gate 	 */
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate 	t = gettok();
362*7c478bd9Sstevel@tonic-gate 	if (*v_stmp == 'y')
363*7c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "#ident\t\"yacc: %s %s\"\n",
364*7c478bd9Sstevel@tonic-gate 		    (const char *)SGU_PKG, (const char *)SGU_REL);
365*7c478bd9Sstevel@tonic-gate 	for (; t != MARK && t != ENDFILE; ) {
366*7c478bd9Sstevel@tonic-gate 		int tok_in_line;
367*7c478bd9Sstevel@tonic-gate 		switch (t) {
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 		case L';':
370*7c478bd9Sstevel@tonic-gate 			t = gettok();
371*7c478bd9Sstevel@tonic-gate 			break;
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 		case START:
374*7c478bd9Sstevel@tonic-gate 			if ((t = gettok()) != IDENTIFIER) {
375*7c478bd9Sstevel@tonic-gate 				error("bad %%start construction");
376*7c478bd9Sstevel@tonic-gate 				}
377*7c478bd9Sstevel@tonic-gate 			start = chfind(1, tokname);
378*7c478bd9Sstevel@tonic-gate 			t = gettok();
379*7c478bd9Sstevel@tonic-gate 			continue;
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate 		case TYPEDEF:
382*7c478bd9Sstevel@tonic-gate 			tok_in_line = 0;
383*7c478bd9Sstevel@tonic-gate 			if ((t = gettok()) != TYPENAME)
384*7c478bd9Sstevel@tonic-gate /*
385*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
386*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
387*7c478bd9Sstevel@tonic-gate  *	Do not translate %%type.
388*7c478bd9Sstevel@tonic-gate  */
389*7c478bd9Sstevel@tonic-gate 				error(gettext(
390*7c478bd9Sstevel@tonic-gate 				"bad syntax in %%type"));
391*7c478bd9Sstevel@tonic-gate 			ty = numbval;
392*7c478bd9Sstevel@tonic-gate 			for (;;) {
393*7c478bd9Sstevel@tonic-gate 				t = gettok();
394*7c478bd9Sstevel@tonic-gate 				switch (t) {
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 				case IDENTIFIER:
397*7c478bd9Sstevel@tonic-gate 			/*
398*7c478bd9Sstevel@tonic-gate 			 * The following lines are idented to left.
399*7c478bd9Sstevel@tonic-gate 			 */
400*7c478bd9Sstevel@tonic-gate 			tok_in_line = 1;
401*7c478bd9Sstevel@tonic-gate 			if ((t = chfind(1, tokname)) < NTBASE) {
402*7c478bd9Sstevel@tonic-gate 				j = TYPE(toklev[t]);
403*7c478bd9Sstevel@tonic-gate 				if (j != 0 && j != ty) {
404*7c478bd9Sstevel@tonic-gate /*
405*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
406*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
407*7c478bd9Sstevel@tonic-gate  */
408*7c478bd9Sstevel@tonic-gate 					error(gettext(
409*7c478bd9Sstevel@tonic-gate 					"type redeclaration of token %ws"),
410*7c478bd9Sstevel@tonic-gate 					tokset[t].name);
411*7c478bd9Sstevel@tonic-gate 					}
412*7c478bd9Sstevel@tonic-gate 				else
413*7c478bd9Sstevel@tonic-gate 					SETTYPE(toklev[t], ty);
414*7c478bd9Sstevel@tonic-gate 			} else {
415*7c478bd9Sstevel@tonic-gate 				j = nontrst[t-NTBASE].tvalue;
416*7c478bd9Sstevel@tonic-gate 				if (j != 0 && j != ty) {
417*7c478bd9Sstevel@tonic-gate /*
418*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
419*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
420*7c478bd9Sstevel@tonic-gate  *	Check how nonterminal is translated in translated
421*7c478bd9Sstevel@tonic-gate  *	yacc man page or yacc user's document.
422*7c478bd9Sstevel@tonic-gate  */
423*7c478bd9Sstevel@tonic-gate 					error(gettext(
424*7c478bd9Sstevel@tonic-gate 				"type redeclaration of nonterminal %ws"),
425*7c478bd9Sstevel@tonic-gate 						nontrst[t-NTBASE].name);
426*7c478bd9Sstevel@tonic-gate 					}
427*7c478bd9Sstevel@tonic-gate 				else
428*7c478bd9Sstevel@tonic-gate 					nontrst[t-NTBASE].tvalue = ty;
429*7c478bd9Sstevel@tonic-gate 				}
430*7c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
431*7c478bd9Sstevel@tonic-gate 			/*
432*7c478bd9Sstevel@tonic-gate 			 * End Indentation
433*7c478bd9Sstevel@tonic-gate 			 */
434*7c478bd9Sstevel@tonic-gate 				case L',':
435*7c478bd9Sstevel@tonic-gate 					continue;
436*7c478bd9Sstevel@tonic-gate 
437*7c478bd9Sstevel@tonic-gate 				case L';':
438*7c478bd9Sstevel@tonic-gate 					t = gettok();
439*7c478bd9Sstevel@tonic-gate 					break;
440*7c478bd9Sstevel@tonic-gate 				default:
441*7c478bd9Sstevel@tonic-gate 					break;
442*7c478bd9Sstevel@tonic-gate 					}
443*7c478bd9Sstevel@tonic-gate 				if (!tok_in_line)
444*7c478bd9Sstevel@tonic-gate /*
445*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
446*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
447*7c478bd9Sstevel@tonic-gate  */
448*7c478bd9Sstevel@tonic-gate 					error(gettext(
449*7c478bd9Sstevel@tonic-gate 					"missing tokens or illegal tokens"));
450*7c478bd9Sstevel@tonic-gate 				break;
451*7c478bd9Sstevel@tonic-gate 				}
452*7c478bd9Sstevel@tonic-gate 			continue;
453*7c478bd9Sstevel@tonic-gate 
454*7c478bd9Sstevel@tonic-gate 		case UNION:
455*7c478bd9Sstevel@tonic-gate 			/* copy the union declaration to the output */
456*7c478bd9Sstevel@tonic-gate 			cpyunion();
457*7c478bd9Sstevel@tonic-gate 			defunion = 1;
458*7c478bd9Sstevel@tonic-gate 			t = gettok();
459*7c478bd9Sstevel@tonic-gate 			continue;
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate 		case LEFT:
462*7c478bd9Sstevel@tonic-gate 		case BINARY:
463*7c478bd9Sstevel@tonic-gate 		case RIGHT:
464*7c478bd9Sstevel@tonic-gate 			i++;
465*7c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
466*7c478bd9Sstevel@tonic-gate 		case TERM:
467*7c478bd9Sstevel@tonic-gate 			tok_in_line = 0;
468*7c478bd9Sstevel@tonic-gate 
469*7c478bd9Sstevel@tonic-gate 			/* nonzero means new prec. and assoc. */
470*7c478bd9Sstevel@tonic-gate 			lev = (t-TERM) | 04;
471*7c478bd9Sstevel@tonic-gate 			ty = 0;
472*7c478bd9Sstevel@tonic-gate 
473*7c478bd9Sstevel@tonic-gate 			/* get identifiers so defined */
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate 			t = gettok();
476*7c478bd9Sstevel@tonic-gate 			if (t == TYPENAME) { /* there is a type defined */
477*7c478bd9Sstevel@tonic-gate 				ty = numbval;
478*7c478bd9Sstevel@tonic-gate 				t = gettok();
479*7c478bd9Sstevel@tonic-gate 				}
480*7c478bd9Sstevel@tonic-gate 
481*7c478bd9Sstevel@tonic-gate 			for (;;) {
482*7c478bd9Sstevel@tonic-gate 				switch (t) {
483*7c478bd9Sstevel@tonic-gate 
484*7c478bd9Sstevel@tonic-gate 				case L',':
485*7c478bd9Sstevel@tonic-gate 					t = gettok();
486*7c478bd9Sstevel@tonic-gate 					continue;
487*7c478bd9Sstevel@tonic-gate 
488*7c478bd9Sstevel@tonic-gate 				case L';':
489*7c478bd9Sstevel@tonic-gate 					break;
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate 				case IDENTIFIER:
492*7c478bd9Sstevel@tonic-gate 					tok_in_line = 1;
493*7c478bd9Sstevel@tonic-gate 					j = chfind(0, tokname);
494*7c478bd9Sstevel@tonic-gate 					if (j > NTBASE) {
495*7c478bd9Sstevel@tonic-gate /*
496*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
497*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
498*7c478bd9Sstevel@tonic-gate  */
499*7c478bd9Sstevel@tonic-gate 						error(gettext(
500*7c478bd9Sstevel@tonic-gate 				"%ws is not a token."),
501*7c478bd9Sstevel@tonic-gate 						tokname);
502*7c478bd9Sstevel@tonic-gate 					}
503*7c478bd9Sstevel@tonic-gate 					if (lev & ~04) {
504*7c478bd9Sstevel@tonic-gate 						if (ASSOC(toklev[j]) & ~04)
505*7c478bd9Sstevel@tonic-gate /*
506*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
507*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
508*7c478bd9Sstevel@tonic-gate  */
509*7c478bd9Sstevel@tonic-gate 							error(gettext(
510*7c478bd9Sstevel@tonic-gate 				"redeclaration of precedence of %ws"),
511*7c478bd9Sstevel@tonic-gate 						tokname);
512*7c478bd9Sstevel@tonic-gate 						SETASC(toklev[j], lev);
513*7c478bd9Sstevel@tonic-gate 						SETPLEV(toklev[j], i);
514*7c478bd9Sstevel@tonic-gate 					} else {
515*7c478bd9Sstevel@tonic-gate 						if (ASSOC(toklev[j]))
516*7c478bd9Sstevel@tonic-gate 						(void) warning(1, gettext(
517*7c478bd9Sstevel@tonic-gate 				"redeclaration of precedence of %ws."),
518*7c478bd9Sstevel@tonic-gate 							tokname);
519*7c478bd9Sstevel@tonic-gate 						SETASC(toklev[j], lev);
520*7c478bd9Sstevel@tonic-gate 						}
521*7c478bd9Sstevel@tonic-gate 					if (ty) {
522*7c478bd9Sstevel@tonic-gate 						if (TYPE(toklev[j]))
523*7c478bd9Sstevel@tonic-gate 							error(gettext(
524*7c478bd9Sstevel@tonic-gate /*
525*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
526*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
527*7c478bd9Sstevel@tonic-gate  */
528*7c478bd9Sstevel@tonic-gate 						"redeclaration of type of %ws"),
529*7c478bd9Sstevel@tonic-gate 							tokname);
530*7c478bd9Sstevel@tonic-gate 						SETTYPE(toklev[j], ty);
531*7c478bd9Sstevel@tonic-gate 						}
532*7c478bd9Sstevel@tonic-gate 					if ((t = gettok()) == NUMBER) {
533*7c478bd9Sstevel@tonic-gate 						tokset[j].value = numbval;
534*7c478bd9Sstevel@tonic-gate 						if (j < ndefout && j > 2) {
535*7c478bd9Sstevel@tonic-gate /*
536*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
537*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
538*7c478bd9Sstevel@tonic-gate  */
539*7c478bd9Sstevel@tonic-gate 							error(gettext(
540*7c478bd9Sstevel@tonic-gate 				"type number of %ws should be defined earlier"),
541*7c478bd9Sstevel@tonic-gate 							tokset[j].name);
542*7c478bd9Sstevel@tonic-gate 							}
543*7c478bd9Sstevel@tonic-gate 						if (numbval >= -YYFLAG1) {
544*7c478bd9Sstevel@tonic-gate /*
545*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
546*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
547*7c478bd9Sstevel@tonic-gate  */
548*7c478bd9Sstevel@tonic-gate 							error(gettext(
549*7c478bd9Sstevel@tonic-gate 				"token numbers must be less than %d"),
550*7c478bd9Sstevel@tonic-gate 							-YYFLAG1);
551*7c478bd9Sstevel@tonic-gate 							}
552*7c478bd9Sstevel@tonic-gate 						t = gettok();
553*7c478bd9Sstevel@tonic-gate 						}
554*7c478bd9Sstevel@tonic-gate 					continue;
555*7c478bd9Sstevel@tonic-gate 
556*7c478bd9Sstevel@tonic-gate 					}
557*7c478bd9Sstevel@tonic-gate 				if (!tok_in_line)
558*7c478bd9Sstevel@tonic-gate /*
559*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
560*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
561*7c478bd9Sstevel@tonic-gate  */
562*7c478bd9Sstevel@tonic-gate 					error(gettext(
563*7c478bd9Sstevel@tonic-gate 					"missing tokens or illegal tokens"));
564*7c478bd9Sstevel@tonic-gate 				break;
565*7c478bd9Sstevel@tonic-gate 				}
566*7c478bd9Sstevel@tonic-gate 			continue;
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 		case LCURLY:
569*7c478bd9Sstevel@tonic-gate 			defout();
570*7c478bd9Sstevel@tonic-gate 			cpycode();
571*7c478bd9Sstevel@tonic-gate 			t = gettok();
572*7c478bd9Sstevel@tonic-gate 			continue;
573*7c478bd9Sstevel@tonic-gate 
574*7c478bd9Sstevel@tonic-gate 		default:
575*7c478bd9Sstevel@tonic-gate 			error("syntax error");
576*7c478bd9Sstevel@tonic-gate 
577*7c478bd9Sstevel@tonic-gate 			}
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate 		}
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate 	if (t == ENDFILE) {
582*7c478bd9Sstevel@tonic-gate /*
583*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
584*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
585*7c478bd9Sstevel@tonic-gate  *	Do not translate %%%%.
586*7c478bd9Sstevel@tonic-gate  */
587*7c478bd9Sstevel@tonic-gate 		error("unexpected EOF before %%%%");
588*7c478bd9Sstevel@tonic-gate 		}
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 	/* t is MARK */
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate 	defout();
593*7c478bd9Sstevel@tonic-gate 	end_toks();	/* all tokens dumped - get ready for reductions */
594*7c478bd9Sstevel@tonic-gate 
595*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#include <inttypes.h>\n");
596*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#ifdef __STDC__\n");
597*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <stdlib.h>\n");
598*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <string.h>\n");
599*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define	YYCONST	const\n");
600*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#else\n");
601*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <malloc.h>\n");
602*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <memory.h>\n");
603*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define	YYCONST\n");
604*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
605*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#include <values.h>\n");
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate 	if (sym_prefix[0] != '\0')
608*7c478bd9Sstevel@tonic-gate 		put_prefix_define(sym_prefix);
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
611*7c478bd9Sstevel@tonic-gate 	"\n#if defined(__cplusplus) || defined(__STDC__)\n");
612*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
613*7c478bd9Sstevel@tonic-gate 	"\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
614*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "extern \"C\" {\n");
615*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
616*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifndef yyerror\n");
617*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#if defined(__cplusplus)\n");
618*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	void yyerror(YYCONST char *);\n");
619*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
620*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
621*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifndef yylex\n");
622*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	int yylex(void);\n");
623*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
624*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	int yyparse(void);\n");
625*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
626*7c478bd9Sstevel@tonic-gate 	"#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
627*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "}\n");
628*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
629*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#endif\n\n");
630*7c478bd9Sstevel@tonic-gate 
631*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define yyclearin yychar = -1\n");
632*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define yyerrok yyerrflag = 0\n");
633*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "extern int yychar;\nextern int yyerrflag;\n");
634*7c478bd9Sstevel@tonic-gate 	if (!(defunion || ntypes))
635*7c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable,
636*7c478bd9Sstevel@tonic-gate 			"#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
637*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yylval;\n");
638*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yyval;\n");
639*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "typedef int yytabelem;\n");
640*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
641*7c478bd9Sstevel@tonic-gate 		"#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n");
642*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#if YYMAXDEPTH > 0\n");
643*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "int yy_yys[YYMAXDEPTH], *yys = yy_yys;\n");
644*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv;\n");
645*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#else	/* user does initial allocation */\n");
646*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "int *yys;\nYYSTYPE *yyv;\n#endif\n");
647*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "static int yymaxdepth = YYMAXDEPTH;\n");
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 	prdptr[0] = mem;
650*7c478bd9Sstevel@tonic-gate 	/* added production */
651*7c478bd9Sstevel@tonic-gate 	*mem++ = NTBASE;
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 	/* if start is 0, we will overwrite with the lhs of the first rule */
654*7c478bd9Sstevel@tonic-gate 	*mem++ = start;
655*7c478bd9Sstevel@tonic-gate 	*mem++ = 1;
656*7c478bd9Sstevel@tonic-gate 	*mem++ = 0;
657*7c478bd9Sstevel@tonic-gate 	prdptr[1] = mem;
658*7c478bd9Sstevel@tonic-gate 
659*7c478bd9Sstevel@tonic-gate 	while ((t = gettok()) == LCURLY)
660*7c478bd9Sstevel@tonic-gate 		cpycode();
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate 	if (t != C_IDENTIFIER)
663*7c478bd9Sstevel@tonic-gate 		error("bad syntax on first rule");
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate 	if (!start)
666*7c478bd9Sstevel@tonic-gate 		prdptr[0][1] = chfind(1, tokname);
667*7c478bd9Sstevel@tonic-gate 
668*7c478bd9Sstevel@tonic-gate 	/* read rules */
669*7c478bd9Sstevel@tonic-gate 
670*7c478bd9Sstevel@tonic-gate 	while (t != MARK && t != ENDFILE) {
671*7c478bd9Sstevel@tonic-gate 
672*7c478bd9Sstevel@tonic-gate 		/* process a rule */
673*7c478bd9Sstevel@tonic-gate 
674*7c478bd9Sstevel@tonic-gate 		if (t == L'|') {
675*7c478bd9Sstevel@tonic-gate 			rhsfill((wchar_t *)0); /* restart fill of rhs */
676*7c478bd9Sstevel@tonic-gate 			*mem = *prdptr[nprod-1];
677*7c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
678*7c478bd9Sstevel@tonic-gate 				exp_mem(1);
679*7c478bd9Sstevel@tonic-gate 		} else if (t == C_IDENTIFIER) {
680*7c478bd9Sstevel@tonic-gate 			*mem = chfind(1, tokname);
681*7c478bd9Sstevel@tonic-gate 			if (*mem < NTBASE)
682*7c478bd9Sstevel@tonic-gate /*
683*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
684*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
685*7c478bd9Sstevel@tonic-gate  *	Check how nonterminal is translated.
686*7c478bd9Sstevel@tonic-gate  */
687*7c478bd9Sstevel@tonic-gate 				error(gettext(
688*7c478bd9Sstevel@tonic-gate 				"illegal nonterminal in grammar rule"));
689*7c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
690*7c478bd9Sstevel@tonic-gate 				exp_mem(1);
691*7c478bd9Sstevel@tonic-gate 			lhsfill(tokname);	/* new rule: restart strings */
692*7c478bd9Sstevel@tonic-gate 		} else
693*7c478bd9Sstevel@tonic-gate /*
694*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
695*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
696*7c478bd9Sstevel@tonic-gate  */
697*7c478bd9Sstevel@tonic-gate 			error(gettext(
698*7c478bd9Sstevel@tonic-gate 			"illegal rule: missing semicolon or | ?"));
699*7c478bd9Sstevel@tonic-gate 
700*7c478bd9Sstevel@tonic-gate 		/* read rule body */
701*7c478bd9Sstevel@tonic-gate 
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate 		t = gettok();
704*7c478bd9Sstevel@tonic-gate 	more_rule:
705*7c478bd9Sstevel@tonic-gate 		while (t == IDENTIFIER) {
706*7c478bd9Sstevel@tonic-gate 			*mem = chfind(1, tokname);
707*7c478bd9Sstevel@tonic-gate 			if (*mem < NTBASE)
708*7c478bd9Sstevel@tonic-gate 				levprd[nprod] = toklev[*mem]& ~04;
709*7c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
710*7c478bd9Sstevel@tonic-gate 				exp_mem(1);
711*7c478bd9Sstevel@tonic-gate 			rhsfill(tokname);	/* add to rhs string */
712*7c478bd9Sstevel@tonic-gate 			t = gettok();
713*7c478bd9Sstevel@tonic-gate 			}
714*7c478bd9Sstevel@tonic-gate 
715*7c478bd9Sstevel@tonic-gate 		if (t == PREC) {
716*7c478bd9Sstevel@tonic-gate 			if (gettok() != IDENTIFIER)
717*7c478bd9Sstevel@tonic-gate /*
718*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
719*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
720*7c478bd9Sstevel@tonic-gate  *	Do not translate %%prec.
721*7c478bd9Sstevel@tonic-gate  */
722*7c478bd9Sstevel@tonic-gate 				error(gettext(
723*7c478bd9Sstevel@tonic-gate 				"illegal %%prec syntax"));
724*7c478bd9Sstevel@tonic-gate 			j = chfind(2, tokname);
725*7c478bd9Sstevel@tonic-gate 			if (j >= NTBASE)
726*7c478bd9Sstevel@tonic-gate /*
727*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
728*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
729*7c478bd9Sstevel@tonic-gate  *	Do not translate %%prec.
730*7c478bd9Sstevel@tonic-gate  */
731*7c478bd9Sstevel@tonic-gate 				error(gettext(
732*7c478bd9Sstevel@tonic-gate 				"nonterminal %ws illegal after %%prec"),
733*7c478bd9Sstevel@tonic-gate 				nontrst[j-NTBASE].name);
734*7c478bd9Sstevel@tonic-gate 			levprd[nprod] = toklev[j] & ~04;
735*7c478bd9Sstevel@tonic-gate 			t = gettok();
736*7c478bd9Sstevel@tonic-gate 			}
737*7c478bd9Sstevel@tonic-gate 
738*7c478bd9Sstevel@tonic-gate 		if (t == L'=') {
739*7c478bd9Sstevel@tonic-gate 			had_act[nprod] = 1;
740*7c478bd9Sstevel@tonic-gate 			levprd[nprod] |= ACTFLAG;
741*7c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "\ncase %d:", nprod);
742*7c478bd9Sstevel@tonic-gate 			cpyact(mem-prdptr[nprod] - 1);
743*7c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, " break;");
744*7c478bd9Sstevel@tonic-gate 			if ((t = gettok()) == IDENTIFIER) {
745*7c478bd9Sstevel@tonic-gate 				/* action within rule... */
746*7c478bd9Sstevel@tonic-gate 
747*7c478bd9Sstevel@tonic-gate 				lrprnt();		/* dump lhs, rhs */
748*7c478bd9Sstevel@tonic-gate 				(void) wsprintf(actname, "$$%d", nprod);
749*7c478bd9Sstevel@tonic-gate 				/*
750*7c478bd9Sstevel@tonic-gate 				 * make it nonterminal
751*7c478bd9Sstevel@tonic-gate 				 */
752*7c478bd9Sstevel@tonic-gate 				j = chfind(1, actname);
753*7c478bd9Sstevel@tonic-gate 
754*7c478bd9Sstevel@tonic-gate 				/*
755*7c478bd9Sstevel@tonic-gate 				 * the current rule will become rule
756*7c478bd9Sstevel@tonic-gate 				 * number nprod+1 move the contents down,
757*7c478bd9Sstevel@tonic-gate 				 * and make room for the null
758*7c478bd9Sstevel@tonic-gate 				 */
759*7c478bd9Sstevel@tonic-gate 
760*7c478bd9Sstevel@tonic-gate 				if (mem + 2 >= &tracemem[new_memsize])
761*7c478bd9Sstevel@tonic-gate 					exp_mem(1);
762*7c478bd9Sstevel@tonic-gate 				for (p = mem; p >= prdptr[nprod]; --p)
763*7c478bd9Sstevel@tonic-gate 					p[2] = *p;
764*7c478bd9Sstevel@tonic-gate 				mem += 2;
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate 				/* enter null production for action */
767*7c478bd9Sstevel@tonic-gate 
768*7c478bd9Sstevel@tonic-gate 				p = prdptr[nprod];
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate 				*p++ = j;
771*7c478bd9Sstevel@tonic-gate 				*p++ = -nprod;
772*7c478bd9Sstevel@tonic-gate 
773*7c478bd9Sstevel@tonic-gate 				/* update the production information */
774*7c478bd9Sstevel@tonic-gate 
775*7c478bd9Sstevel@tonic-gate 				levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
776*7c478bd9Sstevel@tonic-gate 				levprd[nprod] = ACTFLAG;
777*7c478bd9Sstevel@tonic-gate 
778*7c478bd9Sstevel@tonic-gate 				if (++nprod >= nprodsz)
779*7c478bd9Sstevel@tonic-gate 					exp_prod();
780*7c478bd9Sstevel@tonic-gate 				prdptr[nprod] = p;
781*7c478bd9Sstevel@tonic-gate 
782*7c478bd9Sstevel@tonic-gate 				/*
783*7c478bd9Sstevel@tonic-gate 				 * make the action appear in
784*7c478bd9Sstevel@tonic-gate 				 * the original rule
785*7c478bd9Sstevel@tonic-gate 				 */
786*7c478bd9Sstevel@tonic-gate 				*mem++ = j;
787*7c478bd9Sstevel@tonic-gate 				if (mem >= &tracemem[new_memsize])
788*7c478bd9Sstevel@tonic-gate 					exp_mem(1);
789*7c478bd9Sstevel@tonic-gate 				/* get some more of the rule */
790*7c478bd9Sstevel@tonic-gate 				goto more_rule;
791*7c478bd9Sstevel@tonic-gate 			}
792*7c478bd9Sstevel@tonic-gate 		}
793*7c478bd9Sstevel@tonic-gate 		while (t == L';')
794*7c478bd9Sstevel@tonic-gate 			t = gettok();
795*7c478bd9Sstevel@tonic-gate 		*mem++ = -nprod;
796*7c478bd9Sstevel@tonic-gate 		if (mem >= &tracemem[new_memsize])
797*7c478bd9Sstevel@tonic-gate 			exp_mem(1);
798*7c478bd9Sstevel@tonic-gate 
799*7c478bd9Sstevel@tonic-gate 		/* check that default action is reasonable */
800*7c478bd9Sstevel@tonic-gate 
801*7c478bd9Sstevel@tonic-gate 		if (ntypes && !(levprd[nprod] & ACTFLAG) &&
802*7c478bd9Sstevel@tonic-gate 				nontrst[*prdptr[nprod]-NTBASE].tvalue) {
803*7c478bd9Sstevel@tonic-gate 			/* no explicit action, LHS has value */
804*7c478bd9Sstevel@tonic-gate 			register tempty;
805*7c478bd9Sstevel@tonic-gate 			tempty = prdptr[nprod][1];
806*7c478bd9Sstevel@tonic-gate 			if (tempty < 0)
807*7c478bd9Sstevel@tonic-gate /*
808*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
809*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
810*7c478bd9Sstevel@tonic-gate  *	LHS means Left Hand Side. It does not need to be translated.
811*7c478bd9Sstevel@tonic-gate  */
812*7c478bd9Sstevel@tonic-gate 				error(gettext(
813*7c478bd9Sstevel@tonic-gate 				"must return a value, since LHS has a type"));
814*7c478bd9Sstevel@tonic-gate 			else if (tempty >= NTBASE)
815*7c478bd9Sstevel@tonic-gate 				tempty = nontrst[tempty-NTBASE].tvalue;
816*7c478bd9Sstevel@tonic-gate 			else
817*7c478bd9Sstevel@tonic-gate 				tempty = TYPE(toklev[tempty]);
818*7c478bd9Sstevel@tonic-gate 			if (tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue) {
819*7c478bd9Sstevel@tonic-gate /*
820*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
821*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
822*7c478bd9Sstevel@tonic-gate  *	Check how action is transltated in yacc man page or documents.
823*7c478bd9Sstevel@tonic-gate  */
824*7c478bd9Sstevel@tonic-gate 				error(gettext(
825*7c478bd9Sstevel@tonic-gate 				"default action causes potential type clash"));
826*7c478bd9Sstevel@tonic-gate 			}
827*7c478bd9Sstevel@tonic-gate 		}
828*7c478bd9Sstevel@tonic-gate 
829*7c478bd9Sstevel@tonic-gate 		if (++nprod >= nprodsz)
830*7c478bd9Sstevel@tonic-gate 			exp_prod();
831*7c478bd9Sstevel@tonic-gate 		prdptr[nprod] = mem;
832*7c478bd9Sstevel@tonic-gate 		levprd[nprod] = 0;
833*7c478bd9Sstevel@tonic-gate 		}
834*7c478bd9Sstevel@tonic-gate 	/* end of all rules */
835*7c478bd9Sstevel@tonic-gate 
836*7c478bd9Sstevel@tonic-gate 	end_debug();		/* finish fdebug file's input */
837*7c478bd9Sstevel@tonic-gate 	finact();
838*7c478bd9Sstevel@tonic-gate 	if (t == MARK) {
839*7c478bd9Sstevel@tonic-gate 		if (gen_lines)
840*7c478bd9Sstevel@tonic-gate 			(void) fprintf(ftable, "\n# line %d \"%s\"\n",
841*7c478bd9Sstevel@tonic-gate 				lineno, infile);
842*7c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != EOF)
843*7c478bd9Sstevel@tonic-gate 			(void) putwc(c, ftable);
844*7c478bd9Sstevel@tonic-gate 		}
845*7c478bd9Sstevel@tonic-gate 	(void) fclose(finput);
846*7c478bd9Sstevel@tonic-gate }
847*7c478bd9Sstevel@tonic-gate 
848*7c478bd9Sstevel@tonic-gate static void
849*7c478bd9Sstevel@tonic-gate finact()
850*7c478bd9Sstevel@tonic-gate {
851*7c478bd9Sstevel@tonic-gate 	/* finish action routine */
852*7c478bd9Sstevel@tonic-gate 	(void) fclose(faction);
853*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "# define YYERRCODE %d\n", tokset[2].value);
854*7c478bd9Sstevel@tonic-gate }
855*7c478bd9Sstevel@tonic-gate 
856*7c478bd9Sstevel@tonic-gate static wchar_t *
857*7c478bd9Sstevel@tonic-gate cstash(s)
858*7c478bd9Sstevel@tonic-gate register wchar_t *s;
859*7c478bd9Sstevel@tonic-gate {
860*7c478bd9Sstevel@tonic-gate 	wchar_t *temp;
861*7c478bd9Sstevel@tonic-gate 	static int used = 0;
862*7c478bd9Sstevel@tonic-gate 	static int used_save = 0;
863*7c478bd9Sstevel@tonic-gate 	static int exp_cname = CNAMSZ;
864*7c478bd9Sstevel@tonic-gate 	int len = wslen(s);
865*7c478bd9Sstevel@tonic-gate 
866*7c478bd9Sstevel@tonic-gate 	/*
867*7c478bd9Sstevel@tonic-gate 	 * 2/29/88 -
868*7c478bd9Sstevel@tonic-gate 	 * Don't need to expand the table, just allocate new space.
869*7c478bd9Sstevel@tonic-gate 	 */
870*7c478bd9Sstevel@tonic-gate 	used_save = used;
871*7c478bd9Sstevel@tonic-gate 	while (len >= (exp_cname - used_save)) {
872*7c478bd9Sstevel@tonic-gate 		exp_cname += CNAMSZ;
873*7c478bd9Sstevel@tonic-gate 		if (!used)
874*7c478bd9Sstevel@tonic-gate 			free((char *)cnames);
875*7c478bd9Sstevel@tonic-gate 		if ((cnames = (wchar_t *)
876*7c478bd9Sstevel@tonic-gate 			malloc(sizeof (wchar_t)*exp_cname)) == NULL)
877*7c478bd9Sstevel@tonic-gate /*
878*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
879*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
880*7c478bd9Sstevel@tonic-gate  *
881*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
882*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
883*7c478bd9Sstevel@tonic-gate  */
884*7c478bd9Sstevel@tonic-gate 			error(gettext(
885*7c478bd9Sstevel@tonic-gate 			"cannot expand string dump"));
886*7c478bd9Sstevel@tonic-gate 		cnamp = cnames;
887*7c478bd9Sstevel@tonic-gate 		used = 0;
888*7c478bd9Sstevel@tonic-gate 	}
889*7c478bd9Sstevel@tonic-gate 
890*7c478bd9Sstevel@tonic-gate 	temp = cnamp;
891*7c478bd9Sstevel@tonic-gate 	do {
892*7c478bd9Sstevel@tonic-gate 		*cnamp++ = *s;
893*7c478bd9Sstevel@tonic-gate 	} while (*s++);
894*7c478bd9Sstevel@tonic-gate 	used += cnamp - temp;
895*7c478bd9Sstevel@tonic-gate 	return (temp);
896*7c478bd9Sstevel@tonic-gate }
897*7c478bd9Sstevel@tonic-gate 
898*7c478bd9Sstevel@tonic-gate static int
899*7c478bd9Sstevel@tonic-gate defin(t, s)
900*7c478bd9Sstevel@tonic-gate register wchar_t *s;
901*7c478bd9Sstevel@tonic-gate {
902*7c478bd9Sstevel@tonic-gate 	/* define s to be a terminal if t=0 or a nonterminal if t=1 */
903*7c478bd9Sstevel@tonic-gate 
904*7c478bd9Sstevel@tonic-gate 	register val;
905*7c478bd9Sstevel@tonic-gate 
906*7c478bd9Sstevel@tonic-gate 	if (t) {
907*7c478bd9Sstevel@tonic-gate 		if (++nnonter >= nnontersz)
908*7c478bd9Sstevel@tonic-gate 			exp_nonterm();
909*7c478bd9Sstevel@tonic-gate 		nontrst[nnonter].name = cstash(s);
910*7c478bd9Sstevel@tonic-gate 		return (NTBASE + nnonter);
911*7c478bd9Sstevel@tonic-gate 		}
912*7c478bd9Sstevel@tonic-gate 	/* must be a token */
913*7c478bd9Sstevel@tonic-gate 	if (++ntokens >= ntoksz)
914*7c478bd9Sstevel@tonic-gate 		exp_ntok();
915*7c478bd9Sstevel@tonic-gate 	tokset[ntokens].name = cstash(s);
916*7c478bd9Sstevel@tonic-gate 
917*7c478bd9Sstevel@tonic-gate 	/* establish value for token */
918*7c478bd9Sstevel@tonic-gate 
919*7c478bd9Sstevel@tonic-gate 	if (s[0] == L' ' && s[2] == 0) { /* single character literal */
920*7c478bd9Sstevel@tonic-gate 		val = findchtok(s[1]);
921*7c478bd9Sstevel@tonic-gate 	} else if (s[0] == L' ' && s[1] == L'\\') { /* escape sequence */
922*7c478bd9Sstevel@tonic-gate 		if (s[3] == 0) { /* single character escape sequence */
923*7c478bd9Sstevel@tonic-gate 			switch (s[2]) {
924*7c478bd9Sstevel@tonic-gate 				/* character which is escaped */
925*7c478bd9Sstevel@tonic-gate 			case L'a':
926*7c478bd9Sstevel@tonic-gate 				(void) warning(1, gettext(
927*7c478bd9Sstevel@tonic-gate /*
928*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
929*7c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
930*7c478bd9Sstevel@tonic-gate  *	Do not trasnlate ANSI C, \\a.
931*7c478bd9Sstevel@tonic-gate  */
932*7c478bd9Sstevel@tonic-gate 		"\\a is ANSI C \"alert\" character"));
933*7c478bd9Sstevel@tonic-gate #if __STDC__ - 1 == 0
934*7c478bd9Sstevel@tonic-gate 				val = L'\a';
935*7c478bd9Sstevel@tonic-gate 				break;
936*7c478bd9Sstevel@tonic-gate #else
937*7c478bd9Sstevel@tonic-gate 				val = L'\007';
938*7c478bd9Sstevel@tonic-gate 				break;
939*7c478bd9Sstevel@tonic-gate #endif
940*7c478bd9Sstevel@tonic-gate 			case L'v': val = L'\v'; break;
941*7c478bd9Sstevel@tonic-gate 			case L'n': val = L'\n'; break;
942*7c478bd9Sstevel@tonic-gate 			case L'r': val = L'\r'; break;
943*7c478bd9Sstevel@tonic-gate 			case L'b': val = L'\b'; break;
944*7c478bd9Sstevel@tonic-gate 			case L't': val = L'\t'; break;
945*7c478bd9Sstevel@tonic-gate 			case L'f': val = L'\f'; break;
946*7c478bd9Sstevel@tonic-gate 			case L'\'': val = L'\''; break;
947*7c478bd9Sstevel@tonic-gate 			case L'"': val = L'"'; break;
948*7c478bd9Sstevel@tonic-gate 			case L'?': val = L'?'; break;
949*7c478bd9Sstevel@tonic-gate 			case L'\\': val = L'\\'; break;
950*7c478bd9Sstevel@tonic-gate /*
951*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
952*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
953*7c478bd9Sstevel@tonic-gate  */
954*7c478bd9Sstevel@tonic-gate 			default: error(gettext(
955*7c478bd9Sstevel@tonic-gate 				"invalid escape"));
956*7c478bd9Sstevel@tonic-gate 			}
957*7c478bd9Sstevel@tonic-gate 		} else if (s[2] <= L'7' && s[2] >= L'0') { /* \nnn sequence */
958*7c478bd9Sstevel@tonic-gate 			int i = 3;
959*7c478bd9Sstevel@tonic-gate 			val = s[2] - L'0';
960*7c478bd9Sstevel@tonic-gate 			while (iswdigit(s[i]) && i <= 4) {
961*7c478bd9Sstevel@tonic-gate 				if (s[i] >= L'0' && s[i] <= L'7')
962*7c478bd9Sstevel@tonic-gate 					val = val * 8 + s[i] - L'0';
963*7c478bd9Sstevel@tonic-gate 				else
964*7c478bd9Sstevel@tonic-gate /*
965*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
966*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
967*7c478bd9Sstevel@tonic-gate  */
968*7c478bd9Sstevel@tonic-gate 					error(gettext(
969*7c478bd9Sstevel@tonic-gate 					"illegal octal number"));
970*7c478bd9Sstevel@tonic-gate 				i++;
971*7c478bd9Sstevel@tonic-gate 			}
972*7c478bd9Sstevel@tonic-gate 			if (s[i] != 0)
973*7c478bd9Sstevel@tonic-gate /*
974*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
975*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
976*7c478bd9Sstevel@tonic-gate  *	Do not translate \\nnn.
977*7c478bd9Sstevel@tonic-gate  */
978*7c478bd9Sstevel@tonic-gate 				error(gettext(
979*7c478bd9Sstevel@tonic-gate 				"illegal \\nnn construction"));
980*7c478bd9Sstevel@tonic-gate 			if (val > 255)
981*7c478bd9Sstevel@tonic-gate /*
982*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
983*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
984*7c478bd9Sstevel@tonic-gate  *	Do not translate
985*7c478bd9Sstevel@tonic-gate  *		\\nnn, \\xnnnnnnnn.
986*7c478bd9Sstevel@tonic-gate  */
987*7c478bd9Sstevel@tonic-gate 				error(
988*7c478bd9Sstevel@tonic-gate "\\nnn exceed \\377; use \\xnnnnnnnn for wchar_t value of multibyte char");
989*7c478bd9Sstevel@tonic-gate 			if (val == 0 && i >= 4)
990*7c478bd9Sstevel@tonic-gate /*
991*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
992*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
993*7c478bd9Sstevel@tonic-gate  *	Do not translate \\000.
994*7c478bd9Sstevel@tonic-gate  */
995*7c478bd9Sstevel@tonic-gate 				error(gettext(
996*7c478bd9Sstevel@tonic-gate 				"'\\000' is illegal"));
997*7c478bd9Sstevel@tonic-gate 		} else if (s[2] == L'x') { /* hexadecimal \xnnn sequence */
998*7c478bd9Sstevel@tonic-gate 			int i = 3;
999*7c478bd9Sstevel@tonic-gate 			val = 0;
1000*7c478bd9Sstevel@tonic-gate /*
1001*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1002*7c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
1003*7c478bd9Sstevel@tonic-gate  *	Do not translate \\x, ANSI C.
1004*7c478bd9Sstevel@tonic-gate  */
1005*7c478bd9Sstevel@tonic-gate 			(void) warning(1, gettext(
1006*7c478bd9Sstevel@tonic-gate 				"\\x is ANSI C hex escape"));
1007*7c478bd9Sstevel@tonic-gate 			if (iswxdigit(s[i]))
1008*7c478bd9Sstevel@tonic-gate 				while (iswxdigit(s[i])) {
1009*7c478bd9Sstevel@tonic-gate 					int tmpval;
1010*7c478bd9Sstevel@tonic-gate 					if (iswdigit(s[i]))
1011*7c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'0';
1012*7c478bd9Sstevel@tonic-gate 					else if (s[i] >= L'a')
1013*7c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'a' + 10;
1014*7c478bd9Sstevel@tonic-gate 					else
1015*7c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'A' + 10;
1016*7c478bd9Sstevel@tonic-gate 					val = 16 * val + tmpval;
1017*7c478bd9Sstevel@tonic-gate 					i++;
1018*7c478bd9Sstevel@tonic-gate 				}
1019*7c478bd9Sstevel@tonic-gate 			else
1020*7c478bd9Sstevel@tonic-gate 				error(gettext(
1021*7c478bd9Sstevel@tonic-gate 				"illegal hexadecimal number"));
1022*7c478bd9Sstevel@tonic-gate 			if (s[i] != 0)
1023*7c478bd9Sstevel@tonic-gate /*
1024*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1025*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1026*7c478bd9Sstevel@tonic-gate  *	Do not translate \\xnn.
1027*7c478bd9Sstevel@tonic-gate  */
1028*7c478bd9Sstevel@tonic-gate 				error(gettext(
1029*7c478bd9Sstevel@tonic-gate 				"illegal \\xnn construction"));
1030*7c478bd9Sstevel@tonic-gate #define	LWCHAR_MAX	0x7fffffff
1031*7c478bd9Sstevel@tonic-gate 			if ((unsigned)val > LWCHAR_MAX)
1032*7c478bd9Sstevel@tonic-gate /*
1033*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1034*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1035*7c478bd9Sstevel@tonic-gate  *	Do not translate \\xnnnnnnnn and %#x.
1036*7c478bd9Sstevel@tonic-gate  */
1037*7c478bd9Sstevel@tonic-gate 			    error(gettext(
1038*7c478bd9Sstevel@tonic-gate 			    " \\xnnnnnnnn exceed %#x"),
1039*7c478bd9Sstevel@tonic-gate 			    LWCHAR_MAX);
1040*7c478bd9Sstevel@tonic-gate 			if (val == 0)
1041*7c478bd9Sstevel@tonic-gate /*
1042*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1043*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1044*7c478bd9Sstevel@tonic-gate  *	Do not translate \\x00.
1045*7c478bd9Sstevel@tonic-gate  */
1046*7c478bd9Sstevel@tonic-gate 				error(gettext(
1047*7c478bd9Sstevel@tonic-gate 				"'\\x00' is illegal"));
1048*7c478bd9Sstevel@tonic-gate 			val = findchtok(val);
1049*7c478bd9Sstevel@tonic-gate 		} else
1050*7c478bd9Sstevel@tonic-gate 			error(gettext(
1051*7c478bd9Sstevel@tonic-gate 			"invalid escape"));
1052*7c478bd9Sstevel@tonic-gate 	} else {
1053*7c478bd9Sstevel@tonic-gate 		val = extval++;
1054*7c478bd9Sstevel@tonic-gate 	}
1055*7c478bd9Sstevel@tonic-gate 	tokset[ntokens].value = val;
1056*7c478bd9Sstevel@tonic-gate 	toklev[ntokens] = 0;
1057*7c478bd9Sstevel@tonic-gate 	return (ntokens);
1058*7c478bd9Sstevel@tonic-gate }
1059*7c478bd9Sstevel@tonic-gate 
1060*7c478bd9Sstevel@tonic-gate static void
1061*7c478bd9Sstevel@tonic-gate defout()
1062*7c478bd9Sstevel@tonic-gate {
1063*7c478bd9Sstevel@tonic-gate 	/* write out the defines (at the end of the declaration section) */
1064*7c478bd9Sstevel@tonic-gate 
1065*7c478bd9Sstevel@tonic-gate 	register int i, c;
1066*7c478bd9Sstevel@tonic-gate 	register wchar_t *cp;
1067*7c478bd9Sstevel@tonic-gate 
1068*7c478bd9Sstevel@tonic-gate 	for (i = ndefout; i <= ntokens; ++i) {
1069*7c478bd9Sstevel@tonic-gate 
1070*7c478bd9Sstevel@tonic-gate 		cp = tokset[i].name;
1071*7c478bd9Sstevel@tonic-gate 		if (*cp == L' ')	/* literals */
1072*7c478bd9Sstevel@tonic-gate 		{
1073*7c478bd9Sstevel@tonic-gate 			(void) fprintf(fdebug, "\t\"%ws\",\t%d,\n",
1074*7c478bd9Sstevel@tonic-gate 				tokset[i].name + 1, tokset[i].value);
1075*7c478bd9Sstevel@tonic-gate 			continue;	/* was cp++ */
1076*7c478bd9Sstevel@tonic-gate 		}
1077*7c478bd9Sstevel@tonic-gate 
1078*7c478bd9Sstevel@tonic-gate 		for (; (c = *cp) != 0; ++cp) {
1079*7c478bd9Sstevel@tonic-gate 			if (iswlower(c) || iswupper(c) ||
1080*7c478bd9Sstevel@tonic-gate 				iswdigit(c) || c == L'_') /* EMPTY */;
1081*7c478bd9Sstevel@tonic-gate 			else
1082*7c478bd9Sstevel@tonic-gate 				goto nodef;
1083*7c478bd9Sstevel@tonic-gate 			}
1084*7c478bd9Sstevel@tonic-gate 
1085*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fdebug,
1086*7c478bd9Sstevel@tonic-gate 			"\t\"%ws\",\t%d,\n", tokset[i].name,
1087*7c478bd9Sstevel@tonic-gate 			tokset[i].value);
1088*7c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable,
1089*7c478bd9Sstevel@tonic-gate 			"# define %ws %d\n", tokset[i].name,
1090*7c478bd9Sstevel@tonic-gate 			tokset[i].value);
1091*7c478bd9Sstevel@tonic-gate 		if (fdefine != NULL)
1092*7c478bd9Sstevel@tonic-gate 			(void) fprintf(fdefine,
1093*7c478bd9Sstevel@tonic-gate 				"# define %ws %d\n",
1094*7c478bd9Sstevel@tonic-gate 				tokset[i].name,
1095*7c478bd9Sstevel@tonic-gate 				tokset[i].value);
1096*7c478bd9Sstevel@tonic-gate 
1097*7c478bd9Sstevel@tonic-gate 	nodef:;
1098*7c478bd9Sstevel@tonic-gate 	}
1099*7c478bd9Sstevel@tonic-gate 	ndefout = ntokens+1;
1100*7c478bd9Sstevel@tonic-gate }
1101*7c478bd9Sstevel@tonic-gate 
1102*7c478bd9Sstevel@tonic-gate static
1103*7c478bd9Sstevel@tonic-gate gettok()
1104*7c478bd9Sstevel@tonic-gate {
1105*7c478bd9Sstevel@tonic-gate 	register i, base;
1106*7c478bd9Sstevel@tonic-gate 	static int peekline; /* number of '\n' seen in lookahead */
1107*7c478bd9Sstevel@tonic-gate 	register c, match, reserve;
1108*7c478bd9Sstevel@tonic-gate begin:
1109*7c478bd9Sstevel@tonic-gate 	reserve = 0;
1110*7c478bd9Sstevel@tonic-gate 	lineno += peekline;
1111*7c478bd9Sstevel@tonic-gate 	peekline = 0;
1112*7c478bd9Sstevel@tonic-gate 	c = getwc(finput);
1113*7c478bd9Sstevel@tonic-gate 	/*
1114*7c478bd9Sstevel@tonic-gate 	 * while (c == ' ' || c == '\n' || c == '\t' || c == '\f') {
1115*7c478bd9Sstevel@tonic-gate 	 */
1116*7c478bd9Sstevel@tonic-gate 	while (iswspace(c)) {
1117*7c478bd9Sstevel@tonic-gate 		if (c == L'\n')
1118*7c478bd9Sstevel@tonic-gate 			++lineno;
1119*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1120*7c478bd9Sstevel@tonic-gate 	}
1121*7c478bd9Sstevel@tonic-gate 	if (c == L'/') { /* skip comment */
1122*7c478bd9Sstevel@tonic-gate 		lineno += skipcom();
1123*7c478bd9Sstevel@tonic-gate 		goto begin;
1124*7c478bd9Sstevel@tonic-gate 	}
1125*7c478bd9Sstevel@tonic-gate 
1126*7c478bd9Sstevel@tonic-gate 	switch (c) {
1127*7c478bd9Sstevel@tonic-gate 
1128*7c478bd9Sstevel@tonic-gate 	case EOF:
1129*7c478bd9Sstevel@tonic-gate 		return (ENDFILE);
1130*7c478bd9Sstevel@tonic-gate 	case L'{':
1131*7c478bd9Sstevel@tonic-gate 		(void) ungetwc(c, finput);
1132*7c478bd9Sstevel@tonic-gate 		return (L'=');  /* action ... */
1133*7c478bd9Sstevel@tonic-gate 	case L'<':  /* get, and look up, a type name (union member name) */
1134*7c478bd9Sstevel@tonic-gate 		i = 0;
1135*7c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != L'>' &&
1136*7c478bd9Sstevel@tonic-gate 				c != EOF && c != L'\n') {
1137*7c478bd9Sstevel@tonic-gate 			tokname[i] = c;
1138*7c478bd9Sstevel@tonic-gate 			if (++i >= toksize)
1139*7c478bd9Sstevel@tonic-gate 				exp_tokname();
1140*7c478bd9Sstevel@tonic-gate 			}
1141*7c478bd9Sstevel@tonic-gate 		if (c != L'>')
1142*7c478bd9Sstevel@tonic-gate 			error(gettext(
1143*7c478bd9Sstevel@tonic-gate 			"unterminated < ... > clause"));
1144*7c478bd9Sstevel@tonic-gate 		tokname[i] = 0;
1145*7c478bd9Sstevel@tonic-gate 		if (i == 0)
1146*7c478bd9Sstevel@tonic-gate 			error("missing type name in < ... > clause");
1147*7c478bd9Sstevel@tonic-gate 		for (i = 1; i <= ntypes; ++i) {
1148*7c478bd9Sstevel@tonic-gate 			if (!wscmp(typeset[i], tokname)) {
1149*7c478bd9Sstevel@tonic-gate 				numbval = i;
1150*7c478bd9Sstevel@tonic-gate 				return (TYPENAME);
1151*7c478bd9Sstevel@tonic-gate 				}
1152*7c478bd9Sstevel@tonic-gate 			}
1153*7c478bd9Sstevel@tonic-gate 		typeset[numbval = ++ntypes] = cstash(tokname);
1154*7c478bd9Sstevel@tonic-gate 		return (TYPENAME);
1155*7c478bd9Sstevel@tonic-gate 
1156*7c478bd9Sstevel@tonic-gate 	case L'"':
1157*7c478bd9Sstevel@tonic-gate 	case L'\'':
1158*7c478bd9Sstevel@tonic-gate 		match = c;
1159*7c478bd9Sstevel@tonic-gate 		tokname[0] = L' ';
1160*7c478bd9Sstevel@tonic-gate 		i = 1;
1161*7c478bd9Sstevel@tonic-gate 		for (;;) {
1162*7c478bd9Sstevel@tonic-gate 			c = getwc(finput);
1163*7c478bd9Sstevel@tonic-gate 			if (c == L'\n' || c == EOF)
1164*7c478bd9Sstevel@tonic-gate 				error(gettext(
1165*7c478bd9Sstevel@tonic-gate 				"illegal or missing ' or \""));
1166*7c478bd9Sstevel@tonic-gate 			if (c == L'\\') {
1167*7c478bd9Sstevel@tonic-gate 				c = getwc(finput);
1168*7c478bd9Sstevel@tonic-gate 				tokname[i] = L'\\';
1169*7c478bd9Sstevel@tonic-gate 				if (++i >= toksize)
1170*7c478bd9Sstevel@tonic-gate 					exp_tokname();
1171*7c478bd9Sstevel@tonic-gate 			} else if (c == match) break;
1172*7c478bd9Sstevel@tonic-gate 			tokname[i] = c;
1173*7c478bd9Sstevel@tonic-gate 			if (++i >= toksize)
1174*7c478bd9Sstevel@tonic-gate 				exp_tokname();
1175*7c478bd9Sstevel@tonic-gate 			}
1176*7c478bd9Sstevel@tonic-gate 		break;
1177*7c478bd9Sstevel@tonic-gate 
1178*7c478bd9Sstevel@tonic-gate 	case L'%':
1179*7c478bd9Sstevel@tonic-gate 	case L'\\':
1180*7c478bd9Sstevel@tonic-gate 
1181*7c478bd9Sstevel@tonic-gate 		switch (c = getwc(finput)) {
1182*7c478bd9Sstevel@tonic-gate 
1183*7c478bd9Sstevel@tonic-gate 		case L'0':	return (TERM);
1184*7c478bd9Sstevel@tonic-gate 		case L'<':	return (LEFT);
1185*7c478bd9Sstevel@tonic-gate 		case L'2':	return (BINARY);
1186*7c478bd9Sstevel@tonic-gate 		case L'>':	return (RIGHT);
1187*7c478bd9Sstevel@tonic-gate 		case L'%':
1188*7c478bd9Sstevel@tonic-gate 		case L'\\':	return (MARK);
1189*7c478bd9Sstevel@tonic-gate 		case L'=':	return (PREC);
1190*7c478bd9Sstevel@tonic-gate 		case L'{':	return (LCURLY);
1191*7c478bd9Sstevel@tonic-gate 		default:	reserve = 1;
1192*7c478bd9Sstevel@tonic-gate 			}
1193*7c478bd9Sstevel@tonic-gate 
1194*7c478bd9Sstevel@tonic-gate 	default:
1195*7c478bd9Sstevel@tonic-gate 
1196*7c478bd9Sstevel@tonic-gate 		if (iswdigit(c)) { /* number */
1197*7c478bd9Sstevel@tonic-gate 			numbval = c - L'0';
1198*7c478bd9Sstevel@tonic-gate 			base = (c == L'0') ? 8 : 10;
1199*7c478bd9Sstevel@tonic-gate 			for (c = getwc(finput);
1200*7c478bd9Sstevel@tonic-gate 					iswdigit(c);
1201*7c478bd9Sstevel@tonic-gate 					c = getwc(finput)) {
1202*7c478bd9Sstevel@tonic-gate 				numbval = numbval*base + c - L'0';
1203*7c478bd9Sstevel@tonic-gate 				}
1204*7c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
1205*7c478bd9Sstevel@tonic-gate 			return (NUMBER);
1206*7c478bd9Sstevel@tonic-gate 		} else if (iswlower(c) || iswupper(c) ||
1207*7c478bd9Sstevel@tonic-gate 				c == L'_' || c == L'.' ||
1208*7c478bd9Sstevel@tonic-gate 				c == L'$') {
1209*7c478bd9Sstevel@tonic-gate 			i = 0;
1210*7c478bd9Sstevel@tonic-gate 			while (iswlower(c) || iswupper(c) ||
1211*7c478bd9Sstevel@tonic-gate 					iswdigit(c) || c == L'_' ||
1212*7c478bd9Sstevel@tonic-gate 					c == L'.' || c == L'$') {
1213*7c478bd9Sstevel@tonic-gate 				tokname[i] = c;
1214*7c478bd9Sstevel@tonic-gate 				if (reserve && iswupper(c))
1215*7c478bd9Sstevel@tonic-gate 					tokname[i] = towlower(c);
1216*7c478bd9Sstevel@tonic-gate 				if (++i >= toksize)
1217*7c478bd9Sstevel@tonic-gate 					exp_tokname();
1218*7c478bd9Sstevel@tonic-gate 				c = getwc(finput);
1219*7c478bd9Sstevel@tonic-gate 				}
1220*7c478bd9Sstevel@tonic-gate 			}
1221*7c478bd9Sstevel@tonic-gate 		else
1222*7c478bd9Sstevel@tonic-gate 			return (c);
1223*7c478bd9Sstevel@tonic-gate 
1224*7c478bd9Sstevel@tonic-gate 		(void) ungetwc(c, finput);
1225*7c478bd9Sstevel@tonic-gate 		}
1226*7c478bd9Sstevel@tonic-gate 
1227*7c478bd9Sstevel@tonic-gate 	tokname[i] = 0;
1228*7c478bd9Sstevel@tonic-gate 
1229*7c478bd9Sstevel@tonic-gate 	if (reserve) { /* find a reserved word */
1230*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"term"))
1231*7c478bd9Sstevel@tonic-gate 			return (TERM);
1232*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"token"))
1233*7c478bd9Sstevel@tonic-gate 			return (TERM);
1234*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"left"))
1235*7c478bd9Sstevel@tonic-gate 			return (LEFT);
1236*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"nonassoc"))
1237*7c478bd9Sstevel@tonic-gate 			return (BINARY);
1238*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"binary"))
1239*7c478bd9Sstevel@tonic-gate 			return (BINARY);
1240*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"right"))
1241*7c478bd9Sstevel@tonic-gate 			return (RIGHT);
1242*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"prec"))
1243*7c478bd9Sstevel@tonic-gate 			return (PREC);
1244*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"start"))
1245*7c478bd9Sstevel@tonic-gate 			return (START);
1246*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"type"))
1247*7c478bd9Sstevel@tonic-gate 			return (TYPEDEF);
1248*7c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"union"))
1249*7c478bd9Sstevel@tonic-gate 			return (UNION);
1250*7c478bd9Sstevel@tonic-gate 		error(gettext(
1251*7c478bd9Sstevel@tonic-gate 		"invalid escape, or illegal reserved word: %ws"),
1252*7c478bd9Sstevel@tonic-gate 		tokname);
1253*7c478bd9Sstevel@tonic-gate 		}
1254*7c478bd9Sstevel@tonic-gate 
1255*7c478bd9Sstevel@tonic-gate 	/* look ahead to distinguish IDENTIFIER from C_IDENTIFIER */
1256*7c478bd9Sstevel@tonic-gate 
1257*7c478bd9Sstevel@tonic-gate 	c = getwc(finput);
1258*7c478bd9Sstevel@tonic-gate 	/*
1259*7c478bd9Sstevel@tonic-gate 	 * while (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '/')
1260*7c478bd9Sstevel@tonic-gate 	 * {
1261*7c478bd9Sstevel@tonic-gate 	 */
1262*7c478bd9Sstevel@tonic-gate 	while (iswspace(c) || c == L'/') {
1263*7c478bd9Sstevel@tonic-gate 		if (c == L'\n') {
1264*7c478bd9Sstevel@tonic-gate 			++peekline;
1265*7c478bd9Sstevel@tonic-gate 		} else if (c == L'/') { /* look for comments */
1266*7c478bd9Sstevel@tonic-gate 			peekline += skipcom();
1267*7c478bd9Sstevel@tonic-gate 			}
1268*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1269*7c478bd9Sstevel@tonic-gate 		}
1270*7c478bd9Sstevel@tonic-gate 	if (c == L':')
1271*7c478bd9Sstevel@tonic-gate 		return (C_IDENTIFIER);
1272*7c478bd9Sstevel@tonic-gate 	(void) ungetwc(c, finput);
1273*7c478bd9Sstevel@tonic-gate 	return (IDENTIFIER);
1274*7c478bd9Sstevel@tonic-gate }
1275*7c478bd9Sstevel@tonic-gate 
1276*7c478bd9Sstevel@tonic-gate static
1277*7c478bd9Sstevel@tonic-gate fdtype(t)
1278*7c478bd9Sstevel@tonic-gate {
1279*7c478bd9Sstevel@tonic-gate 	/* determine the type of a symbol */
1280*7c478bd9Sstevel@tonic-gate 	register v;
1281*7c478bd9Sstevel@tonic-gate 	if (t >= NTBASE)
1282*7c478bd9Sstevel@tonic-gate 		v = nontrst[t-NTBASE].tvalue;
1283*7c478bd9Sstevel@tonic-gate 	else
1284*7c478bd9Sstevel@tonic-gate 		v = TYPE(toklev[t]);
1285*7c478bd9Sstevel@tonic-gate 	if (v <= 0)
1286*7c478bd9Sstevel@tonic-gate 		error(gettext(
1287*7c478bd9Sstevel@tonic-gate 			"must specify type for %ws"),
1288*7c478bd9Sstevel@tonic-gate 			(t >= NTBASE) ? nontrst[t-NTBASE].name:
1289*7c478bd9Sstevel@tonic-gate 			tokset[t].name);
1290*7c478bd9Sstevel@tonic-gate 	return (v);
1291*7c478bd9Sstevel@tonic-gate }
1292*7c478bd9Sstevel@tonic-gate 
1293*7c478bd9Sstevel@tonic-gate static
1294*7c478bd9Sstevel@tonic-gate chfind(t, s)
1295*7c478bd9Sstevel@tonic-gate register wchar_t *s;
1296*7c478bd9Sstevel@tonic-gate {
1297*7c478bd9Sstevel@tonic-gate 	int i;
1298*7c478bd9Sstevel@tonic-gate 
1299*7c478bd9Sstevel@tonic-gate 	if (s[0] == ' ')
1300*7c478bd9Sstevel@tonic-gate 		t = 0;
1301*7c478bd9Sstevel@tonic-gate 	TLOOP(i) {
1302*7c478bd9Sstevel@tonic-gate 		if (!wscmp(s, tokset[i].name)) {
1303*7c478bd9Sstevel@tonic-gate 			return (i);
1304*7c478bd9Sstevel@tonic-gate 		}
1305*7c478bd9Sstevel@tonic-gate 	}
1306*7c478bd9Sstevel@tonic-gate 	NTLOOP(i) {
1307*7c478bd9Sstevel@tonic-gate 		if (!wscmp(s, nontrst[i].name)) {
1308*7c478bd9Sstevel@tonic-gate 			return (i + NTBASE);
1309*7c478bd9Sstevel@tonic-gate 		}
1310*7c478bd9Sstevel@tonic-gate 	}
1311*7c478bd9Sstevel@tonic-gate 	/* cannot find name */
1312*7c478bd9Sstevel@tonic-gate 	if (t > 1)
1313*7c478bd9Sstevel@tonic-gate 		error(gettext(
1314*7c478bd9Sstevel@tonic-gate 		"%ws should have been defined earlier"), s);
1315*7c478bd9Sstevel@tonic-gate 	return (defin(t, s));
1316*7c478bd9Sstevel@tonic-gate }
1317*7c478bd9Sstevel@tonic-gate 
1318*7c478bd9Sstevel@tonic-gate static void
1319*7c478bd9Sstevel@tonic-gate cpyunion()
1320*7c478bd9Sstevel@tonic-gate {
1321*7c478bd9Sstevel@tonic-gate 	/*
1322*7c478bd9Sstevel@tonic-gate 	 * copy the union declaration to the output,
1323*7c478bd9Sstevel@tonic-gate 	 * and the define file if present
1324*7c478bd9Sstevel@tonic-gate 	 */
1325*7c478bd9Sstevel@tonic-gate 	int level, c;
1326*7c478bd9Sstevel@tonic-gate 	if (gen_lines)
1327*7c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
1328*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "typedef union\n");
1329*7c478bd9Sstevel@tonic-gate 	if (fdefine)
1330*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fdefine, "\ntypedef union\n");
1331*7c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
1332*7c478bd9Sstevel@tonic-gate 	if (fdefine)
1333*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fdefine,
1334*7c478bd9Sstevel@tonic-gate 			"#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
1335*7c478bd9Sstevel@tonic-gate 
1336*7c478bd9Sstevel@tonic-gate 	level = 0;
1337*7c478bd9Sstevel@tonic-gate 	for (;;) {
1338*7c478bd9Sstevel@tonic-gate 		if ((c = getwc(finput)) == EOF)
1339*7c478bd9Sstevel@tonic-gate /*
1340*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1341*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1342*7c478bd9Sstevel@tonic-gate  *	EOF - End Of File.
1343*7c478bd9Sstevel@tonic-gate  *	Do not translate %%union.
1344*7c478bd9Sstevel@tonic-gate  */
1345*7c478bd9Sstevel@tonic-gate 			error(gettext(
1346*7c478bd9Sstevel@tonic-gate 			"EOF encountered while processing %%union"));
1347*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, ftable);
1348*7c478bd9Sstevel@tonic-gate 		if (fdefine)
1349*7c478bd9Sstevel@tonic-gate 			(void) putwc(c, fdefine);
1350*7c478bd9Sstevel@tonic-gate 
1351*7c478bd9Sstevel@tonic-gate 		switch (c) {
1352*7c478bd9Sstevel@tonic-gate 
1353*7c478bd9Sstevel@tonic-gate 		case L'\n':
1354*7c478bd9Sstevel@tonic-gate 			++lineno;
1355*7c478bd9Sstevel@tonic-gate 			break;
1356*7c478bd9Sstevel@tonic-gate 
1357*7c478bd9Sstevel@tonic-gate 		case L'{':
1358*7c478bd9Sstevel@tonic-gate 			++level;
1359*7c478bd9Sstevel@tonic-gate 			break;
1360*7c478bd9Sstevel@tonic-gate 
1361*7c478bd9Sstevel@tonic-gate 		case L'}':
1362*7c478bd9Sstevel@tonic-gate 			--level;
1363*7c478bd9Sstevel@tonic-gate 			if (level == 0) { /* we are finished copying */
1364*7c478bd9Sstevel@tonic-gate 				(void) fprintf(ftable, " YYSTYPE;\n");
1365*7c478bd9Sstevel@tonic-gate 				if (fdefine)
1366*7c478bd9Sstevel@tonic-gate 					(void) fprintf(fdefine,
1367*7c478bd9Sstevel@tonic-gate 					" YYSTYPE;\nextern YYSTYPE yylval;\n");
1368*7c478bd9Sstevel@tonic-gate 				return;
1369*7c478bd9Sstevel@tonic-gate 				}
1370*7c478bd9Sstevel@tonic-gate 			}
1371*7c478bd9Sstevel@tonic-gate 		}
1372*7c478bd9Sstevel@tonic-gate }
1373*7c478bd9Sstevel@tonic-gate 
1374*7c478bd9Sstevel@tonic-gate static void
1375*7c478bd9Sstevel@tonic-gate cpycode()
1376*7c478bd9Sstevel@tonic-gate {
1377*7c478bd9Sstevel@tonic-gate 	/* copies code between \{ and \} */
1378*7c478bd9Sstevel@tonic-gate 
1379*7c478bd9Sstevel@tonic-gate 	int c;
1380*7c478bd9Sstevel@tonic-gate 	c = getwc(finput);
1381*7c478bd9Sstevel@tonic-gate 	if (c == L'\n') {
1382*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1383*7c478bd9Sstevel@tonic-gate 		lineno++;
1384*7c478bd9Sstevel@tonic-gate 		}
1385*7c478bd9Sstevel@tonic-gate 	if (gen_lines)
1386*7c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
1387*7c478bd9Sstevel@tonic-gate 	while (c != EOF) {
1388*7c478bd9Sstevel@tonic-gate 		if (c == L'\\') {
1389*7c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'}')
1390*7c478bd9Sstevel@tonic-gate 				return;
1391*7c478bd9Sstevel@tonic-gate 			else
1392*7c478bd9Sstevel@tonic-gate 				(void) putwc(L'\\', ftable);
1393*7c478bd9Sstevel@tonic-gate 		} else if (c == L'%') {
1394*7c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'}')
1395*7c478bd9Sstevel@tonic-gate 				return;
1396*7c478bd9Sstevel@tonic-gate 			else
1397*7c478bd9Sstevel@tonic-gate 				(void) putwc(L'%', ftable);
1398*7c478bd9Sstevel@tonic-gate 		}
1399*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, ftable);
1400*7c478bd9Sstevel@tonic-gate 		if (c == L'\n')
1401*7c478bd9Sstevel@tonic-gate 			++lineno;
1402*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1403*7c478bd9Sstevel@tonic-gate 		}
1404*7c478bd9Sstevel@tonic-gate /*
1405*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1406*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1407*7c478bd9Sstevel@tonic-gate  *	Do not translate %%}.
1408*7c478bd9Sstevel@tonic-gate  */
1409*7c478bd9Sstevel@tonic-gate 	error(gettext(
1410*7c478bd9Sstevel@tonic-gate 	"eof before %%}"));
1411*7c478bd9Sstevel@tonic-gate }
1412*7c478bd9Sstevel@tonic-gate 
1413*7c478bd9Sstevel@tonic-gate static
1414*7c478bd9Sstevel@tonic-gate skipcom()
1415*7c478bd9Sstevel@tonic-gate {
1416*7c478bd9Sstevel@tonic-gate 	/* skip over comments */
1417*7c478bd9Sstevel@tonic-gate 	register c, i = 0;  /* i is the number of lines skipped */
1418*7c478bd9Sstevel@tonic-gate 
1419*7c478bd9Sstevel@tonic-gate 	/* skipcom is called after reading a / */
1420*7c478bd9Sstevel@tonic-gate 
1421*7c478bd9Sstevel@tonic-gate 	if (getwc(finput) != L'*')
1422*7c478bd9Sstevel@tonic-gate 		error(gettext(
1423*7c478bd9Sstevel@tonic-gate 		"illegal comment"));
1424*7c478bd9Sstevel@tonic-gate 	c = getwc(finput);
1425*7c478bd9Sstevel@tonic-gate 	while (c != EOF) {
1426*7c478bd9Sstevel@tonic-gate 		while (c == L'*') {
1427*7c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'/')
1428*7c478bd9Sstevel@tonic-gate 				return (i);
1429*7c478bd9Sstevel@tonic-gate 			}
1430*7c478bd9Sstevel@tonic-gate 		if (c == L'\n')
1431*7c478bd9Sstevel@tonic-gate 			++i;
1432*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1433*7c478bd9Sstevel@tonic-gate 		}
1434*7c478bd9Sstevel@tonic-gate /*
1435*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1436*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1437*7c478bd9Sstevel@tonic-gate  *	EOF -- End Of File.
1438*7c478bd9Sstevel@tonic-gate  */
1439*7c478bd9Sstevel@tonic-gate 	error(gettext(
1440*7c478bd9Sstevel@tonic-gate 	"EOF inside comment"));
1441*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
1442*7c478bd9Sstevel@tonic-gate }
1443*7c478bd9Sstevel@tonic-gate 
1444*7c478bd9Sstevel@tonic-gate static void
1445*7c478bd9Sstevel@tonic-gate cpyact(offset)
1446*7c478bd9Sstevel@tonic-gate {
1447*7c478bd9Sstevel@tonic-gate 	/* copy C action to the next ; or closing } */
1448*7c478bd9Sstevel@tonic-gate 	int brac, c, match, i, t, j, s, tok, argument, m;
1449*7c478bd9Sstevel@tonic-gate 	wchar_t id_name[NAMESIZE+1];
1450*7c478bd9Sstevel@tonic-gate 	int id_idx = 0;
1451*7c478bd9Sstevel@tonic-gate 
1452*7c478bd9Sstevel@tonic-gate 	if (gen_lines) {
1453*7c478bd9Sstevel@tonic-gate 		(void) fprintf(faction, "\n# line %d \"%s\"\n", lineno, infile);
1454*7c478bd9Sstevel@tonic-gate 		act_lines++;
1455*7c478bd9Sstevel@tonic-gate 	}
1456*7c478bd9Sstevel@tonic-gate 	brac = 0;
1457*7c478bd9Sstevel@tonic-gate 	id_name[0] = 0;
1458*7c478bd9Sstevel@tonic-gate loop:
1459*7c478bd9Sstevel@tonic-gate 	c = getwc(finput);
1460*7c478bd9Sstevel@tonic-gate swt:
1461*7c478bd9Sstevel@tonic-gate 	switch (c) {
1462*7c478bd9Sstevel@tonic-gate 	case L';':
1463*7c478bd9Sstevel@tonic-gate 		if (brac == 0) {
1464*7c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
1465*7c478bd9Sstevel@tonic-gate 			return;
1466*7c478bd9Sstevel@tonic-gate 		}
1467*7c478bd9Sstevel@tonic-gate 		goto lcopy;
1468*7c478bd9Sstevel@tonic-gate 	case L'{':
1469*7c478bd9Sstevel@tonic-gate 		brac++;
1470*7c478bd9Sstevel@tonic-gate 		goto lcopy;
1471*7c478bd9Sstevel@tonic-gate 	case L'$':
1472*7c478bd9Sstevel@tonic-gate 		s = 1;
1473*7c478bd9Sstevel@tonic-gate 		tok = -1;
1474*7c478bd9Sstevel@tonic-gate 		argument = 1;
1475*7c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) == L' ' || c == L'\t') /* EMPTY */;
1476*7c478bd9Sstevel@tonic-gate 		if (c == L'<') { /* type description */
1477*7c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
1478*7c478bd9Sstevel@tonic-gate 			if (gettok() != TYPENAME)
1479*7c478bd9Sstevel@tonic-gate /*
1480*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1481*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1482*7c478bd9Sstevel@tonic-gate  *	Do not translate $<ident>
1483*7c478bd9Sstevel@tonic-gate  */
1484*7c478bd9Sstevel@tonic-gate 				error(gettext(
1485*7c478bd9Sstevel@tonic-gate 				"bad syntax on $<ident> clause"));
1486*7c478bd9Sstevel@tonic-gate 			tok = numbval;
1487*7c478bd9Sstevel@tonic-gate 			c = getwc(finput);
1488*7c478bd9Sstevel@tonic-gate 		}
1489*7c478bd9Sstevel@tonic-gate 		if (c == L'$') {
1490*7c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "yyval");
1491*7c478bd9Sstevel@tonic-gate 			if (ntypes) { /* put out the proper tag... */
1492*7c478bd9Sstevel@tonic-gate 				if (tok < 0)
1493*7c478bd9Sstevel@tonic-gate 					tok = fdtype(*prdptr[nprod]);
1494*7c478bd9Sstevel@tonic-gate 				(void) fprintf(faction,
1495*7c478bd9Sstevel@tonic-gate 					".%ws", typeset[tok]);
1496*7c478bd9Sstevel@tonic-gate 			}
1497*7c478bd9Sstevel@tonic-gate 			goto loop;
1498*7c478bd9Sstevel@tonic-gate 		}
1499*7c478bd9Sstevel@tonic-gate 		if (iswalpha(c)) {
1500*7c478bd9Sstevel@tonic-gate 			int same = 0;
1501*7c478bd9Sstevel@tonic-gate 			int id_sw = 0;
1502*7c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
1503*7c478bd9Sstevel@tonic-gate 			if (gettok() != IDENTIFIER)
1504*7c478bd9Sstevel@tonic-gate /*
1505*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1506*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1507*7c478bd9Sstevel@tonic-gate  *	Check how action is translated in yacc man page/document.
1508*7c478bd9Sstevel@tonic-gate  */
1509*7c478bd9Sstevel@tonic-gate 				error(gettext(
1510*7c478bd9Sstevel@tonic-gate 				"bad action format"));
1511*7c478bd9Sstevel@tonic-gate 			/*
1512*7c478bd9Sstevel@tonic-gate 			 * Save the number of non-terminal
1513*7c478bd9Sstevel@tonic-gate 			 */
1514*7c478bd9Sstevel@tonic-gate 			id_sw = nnonter;
1515*7c478bd9Sstevel@tonic-gate 			t = chfind(1, tokname);
1516*7c478bd9Sstevel@tonic-gate 			/*
1517*7c478bd9Sstevel@tonic-gate 			 * Check if the identifier is added as a non-terminal
1518*7c478bd9Sstevel@tonic-gate 			 */
1519*7c478bd9Sstevel@tonic-gate 			if (id_sw != nnonter)
1520*7c478bd9Sstevel@tonic-gate 				id_sw = 1;
1521*7c478bd9Sstevel@tonic-gate 			else
1522*7c478bd9Sstevel@tonic-gate 				id_sw = 0;
1523*7c478bd9Sstevel@tonic-gate 			while ((c = getwc(finput)) == L' ' ||
1524*7c478bd9Sstevel@tonic-gate 				c == L'\t') /* EMPTY */;
1525*7c478bd9Sstevel@tonic-gate 			if (c == L'#') {
1526*7c478bd9Sstevel@tonic-gate 				while ((c = getwc(finput)) == L' ' ||
1527*7c478bd9Sstevel@tonic-gate 					c == L'\t') /* EMPTY */;
1528*7c478bd9Sstevel@tonic-gate 				if (iswdigit(c)) {
1529*7c478bd9Sstevel@tonic-gate 					m = 0;
1530*7c478bd9Sstevel@tonic-gate 					while (iswdigit(c)) {
1531*7c478bd9Sstevel@tonic-gate 						m = m*10+c-L'0';
1532*7c478bd9Sstevel@tonic-gate 						c = getwc(finput);
1533*7c478bd9Sstevel@tonic-gate 					}
1534*7c478bd9Sstevel@tonic-gate 					argument = m;
1535*7c478bd9Sstevel@tonic-gate 				} else
1536*7c478bd9Sstevel@tonic-gate 					error(gettext(
1537*7c478bd9Sstevel@tonic-gate 					"illegal character \"#\""));
1538*7c478bd9Sstevel@tonic-gate 			}
1539*7c478bd9Sstevel@tonic-gate 			if (argument < 1)
1540*7c478bd9Sstevel@tonic-gate /*
1541*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1542*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1543*7c478bd9Sstevel@tonic-gate  *	Check how action is translated in yacc man page/document.
1544*7c478bd9Sstevel@tonic-gate  */
1545*7c478bd9Sstevel@tonic-gate 				error(gettext(
1546*7c478bd9Sstevel@tonic-gate 				"illegal action argument no."));
1547*7c478bd9Sstevel@tonic-gate 			for (i = 1; i <= offset; ++i)
1548*7c478bd9Sstevel@tonic-gate 				if (prdptr[nprod][i] == t)
1549*7c478bd9Sstevel@tonic-gate 					if (++same == argument) {
1550*7c478bd9Sstevel@tonic-gate 						(void) fprintf(faction,
1551*7c478bd9Sstevel@tonic-gate 							"yypvt[-%d]", offset-i);
1552*7c478bd9Sstevel@tonic-gate 						if (ntypes) {
1553*7c478bd9Sstevel@tonic-gate 							if (tok < 0)
1554*7c478bd9Sstevel@tonic-gate 								tok =
1555*7c478bd9Sstevel@tonic-gate 								/* CSTYLED */
1556*7c478bd9Sstevel@tonic-gate 								fdtype(prdptr[nprod][i]);
1557*7c478bd9Sstevel@tonic-gate 							(void) fprintf(faction,
1558*7c478bd9Sstevel@tonic-gate 							".%ws", typeset[tok]);
1559*7c478bd9Sstevel@tonic-gate 						}
1560*7c478bd9Sstevel@tonic-gate 						goto swt;
1561*7c478bd9Sstevel@tonic-gate 					}
1562*7c478bd9Sstevel@tonic-gate 			/*
1563*7c478bd9Sstevel@tonic-gate 			 * This used to be handled as error.
1564*7c478bd9Sstevel@tonic-gate 			 * Treat this as a valid C statement.
1565*7c478bd9Sstevel@tonic-gate 			 * (Likely id with $ in.)
1566*7c478bd9Sstevel@tonic-gate 			 * If non-terminal is added, remove it from the list.
1567*7c478bd9Sstevel@tonic-gate 			 */
1568*7c478bd9Sstevel@tonic-gate 			fprintf(faction, "$%ws", tokname);
1569*7c478bd9Sstevel@tonic-gate /*
1570*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1571*7c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
1572*7c478bd9Sstevel@tonic-gate  *	Do not translate Ansi C.
1573*7c478bd9Sstevel@tonic-gate  */
1574*7c478bd9Sstevel@tonic-gate 			warning(1, gettext(
1575*7c478bd9Sstevel@tonic-gate 	"Illegal character '$' in Ansi C symbol: %ws$%ws."),
1576*7c478bd9Sstevel@tonic-gate 				id_name, tokname);
1577*7c478bd9Sstevel@tonic-gate 
1578*7c478bd9Sstevel@tonic-gate 			if (id_sw == 1)
1579*7c478bd9Sstevel@tonic-gate 				--nnonter;
1580*7c478bd9Sstevel@tonic-gate 			goto swt;
1581*7c478bd9Sstevel@tonic-gate 		}
1582*7c478bd9Sstevel@tonic-gate 		if (c == '-') {
1583*7c478bd9Sstevel@tonic-gate 			s = -s;
1584*7c478bd9Sstevel@tonic-gate 			c = getwc(finput);
1585*7c478bd9Sstevel@tonic-gate 		}
1586*7c478bd9Sstevel@tonic-gate 		if (iswdigit(c)) {
1587*7c478bd9Sstevel@tonic-gate 			j = 0;
1588*7c478bd9Sstevel@tonic-gate 			while (iswdigit(c)) {
1589*7c478bd9Sstevel@tonic-gate 				j = j*10 + c - L'0';
1590*7c478bd9Sstevel@tonic-gate 				c = getwc(finput);
1591*7c478bd9Sstevel@tonic-gate 			}
1592*7c478bd9Sstevel@tonic-gate 			j = j*s - offset;
1593*7c478bd9Sstevel@tonic-gate 			if (j > 0) {
1594*7c478bd9Sstevel@tonic-gate /*
1595*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1596*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1597*7c478bd9Sstevel@tonic-gate  *	Do not translate $%d.
1598*7c478bd9Sstevel@tonic-gate  */
1599*7c478bd9Sstevel@tonic-gate 				error(gettext(
1600*7c478bd9Sstevel@tonic-gate 				"Illegal use of $%d"),
1601*7c478bd9Sstevel@tonic-gate 				j + offset);
1602*7c478bd9Sstevel@tonic-gate 			}
1603*7c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "yypvt[-%d]", -j);
1604*7c478bd9Sstevel@tonic-gate 			if (ntypes) { /* put out the proper tag */
1605*7c478bd9Sstevel@tonic-gate 				if (j + offset <= 0 && tok < 0)
1606*7c478bd9Sstevel@tonic-gate /*
1607*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1608*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1609*7c478bd9Sstevel@tonic-gate  *	Do not translate $%d.
1610*7c478bd9Sstevel@tonic-gate  */
1611*7c478bd9Sstevel@tonic-gate 					error(gettext(
1612*7c478bd9Sstevel@tonic-gate 					"must specify type of $%d"),
1613*7c478bd9Sstevel@tonic-gate 					j + offset);
1614*7c478bd9Sstevel@tonic-gate 				if (tok < 0)
1615*7c478bd9Sstevel@tonic-gate 					tok = fdtype(prdptr[nprod][j+offset]);
1616*7c478bd9Sstevel@tonic-gate 				(void) fprintf(faction,
1617*7c478bd9Sstevel@tonic-gate 					".%ws", typeset[tok]);
1618*7c478bd9Sstevel@tonic-gate 			}
1619*7c478bd9Sstevel@tonic-gate 			goto swt;
1620*7c478bd9Sstevel@tonic-gate 		}
1621*7c478bd9Sstevel@tonic-gate 		(void) putwc(L'$', faction);
1622*7c478bd9Sstevel@tonic-gate 		if (s < 0)
1623*7c478bd9Sstevel@tonic-gate 			(void) putwc(L'-', faction);
1624*7c478bd9Sstevel@tonic-gate 		goto swt;
1625*7c478bd9Sstevel@tonic-gate 	case L'}':
1626*7c478bd9Sstevel@tonic-gate 		if (--brac)
1627*7c478bd9Sstevel@tonic-gate 			goto lcopy;
1628*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
1629*7c478bd9Sstevel@tonic-gate 		return;
1630*7c478bd9Sstevel@tonic-gate 	case L'/':	/* look for comments */
1631*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
1632*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1633*7c478bd9Sstevel@tonic-gate 		if (c != L'*')
1634*7c478bd9Sstevel@tonic-gate 			goto swt;
1635*7c478bd9Sstevel@tonic-gate 		/* it really is a comment */
1636*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
1637*7c478bd9Sstevel@tonic-gate 		c = getwc(finput);
1638*7c478bd9Sstevel@tonic-gate 		while (c != EOF) {
1639*7c478bd9Sstevel@tonic-gate 			while (c == L'*') {
1640*7c478bd9Sstevel@tonic-gate 				(void) putwc(c, faction);
1641*7c478bd9Sstevel@tonic-gate 				if ((c = getwc(finput)) == L'/')
1642*7c478bd9Sstevel@tonic-gate 					goto lcopy;
1643*7c478bd9Sstevel@tonic-gate 			}
1644*7c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
1645*7c478bd9Sstevel@tonic-gate 			if (c == L'\n')
1646*7c478bd9Sstevel@tonic-gate 				++lineno;
1647*7c478bd9Sstevel@tonic-gate 			c = getwc(finput);
1648*7c478bd9Sstevel@tonic-gate 		}
1649*7c478bd9Sstevel@tonic-gate 		error("EOF inside comment");
1650*7c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
1651*7c478bd9Sstevel@tonic-gate 	case L'\'':	/* character constant */
1652*7c478bd9Sstevel@tonic-gate 	case L'"':	/* character string */
1653*7c478bd9Sstevel@tonic-gate 		match = c;
1654*7c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
1655*7c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != EOF) {
1656*7c478bd9Sstevel@tonic-gate 			if (c == L'\\') {
1657*7c478bd9Sstevel@tonic-gate 				(void) putwc(c, faction);
1658*7c478bd9Sstevel@tonic-gate 				c = getwc(finput);
1659*7c478bd9Sstevel@tonic-gate 				if (c == L'\n')
1660*7c478bd9Sstevel@tonic-gate 					++lineno;
1661*7c478bd9Sstevel@tonic-gate 			} else if (c == match)
1662*7c478bd9Sstevel@tonic-gate 				goto lcopy;
1663*7c478bd9Sstevel@tonic-gate 			else if (c == L'\n')
1664*7c478bd9Sstevel@tonic-gate /*
1665*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1666*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1667*7c478bd9Sstevel@tonic-gate  *	This error message is issued when
1668*7c478bd9Sstevel@tonic-gate  *	quoted string has multiple lines.
1669*7c478bd9Sstevel@tonic-gate  */
1670*7c478bd9Sstevel@tonic-gate 				error(gettext(
1671*7c478bd9Sstevel@tonic-gate 				"newline in string or char. const."));
1672*7c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
1673*7c478bd9Sstevel@tonic-gate 		}
1674*7c478bd9Sstevel@tonic-gate 		error(gettext(
1675*7c478bd9Sstevel@tonic-gate 		"EOF in string or character constant"));
1676*7c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
1677*7c478bd9Sstevel@tonic-gate 	case EOF:
1678*7c478bd9Sstevel@tonic-gate /*
1679*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1680*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1681*7c478bd9Sstevel@tonic-gate  *	Check how 'action' is translated in yacc mapage/document.
1682*7c478bd9Sstevel@tonic-gate  */
1683*7c478bd9Sstevel@tonic-gate 		error(gettext(
1684*7c478bd9Sstevel@tonic-gate 		"action does not terminate"));
1685*7c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
1686*7c478bd9Sstevel@tonic-gate 	case L'\n':
1687*7c478bd9Sstevel@tonic-gate 		++lineno;
1688*7c478bd9Sstevel@tonic-gate 		goto lcopy;
1689*7c478bd9Sstevel@tonic-gate 	}
1690*7c478bd9Sstevel@tonic-gate lcopy:
1691*7c478bd9Sstevel@tonic-gate 	(void) putwc(c, faction);
1692*7c478bd9Sstevel@tonic-gate 	/*
1693*7c478bd9Sstevel@tonic-gate 	 * Save the possible identifier name.
1694*7c478bd9Sstevel@tonic-gate 	 * Used to print out a warning message.
1695*7c478bd9Sstevel@tonic-gate 	 */
1696*7c478bd9Sstevel@tonic-gate 	if (id_idx >= NAMESIZE) {
1697*7c478bd9Sstevel@tonic-gate 		/*
1698*7c478bd9Sstevel@tonic-gate 		 * Error. Silently ignore.
1699*7c478bd9Sstevel@tonic-gate 		 */
1700*7c478bd9Sstevel@tonic-gate 		;
1701*7c478bd9Sstevel@tonic-gate 	}
1702*7c478bd9Sstevel@tonic-gate 	/*
1703*7c478bd9Sstevel@tonic-gate 	 * If c has a possibility to be a
1704*7c478bd9Sstevel@tonic-gate 	 * part of identifier, save it.
1705*7c478bd9Sstevel@tonic-gate 	 */
1706*7c478bd9Sstevel@tonic-gate 	else if (iswalnum(c) || c == L'_') {
1707*7c478bd9Sstevel@tonic-gate 		id_name[id_idx++] = c;
1708*7c478bd9Sstevel@tonic-gate 		id_name[id_idx] = 0;
1709*7c478bd9Sstevel@tonic-gate 	} else {
1710*7c478bd9Sstevel@tonic-gate 		id_idx = 0;
1711*7c478bd9Sstevel@tonic-gate 		id_name[id_idx] = 0;
1712*7c478bd9Sstevel@tonic-gate 	}
1713*7c478bd9Sstevel@tonic-gate 	goto loop;
1714*7c478bd9Sstevel@tonic-gate }
1715*7c478bd9Sstevel@tonic-gate 
1716*7c478bd9Sstevel@tonic-gate static void
1717*7c478bd9Sstevel@tonic-gate lhsfill(s)	/* new rule, dump old (if exists), restart strings */
1718*7c478bd9Sstevel@tonic-gate wchar_t *s;
1719*7c478bd9Sstevel@tonic-gate {
1720*7c478bd9Sstevel@tonic-gate 	static int lhs_len = LHS_TEXT_LEN;
1721*7c478bd9Sstevel@tonic-gate 	int s_lhs = wslen(s);
1722*7c478bd9Sstevel@tonic-gate 	if (s_lhs >= lhs_len) {
1723*7c478bd9Sstevel@tonic-gate 		lhs_len = s_lhs + 2;
1724*7c478bd9Sstevel@tonic-gate 		lhstext = (wchar_t *)
1725*7c478bd9Sstevel@tonic-gate 			realloc((char *)lhstext, sizeof (wchar_t)*lhs_len);
1726*7c478bd9Sstevel@tonic-gate 		if (lhstext == NULL)
1727*7c478bd9Sstevel@tonic-gate /*
1728*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1729*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1730*7c478bd9Sstevel@tonic-gate  *	LHS -- Left Hand Side.
1731*7c478bd9Sstevel@tonic-gate  */
1732*7c478bd9Sstevel@tonic-gate 			error(gettext(
1733*7c478bd9Sstevel@tonic-gate 			"couldn't expanded LHS length"));
1734*7c478bd9Sstevel@tonic-gate 	}
1735*7c478bd9Sstevel@tonic-gate 	rhsfill((wchar_t *)0);
1736*7c478bd9Sstevel@tonic-gate 	(void) wscpy(lhstext, s); /* don't worry about too long of a name */
1737*7c478bd9Sstevel@tonic-gate }
1738*7c478bd9Sstevel@tonic-gate 
1739*7c478bd9Sstevel@tonic-gate static void
1740*7c478bd9Sstevel@tonic-gate rhsfill(s)
1741*7c478bd9Sstevel@tonic-gate wchar_t *s;	/* either name or 0 */
1742*7c478bd9Sstevel@tonic-gate {
1743*7c478bd9Sstevel@tonic-gate 	static wchar_t *loc;	/* next free location in rhstext */
1744*7c478bd9Sstevel@tonic-gate 	static int rhs_len = RHS_TEXT_LEN;
1745*7c478bd9Sstevel@tonic-gate 	static int used = 0;
1746*7c478bd9Sstevel@tonic-gate 	int s_rhs = (s == NULL ? 0 : wslen(s));
1747*7c478bd9Sstevel@tonic-gate 	register wchar_t *p;
1748*7c478bd9Sstevel@tonic-gate 
1749*7c478bd9Sstevel@tonic-gate 	if (!s)	/* print out and erase old text */
1750*7c478bd9Sstevel@tonic-gate 	{
1751*7c478bd9Sstevel@tonic-gate 		if (*lhstext)		/* there was an old rule - dump it */
1752*7c478bd9Sstevel@tonic-gate 			lrprnt();
1753*7c478bd9Sstevel@tonic-gate 		(loc = rhstext)[0] = 0;
1754*7c478bd9Sstevel@tonic-gate 		return;
1755*7c478bd9Sstevel@tonic-gate 	}
1756*7c478bd9Sstevel@tonic-gate 	/* add to stuff in rhstext */
1757*7c478bd9Sstevel@tonic-gate 	p = s;
1758*7c478bd9Sstevel@tonic-gate 
1759*7c478bd9Sstevel@tonic-gate 	used = loc - rhstext;
1760*7c478bd9Sstevel@tonic-gate 	if ((s_rhs + 3) >= (rhs_len - used)) {
1761*7c478bd9Sstevel@tonic-gate 		static wchar_t *textbase;
1762*7c478bd9Sstevel@tonic-gate 		textbase = rhstext;
1763*7c478bd9Sstevel@tonic-gate 		rhs_len += s_rhs + RHS_TEXT_LEN;
1764*7c478bd9Sstevel@tonic-gate 		rhstext = (wchar_t *)
1765*7c478bd9Sstevel@tonic-gate 			realloc((char *)rhstext, sizeof (wchar_t)*rhs_len);
1766*7c478bd9Sstevel@tonic-gate 		if (rhstext == NULL)
1767*7c478bd9Sstevel@tonic-gate /*
1768*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1769*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1770*7c478bd9Sstevel@tonic-gate  *	RHS -- Right Hand Side.
1771*7c478bd9Sstevel@tonic-gate  */
1772*7c478bd9Sstevel@tonic-gate 			error(gettext(
1773*7c478bd9Sstevel@tonic-gate 			"couldn't expanded RHS length"));
1774*7c478bd9Sstevel@tonic-gate 		loc = loc - textbase + rhstext;
1775*7c478bd9Sstevel@tonic-gate 	}
1776*7c478bd9Sstevel@tonic-gate 
1777*7c478bd9Sstevel@tonic-gate 	*loc++ = L' ';
1778*7c478bd9Sstevel@tonic-gate 	if (*s == L' ') /* special quoted symbol */
1779*7c478bd9Sstevel@tonic-gate 	{
1780*7c478bd9Sstevel@tonic-gate 		*loc++ = L'\'';	/* add first quote */
1781*7c478bd9Sstevel@tonic-gate 		p++;
1782*7c478bd9Sstevel@tonic-gate 	}
1783*7c478bd9Sstevel@tonic-gate 	while (*loc = *p++)
1784*7c478bd9Sstevel@tonic-gate 		if (loc++ > &rhstext[ RHS_TEXT_LEN ] - 3)
1785*7c478bd9Sstevel@tonic-gate 			break;
1786*7c478bd9Sstevel@tonic-gate 
1787*7c478bd9Sstevel@tonic-gate 	if (*s == L' ')
1788*7c478bd9Sstevel@tonic-gate 		*loc++ = L'\'';
1789*7c478bd9Sstevel@tonic-gate 	*loc = 0;		/* terminate the string */
1790*7c478bd9Sstevel@tonic-gate }
1791*7c478bd9Sstevel@tonic-gate 
1792*7c478bd9Sstevel@tonic-gate static void
1793*7c478bd9Sstevel@tonic-gate lrprnt()	/* print out the left and right hand sides */
1794*7c478bd9Sstevel@tonic-gate {
1795*7c478bd9Sstevel@tonic-gate 	wchar_t *rhs;
1796*7c478bd9Sstevel@tonic-gate 	wchar_t *m_rhs = NULL;
1797*7c478bd9Sstevel@tonic-gate 
1798*7c478bd9Sstevel@tonic-gate 	if (!*rhstext)		/* empty rhs - print usual comment */
1799*7c478bd9Sstevel@tonic-gate 		rhs = L" /* empty */";
1800*7c478bd9Sstevel@tonic-gate 	else {
1801*7c478bd9Sstevel@tonic-gate 		int idx1; /* tmp idx used to find if there are d_quotes */
1802*7c478bd9Sstevel@tonic-gate 		int idx2; /* tmp idx used to generate escaped string */
1803*7c478bd9Sstevel@tonic-gate 		wchar_t *p;
1804*7c478bd9Sstevel@tonic-gate 		/*
1805*7c478bd9Sstevel@tonic-gate 		 * Check if there are any double quote in RHS.
1806*7c478bd9Sstevel@tonic-gate 		 */
1807*7c478bd9Sstevel@tonic-gate 		for (idx1 = 0; rhstext[idx1] != 0; idx1++) {
1808*7c478bd9Sstevel@tonic-gate 			if (rhstext[idx1] == L'"') {
1809*7c478bd9Sstevel@tonic-gate 				/*
1810*7c478bd9Sstevel@tonic-gate 				 * A double quote is found.
1811*7c478bd9Sstevel@tonic-gate 				 */
1812*7c478bd9Sstevel@tonic-gate 				idx2 = wslen(rhstext)*2;
1813*7c478bd9Sstevel@tonic-gate 				p = m_rhs = (wchar_t *)
1814*7c478bd9Sstevel@tonic-gate 					malloc((idx2 + 1)*sizeof (wchar_t));
1815*7c478bd9Sstevel@tonic-gate 				if (m_rhs == NULL)
1816*7c478bd9Sstevel@tonic-gate /*
1817*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1818*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1819*7c478bd9Sstevel@tonic-gate  *	RHS - Right Hand Side.
1820*7c478bd9Sstevel@tonic-gate  *
1821*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
1822*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
1823*7c478bd9Sstevel@tonic-gate  */
1824*7c478bd9Sstevel@tonic-gate 					error(gettext(
1825*7c478bd9Sstevel@tonic-gate 					"Couldn't allocate memory for RHS."));
1826*7c478bd9Sstevel@tonic-gate 				/*
1827*7c478bd9Sstevel@tonic-gate 				 * Copy string
1828*7c478bd9Sstevel@tonic-gate 				 */
1829*7c478bd9Sstevel@tonic-gate 				for (idx2 = 0; rhstext[idx2] != 0; idx2++) {
1830*7c478bd9Sstevel@tonic-gate 					/*
1831*7c478bd9Sstevel@tonic-gate 					 * Check if this quote is escaped or not
1832*7c478bd9Sstevel@tonic-gate 					 */
1833*7c478bd9Sstevel@tonic-gate 					if (rhstext[idx2] == L'"') {
1834*7c478bd9Sstevel@tonic-gate 						int tmp_l = idx2-1;
1835*7c478bd9Sstevel@tonic-gate 						int cnt = 0;
1836*7c478bd9Sstevel@tonic-gate 						while (tmp_l >= 0 &&
1837*7c478bd9Sstevel@tonic-gate 						rhstext[tmp_l] == '\\') {
1838*7c478bd9Sstevel@tonic-gate 							cnt++;
1839*7c478bd9Sstevel@tonic-gate 							tmp_l--;
1840*7c478bd9Sstevel@tonic-gate 						}
1841*7c478bd9Sstevel@tonic-gate 						/*
1842*7c478bd9Sstevel@tonic-gate 						 * If quote is not escaped,
1843*7c478bd9Sstevel@tonic-gate 						 * then escape it.
1844*7c478bd9Sstevel@tonic-gate 						 */
1845*7c478bd9Sstevel@tonic-gate 						if (cnt%2 == 0)
1846*7c478bd9Sstevel@tonic-gate 							*p++ = L'\\';
1847*7c478bd9Sstevel@tonic-gate 					}
1848*7c478bd9Sstevel@tonic-gate 					*p++ = rhstext[idx2];
1849*7c478bd9Sstevel@tonic-gate 				}
1850*7c478bd9Sstevel@tonic-gate 				*p = 0;
1851*7c478bd9Sstevel@tonic-gate 				/*
1852*7c478bd9Sstevel@tonic-gate 				 * Break from the loop
1853*7c478bd9Sstevel@tonic-gate 				 */
1854*7c478bd9Sstevel@tonic-gate 				break;
1855*7c478bd9Sstevel@tonic-gate 			}
1856*7c478bd9Sstevel@tonic-gate 		}
1857*7c478bd9Sstevel@tonic-gate 		if (m_rhs == NULL)
1858*7c478bd9Sstevel@tonic-gate 			rhs = rhstext;
1859*7c478bd9Sstevel@tonic-gate 		else
1860*7c478bd9Sstevel@tonic-gate 			rhs = m_rhs;
1861*7c478bd9Sstevel@tonic-gate 	}
1862*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"%ws :%ws\",\n", lhstext, rhs);
1863*7c478bd9Sstevel@tonic-gate 	if (m_rhs)
1864*7c478bd9Sstevel@tonic-gate 		free(m_rhs);
1865*7c478bd9Sstevel@tonic-gate }
1866*7c478bd9Sstevel@tonic-gate 
1867*7c478bd9Sstevel@tonic-gate 
1868*7c478bd9Sstevel@tonic-gate static void
1869*7c478bd9Sstevel@tonic-gate beg_debug()	/* dump initial sequence for fdebug file */
1870*7c478bd9Sstevel@tonic-gate {
1871*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
1872*7c478bd9Sstevel@tonic-gate 		"typedef struct\n");
1873*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
1874*7c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\n\tyytoktype\n");
1875*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "#endif\n{\n");
1876*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
1877*7c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\nconst\n#endif\n");
1878*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "char *t_name; int t_val; } yytoktype;\n");
1879*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
1880*7c478bd9Sstevel@tonic-gate 		"#ifndef YYDEBUG\n#\tdefine YYDEBUG\t%d", gen_testing);
1881*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t/*%sallow debugging */\n#endif\n\n",
1882*7c478bd9Sstevel@tonic-gate 		gen_testing ? " " : " don't ");
1883*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "#if YYDEBUG\n\nyytoktype yytoks[] =\n{\n");
1884*7c478bd9Sstevel@tonic-gate }
1885*7c478bd9Sstevel@tonic-gate 
1886*7c478bd9Sstevel@tonic-gate 
1887*7c478bd9Sstevel@tonic-gate static void
1888*7c478bd9Sstevel@tonic-gate end_toks()	/* finish yytoks array, get ready for yyred's strings */
1889*7c478bd9Sstevel@tonic-gate {
1890*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"-unknown-\",\t-1\t/* ends search */\n");
1891*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "};\n\n");
1892*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
1893*7c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\nconst\n#endif\n");
1894*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "char * yyreds[] =\n{\n");
1895*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"-no such reduction-\",\n");
1896*7c478bd9Sstevel@tonic-gate }
1897*7c478bd9Sstevel@tonic-gate 
1898*7c478bd9Sstevel@tonic-gate 
1899*7c478bd9Sstevel@tonic-gate static void
1900*7c478bd9Sstevel@tonic-gate end_debug()	/* finish yyred array, close file */
1901*7c478bd9Sstevel@tonic-gate {
1902*7c478bd9Sstevel@tonic-gate 	lrprnt();		/* dump last lhs, rhs */
1903*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "};\n#endif /* YYDEBUG */\n");
1904*7c478bd9Sstevel@tonic-gate 	(void) fclose(fdebug);
1905*7c478bd9Sstevel@tonic-gate }
1906*7c478bd9Sstevel@tonic-gate 
1907*7c478bd9Sstevel@tonic-gate 
1908*7c478bd9Sstevel@tonic-gate /*
1909*7c478bd9Sstevel@tonic-gate  * 2/29/88 -
1910*7c478bd9Sstevel@tonic-gate  * The normal length for token sizes is NAMESIZE - If a token is
1911*7c478bd9Sstevel@tonic-gate  * seen that has a longer length, expand "tokname" by NAMESIZE.
1912*7c478bd9Sstevel@tonic-gate  */
1913*7c478bd9Sstevel@tonic-gate static void
1914*7c478bd9Sstevel@tonic-gate exp_tokname()
1915*7c478bd9Sstevel@tonic-gate {
1916*7c478bd9Sstevel@tonic-gate 	toksize += NAMESIZE;
1917*7c478bd9Sstevel@tonic-gate 	tokname = (wchar_t *)
1918*7c478bd9Sstevel@tonic-gate 		realloc((char *)tokname, sizeof (wchar_t) * toksize);
1919*7c478bd9Sstevel@tonic-gate }
1920*7c478bd9Sstevel@tonic-gate 
1921*7c478bd9Sstevel@tonic-gate 
1922*7c478bd9Sstevel@tonic-gate /*
1923*7c478bd9Sstevel@tonic-gate  * 2/29/88 -
1924*7c478bd9Sstevel@tonic-gate  *
1925*7c478bd9Sstevel@tonic-gate  */
1926*7c478bd9Sstevel@tonic-gate static void
1927*7c478bd9Sstevel@tonic-gate exp_prod()
1928*7c478bd9Sstevel@tonic-gate {
1929*7c478bd9Sstevel@tonic-gate 	int i;
1930*7c478bd9Sstevel@tonic-gate 	nprodsz += NPROD;
1931*7c478bd9Sstevel@tonic-gate 
1932*7c478bd9Sstevel@tonic-gate 	prdptr = (int **) realloc((char *)prdptr, sizeof (int *) * (nprodsz+2));
1933*7c478bd9Sstevel@tonic-gate 	levprd  = (int *)  realloc((char *)levprd, sizeof (int) * (nprodsz+2));
1934*7c478bd9Sstevel@tonic-gate 	had_act = (wchar_t *)
1935*7c478bd9Sstevel@tonic-gate 		realloc((char *)had_act, sizeof (wchar_t) * (nprodsz+2));
1936*7c478bd9Sstevel@tonic-gate 	for (i = nprodsz-NPROD; i < nprodsz+2; ++i)
1937*7c478bd9Sstevel@tonic-gate 		had_act[i] = 0;
1938*7c478bd9Sstevel@tonic-gate 
1939*7c478bd9Sstevel@tonic-gate 	if ((*prdptr == NULL) || (levprd == NULL) || (had_act == NULL))
1940*7c478bd9Sstevel@tonic-gate /*
1941*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1942*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1943*7c478bd9Sstevel@tonic-gate  *
1944*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
1945*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
1946*7c478bd9Sstevel@tonic-gate  */
1947*7c478bd9Sstevel@tonic-gate 		error(gettext(
1948*7c478bd9Sstevel@tonic-gate 		"couldn't expand productions"));
1949*7c478bd9Sstevel@tonic-gate }
1950*7c478bd9Sstevel@tonic-gate 
1951*7c478bd9Sstevel@tonic-gate /*
1952*7c478bd9Sstevel@tonic-gate  * 2/29/88 -
1953*7c478bd9Sstevel@tonic-gate  * Expand the number of terminals.  Initially there are NTERMS;
1954*7c478bd9Sstevel@tonic-gate  * each time space runs out, the size is increased by NTERMS.
1955*7c478bd9Sstevel@tonic-gate  * The total size, however, cannot exceed MAXTERMS because of
1956*7c478bd9Sstevel@tonic-gate  * the way LOOKSETS(struct looksets) is set up.
1957*7c478bd9Sstevel@tonic-gate  * Tables affected:
1958*7c478bd9Sstevel@tonic-gate  *	tokset, toklev : increased to ntoksz
1959*7c478bd9Sstevel@tonic-gate  *
1960*7c478bd9Sstevel@tonic-gate  *	tables with initial dimensions of TEMPSIZE must be changed if
1961*7c478bd9Sstevel@tonic-gate  *	(ntoksz + NNONTERM) >= TEMPSIZE : temp1[]
1962*7c478bd9Sstevel@tonic-gate  */
1963*7c478bd9Sstevel@tonic-gate static void
1964*7c478bd9Sstevel@tonic-gate exp_ntok()
1965*7c478bd9Sstevel@tonic-gate {
1966*7c478bd9Sstevel@tonic-gate 	ntoksz += NTERMS;
1967*7c478bd9Sstevel@tonic-gate 
1968*7c478bd9Sstevel@tonic-gate 	tokset = (TOKSYMB *) realloc((char *)tokset, sizeof (TOKSYMB) * ntoksz);
1969*7c478bd9Sstevel@tonic-gate 	toklev = (int *) realloc((char *)toklev, sizeof (int) * ntoksz);
1970*7c478bd9Sstevel@tonic-gate 
1971*7c478bd9Sstevel@tonic-gate 	if ((tokset == NULL) || (toklev == NULL))
1972*7c478bd9Sstevel@tonic-gate /*
1973*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1974*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1975*7c478bd9Sstevel@tonic-gate  *	Do not translate NTERMS.
1976*7c478bd9Sstevel@tonic-gate  *
1977*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
1978*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
1979*7c478bd9Sstevel@tonic-gate  */
1980*7c478bd9Sstevel@tonic-gate 		error(gettext(
1981*7c478bd9Sstevel@tonic-gate 		"couldn't expand NTERMS"));
1982*7c478bd9Sstevel@tonic-gate }
1983*7c478bd9Sstevel@tonic-gate 
1984*7c478bd9Sstevel@tonic-gate 
1985*7c478bd9Sstevel@tonic-gate static void
1986*7c478bd9Sstevel@tonic-gate exp_nonterm()
1987*7c478bd9Sstevel@tonic-gate {
1988*7c478bd9Sstevel@tonic-gate 	nnontersz += NNONTERM;
1989*7c478bd9Sstevel@tonic-gate 
1990*7c478bd9Sstevel@tonic-gate 	nontrst = (NTSYMB *)
1991*7c478bd9Sstevel@tonic-gate 		realloc((char *)nontrst, sizeof (TOKSYMB) * nnontersz);
1992*7c478bd9Sstevel@tonic-gate 	if (nontrst == NULL)
1993*7c478bd9Sstevel@tonic-gate /*
1994*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
1995*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
1996*7c478bd9Sstevel@tonic-gate  *	Do not translate NTERMS.
1997*7c478bd9Sstevel@tonic-gate  *
1998*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
1999*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
2000*7c478bd9Sstevel@tonic-gate  */
2001*7c478bd9Sstevel@tonic-gate 		error(gettext(
2002*7c478bd9Sstevel@tonic-gate 		"couldn't expand NNONTERM"));
2003*7c478bd9Sstevel@tonic-gate }
2004*7c478bd9Sstevel@tonic-gate 
2005*7c478bd9Sstevel@tonic-gate void
2006*7c478bd9Sstevel@tonic-gate exp_mem(flag)
2007*7c478bd9Sstevel@tonic-gate int flag;
2008*7c478bd9Sstevel@tonic-gate {
2009*7c478bd9Sstevel@tonic-gate 	int i;
2010*7c478bd9Sstevel@tonic-gate 	static int *membase;
2011*7c478bd9Sstevel@tonic-gate 	new_memsize += MEMSIZE;
2012*7c478bd9Sstevel@tonic-gate 
2013*7c478bd9Sstevel@tonic-gate 	membase = tracemem;
2014*7c478bd9Sstevel@tonic-gate 	tracemem = (int *)
2015*7c478bd9Sstevel@tonic-gate 		realloc((char *)tracemem, sizeof (int) * new_memsize);
2016*7c478bd9Sstevel@tonic-gate 	if (tracemem == NULL)
2017*7c478bd9Sstevel@tonic-gate /*
2018*7c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
2019*7c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
2020*7c478bd9Sstevel@tonic-gate  *
2021*7c478bd9Sstevel@tonic-gate  *	You may just translate this as:
2022*7c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
2023*7c478bd9Sstevel@tonic-gate  */
2024*7c478bd9Sstevel@tonic-gate 		error(gettext(
2025*7c478bd9Sstevel@tonic-gate 		"couldn't expand mem table"));
2026*7c478bd9Sstevel@tonic-gate 	if (flag) {
2027*7c478bd9Sstevel@tonic-gate 		for (i = 0; i <= nprod; ++i)
2028*7c478bd9Sstevel@tonic-gate 			prdptr[i] = prdptr[i] - membase + tracemem;
2029*7c478bd9Sstevel@tonic-gate 		mem = mem - membase + tracemem;
2030*7c478bd9Sstevel@tonic-gate 	} else {
2031*7c478bd9Sstevel@tonic-gate 		size += MEMSIZE;
2032*7c478bd9Sstevel@tonic-gate 		temp1 = (int *)realloc((char *)temp1, sizeof (int)*size);
2033*7c478bd9Sstevel@tonic-gate 		optimmem = optimmem - membase + tracemem;
2034*7c478bd9Sstevel@tonic-gate 	}
2035*7c478bd9Sstevel@tonic-gate }
2036*7c478bd9Sstevel@tonic-gate 
2037*7c478bd9Sstevel@tonic-gate static int
2038*7c478bd9Sstevel@tonic-gate findchtok(chlit)
2039*7c478bd9Sstevel@tonic-gate int chlit;
2040*7c478bd9Sstevel@tonic-gate /*
2041*7c478bd9Sstevel@tonic-gate  * findchtok(chlit) returns the token number for a character literal
2042*7c478bd9Sstevel@tonic-gate  * chlit that is "bigger" than 255 -- the max char value that the
2043*7c478bd9Sstevel@tonic-gate  * original yacc was build for.  This yacc treate them as though
2044*7c478bd9Sstevel@tonic-gate  * an ordinary token.
2045*7c478bd9Sstevel@tonic-gate  */
2046*7c478bd9Sstevel@tonic-gate {
2047*7c478bd9Sstevel@tonic-gate 	int	i;
2048*7c478bd9Sstevel@tonic-gate #ifdef	NOLIBW
2049*7c478bd9Sstevel@tonic-gate 	return (chlit); /* assume always singlebyte char */
2050*7c478bd9Sstevel@tonic-gate #else /* !NOLIBW */
2051*7c478bd9Sstevel@tonic-gate 
2052*7c478bd9Sstevel@tonic-gate 	if (chlit < 0xff)
2053*7c478bd9Sstevel@tonic-gate 		return (chlit); /* single-byte char */
2054*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < nmbchars; ++i) {
2055*7c478bd9Sstevel@tonic-gate 		if (mbchars->character == chlit)
2056*7c478bd9Sstevel@tonic-gate 			return (mbchars->tvalue);
2057*7c478bd9Sstevel@tonic-gate 	}
2058*7c478bd9Sstevel@tonic-gate 
2059*7c478bd9Sstevel@tonic-gate 	/* Not found.  Register it! */
2060*7c478bd9Sstevel@tonic-gate 	if (++nmbchars > nmbcharsz) { /* Make sure there's enough space */
2061*7c478bd9Sstevel@tonic-gate 		nmbcharsz += NMBCHARSZ;
2062*7c478bd9Sstevel@tonic-gate 		mbchars = (MBCLIT *)
2063*7c478bd9Sstevel@tonic-gate 		    realloc((char *)mbchars, sizeof (MBCLIT)*nmbcharsz);
2064*7c478bd9Sstevel@tonic-gate 		if (mbchars == NULL)
2065*7c478bd9Sstevel@tonic-gate 			error(gettext(
2066*7c478bd9Sstevel@tonic-gate 			"too many character literals"));
2067*7c478bd9Sstevel@tonic-gate 	}
2068*7c478bd9Sstevel@tonic-gate 	mbchars[nmbchars-1].character = chlit;
2069*7c478bd9Sstevel@tonic-gate 	return (mbchars[nmbchars-1].tvalue = extval++);
2070*7c478bd9Sstevel@tonic-gate 	/* Return the newly assigned token. */
2071*7c478bd9Sstevel@tonic-gate #endif /* !NOLIBW */
2072*7c478bd9Sstevel@tonic-gate }
2073*7c478bd9Sstevel@tonic-gate 
2074*7c478bd9Sstevel@tonic-gate /*
2075*7c478bd9Sstevel@tonic-gate  * When -p is specified, symbol prefix for
2076*7c478bd9Sstevel@tonic-gate  *	yy{parse, lex, error}(),
2077*7c478bd9Sstevel@tonic-gate  *	yy{lval, val, char, debug, errflag, nerrs}
2078*7c478bd9Sstevel@tonic-gate  * are defined to the specified name.
2079*7c478bd9Sstevel@tonic-gate  */
2080*7c478bd9Sstevel@tonic-gate static void
2081*7c478bd9Sstevel@tonic-gate put_prefix_define(char *pre)
2082*7c478bd9Sstevel@tonic-gate {
2083*7c478bd9Sstevel@tonic-gate 	char *syms[] = {
2084*7c478bd9Sstevel@tonic-gate 		/* Functions */
2085*7c478bd9Sstevel@tonic-gate 		"parse",
2086*7c478bd9Sstevel@tonic-gate 		"lex",
2087*7c478bd9Sstevel@tonic-gate 		"error",
2088*7c478bd9Sstevel@tonic-gate 		/* Variables */
2089*7c478bd9Sstevel@tonic-gate 		"lval",
2090*7c478bd9Sstevel@tonic-gate 		"val",
2091*7c478bd9Sstevel@tonic-gate 		"char",
2092*7c478bd9Sstevel@tonic-gate 		"debug",
2093*7c478bd9Sstevel@tonic-gate 		"errflag",
2094*7c478bd9Sstevel@tonic-gate 		"nerrs",
2095*7c478bd9Sstevel@tonic-gate 		NULL};
2096*7c478bd9Sstevel@tonic-gate 	int i;
2097*7c478bd9Sstevel@tonic-gate 
2098*7c478bd9Sstevel@tonic-gate 	for (i = 0; syms[i]; i++)
2099*7c478bd9Sstevel@tonic-gate 		fprintf(ftable, "#define\tyy%s\t%s%s\n",
2100*7c478bd9Sstevel@tonic-gate 			syms[i], pre, syms[i]);
2101*7c478bd9Sstevel@tonic-gate }
2102