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