xref: /illumos-gate/usr/src/cmd/sgs/yacc/common/y2.c (revision e29394bd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*e29394bdSmike_s  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
32*e29394bdSmike_s #include "dextern.h"
337c478bd9Sstevel@tonic-gate #include "sgs.h"
34*e29394bdSmike_s #include <stdio.h>
35*e29394bdSmike_s 
367c478bd9Sstevel@tonic-gate #define	IDENTIFIER 257
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	MARK 258
397c478bd9Sstevel@tonic-gate #define	TERM 259
407c478bd9Sstevel@tonic-gate #define	LEFT 260
417c478bd9Sstevel@tonic-gate #define	RIGHT 261
427c478bd9Sstevel@tonic-gate #define	BINARY 262
437c478bd9Sstevel@tonic-gate #define	PREC 263
447c478bd9Sstevel@tonic-gate #define	LCURLY 264
457c478bd9Sstevel@tonic-gate #define	C_IDENTIFIER 265  /* name followed by colon */
467c478bd9Sstevel@tonic-gate #define	NUMBER 266
477c478bd9Sstevel@tonic-gate #define	START 267
487c478bd9Sstevel@tonic-gate #define	TYPEDEF 268
497c478bd9Sstevel@tonic-gate #define	TYPENAME 269
507c478bd9Sstevel@tonic-gate #define	UNION 270
517c478bd9Sstevel@tonic-gate #define	ENDFILE 0
527c478bd9Sstevel@tonic-gate #define	LHS_TEXT_LEN		80	/* length of lhstext */
537c478bd9Sstevel@tonic-gate #define	RHS_TEXT_LEN		640	/* length of rhstext */
547c478bd9Sstevel@tonic-gate 	/* communication variables between various I/O routines */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	v_FLAG	0x01
577c478bd9Sstevel@tonic-gate #define	d_FLAG	0x02
587c478bd9Sstevel@tonic-gate #define	DEFAULT_PREFIX	"y"
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate char *infile;				/* input file name 		*/
617c478bd9Sstevel@tonic-gate static int numbval;			/* value of an input number 	*/
627c478bd9Sstevel@tonic-gate static int toksize = NAMESIZE;
637c478bd9Sstevel@tonic-gate static wchar_t *tokname;	/* input token name		*/
647c478bd9Sstevel@tonic-gate char *parser = NULL;		/* location of common parser 	*/
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static void finact(void);
677c478bd9Sstevel@tonic-gate static wchar_t *cstash(wchar_t *);
687c478bd9Sstevel@tonic-gate static void defout(void);
697c478bd9Sstevel@tonic-gate static void cpyunion(void);
707c478bd9Sstevel@tonic-gate static void cpycode(void);
717c478bd9Sstevel@tonic-gate static void cpyact(int);
727c478bd9Sstevel@tonic-gate static void lhsfill(wchar_t *);
737c478bd9Sstevel@tonic-gate static void rhsfill(wchar_t *);
747c478bd9Sstevel@tonic-gate static void lrprnt(void);
757c478bd9Sstevel@tonic-gate static void beg_debug(void);
767c478bd9Sstevel@tonic-gate static void end_toks(void);
777c478bd9Sstevel@tonic-gate static void end_debug(void);
787c478bd9Sstevel@tonic-gate static void exp_tokname(void);
797c478bd9Sstevel@tonic-gate static void exp_prod(void);
807c478bd9Sstevel@tonic-gate static void exp_ntok(void);
817c478bd9Sstevel@tonic-gate static void exp_nonterm(void);
827c478bd9Sstevel@tonic-gate static int defin(int, wchar_t *);
837c478bd9Sstevel@tonic-gate static int gettok(void);
847c478bd9Sstevel@tonic-gate static int chfind(int, wchar_t *);
857c478bd9Sstevel@tonic-gate static int skipcom(void);
867c478bd9Sstevel@tonic-gate static int findchtok(int);
877c478bd9Sstevel@tonic-gate static void put_prefix_define(char *);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /* storage of names */
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * initial block to place token and
947c478bd9Sstevel@tonic-gate  * nonterminal names are stored
957c478bd9Sstevel@tonic-gate  * points to initial block - more space
967c478bd9Sstevel@tonic-gate  * is allocated as needed.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate static wchar_t cnamesblk0[CNAMSZ];
997c478bd9Sstevel@tonic-gate static wchar_t *cnames = cnamesblk0;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /* place where next name is to be put in */
1027c478bd9Sstevel@tonic-gate static wchar_t *cnamp = cnamesblk0;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /* number of defined symbols output */
1057c478bd9Sstevel@tonic-gate static int ndefout = 3;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	/* storage of types */
1087c478bd9Sstevel@tonic-gate static int defunion = 0;	/* union of types defined? */
1097c478bd9Sstevel@tonic-gate static int ntypes = 0;		/* number of types defined */
1107c478bd9Sstevel@tonic-gate static wchar_t *typeset[NTYPES]; /* pointers to type tags */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	/* symbol tables for tokens and nonterminals */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate int ntokens = 0;
1157c478bd9Sstevel@tonic-gate int ntoksz = NTERMS;
1167c478bd9Sstevel@tonic-gate TOKSYMB *tokset;
1177c478bd9Sstevel@tonic-gate int *toklev;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate int nnonter = -1;
1207c478bd9Sstevel@tonic-gate NTSYMB *nontrst;
1217c478bd9Sstevel@tonic-gate int nnontersz = NNONTERM;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate static int start;	/* start symbol */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/* assigned token type values */
1267c478bd9Sstevel@tonic-gate static int extval = 0;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	/* input and output file descriptors */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate FILE *finput;		/* yacc input file */
1317c478bd9Sstevel@tonic-gate FILE *faction;		/* file for saving actions */
1327c478bd9Sstevel@tonic-gate FILE *fdefine;		/* file for # defines */
1337c478bd9Sstevel@tonic-gate FILE *ftable;		/* y.tab.c file */
1347c478bd9Sstevel@tonic-gate FILE *ftemp;		/* tempfile to pass 2 */
1357c478bd9Sstevel@tonic-gate FILE *fdebug;		/* where the strings for debugging are stored */
1367c478bd9Sstevel@tonic-gate FILE *foutput;		/* y.output file */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	/* output string */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate static wchar_t *lhstext;
1417c478bd9Sstevel@tonic-gate static wchar_t *rhstext;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	/* storage for grammar rules */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate int *mem0; /* production storage */
1467c478bd9Sstevel@tonic-gate int *mem;
1477c478bd9Sstevel@tonic-gate int *tracemem;
1487c478bd9Sstevel@tonic-gate extern int *optimmem;
1497c478bd9Sstevel@tonic-gate int new_memsize = MEMSIZE;
1507c478bd9Sstevel@tonic-gate int nprod = 1;	/* number of productions */
1517c478bd9Sstevel@tonic-gate int nprodsz = NPROD;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate int **prdptr;
1547c478bd9Sstevel@tonic-gate int *levprd;
1557c478bd9Sstevel@tonic-gate wchar_t *had_act;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /* flag for generating the # line's default is yes */
1587c478bd9Sstevel@tonic-gate int gen_lines = 1;
1597c478bd9Sstevel@tonic-gate int act_lines = 0;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /* flag for whether to include runtime debugging */
1627c478bd9Sstevel@tonic-gate static int gen_testing = 0;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /* flag for version stamping--default turned off */
1657c478bd9Sstevel@tonic-gate static char *v_stmp = "n";
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate int nmbchars = 0;	/* number of mb literals in mbchars */
1687c478bd9Sstevel@tonic-gate MBCLIT *mbchars = (MBCLIT *) 0; /* array of mb literals */
1697c478bd9Sstevel@tonic-gate int nmbcharsz = 0; /* allocated space for mbchars */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate void
1727c478bd9Sstevel@tonic-gate setup(argc, argv)
1737c478bd9Sstevel@tonic-gate int argc;
1747c478bd9Sstevel@tonic-gate char *argv[];
1757c478bd9Sstevel@tonic-gate {	int ii, i, j, lev, t, ty;
1767c478bd9Sstevel@tonic-gate 		/* ty is the sequencial number of token name in tokset */
1777c478bd9Sstevel@tonic-gate 	int c;
1787c478bd9Sstevel@tonic-gate 	int *p;
1797c478bd9Sstevel@tonic-gate 	char *cp;
1807c478bd9Sstevel@tonic-gate 	wchar_t actname[8];
1817c478bd9Sstevel@tonic-gate 	unsigned int options = 0;
1827c478bd9Sstevel@tonic-gate 	char *file_prefix = DEFAULT_PREFIX;
1837c478bd9Sstevel@tonic-gate 	char *sym_prefix = "";
1847c478bd9Sstevel@tonic-gate #define	F_NAME_LENGTH	128
1857c478bd9Sstevel@tonic-gate 	char	fname[F_NAME_LENGTH+1];
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	foutput = NULL;
1887c478bd9Sstevel@tonic-gate 	fdefine = NULL;
1897c478bd9Sstevel@tonic-gate 	i = 1;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	tokname = (wchar_t *)malloc(sizeof (wchar_t) * toksize);
1927c478bd9Sstevel@tonic-gate 	tokset = (TOKSYMB *)malloc(sizeof (TOKSYMB) * ntoksz);
1937c478bd9Sstevel@tonic-gate 	toklev = (int *)malloc(sizeof (int) * ntoksz);
1947c478bd9Sstevel@tonic-gate 	nontrst = (NTSYMB *)malloc(sizeof (NTSYMB) * nnontersz);
1957c478bd9Sstevel@tonic-gate 	mem0 = (int *)malloc(sizeof (int) * new_memsize);
1967c478bd9Sstevel@tonic-gate 	prdptr = (int **)malloc(sizeof (int *) * (nprodsz+2));
1977c478bd9Sstevel@tonic-gate 	levprd = (int *)malloc(sizeof (int) * (nprodsz+2));
1987c478bd9Sstevel@tonic-gate 	had_act = (wchar_t *)calloc((nprodsz + 2), sizeof (wchar_t));
1997c478bd9Sstevel@tonic-gate 	lhstext = (wchar_t *)malloc(sizeof (wchar_t) * LHS_TEXT_LEN);
2007c478bd9Sstevel@tonic-gate 	rhstext = (wchar_t *)malloc(sizeof (wchar_t) * RHS_TEXT_LEN);
2017c478bd9Sstevel@tonic-gate 	aryfil(toklev, ntoksz, 0);
2027c478bd9Sstevel@tonic-gate 	aryfil(levprd, nprodsz, 0);
2037c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < ntoksz; ++ii)
2047c478bd9Sstevel@tonic-gate 		tokset[ii].value = 0;
2057c478bd9Sstevel@tonic-gate 	for (ii = 0; ii < nnontersz; ++ii)
2067c478bd9Sstevel@tonic-gate 		nontrst[ii].tvalue = 0;
2077c478bd9Sstevel@tonic-gate 	aryfil(mem0, new_memsize, 0);
2087c478bd9Sstevel@tonic-gate 	mem = mem0;
2097c478bd9Sstevel@tonic-gate 	tracemem = mem0;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "vVdltp:Q:Y:P:b:")) != EOF)
2127c478bd9Sstevel@tonic-gate 		switch (c) {
2137c478bd9Sstevel@tonic-gate 		case 'v':
2147c478bd9Sstevel@tonic-gate 			options |= v_FLAG;
2157c478bd9Sstevel@tonic-gate 			break;
2167c478bd9Sstevel@tonic-gate 		case 'V':
2177c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "yacc: %s %s\n",
2187c478bd9Sstevel@tonic-gate 			    (const char *)SGU_PKG,
2197c478bd9Sstevel@tonic-gate 			    (const char *)SGU_REL);
2207c478bd9Sstevel@tonic-gate 			break;
2217c478bd9Sstevel@tonic-gate 		case 'Q':
2227c478bd9Sstevel@tonic-gate 			v_stmp = optarg;
2237c478bd9Sstevel@tonic-gate 			if (*v_stmp != 'y' && *v_stmp != 'n')
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
2267c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
2277c478bd9Sstevel@tonic-gate  *	Do not translate -Q and [y/n].
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate 				error(gettext(
2307c478bd9Sstevel@tonic-gate 			"yacc: -Q should be followed by [y/n]"));
2317c478bd9Sstevel@tonic-gate 			break;
2327c478bd9Sstevel@tonic-gate 		case 'd':
2337c478bd9Sstevel@tonic-gate 			options |= d_FLAG;
2347c478bd9Sstevel@tonic-gate 			break;
2357c478bd9Sstevel@tonic-gate 		case 'l':
2367c478bd9Sstevel@tonic-gate 			gen_lines = 0;	/* don't gen #lines */
2377c478bd9Sstevel@tonic-gate 			break;
2387c478bd9Sstevel@tonic-gate 		case 't':
2397c478bd9Sstevel@tonic-gate 			gen_testing = 1;	/* set YYDEBUG on */
2407c478bd9Sstevel@tonic-gate 			break;
2417c478bd9Sstevel@tonic-gate 		case 'Y':
2427c478bd9Sstevel@tonic-gate 			cp = (char *)malloc(strlen(optarg)+
2437c478bd9Sstevel@tonic-gate 				sizeof ("/yaccpar") + 1);
2447c478bd9Sstevel@tonic-gate 			cp = strcpy(cp, optarg);
2457c478bd9Sstevel@tonic-gate 			parser = strcat(cp, "/yaccpar");
2467c478bd9Sstevel@tonic-gate 			break;
2477c478bd9Sstevel@tonic-gate 		case 'P':
2487c478bd9Sstevel@tonic-gate 			parser = optarg;
2497c478bd9Sstevel@tonic-gate 			break;
2507c478bd9Sstevel@tonic-gate 		case 'p':
2517c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "yy") != 0)
2527c478bd9Sstevel@tonic-gate 				sym_prefix = optarg;
2537c478bd9Sstevel@tonic-gate 			else
2547c478bd9Sstevel@tonic-gate 				sym_prefix = "";
2557c478bd9Sstevel@tonic-gate 			break;
2567c478bd9Sstevel@tonic-gate 		case 'b':
2577c478bd9Sstevel@tonic-gate 			file_prefix = optarg;
2587c478bd9Sstevel@tonic-gate 			break;
2597c478bd9Sstevel@tonic-gate 		case '?':
2607c478bd9Sstevel@tonic-gate 		default:
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
2637c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
2647c478bd9Sstevel@tonic-gate  *	This is a usage message. The translate should be
2657c478bd9Sstevel@tonic-gate  *	consistent with man page translation.
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
2687c478bd9Sstevel@tonic-gate "Usage: yacc [-vVdltY] [-Q(y/n)] [-b file_prefix] [-p sym_prefix]"
2697c478bd9Sstevel@tonic-gate " [-P parser] file\n"));
2707c478bd9Sstevel@tonic-gate 			exit(1);
2717c478bd9Sstevel@tonic-gate 		}
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Open y.output if -v is specified
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	if (options & v_FLAG) {
2767c478bd9Sstevel@tonic-gate 		strncpy(fname,
2777c478bd9Sstevel@tonic-gate 			file_prefix,
2787c478bd9Sstevel@tonic-gate 			F_NAME_LENGTH-strlen(".output"));
2797c478bd9Sstevel@tonic-gate 		strcat(fname, ".output");
2807c478bd9Sstevel@tonic-gate 		foutput = fopen(fname, "w");
2817c478bd9Sstevel@tonic-gate 		if (foutput == NULL)
2827c478bd9Sstevel@tonic-gate 			error(gettext(
2837c478bd9Sstevel@tonic-gate 			"cannot open y.output"));
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	/*
2877c478bd9Sstevel@tonic-gate 	 * Open y.tab.h if -d is specified
2887c478bd9Sstevel@tonic-gate 	 */
2897c478bd9Sstevel@tonic-gate 	if (options & d_FLAG) {
2907c478bd9Sstevel@tonic-gate 		strncpy(fname,
2917c478bd9Sstevel@tonic-gate 			file_prefix,
2927c478bd9Sstevel@tonic-gate 			F_NAME_LENGTH-strlen(".tab.h"));
2937c478bd9Sstevel@tonic-gate 		strcat(fname, ".tab.h");
2947c478bd9Sstevel@tonic-gate 		fdefine = fopen(fname, "w");
2957c478bd9Sstevel@tonic-gate 		if (fdefine == NULL)
2967c478bd9Sstevel@tonic-gate 			error(gettext(
2977c478bd9Sstevel@tonic-gate 			"cannot open y.tab.h"));
2987c478bd9Sstevel@tonic-gate 	}
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	fdebug = fopen(DEBUGNAME, "w");
3017c478bd9Sstevel@tonic-gate 	if (fdebug == NULL)
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
3047c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
3057c478bd9Sstevel@tonic-gate  *	Do not translate yacc.debug.
3067c478bd9Sstevel@tonic-gate  */
3077c478bd9Sstevel@tonic-gate 		error(gettext(
3087c478bd9Sstevel@tonic-gate 		"cannot open yacc.debug"));
3097c478bd9Sstevel@tonic-gate 	/*
3107c478bd9Sstevel@tonic-gate 	 * Open y.tab.c
3117c478bd9Sstevel@tonic-gate 	 */
3127c478bd9Sstevel@tonic-gate 	strncpy(fname,
3137c478bd9Sstevel@tonic-gate 		file_prefix,
3147c478bd9Sstevel@tonic-gate 		F_NAME_LENGTH-strlen(".tab.c"));
3157c478bd9Sstevel@tonic-gate 	strcat(fname, ".tab.c");
3167c478bd9Sstevel@tonic-gate 	ftable = fopen(fname, "w");
3177c478bd9Sstevel@tonic-gate 	if (ftable == NULL)
3187c478bd9Sstevel@tonic-gate 		error(gettext(
3197c478bd9Sstevel@tonic-gate 		"cannot open %s"), fname);
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	ftemp = fopen(TEMPNAME, "w");
3227c478bd9Sstevel@tonic-gate 	faction = fopen(ACTNAME, "w");
3237c478bd9Sstevel@tonic-gate 	if (ftemp == NULL || faction == NULL)
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
3267c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
3277c478bd9Sstevel@tonic-gate  *	The message means: "Could not open a temporary file."
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate 		error(gettext(
3307c478bd9Sstevel@tonic-gate 		"cannot open temp file"));
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	if ((finput = fopen(infile = argv[optind], "r")) == NULL)
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
3357c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
3367c478bd9Sstevel@tonic-gate  */
3377c478bd9Sstevel@tonic-gate 		error(gettext(
3387c478bd9Sstevel@tonic-gate 		"cannot open input file"));
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	lineno = 1;
3417c478bd9Sstevel@tonic-gate 	cnamp = cnames;
3427c478bd9Sstevel@tonic-gate 	(void) defin(0, L"$end");
3437c478bd9Sstevel@tonic-gate 	extval = 0400;
3447c478bd9Sstevel@tonic-gate 	(void) defin(0, L"error");
3457c478bd9Sstevel@tonic-gate 	(void) defin(1, L"$accept");
3467c478bd9Sstevel@tonic-gate 	mem = mem0;
3477c478bd9Sstevel@tonic-gate 	lev = 0;
3487c478bd9Sstevel@tonic-gate 	ty = 0;
3497c478bd9Sstevel@tonic-gate 	i = 0;
3507c478bd9Sstevel@tonic-gate 	beg_debug();	/* initialize fdebug file */
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/*
3537c478bd9Sstevel@tonic-gate 	 * sorry -- no yacc parser here.....
3547c478bd9Sstevel@tonic-gate 	 *	we must bootstrap somehow...
3557c478bd9Sstevel@tonic-gate 	 */
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	t = gettok();
3587c478bd9Sstevel@tonic-gate 	if (*v_stmp == 'y')
3597c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "#ident\t\"yacc: %s %s\"\n",
3607c478bd9Sstevel@tonic-gate 		    (const char *)SGU_PKG, (const char *)SGU_REL);
3617c478bd9Sstevel@tonic-gate 	for (; t != MARK && t != ENDFILE; ) {
3627c478bd9Sstevel@tonic-gate 		int tok_in_line;
3637c478bd9Sstevel@tonic-gate 		switch (t) {
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 		case L';':
3667c478bd9Sstevel@tonic-gate 			t = gettok();
3677c478bd9Sstevel@tonic-gate 			break;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		case START:
3707c478bd9Sstevel@tonic-gate 			if ((t = gettok()) != IDENTIFIER) {
3717c478bd9Sstevel@tonic-gate 				error("bad %%start construction");
3727c478bd9Sstevel@tonic-gate 				}
3737c478bd9Sstevel@tonic-gate 			start = chfind(1, tokname);
3747c478bd9Sstevel@tonic-gate 			t = gettok();
3757c478bd9Sstevel@tonic-gate 			continue;
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 		case TYPEDEF:
3787c478bd9Sstevel@tonic-gate 			tok_in_line = 0;
3797c478bd9Sstevel@tonic-gate 			if ((t = gettok()) != TYPENAME)
3807c478bd9Sstevel@tonic-gate /*
3817c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
3827c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
3837c478bd9Sstevel@tonic-gate  *	Do not translate %%type.
3847c478bd9Sstevel@tonic-gate  */
3857c478bd9Sstevel@tonic-gate 				error(gettext(
3867c478bd9Sstevel@tonic-gate 				"bad syntax in %%type"));
3877c478bd9Sstevel@tonic-gate 			ty = numbval;
3887c478bd9Sstevel@tonic-gate 			for (;;) {
3897c478bd9Sstevel@tonic-gate 				t = gettok();
3907c478bd9Sstevel@tonic-gate 				switch (t) {
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 				case IDENTIFIER:
3937c478bd9Sstevel@tonic-gate 			/*
3947c478bd9Sstevel@tonic-gate 			 * The following lines are idented to left.
3957c478bd9Sstevel@tonic-gate 			 */
3967c478bd9Sstevel@tonic-gate 			tok_in_line = 1;
3977c478bd9Sstevel@tonic-gate 			if ((t = chfind(1, tokname)) < NTBASE) {
3987c478bd9Sstevel@tonic-gate 				j = TYPE(toklev[t]);
3997c478bd9Sstevel@tonic-gate 				if (j != 0 && j != ty) {
4007c478bd9Sstevel@tonic-gate /*
4017c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
4027c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
4037c478bd9Sstevel@tonic-gate  */
4047c478bd9Sstevel@tonic-gate 					error(gettext(
4057c478bd9Sstevel@tonic-gate 					"type redeclaration of token %ws"),
4067c478bd9Sstevel@tonic-gate 					tokset[t].name);
4077c478bd9Sstevel@tonic-gate 					}
4087c478bd9Sstevel@tonic-gate 				else
4097c478bd9Sstevel@tonic-gate 					SETTYPE(toklev[t], ty);
4107c478bd9Sstevel@tonic-gate 			} else {
4117c478bd9Sstevel@tonic-gate 				j = nontrst[t-NTBASE].tvalue;
4127c478bd9Sstevel@tonic-gate 				if (j != 0 && j != ty) {
4137c478bd9Sstevel@tonic-gate /*
4147c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
4157c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
4167c478bd9Sstevel@tonic-gate  *	Check how nonterminal is translated in translated
4177c478bd9Sstevel@tonic-gate  *	yacc man page or yacc user's document.
4187c478bd9Sstevel@tonic-gate  */
4197c478bd9Sstevel@tonic-gate 					error(gettext(
4207c478bd9Sstevel@tonic-gate 				"type redeclaration of nonterminal %ws"),
4217c478bd9Sstevel@tonic-gate 						nontrst[t-NTBASE].name);
4227c478bd9Sstevel@tonic-gate 					}
4237c478bd9Sstevel@tonic-gate 				else
4247c478bd9Sstevel@tonic-gate 					nontrst[t-NTBASE].tvalue = ty;
4257c478bd9Sstevel@tonic-gate 				}
4267c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
4277c478bd9Sstevel@tonic-gate 			/*
4287c478bd9Sstevel@tonic-gate 			 * End Indentation
4297c478bd9Sstevel@tonic-gate 			 */
4307c478bd9Sstevel@tonic-gate 				case L',':
4317c478bd9Sstevel@tonic-gate 					continue;
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 				case L';':
4347c478bd9Sstevel@tonic-gate 					t = gettok();
4357c478bd9Sstevel@tonic-gate 					break;
4367c478bd9Sstevel@tonic-gate 				default:
4377c478bd9Sstevel@tonic-gate 					break;
4387c478bd9Sstevel@tonic-gate 					}
4397c478bd9Sstevel@tonic-gate 				if (!tok_in_line)
4407c478bd9Sstevel@tonic-gate /*
4417c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
4427c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
4437c478bd9Sstevel@tonic-gate  */
4447c478bd9Sstevel@tonic-gate 					error(gettext(
4457c478bd9Sstevel@tonic-gate 					"missing tokens or illegal tokens"));
4467c478bd9Sstevel@tonic-gate 				break;
4477c478bd9Sstevel@tonic-gate 				}
4487c478bd9Sstevel@tonic-gate 			continue;
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 		case UNION:
4517c478bd9Sstevel@tonic-gate 			/* copy the union declaration to the output */
4527c478bd9Sstevel@tonic-gate 			cpyunion();
4537c478bd9Sstevel@tonic-gate 			defunion = 1;
4547c478bd9Sstevel@tonic-gate 			t = gettok();
4557c478bd9Sstevel@tonic-gate 			continue;
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 		case LEFT:
4587c478bd9Sstevel@tonic-gate 		case BINARY:
4597c478bd9Sstevel@tonic-gate 		case RIGHT:
4607c478bd9Sstevel@tonic-gate 			i++;
4617c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
4627c478bd9Sstevel@tonic-gate 		case TERM:
4637c478bd9Sstevel@tonic-gate 			tok_in_line = 0;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 			/* nonzero means new prec. and assoc. */
4667c478bd9Sstevel@tonic-gate 			lev = (t-TERM) | 04;
4677c478bd9Sstevel@tonic-gate 			ty = 0;
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 			/* get identifiers so defined */
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 			t = gettok();
4727c478bd9Sstevel@tonic-gate 			if (t == TYPENAME) { /* there is a type defined */
4737c478bd9Sstevel@tonic-gate 				ty = numbval;
4747c478bd9Sstevel@tonic-gate 				t = gettok();
4757c478bd9Sstevel@tonic-gate 				}
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 			for (;;) {
4787c478bd9Sstevel@tonic-gate 				switch (t) {
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 				case L',':
4817c478bd9Sstevel@tonic-gate 					t = gettok();
4827c478bd9Sstevel@tonic-gate 					continue;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 				case L';':
4857c478bd9Sstevel@tonic-gate 					break;
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 				case IDENTIFIER:
4887c478bd9Sstevel@tonic-gate 					tok_in_line = 1;
4897c478bd9Sstevel@tonic-gate 					j = chfind(0, tokname);
4907c478bd9Sstevel@tonic-gate 					if (j > NTBASE) {
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
4937c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
4947c478bd9Sstevel@tonic-gate  */
4957c478bd9Sstevel@tonic-gate 						error(gettext(
4967c478bd9Sstevel@tonic-gate 				"%ws is not a token."),
4977c478bd9Sstevel@tonic-gate 						tokname);
4987c478bd9Sstevel@tonic-gate 					}
4997c478bd9Sstevel@tonic-gate 					if (lev & ~04) {
5007c478bd9Sstevel@tonic-gate 						if (ASSOC(toklev[j]) & ~04)
5017c478bd9Sstevel@tonic-gate /*
5027c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5037c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5047c478bd9Sstevel@tonic-gate  */
5057c478bd9Sstevel@tonic-gate 							error(gettext(
5067c478bd9Sstevel@tonic-gate 				"redeclaration of precedence of %ws"),
5077c478bd9Sstevel@tonic-gate 						tokname);
5087c478bd9Sstevel@tonic-gate 						SETASC(toklev[j], lev);
5097c478bd9Sstevel@tonic-gate 						SETPLEV(toklev[j], i);
5107c478bd9Sstevel@tonic-gate 					} else {
5117c478bd9Sstevel@tonic-gate 						if (ASSOC(toklev[j]))
5127c478bd9Sstevel@tonic-gate 						(void) warning(1, gettext(
5137c478bd9Sstevel@tonic-gate 				"redeclaration of precedence of %ws."),
5147c478bd9Sstevel@tonic-gate 							tokname);
5157c478bd9Sstevel@tonic-gate 						SETASC(toklev[j], lev);
5167c478bd9Sstevel@tonic-gate 						}
5177c478bd9Sstevel@tonic-gate 					if (ty) {
5187c478bd9Sstevel@tonic-gate 						if (TYPE(toklev[j]))
5197c478bd9Sstevel@tonic-gate 							error(gettext(
5207c478bd9Sstevel@tonic-gate /*
5217c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5227c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate 						"redeclaration of type of %ws"),
5257c478bd9Sstevel@tonic-gate 							tokname);
5267c478bd9Sstevel@tonic-gate 						SETTYPE(toklev[j], ty);
5277c478bd9Sstevel@tonic-gate 						}
5287c478bd9Sstevel@tonic-gate 					if ((t = gettok()) == NUMBER) {
5297c478bd9Sstevel@tonic-gate 						tokset[j].value = numbval;
5307c478bd9Sstevel@tonic-gate 						if (j < ndefout && j > 2) {
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5337c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5347c478bd9Sstevel@tonic-gate  */
5357c478bd9Sstevel@tonic-gate 							error(gettext(
5367c478bd9Sstevel@tonic-gate 				"type number of %ws should be defined earlier"),
5377c478bd9Sstevel@tonic-gate 							tokset[j].name);
5387c478bd9Sstevel@tonic-gate 							}
5397c478bd9Sstevel@tonic-gate 						if (numbval >= -YYFLAG1) {
5407c478bd9Sstevel@tonic-gate /*
5417c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5427c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5437c478bd9Sstevel@tonic-gate  */
5447c478bd9Sstevel@tonic-gate 							error(gettext(
5457c478bd9Sstevel@tonic-gate 				"token numbers must be less than %d"),
5467c478bd9Sstevel@tonic-gate 							-YYFLAG1);
5477c478bd9Sstevel@tonic-gate 							}
5487c478bd9Sstevel@tonic-gate 						t = gettok();
5497c478bd9Sstevel@tonic-gate 						}
5507c478bd9Sstevel@tonic-gate 					continue;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 					}
5537c478bd9Sstevel@tonic-gate 				if (!tok_in_line)
5547c478bd9Sstevel@tonic-gate /*
5557c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5567c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5577c478bd9Sstevel@tonic-gate  */
5587c478bd9Sstevel@tonic-gate 					error(gettext(
5597c478bd9Sstevel@tonic-gate 					"missing tokens or illegal tokens"));
5607c478bd9Sstevel@tonic-gate 				break;
5617c478bd9Sstevel@tonic-gate 				}
5627c478bd9Sstevel@tonic-gate 			continue;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 		case LCURLY:
5657c478bd9Sstevel@tonic-gate 			defout();
5667c478bd9Sstevel@tonic-gate 			cpycode();
5677c478bd9Sstevel@tonic-gate 			t = gettok();
5687c478bd9Sstevel@tonic-gate 			continue;
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 		default:
5717c478bd9Sstevel@tonic-gate 			error("syntax error");
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 			}
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 		}
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	if (t == ENDFILE) {
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
5807c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
5817c478bd9Sstevel@tonic-gate  *	Do not translate %%%%.
5827c478bd9Sstevel@tonic-gate  */
5837c478bd9Sstevel@tonic-gate 		error("unexpected EOF before %%%%");
5847c478bd9Sstevel@tonic-gate 		}
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	/* t is MARK */
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 	defout();
5897c478bd9Sstevel@tonic-gate 	end_toks();	/* all tokens dumped - get ready for reductions */
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#include <inttypes.h>\n");
5927c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#ifdef __STDC__\n");
5937c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <stdlib.h>\n");
5947c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <string.h>\n");
5957c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define	YYCONST	const\n");
5967c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#else\n");
5977c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <malloc.h>\n");
5987c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#include <memory.h>\n");
5997c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define	YYCONST\n");
6007c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6017c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#include <values.h>\n");
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 	if (sym_prefix[0] != '\0')
6047c478bd9Sstevel@tonic-gate 		put_prefix_define(sym_prefix);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
6077c478bd9Sstevel@tonic-gate 	"\n#if defined(__cplusplus) || defined(__STDC__)\n");
6087c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
6097c478bd9Sstevel@tonic-gate 	"\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6107c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "extern \"C\" {\n");
6117c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6127c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifndef yyerror\n");
6137c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#if defined(__cplusplus)\n");
6147c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	void yyerror(YYCONST char *);\n");
6157c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6167c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6177c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifndef yylex\n");
6187c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	int yylex(void);\n");
6197c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6207c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "	int yyparse(void);\n");
6217c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
6227c478bd9Sstevel@tonic-gate 	"#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6237c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "}\n");
6247c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#endif\n");
6257c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "\n#endif\n\n");
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define yyclearin yychar = -1\n");
6287c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#define yyerrok yyerrflag = 0\n");
6297c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "extern int yychar;\nextern int yyerrflag;\n");
6307c478bd9Sstevel@tonic-gate 	if (!(defunion || ntypes))
6317c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable,
6327c478bd9Sstevel@tonic-gate 			"#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
6337c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yylval;\n");
6347c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yyval;\n");
6357c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "typedef int yytabelem;\n");
6367c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable,
6377c478bd9Sstevel@tonic-gate 		"#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n");
6387c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#if YYMAXDEPTH > 0\n");
6397c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "int yy_yys[YYMAXDEPTH], *yys = yy_yys;\n");
6407c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv;\n");
6417c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#else	/* user does initial allocation */\n");
6427c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "int *yys;\nYYSTYPE *yyv;\n#endif\n");
6437c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "static int yymaxdepth = YYMAXDEPTH;\n");
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	prdptr[0] = mem;
6467c478bd9Sstevel@tonic-gate 	/* added production */
6477c478bd9Sstevel@tonic-gate 	*mem++ = NTBASE;
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 	/* if start is 0, we will overwrite with the lhs of the first rule */
6507c478bd9Sstevel@tonic-gate 	*mem++ = start;
6517c478bd9Sstevel@tonic-gate 	*mem++ = 1;
6527c478bd9Sstevel@tonic-gate 	*mem++ = 0;
6537c478bd9Sstevel@tonic-gate 	prdptr[1] = mem;
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	while ((t = gettok()) == LCURLY)
6567c478bd9Sstevel@tonic-gate 		cpycode();
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	if (t != C_IDENTIFIER)
6597c478bd9Sstevel@tonic-gate 		error("bad syntax on first rule");
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	if (!start)
6627c478bd9Sstevel@tonic-gate 		prdptr[0][1] = chfind(1, tokname);
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	/* read rules */
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	while (t != MARK && t != ENDFILE) {
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 		/* process a rule */
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 		if (t == L'|') {
6717c478bd9Sstevel@tonic-gate 			rhsfill((wchar_t *)0); /* restart fill of rhs */
6727c478bd9Sstevel@tonic-gate 			*mem = *prdptr[nprod-1];
6737c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
6747c478bd9Sstevel@tonic-gate 				exp_mem(1);
6757c478bd9Sstevel@tonic-gate 		} else if (t == C_IDENTIFIER) {
6767c478bd9Sstevel@tonic-gate 			*mem = chfind(1, tokname);
6777c478bd9Sstevel@tonic-gate 			if (*mem < NTBASE)
6787c478bd9Sstevel@tonic-gate /*
6797c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
6807c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
6817c478bd9Sstevel@tonic-gate  *	Check how nonterminal is translated.
6827c478bd9Sstevel@tonic-gate  */
6837c478bd9Sstevel@tonic-gate 				error(gettext(
6847c478bd9Sstevel@tonic-gate 				"illegal nonterminal in grammar rule"));
6857c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
6867c478bd9Sstevel@tonic-gate 				exp_mem(1);
6877c478bd9Sstevel@tonic-gate 			lhsfill(tokname);	/* new rule: restart strings */
6887c478bd9Sstevel@tonic-gate 		} else
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
6917c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
6927c478bd9Sstevel@tonic-gate  */
6937c478bd9Sstevel@tonic-gate 			error(gettext(
6947c478bd9Sstevel@tonic-gate 			"illegal rule: missing semicolon or | ?"));
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 		/* read rule body */
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate 		t = gettok();
7007c478bd9Sstevel@tonic-gate 	more_rule:
7017c478bd9Sstevel@tonic-gate 		while (t == IDENTIFIER) {
7027c478bd9Sstevel@tonic-gate 			*mem = chfind(1, tokname);
7037c478bd9Sstevel@tonic-gate 			if (*mem < NTBASE)
7047c478bd9Sstevel@tonic-gate 				levprd[nprod] = toklev[*mem]& ~04;
7057c478bd9Sstevel@tonic-gate 			if (++mem >= &tracemem[new_memsize])
7067c478bd9Sstevel@tonic-gate 				exp_mem(1);
7077c478bd9Sstevel@tonic-gate 			rhsfill(tokname);	/* add to rhs string */
7087c478bd9Sstevel@tonic-gate 			t = gettok();
7097c478bd9Sstevel@tonic-gate 			}
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 		if (t == PREC) {
7127c478bd9Sstevel@tonic-gate 			if (gettok() != IDENTIFIER)
7137c478bd9Sstevel@tonic-gate /*
7147c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
7157c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
7167c478bd9Sstevel@tonic-gate  *	Do not translate %%prec.
7177c478bd9Sstevel@tonic-gate  */
7187c478bd9Sstevel@tonic-gate 				error(gettext(
7197c478bd9Sstevel@tonic-gate 				"illegal %%prec syntax"));
7207c478bd9Sstevel@tonic-gate 			j = chfind(2, tokname);
7217c478bd9Sstevel@tonic-gate 			if (j >= NTBASE)
7227c478bd9Sstevel@tonic-gate /*
7237c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
7247c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
7257c478bd9Sstevel@tonic-gate  *	Do not translate %%prec.
7267c478bd9Sstevel@tonic-gate  */
7277c478bd9Sstevel@tonic-gate 				error(gettext(
7287c478bd9Sstevel@tonic-gate 				"nonterminal %ws illegal after %%prec"),
7297c478bd9Sstevel@tonic-gate 				nontrst[j-NTBASE].name);
7307c478bd9Sstevel@tonic-gate 			levprd[nprod] = toklev[j] & ~04;
7317c478bd9Sstevel@tonic-gate 			t = gettok();
7327c478bd9Sstevel@tonic-gate 			}
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 		if (t == L'=') {
7357c478bd9Sstevel@tonic-gate 			had_act[nprod] = 1;
7367c478bd9Sstevel@tonic-gate 			levprd[nprod] |= ACTFLAG;
7377c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "\ncase %d:", nprod);
7387c478bd9Sstevel@tonic-gate 			cpyact(mem-prdptr[nprod] - 1);
7397c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, " break;");
7407c478bd9Sstevel@tonic-gate 			if ((t = gettok()) == IDENTIFIER) {
7417c478bd9Sstevel@tonic-gate 				/* action within rule... */
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 				lrprnt();		/* dump lhs, rhs */
7447c478bd9Sstevel@tonic-gate 				(void) wsprintf(actname, "$$%d", nprod);
7457c478bd9Sstevel@tonic-gate 				/*
7467c478bd9Sstevel@tonic-gate 				 * make it nonterminal
7477c478bd9Sstevel@tonic-gate 				 */
7487c478bd9Sstevel@tonic-gate 				j = chfind(1, actname);
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 				/*
7517c478bd9Sstevel@tonic-gate 				 * the current rule will become rule
7527c478bd9Sstevel@tonic-gate 				 * number nprod+1 move the contents down,
7537c478bd9Sstevel@tonic-gate 				 * and make room for the null
7547c478bd9Sstevel@tonic-gate 				 */
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 				if (mem + 2 >= &tracemem[new_memsize])
7577c478bd9Sstevel@tonic-gate 					exp_mem(1);
7587c478bd9Sstevel@tonic-gate 				for (p = mem; p >= prdptr[nprod]; --p)
7597c478bd9Sstevel@tonic-gate 					p[2] = *p;
7607c478bd9Sstevel@tonic-gate 				mem += 2;
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 				/* enter null production for action */
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 				p = prdptr[nprod];
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 				*p++ = j;
7677c478bd9Sstevel@tonic-gate 				*p++ = -nprod;
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 				/* update the production information */
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 				levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
7727c478bd9Sstevel@tonic-gate 				levprd[nprod] = ACTFLAG;
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 				if (++nprod >= nprodsz)
7757c478bd9Sstevel@tonic-gate 					exp_prod();
7767c478bd9Sstevel@tonic-gate 				prdptr[nprod] = p;
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 				/*
7797c478bd9Sstevel@tonic-gate 				 * make the action appear in
7807c478bd9Sstevel@tonic-gate 				 * the original rule
7817c478bd9Sstevel@tonic-gate 				 */
7827c478bd9Sstevel@tonic-gate 				*mem++ = j;
7837c478bd9Sstevel@tonic-gate 				if (mem >= &tracemem[new_memsize])
7847c478bd9Sstevel@tonic-gate 					exp_mem(1);
7857c478bd9Sstevel@tonic-gate 				/* get some more of the rule */
7867c478bd9Sstevel@tonic-gate 				goto more_rule;
7877c478bd9Sstevel@tonic-gate 			}
7887c478bd9Sstevel@tonic-gate 		}
7897c478bd9Sstevel@tonic-gate 		while (t == L';')
7907c478bd9Sstevel@tonic-gate 			t = gettok();
7917c478bd9Sstevel@tonic-gate 		*mem++ = -nprod;
7927c478bd9Sstevel@tonic-gate 		if (mem >= &tracemem[new_memsize])
7937c478bd9Sstevel@tonic-gate 			exp_mem(1);
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 		/* check that default action is reasonable */
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 		if (ntypes && !(levprd[nprod] & ACTFLAG) &&
7987c478bd9Sstevel@tonic-gate 				nontrst[*prdptr[nprod]-NTBASE].tvalue) {
7997c478bd9Sstevel@tonic-gate 			/* no explicit action, LHS has value */
800*e29394bdSmike_s 			int tempty;
8017c478bd9Sstevel@tonic-gate 			tempty = prdptr[nprod][1];
8027c478bd9Sstevel@tonic-gate 			if (tempty < 0)
8037c478bd9Sstevel@tonic-gate /*
8047c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
8057c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
8067c478bd9Sstevel@tonic-gate  *	LHS means Left Hand Side. It does not need to be translated.
8077c478bd9Sstevel@tonic-gate  */
8087c478bd9Sstevel@tonic-gate 				error(gettext(
8097c478bd9Sstevel@tonic-gate 				"must return a value, since LHS has a type"));
8107c478bd9Sstevel@tonic-gate 			else if (tempty >= NTBASE)
8117c478bd9Sstevel@tonic-gate 				tempty = nontrst[tempty-NTBASE].tvalue;
8127c478bd9Sstevel@tonic-gate 			else
8137c478bd9Sstevel@tonic-gate 				tempty = TYPE(toklev[tempty]);
8147c478bd9Sstevel@tonic-gate 			if (tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue) {
8157c478bd9Sstevel@tonic-gate /*
8167c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
8177c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
8187c478bd9Sstevel@tonic-gate  *	Check how action is transltated in yacc man page or documents.
8197c478bd9Sstevel@tonic-gate  */
8207c478bd9Sstevel@tonic-gate 				error(gettext(
8217c478bd9Sstevel@tonic-gate 				"default action causes potential type clash"));
8227c478bd9Sstevel@tonic-gate 			}
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 		if (++nprod >= nprodsz)
8267c478bd9Sstevel@tonic-gate 			exp_prod();
8277c478bd9Sstevel@tonic-gate 		prdptr[nprod] = mem;
8287c478bd9Sstevel@tonic-gate 		levprd[nprod] = 0;
8297c478bd9Sstevel@tonic-gate 		}
8307c478bd9Sstevel@tonic-gate 	/* end of all rules */
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	end_debug();		/* finish fdebug file's input */
8337c478bd9Sstevel@tonic-gate 	finact();
8347c478bd9Sstevel@tonic-gate 	if (t == MARK) {
8357c478bd9Sstevel@tonic-gate 		if (gen_lines)
8367c478bd9Sstevel@tonic-gate 			(void) fprintf(ftable, "\n# line %d \"%s\"\n",
8377c478bd9Sstevel@tonic-gate 				lineno, infile);
8387c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != EOF)
8397c478bd9Sstevel@tonic-gate 			(void) putwc(c, ftable);
8407c478bd9Sstevel@tonic-gate 		}
8417c478bd9Sstevel@tonic-gate 	(void) fclose(finput);
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate static void
8457c478bd9Sstevel@tonic-gate finact()
8467c478bd9Sstevel@tonic-gate {
8477c478bd9Sstevel@tonic-gate 	/* finish action routine */
8487c478bd9Sstevel@tonic-gate 	(void) fclose(faction);
8497c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "# define YYERRCODE %d\n", tokset[2].value);
8507c478bd9Sstevel@tonic-gate }
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate static wchar_t *
8537c478bd9Sstevel@tonic-gate cstash(s)
8547c478bd9Sstevel@tonic-gate register wchar_t *s;
8557c478bd9Sstevel@tonic-gate {
8567c478bd9Sstevel@tonic-gate 	wchar_t *temp;
8577c478bd9Sstevel@tonic-gate 	static int used = 0;
8587c478bd9Sstevel@tonic-gate 	static int used_save = 0;
8597c478bd9Sstevel@tonic-gate 	static int exp_cname = CNAMSZ;
8607c478bd9Sstevel@tonic-gate 	int len = wslen(s);
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	/*
8637c478bd9Sstevel@tonic-gate 	 * 2/29/88 -
8647c478bd9Sstevel@tonic-gate 	 * Don't need to expand the table, just allocate new space.
8657c478bd9Sstevel@tonic-gate 	 */
8667c478bd9Sstevel@tonic-gate 	used_save = used;
8677c478bd9Sstevel@tonic-gate 	while (len >= (exp_cname - used_save)) {
8687c478bd9Sstevel@tonic-gate 		exp_cname += CNAMSZ;
8697c478bd9Sstevel@tonic-gate 		if (!used)
8707c478bd9Sstevel@tonic-gate 			free((char *)cnames);
8717c478bd9Sstevel@tonic-gate 		if ((cnames = (wchar_t *)
8727c478bd9Sstevel@tonic-gate 			malloc(sizeof (wchar_t)*exp_cname)) == NULL)
8737c478bd9Sstevel@tonic-gate /*
8747c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
8757c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
8767c478bd9Sstevel@tonic-gate  *
8777c478bd9Sstevel@tonic-gate  *	You may just translate this as:
8787c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
8797c478bd9Sstevel@tonic-gate  */
8807c478bd9Sstevel@tonic-gate 			error(gettext(
8817c478bd9Sstevel@tonic-gate 			"cannot expand string dump"));
8827c478bd9Sstevel@tonic-gate 		cnamp = cnames;
8837c478bd9Sstevel@tonic-gate 		used = 0;
8847c478bd9Sstevel@tonic-gate 	}
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 	temp = cnamp;
8877c478bd9Sstevel@tonic-gate 	do {
8887c478bd9Sstevel@tonic-gate 		*cnamp++ = *s;
8897c478bd9Sstevel@tonic-gate 	} while (*s++);
8907c478bd9Sstevel@tonic-gate 	used += cnamp - temp;
8917c478bd9Sstevel@tonic-gate 	return (temp);
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate static int
895*e29394bdSmike_s defin(int t, wchar_t *s)
8967c478bd9Sstevel@tonic-gate {
8977c478bd9Sstevel@tonic-gate 	/* define s to be a terminal if t=0 or a nonterminal if t=1 */
8987c478bd9Sstevel@tonic-gate 
899*e29394bdSmike_s 	int val;
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 	if (t) {
9027c478bd9Sstevel@tonic-gate 		if (++nnonter >= nnontersz)
9037c478bd9Sstevel@tonic-gate 			exp_nonterm();
9047c478bd9Sstevel@tonic-gate 		nontrst[nnonter].name = cstash(s);
9057c478bd9Sstevel@tonic-gate 		return (NTBASE + nnonter);
9067c478bd9Sstevel@tonic-gate 		}
9077c478bd9Sstevel@tonic-gate 	/* must be a token */
9087c478bd9Sstevel@tonic-gate 	if (++ntokens >= ntoksz)
9097c478bd9Sstevel@tonic-gate 		exp_ntok();
9107c478bd9Sstevel@tonic-gate 	tokset[ntokens].name = cstash(s);
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 	/* establish value for token */
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	if (s[0] == L' ' && s[2] == 0) { /* single character literal */
9157c478bd9Sstevel@tonic-gate 		val = findchtok(s[1]);
9167c478bd9Sstevel@tonic-gate 	} else if (s[0] == L' ' && s[1] == L'\\') { /* escape sequence */
9177c478bd9Sstevel@tonic-gate 		if (s[3] == 0) { /* single character escape sequence */
9187c478bd9Sstevel@tonic-gate 			switch (s[2]) {
9197c478bd9Sstevel@tonic-gate 				/* character which is escaped */
9207c478bd9Sstevel@tonic-gate 			case L'a':
9217c478bd9Sstevel@tonic-gate 				(void) warning(1, gettext(
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9247c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
9257c478bd9Sstevel@tonic-gate  *	Do not trasnlate ANSI C, \\a.
9267c478bd9Sstevel@tonic-gate  */
9277c478bd9Sstevel@tonic-gate 		"\\a is ANSI C \"alert\" character"));
9287c478bd9Sstevel@tonic-gate #if __STDC__ - 1 == 0
9297c478bd9Sstevel@tonic-gate 				val = L'\a';
9307c478bd9Sstevel@tonic-gate 				break;
9317c478bd9Sstevel@tonic-gate #else
9327c478bd9Sstevel@tonic-gate 				val = L'\007';
9337c478bd9Sstevel@tonic-gate 				break;
9347c478bd9Sstevel@tonic-gate #endif
9357c478bd9Sstevel@tonic-gate 			case L'v': val = L'\v'; break;
9367c478bd9Sstevel@tonic-gate 			case L'n': val = L'\n'; break;
9377c478bd9Sstevel@tonic-gate 			case L'r': val = L'\r'; break;
9387c478bd9Sstevel@tonic-gate 			case L'b': val = L'\b'; break;
9397c478bd9Sstevel@tonic-gate 			case L't': val = L'\t'; break;
9407c478bd9Sstevel@tonic-gate 			case L'f': val = L'\f'; break;
9417c478bd9Sstevel@tonic-gate 			case L'\'': val = L'\''; break;
9427c478bd9Sstevel@tonic-gate 			case L'"': val = L'"'; break;
9437c478bd9Sstevel@tonic-gate 			case L'?': val = L'?'; break;
9447c478bd9Sstevel@tonic-gate 			case L'\\': val = L'\\'; break;
9457c478bd9Sstevel@tonic-gate /*
9467c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9477c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
9487c478bd9Sstevel@tonic-gate  */
9497c478bd9Sstevel@tonic-gate 			default: error(gettext(
9507c478bd9Sstevel@tonic-gate 				"invalid escape"));
9517c478bd9Sstevel@tonic-gate 			}
9527c478bd9Sstevel@tonic-gate 		} else if (s[2] <= L'7' && s[2] >= L'0') { /* \nnn sequence */
9537c478bd9Sstevel@tonic-gate 			int i = 3;
9547c478bd9Sstevel@tonic-gate 			val = s[2] - L'0';
9557c478bd9Sstevel@tonic-gate 			while (iswdigit(s[i]) && i <= 4) {
9567c478bd9Sstevel@tonic-gate 				if (s[i] >= L'0' && s[i] <= L'7')
9577c478bd9Sstevel@tonic-gate 					val = val * 8 + s[i] - L'0';
9587c478bd9Sstevel@tonic-gate 				else
9597c478bd9Sstevel@tonic-gate /*
9607c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9617c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
9627c478bd9Sstevel@tonic-gate  */
9637c478bd9Sstevel@tonic-gate 					error(gettext(
9647c478bd9Sstevel@tonic-gate 					"illegal octal number"));
9657c478bd9Sstevel@tonic-gate 				i++;
9667c478bd9Sstevel@tonic-gate 			}
9677c478bd9Sstevel@tonic-gate 			if (s[i] != 0)
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9707c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
9717c478bd9Sstevel@tonic-gate  *	Do not translate \\nnn.
9727c478bd9Sstevel@tonic-gate  */
9737c478bd9Sstevel@tonic-gate 				error(gettext(
9747c478bd9Sstevel@tonic-gate 				"illegal \\nnn construction"));
9757c478bd9Sstevel@tonic-gate 			if (val > 255)
9767c478bd9Sstevel@tonic-gate /*
9777c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9787c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
9797c478bd9Sstevel@tonic-gate  *	Do not translate
9807c478bd9Sstevel@tonic-gate  *		\\nnn, \\xnnnnnnnn.
9817c478bd9Sstevel@tonic-gate  */
9827c478bd9Sstevel@tonic-gate 				error(
9837c478bd9Sstevel@tonic-gate "\\nnn exceed \\377; use \\xnnnnnnnn for wchar_t value of multibyte char");
9847c478bd9Sstevel@tonic-gate 			if (val == 0 && i >= 4)
9857c478bd9Sstevel@tonic-gate /*
9867c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9877c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
9887c478bd9Sstevel@tonic-gate  *	Do not translate \\000.
9897c478bd9Sstevel@tonic-gate  */
9907c478bd9Sstevel@tonic-gate 				error(gettext(
9917c478bd9Sstevel@tonic-gate 				"'\\000' is illegal"));
9927c478bd9Sstevel@tonic-gate 		} else if (s[2] == L'x') { /* hexadecimal \xnnn sequence */
9937c478bd9Sstevel@tonic-gate 			int i = 3;
9947c478bd9Sstevel@tonic-gate 			val = 0;
9957c478bd9Sstevel@tonic-gate /*
9967c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
9977c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
9987c478bd9Sstevel@tonic-gate  *	Do not translate \\x, ANSI C.
9997c478bd9Sstevel@tonic-gate  */
10007c478bd9Sstevel@tonic-gate 			(void) warning(1, gettext(
10017c478bd9Sstevel@tonic-gate 				"\\x is ANSI C hex escape"));
10027c478bd9Sstevel@tonic-gate 			if (iswxdigit(s[i]))
10037c478bd9Sstevel@tonic-gate 				while (iswxdigit(s[i])) {
10047c478bd9Sstevel@tonic-gate 					int tmpval;
10057c478bd9Sstevel@tonic-gate 					if (iswdigit(s[i]))
10067c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'0';
10077c478bd9Sstevel@tonic-gate 					else if (s[i] >= L'a')
10087c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'a' + 10;
10097c478bd9Sstevel@tonic-gate 					else
10107c478bd9Sstevel@tonic-gate 						tmpval = s[i] - L'A' + 10;
10117c478bd9Sstevel@tonic-gate 					val = 16 * val + tmpval;
10127c478bd9Sstevel@tonic-gate 					i++;
10137c478bd9Sstevel@tonic-gate 				}
10147c478bd9Sstevel@tonic-gate 			else
10157c478bd9Sstevel@tonic-gate 				error(gettext(
10167c478bd9Sstevel@tonic-gate 				"illegal hexadecimal number"));
10177c478bd9Sstevel@tonic-gate 			if (s[i] != 0)
10187c478bd9Sstevel@tonic-gate /*
10197c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
10207c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
10217c478bd9Sstevel@tonic-gate  *	Do not translate \\xnn.
10227c478bd9Sstevel@tonic-gate  */
10237c478bd9Sstevel@tonic-gate 				error(gettext(
10247c478bd9Sstevel@tonic-gate 				"illegal \\xnn construction"));
10257c478bd9Sstevel@tonic-gate #define	LWCHAR_MAX	0x7fffffff
10267c478bd9Sstevel@tonic-gate 			if ((unsigned)val > LWCHAR_MAX)
10277c478bd9Sstevel@tonic-gate /*
10287c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
10297c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
10307c478bd9Sstevel@tonic-gate  *	Do not translate \\xnnnnnnnn and %#x.
10317c478bd9Sstevel@tonic-gate  */
10327c478bd9Sstevel@tonic-gate 			    error(gettext(
10337c478bd9Sstevel@tonic-gate 			    " \\xnnnnnnnn exceed %#x"),
10347c478bd9Sstevel@tonic-gate 			    LWCHAR_MAX);
10357c478bd9Sstevel@tonic-gate 			if (val == 0)
10367c478bd9Sstevel@tonic-gate /*
10377c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
10387c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
10397c478bd9Sstevel@tonic-gate  *	Do not translate \\x00.
10407c478bd9Sstevel@tonic-gate  */
10417c478bd9Sstevel@tonic-gate 				error(gettext(
10427c478bd9Sstevel@tonic-gate 				"'\\x00' is illegal"));
10437c478bd9Sstevel@tonic-gate 			val = findchtok(val);
10447c478bd9Sstevel@tonic-gate 		} else
10457c478bd9Sstevel@tonic-gate 			error(gettext(
10467c478bd9Sstevel@tonic-gate 			"invalid escape"));
10477c478bd9Sstevel@tonic-gate 	} else {
10487c478bd9Sstevel@tonic-gate 		val = extval++;
10497c478bd9Sstevel@tonic-gate 	}
10507c478bd9Sstevel@tonic-gate 	tokset[ntokens].value = val;
10517c478bd9Sstevel@tonic-gate 	toklev[ntokens] = 0;
10527c478bd9Sstevel@tonic-gate 	return (ntokens);
10537c478bd9Sstevel@tonic-gate }
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate static void
10567c478bd9Sstevel@tonic-gate defout()
10577c478bd9Sstevel@tonic-gate {
10587c478bd9Sstevel@tonic-gate 	/* write out the defines (at the end of the declaration section) */
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate 	register int i, c;
10617c478bd9Sstevel@tonic-gate 	register wchar_t *cp;
10627c478bd9Sstevel@tonic-gate 
10637c478bd9Sstevel@tonic-gate 	for (i = ndefout; i <= ntokens; ++i) {
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 		cp = tokset[i].name;
10667c478bd9Sstevel@tonic-gate 		if (*cp == L' ')	/* literals */
10677c478bd9Sstevel@tonic-gate 		{
10687c478bd9Sstevel@tonic-gate 			(void) fprintf(fdebug, "\t\"%ws\",\t%d,\n",
10697c478bd9Sstevel@tonic-gate 				tokset[i].name + 1, tokset[i].value);
10707c478bd9Sstevel@tonic-gate 			continue;	/* was cp++ */
10717c478bd9Sstevel@tonic-gate 		}
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 		for (; (c = *cp) != 0; ++cp) {
10747c478bd9Sstevel@tonic-gate 			if (iswlower(c) || iswupper(c) ||
10757c478bd9Sstevel@tonic-gate 				iswdigit(c) || c == L'_') /* EMPTY */;
10767c478bd9Sstevel@tonic-gate 			else
10777c478bd9Sstevel@tonic-gate 				goto nodef;
10787c478bd9Sstevel@tonic-gate 			}
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate 		(void) fprintf(fdebug,
10817c478bd9Sstevel@tonic-gate 			"\t\"%ws\",\t%d,\n", tokset[i].name,
10827c478bd9Sstevel@tonic-gate 			tokset[i].value);
10837c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable,
10847c478bd9Sstevel@tonic-gate 			"# define %ws %d\n", tokset[i].name,
10857c478bd9Sstevel@tonic-gate 			tokset[i].value);
10867c478bd9Sstevel@tonic-gate 		if (fdefine != NULL)
10877c478bd9Sstevel@tonic-gate 			(void) fprintf(fdefine,
10887c478bd9Sstevel@tonic-gate 				"# define %ws %d\n",
10897c478bd9Sstevel@tonic-gate 				tokset[i].name,
10907c478bd9Sstevel@tonic-gate 				tokset[i].value);
10917c478bd9Sstevel@tonic-gate 
10927c478bd9Sstevel@tonic-gate 	nodef:;
10937c478bd9Sstevel@tonic-gate 	}
10947c478bd9Sstevel@tonic-gate 	ndefout = ntokens+1;
10957c478bd9Sstevel@tonic-gate }
10967c478bd9Sstevel@tonic-gate 
1097*e29394bdSmike_s static int
10987c478bd9Sstevel@tonic-gate gettok()
10997c478bd9Sstevel@tonic-gate {
1100*e29394bdSmike_s 	int i, base;
11017c478bd9Sstevel@tonic-gate 	static int peekline; /* number of '\n' seen in lookahead */
1102*e29394bdSmike_s 	int c, match, reserve;
11037c478bd9Sstevel@tonic-gate begin:
11047c478bd9Sstevel@tonic-gate 	reserve = 0;
11057c478bd9Sstevel@tonic-gate 	lineno += peekline;
11067c478bd9Sstevel@tonic-gate 	peekline = 0;
11077c478bd9Sstevel@tonic-gate 	c = getwc(finput);
11087c478bd9Sstevel@tonic-gate 	/*
11097c478bd9Sstevel@tonic-gate 	 * while (c == ' ' || c == '\n' || c == '\t' || c == '\f') {
11107c478bd9Sstevel@tonic-gate 	 */
11117c478bd9Sstevel@tonic-gate 	while (iswspace(c)) {
11127c478bd9Sstevel@tonic-gate 		if (c == L'\n')
11137c478bd9Sstevel@tonic-gate 			++lineno;
11147c478bd9Sstevel@tonic-gate 		c = getwc(finput);
11157c478bd9Sstevel@tonic-gate 	}
11167c478bd9Sstevel@tonic-gate 	if (c == L'/') { /* skip comment */
11177c478bd9Sstevel@tonic-gate 		lineno += skipcom();
11187c478bd9Sstevel@tonic-gate 		goto begin;
11197c478bd9Sstevel@tonic-gate 	}
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	switch (c) {
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	case EOF:
11247c478bd9Sstevel@tonic-gate 		return (ENDFILE);
11257c478bd9Sstevel@tonic-gate 	case L'{':
11267c478bd9Sstevel@tonic-gate 		(void) ungetwc(c, finput);
11277c478bd9Sstevel@tonic-gate 		return (L'=');  /* action ... */
11287c478bd9Sstevel@tonic-gate 	case L'<':  /* get, and look up, a type name (union member name) */
11297c478bd9Sstevel@tonic-gate 		i = 0;
11307c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != L'>' &&
11317c478bd9Sstevel@tonic-gate 				c != EOF && c != L'\n') {
11327c478bd9Sstevel@tonic-gate 			tokname[i] = c;
11337c478bd9Sstevel@tonic-gate 			if (++i >= toksize)
11347c478bd9Sstevel@tonic-gate 				exp_tokname();
11357c478bd9Sstevel@tonic-gate 			}
11367c478bd9Sstevel@tonic-gate 		if (c != L'>')
11377c478bd9Sstevel@tonic-gate 			error(gettext(
11387c478bd9Sstevel@tonic-gate 			"unterminated < ... > clause"));
11397c478bd9Sstevel@tonic-gate 		tokname[i] = 0;
11407c478bd9Sstevel@tonic-gate 		if (i == 0)
11417c478bd9Sstevel@tonic-gate 			error("missing type name in < ... > clause");
11427c478bd9Sstevel@tonic-gate 		for (i = 1; i <= ntypes; ++i) {
11437c478bd9Sstevel@tonic-gate 			if (!wscmp(typeset[i], tokname)) {
11447c478bd9Sstevel@tonic-gate 				numbval = i;
11457c478bd9Sstevel@tonic-gate 				return (TYPENAME);
11467c478bd9Sstevel@tonic-gate 				}
11477c478bd9Sstevel@tonic-gate 			}
11487c478bd9Sstevel@tonic-gate 		typeset[numbval = ++ntypes] = cstash(tokname);
11497c478bd9Sstevel@tonic-gate 		return (TYPENAME);
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate 	case L'"':
11527c478bd9Sstevel@tonic-gate 	case L'\'':
11537c478bd9Sstevel@tonic-gate 		match = c;
11547c478bd9Sstevel@tonic-gate 		tokname[0] = L' ';
11557c478bd9Sstevel@tonic-gate 		i = 1;
11567c478bd9Sstevel@tonic-gate 		for (;;) {
11577c478bd9Sstevel@tonic-gate 			c = getwc(finput);
11587c478bd9Sstevel@tonic-gate 			if (c == L'\n' || c == EOF)
11597c478bd9Sstevel@tonic-gate 				error(gettext(
11607c478bd9Sstevel@tonic-gate 				"illegal or missing ' or \""));
11617c478bd9Sstevel@tonic-gate 			if (c == L'\\') {
11627c478bd9Sstevel@tonic-gate 				c = getwc(finput);
11637c478bd9Sstevel@tonic-gate 				tokname[i] = L'\\';
11647c478bd9Sstevel@tonic-gate 				if (++i >= toksize)
11657c478bd9Sstevel@tonic-gate 					exp_tokname();
11667c478bd9Sstevel@tonic-gate 			} else if (c == match) break;
11677c478bd9Sstevel@tonic-gate 			tokname[i] = c;
11687c478bd9Sstevel@tonic-gate 			if (++i >= toksize)
11697c478bd9Sstevel@tonic-gate 				exp_tokname();
11707c478bd9Sstevel@tonic-gate 			}
11717c478bd9Sstevel@tonic-gate 		break;
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate 	case L'%':
11747c478bd9Sstevel@tonic-gate 	case L'\\':
11757c478bd9Sstevel@tonic-gate 
11767c478bd9Sstevel@tonic-gate 		switch (c = getwc(finput)) {
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 		case L'0':	return (TERM);
11797c478bd9Sstevel@tonic-gate 		case L'<':	return (LEFT);
11807c478bd9Sstevel@tonic-gate 		case L'2':	return (BINARY);
11817c478bd9Sstevel@tonic-gate 		case L'>':	return (RIGHT);
11827c478bd9Sstevel@tonic-gate 		case L'%':
11837c478bd9Sstevel@tonic-gate 		case L'\\':	return (MARK);
11847c478bd9Sstevel@tonic-gate 		case L'=':	return (PREC);
11857c478bd9Sstevel@tonic-gate 		case L'{':	return (LCURLY);
11867c478bd9Sstevel@tonic-gate 		default:	reserve = 1;
11877c478bd9Sstevel@tonic-gate 			}
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 	default:
11907c478bd9Sstevel@tonic-gate 
11917c478bd9Sstevel@tonic-gate 		if (iswdigit(c)) { /* number */
11927c478bd9Sstevel@tonic-gate 			numbval = c - L'0';
11937c478bd9Sstevel@tonic-gate 			base = (c == L'0') ? 8 : 10;
11947c478bd9Sstevel@tonic-gate 			for (c = getwc(finput);
11957c478bd9Sstevel@tonic-gate 					iswdigit(c);
11967c478bd9Sstevel@tonic-gate 					c = getwc(finput)) {
11977c478bd9Sstevel@tonic-gate 				numbval = numbval*base + c - L'0';
11987c478bd9Sstevel@tonic-gate 				}
11997c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
12007c478bd9Sstevel@tonic-gate 			return (NUMBER);
12017c478bd9Sstevel@tonic-gate 		} else if (iswlower(c) || iswupper(c) ||
12027c478bd9Sstevel@tonic-gate 				c == L'_' || c == L'.' ||
12037c478bd9Sstevel@tonic-gate 				c == L'$') {
12047c478bd9Sstevel@tonic-gate 			i = 0;
12057c478bd9Sstevel@tonic-gate 			while (iswlower(c) || iswupper(c) ||
12067c478bd9Sstevel@tonic-gate 					iswdigit(c) || c == L'_' ||
12077c478bd9Sstevel@tonic-gate 					c == L'.' || c == L'$') {
12087c478bd9Sstevel@tonic-gate 				tokname[i] = c;
12097c478bd9Sstevel@tonic-gate 				if (reserve && iswupper(c))
12107c478bd9Sstevel@tonic-gate 					tokname[i] = towlower(c);
12117c478bd9Sstevel@tonic-gate 				if (++i >= toksize)
12127c478bd9Sstevel@tonic-gate 					exp_tokname();
12137c478bd9Sstevel@tonic-gate 				c = getwc(finput);
12147c478bd9Sstevel@tonic-gate 				}
12157c478bd9Sstevel@tonic-gate 			}
12167c478bd9Sstevel@tonic-gate 		else
12177c478bd9Sstevel@tonic-gate 			return (c);
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 		(void) ungetwc(c, finput);
12207c478bd9Sstevel@tonic-gate 		}
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	tokname[i] = 0;
12237c478bd9Sstevel@tonic-gate 
12247c478bd9Sstevel@tonic-gate 	if (reserve) { /* find a reserved word */
12257c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"term"))
12267c478bd9Sstevel@tonic-gate 			return (TERM);
12277c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"token"))
12287c478bd9Sstevel@tonic-gate 			return (TERM);
12297c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"left"))
12307c478bd9Sstevel@tonic-gate 			return (LEFT);
12317c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"nonassoc"))
12327c478bd9Sstevel@tonic-gate 			return (BINARY);
12337c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"binary"))
12347c478bd9Sstevel@tonic-gate 			return (BINARY);
12357c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"right"))
12367c478bd9Sstevel@tonic-gate 			return (RIGHT);
12377c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"prec"))
12387c478bd9Sstevel@tonic-gate 			return (PREC);
12397c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"start"))
12407c478bd9Sstevel@tonic-gate 			return (START);
12417c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"type"))
12427c478bd9Sstevel@tonic-gate 			return (TYPEDEF);
12437c478bd9Sstevel@tonic-gate 		if (!wscmp(tokname, L"union"))
12447c478bd9Sstevel@tonic-gate 			return (UNION);
12457c478bd9Sstevel@tonic-gate 		error(gettext(
12467c478bd9Sstevel@tonic-gate 		"invalid escape, or illegal reserved word: %ws"),
12477c478bd9Sstevel@tonic-gate 		tokname);
12487c478bd9Sstevel@tonic-gate 		}
12497c478bd9Sstevel@tonic-gate 
12507c478bd9Sstevel@tonic-gate 	/* look ahead to distinguish IDENTIFIER from C_IDENTIFIER */
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	c = getwc(finput);
12537c478bd9Sstevel@tonic-gate 	/*
12547c478bd9Sstevel@tonic-gate 	 * while (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '/')
12557c478bd9Sstevel@tonic-gate 	 * {
12567c478bd9Sstevel@tonic-gate 	 */
12577c478bd9Sstevel@tonic-gate 	while (iswspace(c) || c == L'/') {
12587c478bd9Sstevel@tonic-gate 		if (c == L'\n') {
12597c478bd9Sstevel@tonic-gate 			++peekline;
12607c478bd9Sstevel@tonic-gate 		} else if (c == L'/') { /* look for comments */
12617c478bd9Sstevel@tonic-gate 			peekline += skipcom();
12627c478bd9Sstevel@tonic-gate 			}
12637c478bd9Sstevel@tonic-gate 		c = getwc(finput);
12647c478bd9Sstevel@tonic-gate 		}
12657c478bd9Sstevel@tonic-gate 	if (c == L':')
12667c478bd9Sstevel@tonic-gate 		return (C_IDENTIFIER);
12677c478bd9Sstevel@tonic-gate 	(void) ungetwc(c, finput);
12687c478bd9Sstevel@tonic-gate 	return (IDENTIFIER);
12697c478bd9Sstevel@tonic-gate }
12707c478bd9Sstevel@tonic-gate 
1271*e29394bdSmike_s static int
1272*e29394bdSmike_s fdtype(int t)
12737c478bd9Sstevel@tonic-gate {
12747c478bd9Sstevel@tonic-gate 	/* determine the type of a symbol */
1275*e29394bdSmike_s 	int v;
12767c478bd9Sstevel@tonic-gate 	if (t >= NTBASE)
12777c478bd9Sstevel@tonic-gate 		v = nontrst[t-NTBASE].tvalue;
12787c478bd9Sstevel@tonic-gate 	else
12797c478bd9Sstevel@tonic-gate 		v = TYPE(toklev[t]);
12807c478bd9Sstevel@tonic-gate 	if (v <= 0)
12817c478bd9Sstevel@tonic-gate 		error(gettext(
12827c478bd9Sstevel@tonic-gate 			"must specify type for %ws"),
12837c478bd9Sstevel@tonic-gate 			(t >= NTBASE) ? nontrst[t-NTBASE].name:
12847c478bd9Sstevel@tonic-gate 			tokset[t].name);
12857c478bd9Sstevel@tonic-gate 	return (v);
12867c478bd9Sstevel@tonic-gate }
12877c478bd9Sstevel@tonic-gate 
1288*e29394bdSmike_s static int
1289*e29394bdSmike_s chfind(int t, wchar_t *s)
12907c478bd9Sstevel@tonic-gate {
12917c478bd9Sstevel@tonic-gate 	int i;
12927c478bd9Sstevel@tonic-gate 
12937c478bd9Sstevel@tonic-gate 	if (s[0] == ' ')
12947c478bd9Sstevel@tonic-gate 		t = 0;
12957c478bd9Sstevel@tonic-gate 	TLOOP(i) {
12967c478bd9Sstevel@tonic-gate 		if (!wscmp(s, tokset[i].name)) {
12977c478bd9Sstevel@tonic-gate 			return (i);
12987c478bd9Sstevel@tonic-gate 		}
12997c478bd9Sstevel@tonic-gate 	}
13007c478bd9Sstevel@tonic-gate 	NTLOOP(i) {
13017c478bd9Sstevel@tonic-gate 		if (!wscmp(s, nontrst[i].name)) {
13027c478bd9Sstevel@tonic-gate 			return (i + NTBASE);
13037c478bd9Sstevel@tonic-gate 		}
13047c478bd9Sstevel@tonic-gate 	}
13057c478bd9Sstevel@tonic-gate 	/* cannot find name */
13067c478bd9Sstevel@tonic-gate 	if (t > 1)
13077c478bd9Sstevel@tonic-gate 		error(gettext(
13087c478bd9Sstevel@tonic-gate 		"%ws should have been defined earlier"), s);
13097c478bd9Sstevel@tonic-gate 	return (defin(t, s));
13107c478bd9Sstevel@tonic-gate }
13117c478bd9Sstevel@tonic-gate 
13127c478bd9Sstevel@tonic-gate static void
13137c478bd9Sstevel@tonic-gate cpyunion()
13147c478bd9Sstevel@tonic-gate {
13157c478bd9Sstevel@tonic-gate 	/*
13167c478bd9Sstevel@tonic-gate 	 * copy the union declaration to the output,
13177c478bd9Sstevel@tonic-gate 	 * and the define file if present
13187c478bd9Sstevel@tonic-gate 	 */
13197c478bd9Sstevel@tonic-gate 	int level, c;
13207c478bd9Sstevel@tonic-gate 	if (gen_lines)
13217c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
13227c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "typedef union\n");
13237c478bd9Sstevel@tonic-gate 	if (fdefine)
13247c478bd9Sstevel@tonic-gate 		(void) fprintf(fdefine, "\ntypedef union\n");
13257c478bd9Sstevel@tonic-gate 	(void) fprintf(ftable, "#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
13267c478bd9Sstevel@tonic-gate 	if (fdefine)
13277c478bd9Sstevel@tonic-gate 		(void) fprintf(fdefine,
13287c478bd9Sstevel@tonic-gate 			"#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
13297c478bd9Sstevel@tonic-gate 
13307c478bd9Sstevel@tonic-gate 	level = 0;
13317c478bd9Sstevel@tonic-gate 	for (;;) {
13327c478bd9Sstevel@tonic-gate 		if ((c = getwc(finput)) == EOF)
13337c478bd9Sstevel@tonic-gate /*
13347c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
13357c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
13367c478bd9Sstevel@tonic-gate  *	EOF - End Of File.
13377c478bd9Sstevel@tonic-gate  *	Do not translate %%union.
13387c478bd9Sstevel@tonic-gate  */
13397c478bd9Sstevel@tonic-gate 			error(gettext(
13407c478bd9Sstevel@tonic-gate 			"EOF encountered while processing %%union"));
13417c478bd9Sstevel@tonic-gate 		(void) putwc(c, ftable);
13427c478bd9Sstevel@tonic-gate 		if (fdefine)
13437c478bd9Sstevel@tonic-gate 			(void) putwc(c, fdefine);
13447c478bd9Sstevel@tonic-gate 
13457c478bd9Sstevel@tonic-gate 		switch (c) {
13467c478bd9Sstevel@tonic-gate 
13477c478bd9Sstevel@tonic-gate 		case L'\n':
13487c478bd9Sstevel@tonic-gate 			++lineno;
13497c478bd9Sstevel@tonic-gate 			break;
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 		case L'{':
13527c478bd9Sstevel@tonic-gate 			++level;
13537c478bd9Sstevel@tonic-gate 			break;
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 		case L'}':
13567c478bd9Sstevel@tonic-gate 			--level;
13577c478bd9Sstevel@tonic-gate 			if (level == 0) { /* we are finished copying */
13587c478bd9Sstevel@tonic-gate 				(void) fprintf(ftable, " YYSTYPE;\n");
13597c478bd9Sstevel@tonic-gate 				if (fdefine)
13607c478bd9Sstevel@tonic-gate 					(void) fprintf(fdefine,
13617c478bd9Sstevel@tonic-gate 					" YYSTYPE;\nextern YYSTYPE yylval;\n");
13627c478bd9Sstevel@tonic-gate 				return;
13637c478bd9Sstevel@tonic-gate 				}
13647c478bd9Sstevel@tonic-gate 			}
13657c478bd9Sstevel@tonic-gate 		}
13667c478bd9Sstevel@tonic-gate }
13677c478bd9Sstevel@tonic-gate 
13687c478bd9Sstevel@tonic-gate static void
13697c478bd9Sstevel@tonic-gate cpycode()
13707c478bd9Sstevel@tonic-gate {
13717c478bd9Sstevel@tonic-gate 	/* copies code between \{ and \} */
13727c478bd9Sstevel@tonic-gate 
13737c478bd9Sstevel@tonic-gate 	int c;
13747c478bd9Sstevel@tonic-gate 	c = getwc(finput);
13757c478bd9Sstevel@tonic-gate 	if (c == L'\n') {
13767c478bd9Sstevel@tonic-gate 		c = getwc(finput);
13777c478bd9Sstevel@tonic-gate 		lineno++;
13787c478bd9Sstevel@tonic-gate 		}
13797c478bd9Sstevel@tonic-gate 	if (gen_lines)
13807c478bd9Sstevel@tonic-gate 		(void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
13817c478bd9Sstevel@tonic-gate 	while (c != EOF) {
13827c478bd9Sstevel@tonic-gate 		if (c == L'\\') {
13837c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'}')
13847c478bd9Sstevel@tonic-gate 				return;
13857c478bd9Sstevel@tonic-gate 			else
13867c478bd9Sstevel@tonic-gate 				(void) putwc(L'\\', ftable);
13877c478bd9Sstevel@tonic-gate 		} else if (c == L'%') {
13887c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'}')
13897c478bd9Sstevel@tonic-gate 				return;
13907c478bd9Sstevel@tonic-gate 			else
13917c478bd9Sstevel@tonic-gate 				(void) putwc(L'%', ftable);
13927c478bd9Sstevel@tonic-gate 		}
13937c478bd9Sstevel@tonic-gate 		(void) putwc(c, ftable);
13947c478bd9Sstevel@tonic-gate 		if (c == L'\n')
13957c478bd9Sstevel@tonic-gate 			++lineno;
13967c478bd9Sstevel@tonic-gate 		c = getwc(finput);
13977c478bd9Sstevel@tonic-gate 		}
13987c478bd9Sstevel@tonic-gate /*
13997c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
14007c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
14017c478bd9Sstevel@tonic-gate  *	Do not translate %%}.
14027c478bd9Sstevel@tonic-gate  */
14037c478bd9Sstevel@tonic-gate 	error(gettext(
14047c478bd9Sstevel@tonic-gate 	"eof before %%}"));
14057c478bd9Sstevel@tonic-gate }
14067c478bd9Sstevel@tonic-gate 
1407*e29394bdSmike_s static int
14087c478bd9Sstevel@tonic-gate skipcom()
14097c478bd9Sstevel@tonic-gate {
14107c478bd9Sstevel@tonic-gate 	/* skip over comments */
1411*e29394bdSmike_s 	int c, i = 0;  /* i is the number of lines skipped */
14127c478bd9Sstevel@tonic-gate 
14137c478bd9Sstevel@tonic-gate 	/* skipcom is called after reading a / */
14147c478bd9Sstevel@tonic-gate 
14157c478bd9Sstevel@tonic-gate 	if (getwc(finput) != L'*')
14167c478bd9Sstevel@tonic-gate 		error(gettext(
14177c478bd9Sstevel@tonic-gate 		"illegal comment"));
14187c478bd9Sstevel@tonic-gate 	c = getwc(finput);
14197c478bd9Sstevel@tonic-gate 	while (c != EOF) {
14207c478bd9Sstevel@tonic-gate 		while (c == L'*') {
14217c478bd9Sstevel@tonic-gate 			if ((c = getwc(finput)) == L'/')
14227c478bd9Sstevel@tonic-gate 				return (i);
14237c478bd9Sstevel@tonic-gate 			}
14247c478bd9Sstevel@tonic-gate 		if (c == L'\n')
14257c478bd9Sstevel@tonic-gate 			++i;
14267c478bd9Sstevel@tonic-gate 		c = getwc(finput);
14277c478bd9Sstevel@tonic-gate 		}
14287c478bd9Sstevel@tonic-gate /*
14297c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
14307c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
14317c478bd9Sstevel@tonic-gate  *	EOF -- End Of File.
14327c478bd9Sstevel@tonic-gate  */
14337c478bd9Sstevel@tonic-gate 	error(gettext(
14347c478bd9Sstevel@tonic-gate 	"EOF inside comment"));
14357c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
1436*e29394bdSmike_s 	return (0);
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate static void
1440*e29394bdSmike_s cpyact(int offset)
14417c478bd9Sstevel@tonic-gate {
14427c478bd9Sstevel@tonic-gate 	/* copy C action to the next ; or closing } */
14437c478bd9Sstevel@tonic-gate 	int brac, c, match, i, t, j, s, tok, argument, m;
14447c478bd9Sstevel@tonic-gate 	wchar_t id_name[NAMESIZE+1];
14457c478bd9Sstevel@tonic-gate 	int id_idx = 0;
14467c478bd9Sstevel@tonic-gate 
14477c478bd9Sstevel@tonic-gate 	if (gen_lines) {
14487c478bd9Sstevel@tonic-gate 		(void) fprintf(faction, "\n# line %d \"%s\"\n", lineno, infile);
14497c478bd9Sstevel@tonic-gate 		act_lines++;
14507c478bd9Sstevel@tonic-gate 	}
14517c478bd9Sstevel@tonic-gate 	brac = 0;
14527c478bd9Sstevel@tonic-gate 	id_name[0] = 0;
14537c478bd9Sstevel@tonic-gate loop:
14547c478bd9Sstevel@tonic-gate 	c = getwc(finput);
14557c478bd9Sstevel@tonic-gate swt:
14567c478bd9Sstevel@tonic-gate 	switch (c) {
14577c478bd9Sstevel@tonic-gate 	case L';':
14587c478bd9Sstevel@tonic-gate 		if (brac == 0) {
14597c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
14607c478bd9Sstevel@tonic-gate 			return;
14617c478bd9Sstevel@tonic-gate 		}
14627c478bd9Sstevel@tonic-gate 		goto lcopy;
14637c478bd9Sstevel@tonic-gate 	case L'{':
14647c478bd9Sstevel@tonic-gate 		brac++;
14657c478bd9Sstevel@tonic-gate 		goto lcopy;
14667c478bd9Sstevel@tonic-gate 	case L'$':
14677c478bd9Sstevel@tonic-gate 		s = 1;
14687c478bd9Sstevel@tonic-gate 		tok = -1;
14697c478bd9Sstevel@tonic-gate 		argument = 1;
1470*e29394bdSmike_s 		while ((c = getwc(finput)) == L' ' || c == L'\t') /* NULL */;
14717c478bd9Sstevel@tonic-gate 		if (c == L'<') { /* type description */
14727c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
14737c478bd9Sstevel@tonic-gate 			if (gettok() != TYPENAME)
14747c478bd9Sstevel@tonic-gate /*
14757c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
14767c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
14777c478bd9Sstevel@tonic-gate  *	Do not translate $<ident>
14787c478bd9Sstevel@tonic-gate  */
14797c478bd9Sstevel@tonic-gate 				error(gettext(
14807c478bd9Sstevel@tonic-gate 				"bad syntax on $<ident> clause"));
14817c478bd9Sstevel@tonic-gate 			tok = numbval;
14827c478bd9Sstevel@tonic-gate 			c = getwc(finput);
14837c478bd9Sstevel@tonic-gate 		}
14847c478bd9Sstevel@tonic-gate 		if (c == L'$') {
14857c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "yyval");
14867c478bd9Sstevel@tonic-gate 			if (ntypes) { /* put out the proper tag... */
14877c478bd9Sstevel@tonic-gate 				if (tok < 0)
14887c478bd9Sstevel@tonic-gate 					tok = fdtype(*prdptr[nprod]);
14897c478bd9Sstevel@tonic-gate 				(void) fprintf(faction,
14907c478bd9Sstevel@tonic-gate 					".%ws", typeset[tok]);
14917c478bd9Sstevel@tonic-gate 			}
14927c478bd9Sstevel@tonic-gate 			goto loop;
14937c478bd9Sstevel@tonic-gate 		}
14947c478bd9Sstevel@tonic-gate 		if (iswalpha(c)) {
14957c478bd9Sstevel@tonic-gate 			int same = 0;
14967c478bd9Sstevel@tonic-gate 			int id_sw = 0;
14977c478bd9Sstevel@tonic-gate 			(void) ungetwc(c, finput);
14987c478bd9Sstevel@tonic-gate 			if (gettok() != IDENTIFIER)
14997c478bd9Sstevel@tonic-gate /*
15007c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
15017c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
15027c478bd9Sstevel@tonic-gate  *	Check how action is translated in yacc man page/document.
15037c478bd9Sstevel@tonic-gate  */
15047c478bd9Sstevel@tonic-gate 				error(gettext(
15057c478bd9Sstevel@tonic-gate 				"bad action format"));
15067c478bd9Sstevel@tonic-gate 			/*
15077c478bd9Sstevel@tonic-gate 			 * Save the number of non-terminal
15087c478bd9Sstevel@tonic-gate 			 */
15097c478bd9Sstevel@tonic-gate 			id_sw = nnonter;
15107c478bd9Sstevel@tonic-gate 			t = chfind(1, tokname);
15117c478bd9Sstevel@tonic-gate 			/*
15127c478bd9Sstevel@tonic-gate 			 * Check if the identifier is added as a non-terminal
15137c478bd9Sstevel@tonic-gate 			 */
15147c478bd9Sstevel@tonic-gate 			if (id_sw != nnonter)
15157c478bd9Sstevel@tonic-gate 				id_sw = 1;
15167c478bd9Sstevel@tonic-gate 			else
15177c478bd9Sstevel@tonic-gate 				id_sw = 0;
15187c478bd9Sstevel@tonic-gate 			while ((c = getwc(finput)) == L' ' ||
1519*e29394bdSmike_s 				c == L'\t') /* NULL */;
15207c478bd9Sstevel@tonic-gate 			if (c == L'#') {
15217c478bd9Sstevel@tonic-gate 				while ((c = getwc(finput)) == L' ' ||
1522*e29394bdSmike_s 					c == L'\t') /* NULL */;
15237c478bd9Sstevel@tonic-gate 				if (iswdigit(c)) {
15247c478bd9Sstevel@tonic-gate 					m = 0;
15257c478bd9Sstevel@tonic-gate 					while (iswdigit(c)) {
15267c478bd9Sstevel@tonic-gate 						m = m*10+c-L'0';
15277c478bd9Sstevel@tonic-gate 						c = getwc(finput);
15287c478bd9Sstevel@tonic-gate 					}
15297c478bd9Sstevel@tonic-gate 					argument = m;
15307c478bd9Sstevel@tonic-gate 				} else
15317c478bd9Sstevel@tonic-gate 					error(gettext(
15327c478bd9Sstevel@tonic-gate 					"illegal character \"#\""));
15337c478bd9Sstevel@tonic-gate 			}
15347c478bd9Sstevel@tonic-gate 			if (argument < 1)
15357c478bd9Sstevel@tonic-gate /*
15367c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
15377c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
15387c478bd9Sstevel@tonic-gate  *	Check how action is translated in yacc man page/document.
15397c478bd9Sstevel@tonic-gate  */
15407c478bd9Sstevel@tonic-gate 				error(gettext(
15417c478bd9Sstevel@tonic-gate 				"illegal action argument no."));
15427c478bd9Sstevel@tonic-gate 			for (i = 1; i <= offset; ++i)
15437c478bd9Sstevel@tonic-gate 				if (prdptr[nprod][i] == t)
15447c478bd9Sstevel@tonic-gate 					if (++same == argument) {
15457c478bd9Sstevel@tonic-gate 						(void) fprintf(faction,
15467c478bd9Sstevel@tonic-gate 							"yypvt[-%d]", offset-i);
15477c478bd9Sstevel@tonic-gate 						if (ntypes) {
15487c478bd9Sstevel@tonic-gate 							if (tok < 0)
15497c478bd9Sstevel@tonic-gate 								tok =
15507c478bd9Sstevel@tonic-gate 								/* CSTYLED */
15517c478bd9Sstevel@tonic-gate 								fdtype(prdptr[nprod][i]);
15527c478bd9Sstevel@tonic-gate 							(void) fprintf(faction,
15537c478bd9Sstevel@tonic-gate 							".%ws", typeset[tok]);
15547c478bd9Sstevel@tonic-gate 						}
15557c478bd9Sstevel@tonic-gate 						goto swt;
15567c478bd9Sstevel@tonic-gate 					}
15577c478bd9Sstevel@tonic-gate 			/*
15587c478bd9Sstevel@tonic-gate 			 * This used to be handled as error.
15597c478bd9Sstevel@tonic-gate 			 * Treat this as a valid C statement.
15607c478bd9Sstevel@tonic-gate 			 * (Likely id with $ in.)
15617c478bd9Sstevel@tonic-gate 			 * If non-terminal is added, remove it from the list.
15627c478bd9Sstevel@tonic-gate 			 */
15637c478bd9Sstevel@tonic-gate 			fprintf(faction, "$%ws", tokname);
15647c478bd9Sstevel@tonic-gate /*
15657c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
15667c478bd9Sstevel@tonic-gate  *	This message is passed to warning() function.
15677c478bd9Sstevel@tonic-gate  *	Do not translate Ansi C.
15687c478bd9Sstevel@tonic-gate  */
15697c478bd9Sstevel@tonic-gate 			warning(1, gettext(
15707c478bd9Sstevel@tonic-gate 	"Illegal character '$' in Ansi C symbol: %ws$%ws."),
15717c478bd9Sstevel@tonic-gate 				id_name, tokname);
15727c478bd9Sstevel@tonic-gate 
15737c478bd9Sstevel@tonic-gate 			if (id_sw == 1)
15747c478bd9Sstevel@tonic-gate 				--nnonter;
15757c478bd9Sstevel@tonic-gate 			goto swt;
15767c478bd9Sstevel@tonic-gate 		}
15777c478bd9Sstevel@tonic-gate 		if (c == '-') {
15787c478bd9Sstevel@tonic-gate 			s = -s;
15797c478bd9Sstevel@tonic-gate 			c = getwc(finput);
15807c478bd9Sstevel@tonic-gate 		}
15817c478bd9Sstevel@tonic-gate 		if (iswdigit(c)) {
15827c478bd9Sstevel@tonic-gate 			j = 0;
15837c478bd9Sstevel@tonic-gate 			while (iswdigit(c)) {
15847c478bd9Sstevel@tonic-gate 				j = j*10 + c - L'0';
15857c478bd9Sstevel@tonic-gate 				c = getwc(finput);
15867c478bd9Sstevel@tonic-gate 			}
15877c478bd9Sstevel@tonic-gate 			j = j*s - offset;
15887c478bd9Sstevel@tonic-gate 			if (j > 0) {
15897c478bd9Sstevel@tonic-gate /*
15907c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
15917c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
15927c478bd9Sstevel@tonic-gate  *	Do not translate $%d.
15937c478bd9Sstevel@tonic-gate  */
15947c478bd9Sstevel@tonic-gate 				error(gettext(
15957c478bd9Sstevel@tonic-gate 				"Illegal use of $%d"),
15967c478bd9Sstevel@tonic-gate 				j + offset);
15977c478bd9Sstevel@tonic-gate 			}
15987c478bd9Sstevel@tonic-gate 			(void) fprintf(faction, "yypvt[-%d]", -j);
15997c478bd9Sstevel@tonic-gate 			if (ntypes) { /* put out the proper tag */
16007c478bd9Sstevel@tonic-gate 				if (j + offset <= 0 && tok < 0)
16017c478bd9Sstevel@tonic-gate /*
16027c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
16037c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
16047c478bd9Sstevel@tonic-gate  *	Do not translate $%d.
16057c478bd9Sstevel@tonic-gate  */
16067c478bd9Sstevel@tonic-gate 					error(gettext(
16077c478bd9Sstevel@tonic-gate 					"must specify type of $%d"),
16087c478bd9Sstevel@tonic-gate 					j + offset);
16097c478bd9Sstevel@tonic-gate 				if (tok < 0)
16107c478bd9Sstevel@tonic-gate 					tok = fdtype(prdptr[nprod][j+offset]);
16117c478bd9Sstevel@tonic-gate 				(void) fprintf(faction,
16127c478bd9Sstevel@tonic-gate 					".%ws", typeset[tok]);
16137c478bd9Sstevel@tonic-gate 			}
16147c478bd9Sstevel@tonic-gate 			goto swt;
16157c478bd9Sstevel@tonic-gate 		}
16167c478bd9Sstevel@tonic-gate 		(void) putwc(L'$', faction);
16177c478bd9Sstevel@tonic-gate 		if (s < 0)
16187c478bd9Sstevel@tonic-gate 			(void) putwc(L'-', faction);
16197c478bd9Sstevel@tonic-gate 		goto swt;
16207c478bd9Sstevel@tonic-gate 	case L'}':
16217c478bd9Sstevel@tonic-gate 		if (--brac)
16227c478bd9Sstevel@tonic-gate 			goto lcopy;
16237c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
16247c478bd9Sstevel@tonic-gate 		return;
16257c478bd9Sstevel@tonic-gate 	case L'/':	/* look for comments */
16267c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
16277c478bd9Sstevel@tonic-gate 		c = getwc(finput);
16287c478bd9Sstevel@tonic-gate 		if (c != L'*')
16297c478bd9Sstevel@tonic-gate 			goto swt;
16307c478bd9Sstevel@tonic-gate 		/* it really is a comment */
16317c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
16327c478bd9Sstevel@tonic-gate 		c = getwc(finput);
16337c478bd9Sstevel@tonic-gate 		while (c != EOF) {
16347c478bd9Sstevel@tonic-gate 			while (c == L'*') {
16357c478bd9Sstevel@tonic-gate 				(void) putwc(c, faction);
16367c478bd9Sstevel@tonic-gate 				if ((c = getwc(finput)) == L'/')
16377c478bd9Sstevel@tonic-gate 					goto lcopy;
16387c478bd9Sstevel@tonic-gate 			}
16397c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
16407c478bd9Sstevel@tonic-gate 			if (c == L'\n')
16417c478bd9Sstevel@tonic-gate 				++lineno;
16427c478bd9Sstevel@tonic-gate 			c = getwc(finput);
16437c478bd9Sstevel@tonic-gate 		}
16447c478bd9Sstevel@tonic-gate 		error("EOF inside comment");
16457c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
16467c478bd9Sstevel@tonic-gate 	case L'\'':	/* character constant */
16477c478bd9Sstevel@tonic-gate 	case L'"':	/* character string */
16487c478bd9Sstevel@tonic-gate 		match = c;
16497c478bd9Sstevel@tonic-gate 		(void) putwc(c, faction);
16507c478bd9Sstevel@tonic-gate 		while ((c = getwc(finput)) != EOF) {
16517c478bd9Sstevel@tonic-gate 			if (c == L'\\') {
16527c478bd9Sstevel@tonic-gate 				(void) putwc(c, faction);
16537c478bd9Sstevel@tonic-gate 				c = getwc(finput);
16547c478bd9Sstevel@tonic-gate 				if (c == L'\n')
16557c478bd9Sstevel@tonic-gate 					++lineno;
16567c478bd9Sstevel@tonic-gate 			} else if (c == match)
16577c478bd9Sstevel@tonic-gate 				goto lcopy;
16587c478bd9Sstevel@tonic-gate 			else if (c == L'\n')
16597c478bd9Sstevel@tonic-gate /*
16607c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
16617c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
16627c478bd9Sstevel@tonic-gate  *	This error message is issued when
16637c478bd9Sstevel@tonic-gate  *	quoted string has multiple lines.
16647c478bd9Sstevel@tonic-gate  */
16657c478bd9Sstevel@tonic-gate 				error(gettext(
16667c478bd9Sstevel@tonic-gate 				"newline in string or char. const."));
16677c478bd9Sstevel@tonic-gate 			(void) putwc(c, faction);
16687c478bd9Sstevel@tonic-gate 		}
16697c478bd9Sstevel@tonic-gate 		error(gettext(
16707c478bd9Sstevel@tonic-gate 		"EOF in string or character constant"));
16717c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
16727c478bd9Sstevel@tonic-gate 	case EOF:
16737c478bd9Sstevel@tonic-gate /*
16747c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
16757c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
16767c478bd9Sstevel@tonic-gate  *	Check how 'action' is translated in yacc mapage/document.
16777c478bd9Sstevel@tonic-gate  */
16787c478bd9Sstevel@tonic-gate 		error(gettext(
16797c478bd9Sstevel@tonic-gate 		"action does not terminate"));
16807c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
16817c478bd9Sstevel@tonic-gate 	case L'\n':
16827c478bd9Sstevel@tonic-gate 		++lineno;
16837c478bd9Sstevel@tonic-gate 		goto lcopy;
16847c478bd9Sstevel@tonic-gate 	}
16857c478bd9Sstevel@tonic-gate lcopy:
16867c478bd9Sstevel@tonic-gate 	(void) putwc(c, faction);
16877c478bd9Sstevel@tonic-gate 	/*
16887c478bd9Sstevel@tonic-gate 	 * Save the possible identifier name.
16897c478bd9Sstevel@tonic-gate 	 * Used to print out a warning message.
16907c478bd9Sstevel@tonic-gate 	 */
16917c478bd9Sstevel@tonic-gate 	if (id_idx >= NAMESIZE) {
16927c478bd9Sstevel@tonic-gate 		/*
16937c478bd9Sstevel@tonic-gate 		 * Error. Silently ignore.
16947c478bd9Sstevel@tonic-gate 		 */
1695*e29394bdSmike_s 		/* EMPTY */;
16967c478bd9Sstevel@tonic-gate 	}
16977c478bd9Sstevel@tonic-gate 	/*
16987c478bd9Sstevel@tonic-gate 	 * If c has a possibility to be a
16997c478bd9Sstevel@tonic-gate 	 * part of identifier, save it.
17007c478bd9Sstevel@tonic-gate 	 */
17017c478bd9Sstevel@tonic-gate 	else if (iswalnum(c) || c == L'_') {
17027c478bd9Sstevel@tonic-gate 		id_name[id_idx++] = c;
17037c478bd9Sstevel@tonic-gate 		id_name[id_idx] = 0;
17047c478bd9Sstevel@tonic-gate 	} else {
17057c478bd9Sstevel@tonic-gate 		id_idx = 0;
17067c478bd9Sstevel@tonic-gate 		id_name[id_idx] = 0;
17077c478bd9Sstevel@tonic-gate 	}
17087c478bd9Sstevel@tonic-gate 	goto loop;
17097c478bd9Sstevel@tonic-gate }
17107c478bd9Sstevel@tonic-gate 
17117c478bd9Sstevel@tonic-gate static void
17127c478bd9Sstevel@tonic-gate lhsfill(s)	/* new rule, dump old (if exists), restart strings */
17137c478bd9Sstevel@tonic-gate wchar_t *s;
17147c478bd9Sstevel@tonic-gate {
17157c478bd9Sstevel@tonic-gate 	static int lhs_len = LHS_TEXT_LEN;
17167c478bd9Sstevel@tonic-gate 	int s_lhs = wslen(s);
17177c478bd9Sstevel@tonic-gate 	if (s_lhs >= lhs_len) {
17187c478bd9Sstevel@tonic-gate 		lhs_len = s_lhs + 2;
17197c478bd9Sstevel@tonic-gate 		lhstext = (wchar_t *)
17207c478bd9Sstevel@tonic-gate 			realloc((char *)lhstext, sizeof (wchar_t)*lhs_len);
17217c478bd9Sstevel@tonic-gate 		if (lhstext == NULL)
17227c478bd9Sstevel@tonic-gate /*
17237c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
17247c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
17257c478bd9Sstevel@tonic-gate  *	LHS -- Left Hand Side.
17267c478bd9Sstevel@tonic-gate  */
17277c478bd9Sstevel@tonic-gate 			error(gettext(
17287c478bd9Sstevel@tonic-gate 			"couldn't expanded LHS length"));
17297c478bd9Sstevel@tonic-gate 	}
17307c478bd9Sstevel@tonic-gate 	rhsfill((wchar_t *)0);
17317c478bd9Sstevel@tonic-gate 	(void) wscpy(lhstext, s); /* don't worry about too long of a name */
17327c478bd9Sstevel@tonic-gate }
17337c478bd9Sstevel@tonic-gate 
17347c478bd9Sstevel@tonic-gate static void
17357c478bd9Sstevel@tonic-gate rhsfill(s)
17367c478bd9Sstevel@tonic-gate wchar_t *s;	/* either name or 0 */
17377c478bd9Sstevel@tonic-gate {
17387c478bd9Sstevel@tonic-gate 	static wchar_t *loc;	/* next free location in rhstext */
17397c478bd9Sstevel@tonic-gate 	static int rhs_len = RHS_TEXT_LEN;
17407c478bd9Sstevel@tonic-gate 	static int used = 0;
17417c478bd9Sstevel@tonic-gate 	int s_rhs = (s == NULL ? 0 : wslen(s));
17427c478bd9Sstevel@tonic-gate 	register wchar_t *p;
17437c478bd9Sstevel@tonic-gate 
17447c478bd9Sstevel@tonic-gate 	if (!s)	/* print out and erase old text */
17457c478bd9Sstevel@tonic-gate 	{
17467c478bd9Sstevel@tonic-gate 		if (*lhstext)		/* there was an old rule - dump it */
17477c478bd9Sstevel@tonic-gate 			lrprnt();
17487c478bd9Sstevel@tonic-gate 		(loc = rhstext)[0] = 0;
17497c478bd9Sstevel@tonic-gate 		return;
17507c478bd9Sstevel@tonic-gate 	}
17517c478bd9Sstevel@tonic-gate 	/* add to stuff in rhstext */
17527c478bd9Sstevel@tonic-gate 	p = s;
17537c478bd9Sstevel@tonic-gate 
17547c478bd9Sstevel@tonic-gate 	used = loc - rhstext;
17557c478bd9Sstevel@tonic-gate 	if ((s_rhs + 3) >= (rhs_len - used)) {
17567c478bd9Sstevel@tonic-gate 		static wchar_t *textbase;
17577c478bd9Sstevel@tonic-gate 		textbase = rhstext;
17587c478bd9Sstevel@tonic-gate 		rhs_len += s_rhs + RHS_TEXT_LEN;
17597c478bd9Sstevel@tonic-gate 		rhstext = (wchar_t *)
17607c478bd9Sstevel@tonic-gate 			realloc((char *)rhstext, sizeof (wchar_t)*rhs_len);
17617c478bd9Sstevel@tonic-gate 		if (rhstext == NULL)
17627c478bd9Sstevel@tonic-gate /*
17637c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
17647c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
17657c478bd9Sstevel@tonic-gate  *	RHS -- Right Hand Side.
17667c478bd9Sstevel@tonic-gate  */
17677c478bd9Sstevel@tonic-gate 			error(gettext(
17687c478bd9Sstevel@tonic-gate 			"couldn't expanded RHS length"));
17697c478bd9Sstevel@tonic-gate 		loc = loc - textbase + rhstext;
17707c478bd9Sstevel@tonic-gate 	}
17717c478bd9Sstevel@tonic-gate 
17727c478bd9Sstevel@tonic-gate 	*loc++ = L' ';
17737c478bd9Sstevel@tonic-gate 	if (*s == L' ') /* special quoted symbol */
17747c478bd9Sstevel@tonic-gate 	{
17757c478bd9Sstevel@tonic-gate 		*loc++ = L'\'';	/* add first quote */
17767c478bd9Sstevel@tonic-gate 		p++;
17777c478bd9Sstevel@tonic-gate 	}
17787c478bd9Sstevel@tonic-gate 	while (*loc = *p++)
17797c478bd9Sstevel@tonic-gate 		if (loc++ > &rhstext[ RHS_TEXT_LEN ] - 3)
17807c478bd9Sstevel@tonic-gate 			break;
17817c478bd9Sstevel@tonic-gate 
17827c478bd9Sstevel@tonic-gate 	if (*s == L' ')
17837c478bd9Sstevel@tonic-gate 		*loc++ = L'\'';
17847c478bd9Sstevel@tonic-gate 	*loc = 0;		/* terminate the string */
17857c478bd9Sstevel@tonic-gate }
17867c478bd9Sstevel@tonic-gate 
17877c478bd9Sstevel@tonic-gate static void
17887c478bd9Sstevel@tonic-gate lrprnt()	/* print out the left and right hand sides */
17897c478bd9Sstevel@tonic-gate {
17907c478bd9Sstevel@tonic-gate 	wchar_t *rhs;
17917c478bd9Sstevel@tonic-gate 	wchar_t *m_rhs = NULL;
17927c478bd9Sstevel@tonic-gate 
17937c478bd9Sstevel@tonic-gate 	if (!*rhstext)		/* empty rhs - print usual comment */
17947c478bd9Sstevel@tonic-gate 		rhs = L" /* empty */";
17957c478bd9Sstevel@tonic-gate 	else {
17967c478bd9Sstevel@tonic-gate 		int idx1; /* tmp idx used to find if there are d_quotes */
17977c478bd9Sstevel@tonic-gate 		int idx2; /* tmp idx used to generate escaped string */
17987c478bd9Sstevel@tonic-gate 		wchar_t *p;
17997c478bd9Sstevel@tonic-gate 		/*
18007c478bd9Sstevel@tonic-gate 		 * Check if there are any double quote in RHS.
18017c478bd9Sstevel@tonic-gate 		 */
18027c478bd9Sstevel@tonic-gate 		for (idx1 = 0; rhstext[idx1] != 0; idx1++) {
18037c478bd9Sstevel@tonic-gate 			if (rhstext[idx1] == L'"') {
18047c478bd9Sstevel@tonic-gate 				/*
18057c478bd9Sstevel@tonic-gate 				 * A double quote is found.
18067c478bd9Sstevel@tonic-gate 				 */
18077c478bd9Sstevel@tonic-gate 				idx2 = wslen(rhstext)*2;
18087c478bd9Sstevel@tonic-gate 				p = m_rhs = (wchar_t *)
18097c478bd9Sstevel@tonic-gate 					malloc((idx2 + 1)*sizeof (wchar_t));
18107c478bd9Sstevel@tonic-gate 				if (m_rhs == NULL)
18117c478bd9Sstevel@tonic-gate /*
18127c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
18137c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
18147c478bd9Sstevel@tonic-gate  *	RHS - Right Hand Side.
18157c478bd9Sstevel@tonic-gate  *
18167c478bd9Sstevel@tonic-gate  *	You may just translate this as:
18177c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
18187c478bd9Sstevel@tonic-gate  */
18197c478bd9Sstevel@tonic-gate 					error(gettext(
18207c478bd9Sstevel@tonic-gate 					"Couldn't allocate memory for RHS."));
18217c478bd9Sstevel@tonic-gate 				/*
18227c478bd9Sstevel@tonic-gate 				 * Copy string
18237c478bd9Sstevel@tonic-gate 				 */
18247c478bd9Sstevel@tonic-gate 				for (idx2 = 0; rhstext[idx2] != 0; idx2++) {
18257c478bd9Sstevel@tonic-gate 					/*
18267c478bd9Sstevel@tonic-gate 					 * Check if this quote is escaped or not
18277c478bd9Sstevel@tonic-gate 					 */
18287c478bd9Sstevel@tonic-gate 					if (rhstext[idx2] == L'"') {
18297c478bd9Sstevel@tonic-gate 						int tmp_l = idx2-1;
18307c478bd9Sstevel@tonic-gate 						int cnt = 0;
18317c478bd9Sstevel@tonic-gate 						while (tmp_l >= 0 &&
18327c478bd9Sstevel@tonic-gate 						rhstext[tmp_l] == '\\') {
18337c478bd9Sstevel@tonic-gate 							cnt++;
18347c478bd9Sstevel@tonic-gate 							tmp_l--;
18357c478bd9Sstevel@tonic-gate 						}
18367c478bd9Sstevel@tonic-gate 						/*
18377c478bd9Sstevel@tonic-gate 						 * If quote is not escaped,
18387c478bd9Sstevel@tonic-gate 						 * then escape it.
18397c478bd9Sstevel@tonic-gate 						 */
18407c478bd9Sstevel@tonic-gate 						if (cnt%2 == 0)
18417c478bd9Sstevel@tonic-gate 							*p++ = L'\\';
18427c478bd9Sstevel@tonic-gate 					}
18437c478bd9Sstevel@tonic-gate 					*p++ = rhstext[idx2];
18447c478bd9Sstevel@tonic-gate 				}
18457c478bd9Sstevel@tonic-gate 				*p = 0;
18467c478bd9Sstevel@tonic-gate 				/*
18477c478bd9Sstevel@tonic-gate 				 * Break from the loop
18487c478bd9Sstevel@tonic-gate 				 */
18497c478bd9Sstevel@tonic-gate 				break;
18507c478bd9Sstevel@tonic-gate 			}
18517c478bd9Sstevel@tonic-gate 		}
18527c478bd9Sstevel@tonic-gate 		if (m_rhs == NULL)
18537c478bd9Sstevel@tonic-gate 			rhs = rhstext;
18547c478bd9Sstevel@tonic-gate 		else
18557c478bd9Sstevel@tonic-gate 			rhs = m_rhs;
18567c478bd9Sstevel@tonic-gate 	}
18577c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"%ws :%ws\",\n", lhstext, rhs);
18587c478bd9Sstevel@tonic-gate 	if (m_rhs)
18597c478bd9Sstevel@tonic-gate 		free(m_rhs);
18607c478bd9Sstevel@tonic-gate }
18617c478bd9Sstevel@tonic-gate 
18627c478bd9Sstevel@tonic-gate 
18637c478bd9Sstevel@tonic-gate static void
18647c478bd9Sstevel@tonic-gate beg_debug()	/* dump initial sequence for fdebug file */
18657c478bd9Sstevel@tonic-gate {
18667c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
18677c478bd9Sstevel@tonic-gate 		"typedef struct\n");
18687c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
18697c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\n\tyytoktype\n");
18707c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "#endif\n{\n");
18717c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
18727c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\nconst\n#endif\n");
18737c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "char *t_name; int t_val; } yytoktype;\n");
18747c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
18757c478bd9Sstevel@tonic-gate 		"#ifndef YYDEBUG\n#\tdefine YYDEBUG\t%d", gen_testing);
18767c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t/*%sallow debugging */\n#endif\n\n",
18777c478bd9Sstevel@tonic-gate 		gen_testing ? " " : " don't ");
18787c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "#if YYDEBUG\n\nyytoktype yytoks[] =\n{\n");
18797c478bd9Sstevel@tonic-gate }
18807c478bd9Sstevel@tonic-gate 
18817c478bd9Sstevel@tonic-gate 
18827c478bd9Sstevel@tonic-gate static void
18837c478bd9Sstevel@tonic-gate end_toks()	/* finish yytoks array, get ready for yyred's strings */
18847c478bd9Sstevel@tonic-gate {
18857c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"-unknown-\",\t-1\t/* ends search */\n");
18867c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "};\n\n");
18877c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug,
18887c478bd9Sstevel@tonic-gate 		"#ifdef __cplusplus\nconst\n#endif\n");
18897c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "char * yyreds[] =\n{\n");
18907c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "\t\"-no such reduction-\",\n");
18917c478bd9Sstevel@tonic-gate }
18927c478bd9Sstevel@tonic-gate 
18937c478bd9Sstevel@tonic-gate 
18947c478bd9Sstevel@tonic-gate static void
18957c478bd9Sstevel@tonic-gate end_debug()	/* finish yyred array, close file */
18967c478bd9Sstevel@tonic-gate {
18977c478bd9Sstevel@tonic-gate 	lrprnt();		/* dump last lhs, rhs */
18987c478bd9Sstevel@tonic-gate 	(void) fprintf(fdebug, "};\n#endif /* YYDEBUG */\n");
18997c478bd9Sstevel@tonic-gate 	(void) fclose(fdebug);
19007c478bd9Sstevel@tonic-gate }
19017c478bd9Sstevel@tonic-gate 
19027c478bd9Sstevel@tonic-gate 
19037c478bd9Sstevel@tonic-gate /*
19047c478bd9Sstevel@tonic-gate  * 2/29/88 -
19057c478bd9Sstevel@tonic-gate  * The normal length for token sizes is NAMESIZE - If a token is
19067c478bd9Sstevel@tonic-gate  * seen that has a longer length, expand "tokname" by NAMESIZE.
19077c478bd9Sstevel@tonic-gate  */
19087c478bd9Sstevel@tonic-gate static void
19097c478bd9Sstevel@tonic-gate exp_tokname()
19107c478bd9Sstevel@tonic-gate {
19117c478bd9Sstevel@tonic-gate 	toksize += NAMESIZE;
19127c478bd9Sstevel@tonic-gate 	tokname = (wchar_t *)
19137c478bd9Sstevel@tonic-gate 		realloc((char *)tokname, sizeof (wchar_t) * toksize);
19147c478bd9Sstevel@tonic-gate }
19157c478bd9Sstevel@tonic-gate 
19167c478bd9Sstevel@tonic-gate 
19177c478bd9Sstevel@tonic-gate /*
19187c478bd9Sstevel@tonic-gate  * 2/29/88 -
19197c478bd9Sstevel@tonic-gate  *
19207c478bd9Sstevel@tonic-gate  */
19217c478bd9Sstevel@tonic-gate static void
19227c478bd9Sstevel@tonic-gate exp_prod()
19237c478bd9Sstevel@tonic-gate {
19247c478bd9Sstevel@tonic-gate 	int i;
19257c478bd9Sstevel@tonic-gate 	nprodsz += NPROD;
19267c478bd9Sstevel@tonic-gate 
19277c478bd9Sstevel@tonic-gate 	prdptr = (int **) realloc((char *)prdptr, sizeof (int *) * (nprodsz+2));
19287c478bd9Sstevel@tonic-gate 	levprd  = (int *)  realloc((char *)levprd, sizeof (int) * (nprodsz+2));
19297c478bd9Sstevel@tonic-gate 	had_act = (wchar_t *)
19307c478bd9Sstevel@tonic-gate 		realloc((char *)had_act, sizeof (wchar_t) * (nprodsz+2));
19317c478bd9Sstevel@tonic-gate 	for (i = nprodsz-NPROD; i < nprodsz+2; ++i)
19327c478bd9Sstevel@tonic-gate 		had_act[i] = 0;
19337c478bd9Sstevel@tonic-gate 
19347c478bd9Sstevel@tonic-gate 	if ((*prdptr == NULL) || (levprd == NULL) || (had_act == NULL))
19357c478bd9Sstevel@tonic-gate /*
19367c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
19377c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
19387c478bd9Sstevel@tonic-gate  *
19397c478bd9Sstevel@tonic-gate  *	You may just translate this as:
19407c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
19417c478bd9Sstevel@tonic-gate  */
19427c478bd9Sstevel@tonic-gate 		error(gettext(
19437c478bd9Sstevel@tonic-gate 		"couldn't expand productions"));
19447c478bd9Sstevel@tonic-gate }
19457c478bd9Sstevel@tonic-gate 
19467c478bd9Sstevel@tonic-gate /*
19477c478bd9Sstevel@tonic-gate  * 2/29/88 -
19487c478bd9Sstevel@tonic-gate  * Expand the number of terminals.  Initially there are NTERMS;
19497c478bd9Sstevel@tonic-gate  * each time space runs out, the size is increased by NTERMS.
19507c478bd9Sstevel@tonic-gate  * The total size, however, cannot exceed MAXTERMS because of
19517c478bd9Sstevel@tonic-gate  * the way LOOKSETS(struct looksets) is set up.
19527c478bd9Sstevel@tonic-gate  * Tables affected:
19537c478bd9Sstevel@tonic-gate  *	tokset, toklev : increased to ntoksz
19547c478bd9Sstevel@tonic-gate  *
19557c478bd9Sstevel@tonic-gate  *	tables with initial dimensions of TEMPSIZE must be changed if
19567c478bd9Sstevel@tonic-gate  *	(ntoksz + NNONTERM) >= TEMPSIZE : temp1[]
19577c478bd9Sstevel@tonic-gate  */
19587c478bd9Sstevel@tonic-gate static void
19597c478bd9Sstevel@tonic-gate exp_ntok()
19607c478bd9Sstevel@tonic-gate {
19617c478bd9Sstevel@tonic-gate 	ntoksz += NTERMS;
19627c478bd9Sstevel@tonic-gate 
19637c478bd9Sstevel@tonic-gate 	tokset = (TOKSYMB *) realloc((char *)tokset, sizeof (TOKSYMB) * ntoksz);
19647c478bd9Sstevel@tonic-gate 	toklev = (int *) realloc((char *)toklev, sizeof (int) * ntoksz);
19657c478bd9Sstevel@tonic-gate 
19667c478bd9Sstevel@tonic-gate 	if ((tokset == NULL) || (toklev == NULL))
19677c478bd9Sstevel@tonic-gate /*
19687c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
19697c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
19707c478bd9Sstevel@tonic-gate  *	Do not translate NTERMS.
19717c478bd9Sstevel@tonic-gate  *
19727c478bd9Sstevel@tonic-gate  *	You may just translate this as:
19737c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
19747c478bd9Sstevel@tonic-gate  */
19757c478bd9Sstevel@tonic-gate 		error(gettext(
19767c478bd9Sstevel@tonic-gate 		"couldn't expand NTERMS"));
19777c478bd9Sstevel@tonic-gate }
19787c478bd9Sstevel@tonic-gate 
19797c478bd9Sstevel@tonic-gate 
19807c478bd9Sstevel@tonic-gate static void
19817c478bd9Sstevel@tonic-gate exp_nonterm()
19827c478bd9Sstevel@tonic-gate {
19837c478bd9Sstevel@tonic-gate 	nnontersz += NNONTERM;
19847c478bd9Sstevel@tonic-gate 
19857c478bd9Sstevel@tonic-gate 	nontrst = (NTSYMB *)
19867c478bd9Sstevel@tonic-gate 		realloc((char *)nontrst, sizeof (TOKSYMB) * nnontersz);
19877c478bd9Sstevel@tonic-gate 	if (nontrst == NULL)
19887c478bd9Sstevel@tonic-gate /*
19897c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
19907c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
19917c478bd9Sstevel@tonic-gate  *	Do not translate NTERMS.
19927c478bd9Sstevel@tonic-gate  *
19937c478bd9Sstevel@tonic-gate  *	You may just translate this as:
19947c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
19957c478bd9Sstevel@tonic-gate  */
19967c478bd9Sstevel@tonic-gate 		error(gettext(
19977c478bd9Sstevel@tonic-gate 		"couldn't expand NNONTERM"));
19987c478bd9Sstevel@tonic-gate }
19997c478bd9Sstevel@tonic-gate 
20007c478bd9Sstevel@tonic-gate void
20017c478bd9Sstevel@tonic-gate exp_mem(flag)
20027c478bd9Sstevel@tonic-gate int flag;
20037c478bd9Sstevel@tonic-gate {
20047c478bd9Sstevel@tonic-gate 	int i;
20057c478bd9Sstevel@tonic-gate 	static int *membase;
20067c478bd9Sstevel@tonic-gate 	new_memsize += MEMSIZE;
20077c478bd9Sstevel@tonic-gate 
20087c478bd9Sstevel@tonic-gate 	membase = tracemem;
20097c478bd9Sstevel@tonic-gate 	tracemem = (int *)
20107c478bd9Sstevel@tonic-gate 		realloc((char *)tracemem, sizeof (int) * new_memsize);
20117c478bd9Sstevel@tonic-gate 	if (tracemem == NULL)
20127c478bd9Sstevel@tonic-gate /*
20137c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE  -- This is a message from yacc.
20147c478bd9Sstevel@tonic-gate  *	This message is passed to error() function.
20157c478bd9Sstevel@tonic-gate  *
20167c478bd9Sstevel@tonic-gate  *	You may just translate this as:
20177c478bd9Sstevel@tonic-gate  *	'Could not allocate internally used memory.'
20187c478bd9Sstevel@tonic-gate  */
20197c478bd9Sstevel@tonic-gate 		error(gettext(
20207c478bd9Sstevel@tonic-gate 		"couldn't expand mem table"));
20217c478bd9Sstevel@tonic-gate 	if (flag) {
20227c478bd9Sstevel@tonic-gate 		for (i = 0; i <= nprod; ++i)
20237c478bd9Sstevel@tonic-gate 			prdptr[i] = prdptr[i] - membase + tracemem;
20247c478bd9Sstevel@tonic-gate 		mem = mem - membase + tracemem;
20257c478bd9Sstevel@tonic-gate 	} else {
20267c478bd9Sstevel@tonic-gate 		size += MEMSIZE;
20277c478bd9Sstevel@tonic-gate 		temp1 = (int *)realloc((char *)temp1, sizeof (int)*size);
20287c478bd9Sstevel@tonic-gate 		optimmem = optimmem - membase + tracemem;
20297c478bd9Sstevel@tonic-gate 	}
20307c478bd9Sstevel@tonic-gate }
20317c478bd9Sstevel@tonic-gate 
20327c478bd9Sstevel@tonic-gate static int
20337c478bd9Sstevel@tonic-gate findchtok(chlit)
20347c478bd9Sstevel@tonic-gate int chlit;
20357c478bd9Sstevel@tonic-gate /*
20367c478bd9Sstevel@tonic-gate  * findchtok(chlit) returns the token number for a character literal
20377c478bd9Sstevel@tonic-gate  * chlit that is "bigger" than 255 -- the max char value that the
20387c478bd9Sstevel@tonic-gate  * original yacc was build for.  This yacc treate them as though
20397c478bd9Sstevel@tonic-gate  * an ordinary token.
20407c478bd9Sstevel@tonic-gate  */
20417c478bd9Sstevel@tonic-gate {
20427c478bd9Sstevel@tonic-gate 	int	i;
20437c478bd9Sstevel@tonic-gate 
20447c478bd9Sstevel@tonic-gate 	if (chlit < 0xff)
20457c478bd9Sstevel@tonic-gate 		return (chlit); /* single-byte char */
20467c478bd9Sstevel@tonic-gate 	for (i = 0; i < nmbchars; ++i) {
20477c478bd9Sstevel@tonic-gate 		if (mbchars->character == chlit)
20487c478bd9Sstevel@tonic-gate 			return (mbchars->tvalue);
20497c478bd9Sstevel@tonic-gate 	}
20507c478bd9Sstevel@tonic-gate 
20517c478bd9Sstevel@tonic-gate 	/* Not found.  Register it! */
20527c478bd9Sstevel@tonic-gate 	if (++nmbchars > nmbcharsz) { /* Make sure there's enough space */
20537c478bd9Sstevel@tonic-gate 		nmbcharsz += NMBCHARSZ;
20547c478bd9Sstevel@tonic-gate 		mbchars = (MBCLIT *)
20557c478bd9Sstevel@tonic-gate 		    realloc((char *)mbchars, sizeof (MBCLIT)*nmbcharsz);
20567c478bd9Sstevel@tonic-gate 		if (mbchars == NULL)
20577c478bd9Sstevel@tonic-gate 			error(gettext(
20587c478bd9Sstevel@tonic-gate 			"too many character literals"));
20597c478bd9Sstevel@tonic-gate 	}
20607c478bd9Sstevel@tonic-gate 	mbchars[nmbchars-1].character = chlit;
20617c478bd9Sstevel@tonic-gate 	return (mbchars[nmbchars-1].tvalue = extval++);
20627c478bd9Sstevel@tonic-gate 	/* Return the newly assigned token. */
20637c478bd9Sstevel@tonic-gate }
20647c478bd9Sstevel@tonic-gate 
20657c478bd9Sstevel@tonic-gate /*
20667c478bd9Sstevel@tonic-gate  * When -p is specified, symbol prefix for
20677c478bd9Sstevel@tonic-gate  *	yy{parse, lex, error}(),
20687c478bd9Sstevel@tonic-gate  *	yy{lval, val, char, debug, errflag, nerrs}
20697c478bd9Sstevel@tonic-gate  * are defined to the specified name.
20707c478bd9Sstevel@tonic-gate  */
20717c478bd9Sstevel@tonic-gate static void
20727c478bd9Sstevel@tonic-gate put_prefix_define(char *pre)
20737c478bd9Sstevel@tonic-gate {
20747c478bd9Sstevel@tonic-gate 	char *syms[] = {
20757c478bd9Sstevel@tonic-gate 		/* Functions */
20767c478bd9Sstevel@tonic-gate 		"parse",
20777c478bd9Sstevel@tonic-gate 		"lex",
20787c478bd9Sstevel@tonic-gate 		"error",
20797c478bd9Sstevel@tonic-gate 		/* Variables */
20807c478bd9Sstevel@tonic-gate 		"lval",
20817c478bd9Sstevel@tonic-gate 		"val",
20827c478bd9Sstevel@tonic-gate 		"char",
20837c478bd9Sstevel@tonic-gate 		"debug",
20847c478bd9Sstevel@tonic-gate 		"errflag",
20857c478bd9Sstevel@tonic-gate 		"nerrs",
20867c478bd9Sstevel@tonic-gate 		NULL};
20877c478bd9Sstevel@tonic-gate 	int i;
20887c478bd9Sstevel@tonic-gate 
20897c478bd9Sstevel@tonic-gate 	for (i = 0; syms[i]; i++)
20907c478bd9Sstevel@tonic-gate 		fprintf(ftable, "#define\tyy%s\t%s%s\n",
20917c478bd9Sstevel@tonic-gate 			syms[i], pre, syms[i]);
20927c478bd9Sstevel@tonic-gate }
2093