10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54538Sdamico * Common Development and Distribution License (the "License").
64538Sdamico * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
226451Sedp * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
300Sstevel@tonic-gate
31100Smike_s #include "dextern.h"
320Sstevel@tonic-gate #include "sgs.h"
33100Smike_s #include <stdio.h>
34100Smike_s
350Sstevel@tonic-gate #define IDENTIFIER 257
360Sstevel@tonic-gate
370Sstevel@tonic-gate #define MARK 258
380Sstevel@tonic-gate #define TERM 259
390Sstevel@tonic-gate #define LEFT 260
400Sstevel@tonic-gate #define RIGHT 261
410Sstevel@tonic-gate #define BINARY 262
420Sstevel@tonic-gate #define PREC 263
430Sstevel@tonic-gate #define LCURLY 264
440Sstevel@tonic-gate #define C_IDENTIFIER 265 /* name followed by colon */
450Sstevel@tonic-gate #define NUMBER 266
460Sstevel@tonic-gate #define START 267
470Sstevel@tonic-gate #define TYPEDEF 268
480Sstevel@tonic-gate #define TYPENAME 269
490Sstevel@tonic-gate #define UNION 270
500Sstevel@tonic-gate #define ENDFILE 0
510Sstevel@tonic-gate #define LHS_TEXT_LEN 80 /* length of lhstext */
520Sstevel@tonic-gate #define RHS_TEXT_LEN 640 /* length of rhstext */
530Sstevel@tonic-gate /* communication variables between various I/O routines */
540Sstevel@tonic-gate
550Sstevel@tonic-gate #define v_FLAG 0x01
560Sstevel@tonic-gate #define d_FLAG 0x02
570Sstevel@tonic-gate #define DEFAULT_PREFIX "y"
580Sstevel@tonic-gate
590Sstevel@tonic-gate char *infile; /* input file name */
600Sstevel@tonic-gate static int numbval; /* value of an input number */
610Sstevel@tonic-gate static int toksize = NAMESIZE;
620Sstevel@tonic-gate static wchar_t *tokname; /* input token name */
634538Sdamico char *parser = PARSER; /* location of common parser */
640Sstevel@tonic-gate
650Sstevel@tonic-gate static void finact(void);
660Sstevel@tonic-gate static wchar_t *cstash(wchar_t *);
670Sstevel@tonic-gate static void defout(void);
680Sstevel@tonic-gate static void cpyunion(void);
690Sstevel@tonic-gate static void cpycode(void);
700Sstevel@tonic-gate static void cpyact(int);
710Sstevel@tonic-gate static void lhsfill(wchar_t *);
720Sstevel@tonic-gate static void rhsfill(wchar_t *);
730Sstevel@tonic-gate static void lrprnt(void);
740Sstevel@tonic-gate static void beg_debug(void);
750Sstevel@tonic-gate static void end_toks(void);
760Sstevel@tonic-gate static void end_debug(void);
770Sstevel@tonic-gate static void exp_tokname(void);
780Sstevel@tonic-gate static void exp_prod(void);
790Sstevel@tonic-gate static void exp_ntok(void);
800Sstevel@tonic-gate static void exp_nonterm(void);
810Sstevel@tonic-gate static int defin(int, wchar_t *);
820Sstevel@tonic-gate static int gettok(void);
830Sstevel@tonic-gate static int chfind(int, wchar_t *);
840Sstevel@tonic-gate static int skipcom(void);
850Sstevel@tonic-gate static int findchtok(int);
860Sstevel@tonic-gate static void put_prefix_define(char *);
870Sstevel@tonic-gate
880Sstevel@tonic-gate
890Sstevel@tonic-gate /* storage of names */
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * initial block to place token and
930Sstevel@tonic-gate * nonterminal names are stored
940Sstevel@tonic-gate * points to initial block - more space
950Sstevel@tonic-gate * is allocated as needed.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate static wchar_t cnamesblk0[CNAMSZ];
980Sstevel@tonic-gate static wchar_t *cnames = cnamesblk0;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate /* place where next name is to be put in */
1010Sstevel@tonic-gate static wchar_t *cnamp = cnamesblk0;
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate /* number of defined symbols output */
1040Sstevel@tonic-gate static int ndefout = 3;
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate /* storage of types */
1070Sstevel@tonic-gate static int defunion = 0; /* union of types defined? */
1080Sstevel@tonic-gate static int ntypes = 0; /* number of types defined */
1090Sstevel@tonic-gate static wchar_t *typeset[NTYPES]; /* pointers to type tags */
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate /* symbol tables for tokens and nonterminals */
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate int ntokens = 0;
1140Sstevel@tonic-gate int ntoksz = NTERMS;
1150Sstevel@tonic-gate TOKSYMB *tokset;
1160Sstevel@tonic-gate int *toklev;
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate int nnonter = -1;
1190Sstevel@tonic-gate NTSYMB *nontrst;
1200Sstevel@tonic-gate int nnontersz = NNONTERM;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate static int start; /* start symbol */
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate /* assigned token type values */
1250Sstevel@tonic-gate static int extval = 0;
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate /* input and output file descriptors */
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate FILE *finput; /* yacc input file */
1300Sstevel@tonic-gate FILE *faction; /* file for saving actions */
1310Sstevel@tonic-gate FILE *fdefine; /* file for # defines */
1320Sstevel@tonic-gate FILE *ftable; /* y.tab.c file */
1330Sstevel@tonic-gate FILE *ftemp; /* tempfile to pass 2 */
1340Sstevel@tonic-gate FILE *fdebug; /* where the strings for debugging are stored */
1350Sstevel@tonic-gate FILE *foutput; /* y.output file */
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /* output string */
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate static wchar_t *lhstext;
1400Sstevel@tonic-gate static wchar_t *rhstext;
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /* storage for grammar rules */
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate int *mem0; /* production storage */
1450Sstevel@tonic-gate int *mem;
1460Sstevel@tonic-gate int *tracemem;
1470Sstevel@tonic-gate extern int *optimmem;
1480Sstevel@tonic-gate int new_memsize = MEMSIZE;
1490Sstevel@tonic-gate int nprod = 1; /* number of productions */
1500Sstevel@tonic-gate int nprodsz = NPROD;
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate int **prdptr;
1530Sstevel@tonic-gate int *levprd;
1540Sstevel@tonic-gate wchar_t *had_act;
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /* flag for generating the # line's default is yes */
1570Sstevel@tonic-gate int gen_lines = 1;
1580Sstevel@tonic-gate int act_lines = 0;
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate /* flag for whether to include runtime debugging */
1610Sstevel@tonic-gate static int gen_testing = 0;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate /* flag for version stamping--default turned off */
1640Sstevel@tonic-gate static char *v_stmp = "n";
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate int nmbchars = 0; /* number of mb literals in mbchars */
1670Sstevel@tonic-gate MBCLIT *mbchars = (MBCLIT *) 0; /* array of mb literals */
1680Sstevel@tonic-gate int nmbcharsz = 0; /* allocated space for mbchars */
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate void
setup(argc,argv)1710Sstevel@tonic-gate setup(argc, argv)
1720Sstevel@tonic-gate int argc;
1730Sstevel@tonic-gate char *argv[];
1740Sstevel@tonic-gate { int ii, i, j, lev, t, ty;
1750Sstevel@tonic-gate /* ty is the sequencial number of token name in tokset */
1760Sstevel@tonic-gate int c;
1770Sstevel@tonic-gate int *p;
1780Sstevel@tonic-gate char *cp;
1790Sstevel@tonic-gate wchar_t actname[8];
1800Sstevel@tonic-gate unsigned int options = 0;
1810Sstevel@tonic-gate char *file_prefix = DEFAULT_PREFIX;
1820Sstevel@tonic-gate char *sym_prefix = "";
1830Sstevel@tonic-gate #define F_NAME_LENGTH 128
1840Sstevel@tonic-gate char fname[F_NAME_LENGTH+1];
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate foutput = NULL;
1870Sstevel@tonic-gate fdefine = NULL;
1880Sstevel@tonic-gate i = 1;
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate tokname = (wchar_t *)malloc(sizeof (wchar_t) * toksize);
1910Sstevel@tonic-gate tokset = (TOKSYMB *)malloc(sizeof (TOKSYMB) * ntoksz);
1920Sstevel@tonic-gate toklev = (int *)malloc(sizeof (int) * ntoksz);
1930Sstevel@tonic-gate nontrst = (NTSYMB *)malloc(sizeof (NTSYMB) * nnontersz);
1940Sstevel@tonic-gate mem0 = (int *)malloc(sizeof (int) * new_memsize);
1950Sstevel@tonic-gate prdptr = (int **)malloc(sizeof (int *) * (nprodsz+2));
1960Sstevel@tonic-gate levprd = (int *)malloc(sizeof (int) * (nprodsz+2));
1970Sstevel@tonic-gate had_act = (wchar_t *)calloc((nprodsz + 2), sizeof (wchar_t));
1986451Sedp lhstext = (wchar_t *)calloc(1, sizeof (wchar_t) * LHS_TEXT_LEN);
1996451Sedp rhstext = (wchar_t *)calloc(1, sizeof (wchar_t) * RHS_TEXT_LEN);
2000Sstevel@tonic-gate aryfil(toklev, ntoksz, 0);
2010Sstevel@tonic-gate aryfil(levprd, nprodsz, 0);
2020Sstevel@tonic-gate for (ii = 0; ii < ntoksz; ++ii)
2030Sstevel@tonic-gate tokset[ii].value = 0;
2040Sstevel@tonic-gate for (ii = 0; ii < nnontersz; ++ii)
2050Sstevel@tonic-gate nontrst[ii].tvalue = 0;
2060Sstevel@tonic-gate aryfil(mem0, new_memsize, 0);
2070Sstevel@tonic-gate mem = mem0;
2080Sstevel@tonic-gate tracemem = mem0;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate while ((c = getopt(argc, argv, "vVdltp:Q:Y:P:b:")) != EOF)
2110Sstevel@tonic-gate switch (c) {
2120Sstevel@tonic-gate case 'v':
2130Sstevel@tonic-gate options |= v_FLAG;
2140Sstevel@tonic-gate break;
2150Sstevel@tonic-gate case 'V':
2160Sstevel@tonic-gate (void) fprintf(stderr, "yacc: %s %s\n",
2170Sstevel@tonic-gate (const char *)SGU_PKG,
2180Sstevel@tonic-gate (const char *)SGU_REL);
2190Sstevel@tonic-gate break;
2200Sstevel@tonic-gate case 'Q':
2210Sstevel@tonic-gate v_stmp = optarg;
2220Sstevel@tonic-gate if (*v_stmp != 'y' && *v_stmp != 'n')
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
2250Sstevel@tonic-gate * This message is passed to error() function.
2260Sstevel@tonic-gate * Do not translate -Q and [y/n].
2270Sstevel@tonic-gate */
2280Sstevel@tonic-gate error(gettext(
2290Sstevel@tonic-gate "yacc: -Q should be followed by [y/n]"));
2300Sstevel@tonic-gate break;
2310Sstevel@tonic-gate case 'd':
2320Sstevel@tonic-gate options |= d_FLAG;
2330Sstevel@tonic-gate break;
2340Sstevel@tonic-gate case 'l':
2350Sstevel@tonic-gate gen_lines = 0; /* don't gen #lines */
2360Sstevel@tonic-gate break;
2370Sstevel@tonic-gate case 't':
2380Sstevel@tonic-gate gen_testing = 1; /* set YYDEBUG on */
2390Sstevel@tonic-gate break;
2400Sstevel@tonic-gate case 'Y':
2410Sstevel@tonic-gate cp = (char *)malloc(strlen(optarg)+
2420Sstevel@tonic-gate sizeof ("/yaccpar") + 1);
2430Sstevel@tonic-gate cp = strcpy(cp, optarg);
2440Sstevel@tonic-gate parser = strcat(cp, "/yaccpar");
2450Sstevel@tonic-gate break;
2460Sstevel@tonic-gate case 'P':
2470Sstevel@tonic-gate parser = optarg;
2480Sstevel@tonic-gate break;
2490Sstevel@tonic-gate case 'p':
2500Sstevel@tonic-gate if (strcmp(optarg, "yy") != 0)
2510Sstevel@tonic-gate sym_prefix = optarg;
2520Sstevel@tonic-gate else
2530Sstevel@tonic-gate sym_prefix = "";
2540Sstevel@tonic-gate break;
2550Sstevel@tonic-gate case 'b':
2560Sstevel@tonic-gate file_prefix = optarg;
2570Sstevel@tonic-gate break;
2580Sstevel@tonic-gate case '?':
2590Sstevel@tonic-gate default:
2600Sstevel@tonic-gate /*
2610Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
2620Sstevel@tonic-gate * This message is passed to error() function.
2630Sstevel@tonic-gate * This is a usage message. The translate should be
2640Sstevel@tonic-gate * consistent with man page translation.
2650Sstevel@tonic-gate */
2660Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2670Sstevel@tonic-gate "Usage: yacc [-vVdltY] [-Q(y/n)] [-b file_prefix] [-p sym_prefix]"
2680Sstevel@tonic-gate " [-P parser] file\n"));
2690Sstevel@tonic-gate exit(1);
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate * Open y.output if -v is specified
2730Sstevel@tonic-gate */
2740Sstevel@tonic-gate if (options & v_FLAG) {
275*6951Sab196087 (void) strncpy(fname,
2760Sstevel@tonic-gate file_prefix,
2770Sstevel@tonic-gate F_NAME_LENGTH-strlen(".output"));
278*6951Sab196087 (void) strcat(fname, ".output");
2790Sstevel@tonic-gate foutput = fopen(fname, "w");
2800Sstevel@tonic-gate if (foutput == NULL)
2810Sstevel@tonic-gate error(gettext(
2820Sstevel@tonic-gate "cannot open y.output"));
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate /*
2860Sstevel@tonic-gate * Open y.tab.h if -d is specified
2870Sstevel@tonic-gate */
2880Sstevel@tonic-gate if (options & d_FLAG) {
289*6951Sab196087 (void) strncpy(fname,
2900Sstevel@tonic-gate file_prefix,
2910Sstevel@tonic-gate F_NAME_LENGTH-strlen(".tab.h"));
292*6951Sab196087 (void) strcat(fname, ".tab.h");
2930Sstevel@tonic-gate fdefine = fopen(fname, "w");
2940Sstevel@tonic-gate if (fdefine == NULL)
2950Sstevel@tonic-gate error(gettext(
2960Sstevel@tonic-gate "cannot open y.tab.h"));
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate fdebug = fopen(DEBUGNAME, "w");
3000Sstevel@tonic-gate if (fdebug == NULL)
3010Sstevel@tonic-gate /*
3020Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3030Sstevel@tonic-gate * This message is passed to error() function.
3040Sstevel@tonic-gate * Do not translate yacc.debug.
3050Sstevel@tonic-gate */
3060Sstevel@tonic-gate error(gettext(
3070Sstevel@tonic-gate "cannot open yacc.debug"));
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate * Open y.tab.c
3100Sstevel@tonic-gate */
311*6951Sab196087 (void) strncpy(fname,
3120Sstevel@tonic-gate file_prefix,
3130Sstevel@tonic-gate F_NAME_LENGTH-strlen(".tab.c"));
314*6951Sab196087 (void) strcat(fname, ".tab.c");
3150Sstevel@tonic-gate ftable = fopen(fname, "w");
3160Sstevel@tonic-gate if (ftable == NULL)
3170Sstevel@tonic-gate error(gettext(
3180Sstevel@tonic-gate "cannot open %s"), fname);
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate ftemp = fopen(TEMPNAME, "w");
3210Sstevel@tonic-gate faction = fopen(ACTNAME, "w");
3220Sstevel@tonic-gate if (ftemp == NULL || faction == NULL)
3230Sstevel@tonic-gate /*
3240Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3250Sstevel@tonic-gate * This message is passed to error() function.
3260Sstevel@tonic-gate * The message means: "Could not open a temporary file."
3270Sstevel@tonic-gate */
3280Sstevel@tonic-gate error(gettext(
3290Sstevel@tonic-gate "cannot open temp file"));
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate if ((finput = fopen(infile = argv[optind], "r")) == NULL)
3320Sstevel@tonic-gate /*
3330Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3340Sstevel@tonic-gate * This message is passed to error() function.
3350Sstevel@tonic-gate */
3360Sstevel@tonic-gate error(gettext(
3370Sstevel@tonic-gate "cannot open input file"));
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate lineno = 1;
3400Sstevel@tonic-gate cnamp = cnames;
3410Sstevel@tonic-gate (void) defin(0, L"$end");
3420Sstevel@tonic-gate extval = 0400;
3430Sstevel@tonic-gate (void) defin(0, L"error");
3440Sstevel@tonic-gate (void) defin(1, L"$accept");
3450Sstevel@tonic-gate mem = mem0;
3460Sstevel@tonic-gate lev = 0;
3470Sstevel@tonic-gate ty = 0;
3480Sstevel@tonic-gate i = 0;
3490Sstevel@tonic-gate beg_debug(); /* initialize fdebug file */
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate /*
3520Sstevel@tonic-gate * sorry -- no yacc parser here.....
3530Sstevel@tonic-gate * we must bootstrap somehow...
3540Sstevel@tonic-gate */
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate t = gettok();
3570Sstevel@tonic-gate if (*v_stmp == 'y')
3580Sstevel@tonic-gate (void) fprintf(ftable, "#ident\t\"yacc: %s %s\"\n",
3590Sstevel@tonic-gate (const char *)SGU_PKG, (const char *)SGU_REL);
3600Sstevel@tonic-gate for (; t != MARK && t != ENDFILE; ) {
3610Sstevel@tonic-gate int tok_in_line;
3620Sstevel@tonic-gate switch (t) {
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate case L';':
3650Sstevel@tonic-gate t = gettok();
3660Sstevel@tonic-gate break;
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate case START:
3690Sstevel@tonic-gate if ((t = gettok()) != IDENTIFIER) {
3700Sstevel@tonic-gate error("bad %%start construction");
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate start = chfind(1, tokname);
3730Sstevel@tonic-gate t = gettok();
3740Sstevel@tonic-gate continue;
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate case TYPEDEF:
3770Sstevel@tonic-gate tok_in_line = 0;
3780Sstevel@tonic-gate if ((t = gettok()) != TYPENAME)
3790Sstevel@tonic-gate /*
3800Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3810Sstevel@tonic-gate * This message is passed to error() function.
3820Sstevel@tonic-gate * Do not translate %%type.
3830Sstevel@tonic-gate */
3840Sstevel@tonic-gate error(gettext(
3850Sstevel@tonic-gate "bad syntax in %%type"));
3860Sstevel@tonic-gate ty = numbval;
3870Sstevel@tonic-gate for (;;) {
3880Sstevel@tonic-gate t = gettok();
3890Sstevel@tonic-gate switch (t) {
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate case IDENTIFIER:
3920Sstevel@tonic-gate /*
3930Sstevel@tonic-gate * The following lines are idented to left.
3940Sstevel@tonic-gate */
3950Sstevel@tonic-gate tok_in_line = 1;
3960Sstevel@tonic-gate if ((t = chfind(1, tokname)) < NTBASE) {
3970Sstevel@tonic-gate j = TYPE(toklev[t]);
3980Sstevel@tonic-gate if (j != 0 && j != ty) {
3990Sstevel@tonic-gate /*
4000Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4010Sstevel@tonic-gate * This message is passed to error() function.
4020Sstevel@tonic-gate */
4030Sstevel@tonic-gate error(gettext(
4040Sstevel@tonic-gate "type redeclaration of token %ws"),
4050Sstevel@tonic-gate tokset[t].name);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate else
4080Sstevel@tonic-gate SETTYPE(toklev[t], ty);
4090Sstevel@tonic-gate } else {
4100Sstevel@tonic-gate j = nontrst[t-NTBASE].tvalue;
4110Sstevel@tonic-gate if (j != 0 && j != ty) {
4120Sstevel@tonic-gate /*
4130Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4140Sstevel@tonic-gate * This message is passed to error() function.
4150Sstevel@tonic-gate * Check how nonterminal is translated in translated
4160Sstevel@tonic-gate * yacc man page or yacc user's document.
4170Sstevel@tonic-gate */
4180Sstevel@tonic-gate error(gettext(
4190Sstevel@tonic-gate "type redeclaration of nonterminal %ws"),
4200Sstevel@tonic-gate nontrst[t-NTBASE].name);
4210Sstevel@tonic-gate }
4220Sstevel@tonic-gate else
4230Sstevel@tonic-gate nontrst[t-NTBASE].tvalue = ty;
4240Sstevel@tonic-gate }
4250Sstevel@tonic-gate /* FALLTHRU */
4260Sstevel@tonic-gate /*
4270Sstevel@tonic-gate * End Indentation
4280Sstevel@tonic-gate */
4290Sstevel@tonic-gate case L',':
4300Sstevel@tonic-gate continue;
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate case L';':
4330Sstevel@tonic-gate t = gettok();
4340Sstevel@tonic-gate break;
4350Sstevel@tonic-gate default:
4360Sstevel@tonic-gate break;
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate if (!tok_in_line)
4390Sstevel@tonic-gate /*
4400Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4410Sstevel@tonic-gate * This message is passed to error() function.
4420Sstevel@tonic-gate */
4430Sstevel@tonic-gate error(gettext(
4440Sstevel@tonic-gate "missing tokens or illegal tokens"));
4450Sstevel@tonic-gate break;
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate continue;
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate case UNION:
4500Sstevel@tonic-gate /* copy the union declaration to the output */
4510Sstevel@tonic-gate cpyunion();
4520Sstevel@tonic-gate defunion = 1;
4530Sstevel@tonic-gate t = gettok();
4540Sstevel@tonic-gate continue;
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate case LEFT:
4570Sstevel@tonic-gate case BINARY:
4580Sstevel@tonic-gate case RIGHT:
4590Sstevel@tonic-gate i++;
4600Sstevel@tonic-gate /* FALLTHRU */
4610Sstevel@tonic-gate case TERM:
4620Sstevel@tonic-gate tok_in_line = 0;
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate /* nonzero means new prec. and assoc. */
4650Sstevel@tonic-gate lev = (t-TERM) | 04;
4660Sstevel@tonic-gate ty = 0;
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate /* get identifiers so defined */
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate t = gettok();
4710Sstevel@tonic-gate if (t == TYPENAME) { /* there is a type defined */
4720Sstevel@tonic-gate ty = numbval;
4730Sstevel@tonic-gate t = gettok();
4740Sstevel@tonic-gate }
4750Sstevel@tonic-gate
4760Sstevel@tonic-gate for (;;) {
4770Sstevel@tonic-gate switch (t) {
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate case L',':
4800Sstevel@tonic-gate t = gettok();
4810Sstevel@tonic-gate continue;
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate case L';':
4840Sstevel@tonic-gate break;
4850Sstevel@tonic-gate
4860Sstevel@tonic-gate case IDENTIFIER:
4870Sstevel@tonic-gate tok_in_line = 1;
4880Sstevel@tonic-gate j = chfind(0, tokname);
4890Sstevel@tonic-gate if (j > NTBASE) {
4900Sstevel@tonic-gate /*
4910Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4920Sstevel@tonic-gate * This message is passed to error() function.
4930Sstevel@tonic-gate */
4940Sstevel@tonic-gate error(gettext(
4950Sstevel@tonic-gate "%ws is not a token."),
4960Sstevel@tonic-gate tokname);
4970Sstevel@tonic-gate }
4980Sstevel@tonic-gate if (lev & ~04) {
4990Sstevel@tonic-gate if (ASSOC(toklev[j]) & ~04)
5000Sstevel@tonic-gate /*
5010Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5020Sstevel@tonic-gate * This message is passed to error() function.
5030Sstevel@tonic-gate */
5040Sstevel@tonic-gate error(gettext(
5050Sstevel@tonic-gate "redeclaration of precedence of %ws"),
5060Sstevel@tonic-gate tokname);
5070Sstevel@tonic-gate SETASC(toklev[j], lev);
5080Sstevel@tonic-gate SETPLEV(toklev[j], i);
5090Sstevel@tonic-gate } else {
5100Sstevel@tonic-gate if (ASSOC(toklev[j]))
5110Sstevel@tonic-gate (void) warning(1, gettext(
5120Sstevel@tonic-gate "redeclaration of precedence of %ws."),
5130Sstevel@tonic-gate tokname);
5140Sstevel@tonic-gate SETASC(toklev[j], lev);
5150Sstevel@tonic-gate }
5160Sstevel@tonic-gate if (ty) {
5170Sstevel@tonic-gate if (TYPE(toklev[j]))
5180Sstevel@tonic-gate error(gettext(
5190Sstevel@tonic-gate /*
5200Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5210Sstevel@tonic-gate * This message is passed to error() function.
5220Sstevel@tonic-gate */
5230Sstevel@tonic-gate "redeclaration of type of %ws"),
5240Sstevel@tonic-gate tokname);
5250Sstevel@tonic-gate SETTYPE(toklev[j], ty);
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate if ((t = gettok()) == NUMBER) {
5280Sstevel@tonic-gate tokset[j].value = numbval;
5290Sstevel@tonic-gate if (j < ndefout && j > 2) {
5300Sstevel@tonic-gate /*
5310Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5320Sstevel@tonic-gate * This message is passed to error() function.
5330Sstevel@tonic-gate */
5340Sstevel@tonic-gate error(gettext(
5350Sstevel@tonic-gate "type number of %ws should be defined earlier"),
5360Sstevel@tonic-gate tokset[j].name);
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate if (numbval >= -YYFLAG1) {
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5410Sstevel@tonic-gate * This message is passed to error() function.
5420Sstevel@tonic-gate */
5430Sstevel@tonic-gate error(gettext(
5440Sstevel@tonic-gate "token numbers must be less than %d"),
5450Sstevel@tonic-gate -YYFLAG1);
5460Sstevel@tonic-gate }
5470Sstevel@tonic-gate t = gettok();
5480Sstevel@tonic-gate }
5490Sstevel@tonic-gate continue;
5500Sstevel@tonic-gate
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate if (!tok_in_line)
5530Sstevel@tonic-gate /*
5540Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5550Sstevel@tonic-gate * This message is passed to error() function.
5560Sstevel@tonic-gate */
5570Sstevel@tonic-gate error(gettext(
5580Sstevel@tonic-gate "missing tokens or illegal tokens"));
5590Sstevel@tonic-gate break;
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate continue;
5620Sstevel@tonic-gate
5630Sstevel@tonic-gate case LCURLY:
5640Sstevel@tonic-gate defout();
5650Sstevel@tonic-gate cpycode();
5660Sstevel@tonic-gate t = gettok();
5670Sstevel@tonic-gate continue;
5680Sstevel@tonic-gate
5690Sstevel@tonic-gate default:
5700Sstevel@tonic-gate error("syntax error");
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate }
5730Sstevel@tonic-gate
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate
5760Sstevel@tonic-gate if (t == ENDFILE) {
5770Sstevel@tonic-gate /*
5780Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5790Sstevel@tonic-gate * This message is passed to error() function.
5800Sstevel@tonic-gate * Do not translate %%%%.
5810Sstevel@tonic-gate */
5820Sstevel@tonic-gate error("unexpected EOF before %%%%");
5830Sstevel@tonic-gate }
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate /* t is MARK */
5860Sstevel@tonic-gate
5870Sstevel@tonic-gate defout();
5880Sstevel@tonic-gate end_toks(); /* all tokens dumped - get ready for reductions */
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate (void) fprintf(ftable, "\n#include <inttypes.h>\n");
5910Sstevel@tonic-gate (void) fprintf(ftable, "\n#ifdef __STDC__\n");
5920Sstevel@tonic-gate (void) fprintf(ftable, "#include <stdlib.h>\n");
5930Sstevel@tonic-gate (void) fprintf(ftable, "#include <string.h>\n");
5940Sstevel@tonic-gate (void) fprintf(ftable, "#define YYCONST const\n");
5950Sstevel@tonic-gate (void) fprintf(ftable, "#else\n");
5960Sstevel@tonic-gate (void) fprintf(ftable, "#include <malloc.h>\n");
5970Sstevel@tonic-gate (void) fprintf(ftable, "#include <memory.h>\n");
5980Sstevel@tonic-gate (void) fprintf(ftable, "#define YYCONST\n");
5990Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6000Sstevel@tonic-gate (void) fprintf(ftable, "\n#include <values.h>\n");
6010Sstevel@tonic-gate
6020Sstevel@tonic-gate if (sym_prefix[0] != '\0')
6030Sstevel@tonic-gate put_prefix_define(sym_prefix);
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate (void) fprintf(ftable,
6060Sstevel@tonic-gate "\n#if defined(__cplusplus) || defined(__STDC__)\n");
6070Sstevel@tonic-gate (void) fprintf(ftable,
6080Sstevel@tonic-gate "\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6090Sstevel@tonic-gate (void) fprintf(ftable, "extern \"C\" {\n");
6100Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6110Sstevel@tonic-gate (void) fprintf(ftable, "#ifndef yyerror\n");
6120Sstevel@tonic-gate (void) fprintf(ftable, "#if defined(__cplusplus)\n");
6130Sstevel@tonic-gate (void) fprintf(ftable, " void yyerror(YYCONST char *);\n");
6140Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6150Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6160Sstevel@tonic-gate (void) fprintf(ftable, "#ifndef yylex\n");
6170Sstevel@tonic-gate (void) fprintf(ftable, " int yylex(void);\n");
6180Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6190Sstevel@tonic-gate (void) fprintf(ftable, " int yyparse(void);\n");
6200Sstevel@tonic-gate (void) fprintf(ftable,
6210Sstevel@tonic-gate "#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6220Sstevel@tonic-gate (void) fprintf(ftable, "}\n");
6230Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6240Sstevel@tonic-gate (void) fprintf(ftable, "\n#endif\n\n");
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate (void) fprintf(ftable, "#define yyclearin yychar = -1\n");
6270Sstevel@tonic-gate (void) fprintf(ftable, "#define yyerrok yyerrflag = 0\n");
6280Sstevel@tonic-gate (void) fprintf(ftable, "extern int yychar;\nextern int yyerrflag;\n");
6290Sstevel@tonic-gate if (!(defunion || ntypes))
6300Sstevel@tonic-gate (void) fprintf(ftable,
6310Sstevel@tonic-gate "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
6320Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yylval;\n");
6330Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yyval;\n");
6340Sstevel@tonic-gate (void) fprintf(ftable, "typedef int yytabelem;\n");
6350Sstevel@tonic-gate (void) fprintf(ftable,
6360Sstevel@tonic-gate "#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n");
6370Sstevel@tonic-gate (void) fprintf(ftable, "#if YYMAXDEPTH > 0\n");
6380Sstevel@tonic-gate (void) fprintf(ftable, "int yy_yys[YYMAXDEPTH], *yys = yy_yys;\n");
6390Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv;\n");
6400Sstevel@tonic-gate (void) fprintf(ftable, "#else /* user does initial allocation */\n");
6410Sstevel@tonic-gate (void) fprintf(ftable, "int *yys;\nYYSTYPE *yyv;\n#endif\n");
6420Sstevel@tonic-gate (void) fprintf(ftable, "static int yymaxdepth = YYMAXDEPTH;\n");
6430Sstevel@tonic-gate
6440Sstevel@tonic-gate prdptr[0] = mem;
6450Sstevel@tonic-gate /* added production */
6460Sstevel@tonic-gate *mem++ = NTBASE;
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate /* if start is 0, we will overwrite with the lhs of the first rule */
6490Sstevel@tonic-gate *mem++ = start;
6500Sstevel@tonic-gate *mem++ = 1;
6510Sstevel@tonic-gate *mem++ = 0;
6520Sstevel@tonic-gate prdptr[1] = mem;
6530Sstevel@tonic-gate
6540Sstevel@tonic-gate while ((t = gettok()) == LCURLY)
6550Sstevel@tonic-gate cpycode();
6560Sstevel@tonic-gate
6570Sstevel@tonic-gate if (t != C_IDENTIFIER)
6580Sstevel@tonic-gate error("bad syntax on first rule");
6590Sstevel@tonic-gate
6600Sstevel@tonic-gate if (!start)
6610Sstevel@tonic-gate prdptr[0][1] = chfind(1, tokname);
6620Sstevel@tonic-gate
6630Sstevel@tonic-gate /* read rules */
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate while (t != MARK && t != ENDFILE) {
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate /* process a rule */
6680Sstevel@tonic-gate
6690Sstevel@tonic-gate if (t == L'|') {
6700Sstevel@tonic-gate rhsfill((wchar_t *)0); /* restart fill of rhs */
6710Sstevel@tonic-gate *mem = *prdptr[nprod-1];
6720Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
6730Sstevel@tonic-gate exp_mem(1);
6740Sstevel@tonic-gate } else if (t == C_IDENTIFIER) {
6750Sstevel@tonic-gate *mem = chfind(1, tokname);
6760Sstevel@tonic-gate if (*mem < NTBASE)
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6790Sstevel@tonic-gate * This message is passed to error() function.
6800Sstevel@tonic-gate * Check how nonterminal is translated.
6810Sstevel@tonic-gate */
6820Sstevel@tonic-gate error(gettext(
6830Sstevel@tonic-gate "illegal nonterminal in grammar rule"));
6840Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
6850Sstevel@tonic-gate exp_mem(1);
6860Sstevel@tonic-gate lhsfill(tokname); /* new rule: restart strings */
6870Sstevel@tonic-gate } else
6880Sstevel@tonic-gate /*
6890Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6900Sstevel@tonic-gate * This message is passed to error() function.
6910Sstevel@tonic-gate */
6920Sstevel@tonic-gate error(gettext(
6930Sstevel@tonic-gate "illegal rule: missing semicolon or | ?"));
6940Sstevel@tonic-gate
6950Sstevel@tonic-gate /* read rule body */
6960Sstevel@tonic-gate
6970Sstevel@tonic-gate
6980Sstevel@tonic-gate t = gettok();
6990Sstevel@tonic-gate more_rule:
7000Sstevel@tonic-gate while (t == IDENTIFIER) {
7010Sstevel@tonic-gate *mem = chfind(1, tokname);
7020Sstevel@tonic-gate if (*mem < NTBASE)
7030Sstevel@tonic-gate levprd[nprod] = toklev[*mem]& ~04;
7040Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
7050Sstevel@tonic-gate exp_mem(1);
7060Sstevel@tonic-gate rhsfill(tokname); /* add to rhs string */
7070Sstevel@tonic-gate t = gettok();
7080Sstevel@tonic-gate }
7090Sstevel@tonic-gate
7100Sstevel@tonic-gate if (t == PREC) {
7110Sstevel@tonic-gate if (gettok() != IDENTIFIER)
7120Sstevel@tonic-gate /*
7130Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
7140Sstevel@tonic-gate * This message is passed to error() function.
7150Sstevel@tonic-gate * Do not translate %%prec.
7160Sstevel@tonic-gate */
7170Sstevel@tonic-gate error(gettext(
7180Sstevel@tonic-gate "illegal %%prec syntax"));
7190Sstevel@tonic-gate j = chfind(2, tokname);
7200Sstevel@tonic-gate if (j >= NTBASE)
7210Sstevel@tonic-gate /*
7220Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
7230Sstevel@tonic-gate * This message is passed to error() function.
7240Sstevel@tonic-gate * Do not translate %%prec.
7250Sstevel@tonic-gate */
7260Sstevel@tonic-gate error(gettext(
7270Sstevel@tonic-gate "nonterminal %ws illegal after %%prec"),
7280Sstevel@tonic-gate nontrst[j-NTBASE].name);
7290Sstevel@tonic-gate levprd[nprod] = toklev[j] & ~04;
7300Sstevel@tonic-gate t = gettok();
7310Sstevel@tonic-gate }
7320Sstevel@tonic-gate
7330Sstevel@tonic-gate if (t == L'=') {
7340Sstevel@tonic-gate had_act[nprod] = 1;
7350Sstevel@tonic-gate levprd[nprod] |= ACTFLAG;
7360Sstevel@tonic-gate (void) fprintf(faction, "\ncase %d:", nprod);
7370Sstevel@tonic-gate cpyact(mem-prdptr[nprod] - 1);
7380Sstevel@tonic-gate (void) fprintf(faction, " break;");
7390Sstevel@tonic-gate if ((t = gettok()) == IDENTIFIER) {
7400Sstevel@tonic-gate /* action within rule... */
7410Sstevel@tonic-gate
7420Sstevel@tonic-gate lrprnt(); /* dump lhs, rhs */
7430Sstevel@tonic-gate (void) wsprintf(actname, "$$%d", nprod);
7440Sstevel@tonic-gate /*
7450Sstevel@tonic-gate * make it nonterminal
7460Sstevel@tonic-gate */
7470Sstevel@tonic-gate j = chfind(1, actname);
7480Sstevel@tonic-gate
7490Sstevel@tonic-gate /*
7500Sstevel@tonic-gate * the current rule will become rule
7510Sstevel@tonic-gate * number nprod+1 move the contents down,
7520Sstevel@tonic-gate * and make room for the null
7530Sstevel@tonic-gate */
7540Sstevel@tonic-gate
7550Sstevel@tonic-gate if (mem + 2 >= &tracemem[new_memsize])
7560Sstevel@tonic-gate exp_mem(1);
7570Sstevel@tonic-gate for (p = mem; p >= prdptr[nprod]; --p)
7580Sstevel@tonic-gate p[2] = *p;
7590Sstevel@tonic-gate mem += 2;
7600Sstevel@tonic-gate
7610Sstevel@tonic-gate /* enter null production for action */
7620Sstevel@tonic-gate
7630Sstevel@tonic-gate p = prdptr[nprod];
7640Sstevel@tonic-gate
7650Sstevel@tonic-gate *p++ = j;
7660Sstevel@tonic-gate *p++ = -nprod;
7670Sstevel@tonic-gate
7680Sstevel@tonic-gate /* update the production information */
7690Sstevel@tonic-gate
7700Sstevel@tonic-gate levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
7710Sstevel@tonic-gate levprd[nprod] = ACTFLAG;
7720Sstevel@tonic-gate
7730Sstevel@tonic-gate if (++nprod >= nprodsz)
7740Sstevel@tonic-gate exp_prod();
7750Sstevel@tonic-gate prdptr[nprod] = p;
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate /*
7780Sstevel@tonic-gate * make the action appear in
7790Sstevel@tonic-gate * the original rule
7800Sstevel@tonic-gate */
7810Sstevel@tonic-gate *mem++ = j;
7820Sstevel@tonic-gate if (mem >= &tracemem[new_memsize])
7830Sstevel@tonic-gate exp_mem(1);
7840Sstevel@tonic-gate /* get some more of the rule */
7850Sstevel@tonic-gate goto more_rule;
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate while (t == L';')
7890Sstevel@tonic-gate t = gettok();
7900Sstevel@tonic-gate *mem++ = -nprod;
7910Sstevel@tonic-gate if (mem >= &tracemem[new_memsize])
7920Sstevel@tonic-gate exp_mem(1);
7930Sstevel@tonic-gate
7940Sstevel@tonic-gate /* check that default action is reasonable */
7950Sstevel@tonic-gate
7960Sstevel@tonic-gate if (ntypes && !(levprd[nprod] & ACTFLAG) &&
7970Sstevel@tonic-gate nontrst[*prdptr[nprod]-NTBASE].tvalue) {
7980Sstevel@tonic-gate /* no explicit action, LHS has value */
799100Smike_s int tempty;
8000Sstevel@tonic-gate tempty = prdptr[nprod][1];
8010Sstevel@tonic-gate if (tempty < 0)
8020Sstevel@tonic-gate /*
8030Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8040Sstevel@tonic-gate * This message is passed to error() function.
8050Sstevel@tonic-gate * LHS means Left Hand Side. It does not need to be translated.
8060Sstevel@tonic-gate */
8070Sstevel@tonic-gate error(gettext(
8080Sstevel@tonic-gate "must return a value, since LHS has a type"));
8090Sstevel@tonic-gate else if (tempty >= NTBASE)
8100Sstevel@tonic-gate tempty = nontrst[tempty-NTBASE].tvalue;
8110Sstevel@tonic-gate else
8120Sstevel@tonic-gate tempty = TYPE(toklev[tempty]);
8130Sstevel@tonic-gate if (tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue) {
8140Sstevel@tonic-gate /*
8150Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8160Sstevel@tonic-gate * This message is passed to error() function.
8170Sstevel@tonic-gate * Check how action is transltated in yacc man page or documents.
8180Sstevel@tonic-gate */
8190Sstevel@tonic-gate error(gettext(
8200Sstevel@tonic-gate "default action causes potential type clash"));
8210Sstevel@tonic-gate }
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate
8240Sstevel@tonic-gate if (++nprod >= nprodsz)
8250Sstevel@tonic-gate exp_prod();
8260Sstevel@tonic-gate prdptr[nprod] = mem;
8270Sstevel@tonic-gate levprd[nprod] = 0;
8280Sstevel@tonic-gate }
8290Sstevel@tonic-gate /* end of all rules */
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate end_debug(); /* finish fdebug file's input */
8320Sstevel@tonic-gate finact();
8330Sstevel@tonic-gate if (t == MARK) {
8340Sstevel@tonic-gate if (gen_lines)
8350Sstevel@tonic-gate (void) fprintf(ftable, "\n# line %d \"%s\"\n",
8360Sstevel@tonic-gate lineno, infile);
8370Sstevel@tonic-gate while ((c = getwc(finput)) != EOF)
8380Sstevel@tonic-gate (void) putwc(c, ftable);
8390Sstevel@tonic-gate }
8400Sstevel@tonic-gate (void) fclose(finput);
8410Sstevel@tonic-gate }
8420Sstevel@tonic-gate
8430Sstevel@tonic-gate static void
finact()8440Sstevel@tonic-gate finact()
8450Sstevel@tonic-gate {
8460Sstevel@tonic-gate /* finish action routine */
8470Sstevel@tonic-gate (void) fclose(faction);
8480Sstevel@tonic-gate (void) fprintf(ftable, "# define YYERRCODE %d\n", tokset[2].value);
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate static wchar_t *
cstash(s)8520Sstevel@tonic-gate cstash(s)
8530Sstevel@tonic-gate register wchar_t *s;
8540Sstevel@tonic-gate {
8550Sstevel@tonic-gate wchar_t *temp;
8560Sstevel@tonic-gate static int used = 0;
8570Sstevel@tonic-gate static int used_save = 0;
8580Sstevel@tonic-gate static int exp_cname = CNAMSZ;
8590Sstevel@tonic-gate int len = wslen(s);
8600Sstevel@tonic-gate
8610Sstevel@tonic-gate /*
8620Sstevel@tonic-gate * 2/29/88 -
8630Sstevel@tonic-gate * Don't need to expand the table, just allocate new space.
8640Sstevel@tonic-gate */
8650Sstevel@tonic-gate used_save = used;
8660Sstevel@tonic-gate while (len >= (exp_cname - used_save)) {
8670Sstevel@tonic-gate exp_cname += CNAMSZ;
8680Sstevel@tonic-gate if (!used)
8690Sstevel@tonic-gate free((char *)cnames);
8700Sstevel@tonic-gate if ((cnames = (wchar_t *)
8710Sstevel@tonic-gate malloc(sizeof (wchar_t)*exp_cname)) == NULL)
8720Sstevel@tonic-gate /*
8730Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8740Sstevel@tonic-gate * This message is passed to error() function.
8750Sstevel@tonic-gate *
8760Sstevel@tonic-gate * You may just translate this as:
8770Sstevel@tonic-gate * 'Could not allocate internally used memory.'
8780Sstevel@tonic-gate */
8790Sstevel@tonic-gate error(gettext(
8800Sstevel@tonic-gate "cannot expand string dump"));
8810Sstevel@tonic-gate cnamp = cnames;
8820Sstevel@tonic-gate used = 0;
8830Sstevel@tonic-gate }
8840Sstevel@tonic-gate
8850Sstevel@tonic-gate temp = cnamp;
8860Sstevel@tonic-gate do {
8870Sstevel@tonic-gate *cnamp++ = *s;
8880Sstevel@tonic-gate } while (*s++);
8890Sstevel@tonic-gate used += cnamp - temp;
8900Sstevel@tonic-gate return (temp);
8910Sstevel@tonic-gate }
8920Sstevel@tonic-gate
8930Sstevel@tonic-gate static int
defin(int t,wchar_t * s)894100Smike_s defin(int t, wchar_t *s)
8950Sstevel@tonic-gate {
8960Sstevel@tonic-gate /* define s to be a terminal if t=0 or a nonterminal if t=1 */
8970Sstevel@tonic-gate
898100Smike_s int val;
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate if (t) {
9010Sstevel@tonic-gate if (++nnonter >= nnontersz)
9020Sstevel@tonic-gate exp_nonterm();
9030Sstevel@tonic-gate nontrst[nnonter].name = cstash(s);
9040Sstevel@tonic-gate return (NTBASE + nnonter);
9050Sstevel@tonic-gate }
9060Sstevel@tonic-gate /* must be a token */
9070Sstevel@tonic-gate if (++ntokens >= ntoksz)
9080Sstevel@tonic-gate exp_ntok();
9090Sstevel@tonic-gate tokset[ntokens].name = cstash(s);
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate /* establish value for token */
9120Sstevel@tonic-gate
9130Sstevel@tonic-gate if (s[0] == L' ' && s[2] == 0) { /* single character literal */
9140Sstevel@tonic-gate val = findchtok(s[1]);
9150Sstevel@tonic-gate } else if (s[0] == L' ' && s[1] == L'\\') { /* escape sequence */
9160Sstevel@tonic-gate if (s[3] == 0) { /* single character escape sequence */
9170Sstevel@tonic-gate switch (s[2]) {
9180Sstevel@tonic-gate /* character which is escaped */
9190Sstevel@tonic-gate case L'a':
9200Sstevel@tonic-gate (void) warning(1, gettext(
9210Sstevel@tonic-gate /*
9220Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9230Sstevel@tonic-gate * This message is passed to warning() function.
9240Sstevel@tonic-gate * Do not trasnlate ANSI C, \\a.
9250Sstevel@tonic-gate */
9260Sstevel@tonic-gate "\\a is ANSI C \"alert\" character"));
9270Sstevel@tonic-gate #if __STDC__ - 1 == 0
9280Sstevel@tonic-gate val = L'\a';
9290Sstevel@tonic-gate break;
9300Sstevel@tonic-gate #else
9310Sstevel@tonic-gate val = L'\007';
9320Sstevel@tonic-gate break;
9330Sstevel@tonic-gate #endif
9340Sstevel@tonic-gate case L'v': val = L'\v'; break;
9350Sstevel@tonic-gate case L'n': val = L'\n'; break;
9360Sstevel@tonic-gate case L'r': val = L'\r'; break;
9370Sstevel@tonic-gate case L'b': val = L'\b'; break;
9380Sstevel@tonic-gate case L't': val = L'\t'; break;
9390Sstevel@tonic-gate case L'f': val = L'\f'; break;
9400Sstevel@tonic-gate case L'\'': val = L'\''; break;
9410Sstevel@tonic-gate case L'"': val = L'"'; break;
9420Sstevel@tonic-gate case L'?': val = L'?'; break;
9430Sstevel@tonic-gate case L'\\': val = L'\\'; break;
9440Sstevel@tonic-gate /*
9450Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9460Sstevel@tonic-gate * This message is passed to error() function.
9470Sstevel@tonic-gate */
9480Sstevel@tonic-gate default: error(gettext(
9490Sstevel@tonic-gate "invalid escape"));
9500Sstevel@tonic-gate }
9510Sstevel@tonic-gate } else if (s[2] <= L'7' && s[2] >= L'0') { /* \nnn sequence */
9520Sstevel@tonic-gate int i = 3;
9530Sstevel@tonic-gate val = s[2] - L'0';
9540Sstevel@tonic-gate while (iswdigit(s[i]) && i <= 4) {
9550Sstevel@tonic-gate if (s[i] >= L'0' && s[i] <= L'7')
9560Sstevel@tonic-gate val = val * 8 + s[i] - L'0';
9570Sstevel@tonic-gate else
9580Sstevel@tonic-gate /*
9590Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9600Sstevel@tonic-gate * This message is passed to error() function.
9610Sstevel@tonic-gate */
9620Sstevel@tonic-gate error(gettext(
9630Sstevel@tonic-gate "illegal octal number"));
9640Sstevel@tonic-gate i++;
9650Sstevel@tonic-gate }
9660Sstevel@tonic-gate if (s[i] != 0)
9670Sstevel@tonic-gate /*
9680Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9690Sstevel@tonic-gate * This message is passed to error() function.
9700Sstevel@tonic-gate * Do not translate \\nnn.
9710Sstevel@tonic-gate */
9720Sstevel@tonic-gate error(gettext(
9730Sstevel@tonic-gate "illegal \\nnn construction"));
9740Sstevel@tonic-gate if (val > 255)
9750Sstevel@tonic-gate /*
9760Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9770Sstevel@tonic-gate * This message is passed to error() function.
9780Sstevel@tonic-gate * Do not translate
9790Sstevel@tonic-gate * \\nnn, \\xnnnnnnnn.
9800Sstevel@tonic-gate */
9810Sstevel@tonic-gate error(
9820Sstevel@tonic-gate "\\nnn exceed \\377; use \\xnnnnnnnn for wchar_t value of multibyte char");
9830Sstevel@tonic-gate if (val == 0 && i >= 4)
9840Sstevel@tonic-gate /*
9850Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9860Sstevel@tonic-gate * This message is passed to error() function.
9870Sstevel@tonic-gate * Do not translate \\000.
9880Sstevel@tonic-gate */
9890Sstevel@tonic-gate error(gettext(
9900Sstevel@tonic-gate "'\\000' is illegal"));
9910Sstevel@tonic-gate } else if (s[2] == L'x') { /* hexadecimal \xnnn sequence */
9920Sstevel@tonic-gate int i = 3;
9930Sstevel@tonic-gate val = 0;
9940Sstevel@tonic-gate /*
9950Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9960Sstevel@tonic-gate * This message is passed to warning() function.
9970Sstevel@tonic-gate * Do not translate \\x, ANSI C.
9980Sstevel@tonic-gate */
9990Sstevel@tonic-gate (void) warning(1, gettext(
10004538Sdamico "\\x is ANSI C hex escape"));
10010Sstevel@tonic-gate if (iswxdigit(s[i]))
10020Sstevel@tonic-gate while (iswxdigit(s[i])) {
10030Sstevel@tonic-gate int tmpval;
10040Sstevel@tonic-gate if (iswdigit(s[i]))
10050Sstevel@tonic-gate tmpval = s[i] - L'0';
10060Sstevel@tonic-gate else if (s[i] >= L'a')
10070Sstevel@tonic-gate tmpval = s[i] - L'a' + 10;
10080Sstevel@tonic-gate else
10090Sstevel@tonic-gate tmpval = s[i] - L'A' + 10;
10100Sstevel@tonic-gate val = 16 * val + tmpval;
10110Sstevel@tonic-gate i++;
10120Sstevel@tonic-gate }
10130Sstevel@tonic-gate else
10140Sstevel@tonic-gate error(gettext(
10150Sstevel@tonic-gate "illegal hexadecimal number"));
10160Sstevel@tonic-gate if (s[i] != 0)
10170Sstevel@tonic-gate /*
10180Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10190Sstevel@tonic-gate * This message is passed to error() function.
10200Sstevel@tonic-gate * Do not translate \\xnn.
10210Sstevel@tonic-gate */
10220Sstevel@tonic-gate error(gettext(
10230Sstevel@tonic-gate "illegal \\xnn construction"));
10240Sstevel@tonic-gate #define LWCHAR_MAX 0x7fffffff
10250Sstevel@tonic-gate if ((unsigned)val > LWCHAR_MAX)
10260Sstevel@tonic-gate /*
10270Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10280Sstevel@tonic-gate * This message is passed to error() function.
10290Sstevel@tonic-gate * Do not translate \\xnnnnnnnn and %#x.
10300Sstevel@tonic-gate */
10314538Sdamico error(gettext(
10324538Sdamico " \\xnnnnnnnn exceed %#x"),
10334538Sdamico LWCHAR_MAX);
10340Sstevel@tonic-gate if (val == 0)
10350Sstevel@tonic-gate /*
10360Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10370Sstevel@tonic-gate * This message is passed to error() function.
10380Sstevel@tonic-gate * Do not translate \\x00.
10390Sstevel@tonic-gate */
10400Sstevel@tonic-gate error(gettext(
10410Sstevel@tonic-gate "'\\x00' is illegal"));
10420Sstevel@tonic-gate val = findchtok(val);
10430Sstevel@tonic-gate } else
10440Sstevel@tonic-gate error(gettext(
10450Sstevel@tonic-gate "invalid escape"));
10460Sstevel@tonic-gate } else {
10470Sstevel@tonic-gate val = extval++;
10480Sstevel@tonic-gate }
10490Sstevel@tonic-gate tokset[ntokens].value = val;
10500Sstevel@tonic-gate toklev[ntokens] = 0;
10510Sstevel@tonic-gate return (ntokens);
10520Sstevel@tonic-gate }
10530Sstevel@tonic-gate
10540Sstevel@tonic-gate static void
defout()10550Sstevel@tonic-gate defout()
10560Sstevel@tonic-gate {
10570Sstevel@tonic-gate /* write out the defines (at the end of the declaration section) */
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate register int i, c;
10600Sstevel@tonic-gate register wchar_t *cp;
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate for (i = ndefout; i <= ntokens; ++i) {
10630Sstevel@tonic-gate
10640Sstevel@tonic-gate cp = tokset[i].name;
10650Sstevel@tonic-gate if (*cp == L' ') /* literals */
10660Sstevel@tonic-gate {
1067*6951Sab196087 (void) fprintf(fdebug, WSFMT("\t\"%ws\",\t%d,\n"),
10684538Sdamico tokset[i].name + 1, tokset[i].value);
10690Sstevel@tonic-gate continue; /* was cp++ */
10700Sstevel@tonic-gate }
10710Sstevel@tonic-gate
10720Sstevel@tonic-gate for (; (c = *cp) != 0; ++cp) {
10730Sstevel@tonic-gate if (iswlower(c) || iswupper(c) ||
10744538Sdamico iswdigit(c) || c == L'_')
10754538Sdamico /* EMPTY */;
10760Sstevel@tonic-gate else
10770Sstevel@tonic-gate goto nodef;
10784538Sdamico }
10790Sstevel@tonic-gate
10800Sstevel@tonic-gate (void) fprintf(fdebug,
1081*6951Sab196087 WSFMT("\t\"%ws\",\t%d,\n"), tokset[i].name,
10824538Sdamico tokset[i].value);
10830Sstevel@tonic-gate (void) fprintf(ftable,
1084*6951Sab196087 WSFMT("# define %ws %d\n"), tokset[i].name,
10854538Sdamico tokset[i].value);
10860Sstevel@tonic-gate if (fdefine != NULL)
10870Sstevel@tonic-gate (void) fprintf(fdefine,
1088*6951Sab196087 WSFMT("# define %ws %d\n"),
10894538Sdamico tokset[i].name,
10904538Sdamico tokset[i].value);
10910Sstevel@tonic-gate
10920Sstevel@tonic-gate nodef:;
10930Sstevel@tonic-gate }
10940Sstevel@tonic-gate ndefout = ntokens+1;
10950Sstevel@tonic-gate }
10960Sstevel@tonic-gate
1097100Smike_s static int
gettok()10980Sstevel@tonic-gate gettok()
10990Sstevel@tonic-gate {
1100100Smike_s int i, base;
11010Sstevel@tonic-gate static int peekline; /* number of '\n' seen in lookahead */
1102100Smike_s int c, match, reserve;
11030Sstevel@tonic-gate begin:
11040Sstevel@tonic-gate reserve = 0;
11050Sstevel@tonic-gate lineno += peekline;
11060Sstevel@tonic-gate peekline = 0;
11070Sstevel@tonic-gate c = getwc(finput);
11080Sstevel@tonic-gate /*
11090Sstevel@tonic-gate * while (c == ' ' || c == '\n' || c == '\t' || c == '\f') {
11100Sstevel@tonic-gate */
11110Sstevel@tonic-gate while (iswspace(c)) {
11120Sstevel@tonic-gate if (c == L'\n')
11130Sstevel@tonic-gate ++lineno;
11140Sstevel@tonic-gate c = getwc(finput);
11150Sstevel@tonic-gate }
11160Sstevel@tonic-gate if (c == L'/') { /* skip comment */
11170Sstevel@tonic-gate lineno += skipcom();
11180Sstevel@tonic-gate goto begin;
11190Sstevel@tonic-gate }
11200Sstevel@tonic-gate
11210Sstevel@tonic-gate switch (c) {
11220Sstevel@tonic-gate
11230Sstevel@tonic-gate case EOF:
11240Sstevel@tonic-gate return (ENDFILE);
11250Sstevel@tonic-gate case L'{':
11260Sstevel@tonic-gate (void) ungetwc(c, finput);
11270Sstevel@tonic-gate return (L'='); /* action ... */
11280Sstevel@tonic-gate case L'<': /* get, and look up, a type name (union member name) */
11290Sstevel@tonic-gate i = 0;
11300Sstevel@tonic-gate while ((c = getwc(finput)) != L'>' &&
11314538Sdamico c != EOF && c != L'\n') {
11320Sstevel@tonic-gate tokname[i] = c;
11330Sstevel@tonic-gate if (++i >= toksize)
11340Sstevel@tonic-gate exp_tokname();
11350Sstevel@tonic-gate }
11360Sstevel@tonic-gate if (c != L'>')
11370Sstevel@tonic-gate error(gettext(
11380Sstevel@tonic-gate "unterminated < ... > clause"));
11390Sstevel@tonic-gate tokname[i] = 0;
11400Sstevel@tonic-gate if (i == 0)
11410Sstevel@tonic-gate error("missing type name in < ... > clause");
11420Sstevel@tonic-gate for (i = 1; i <= ntypes; ++i) {
11430Sstevel@tonic-gate if (!wscmp(typeset[i], tokname)) {
11440Sstevel@tonic-gate numbval = i;
11450Sstevel@tonic-gate return (TYPENAME);
11460Sstevel@tonic-gate }
11470Sstevel@tonic-gate }
11480Sstevel@tonic-gate typeset[numbval = ++ntypes] = cstash(tokname);
11490Sstevel@tonic-gate return (TYPENAME);
11500Sstevel@tonic-gate
11510Sstevel@tonic-gate case L'"':
11520Sstevel@tonic-gate case L'\'':
11530Sstevel@tonic-gate match = c;
11540Sstevel@tonic-gate tokname[0] = L' ';
11550Sstevel@tonic-gate i = 1;
11560Sstevel@tonic-gate for (;;) {
11570Sstevel@tonic-gate c = getwc(finput);
11580Sstevel@tonic-gate if (c == L'\n' || c == EOF)
11590Sstevel@tonic-gate error(gettext(
11600Sstevel@tonic-gate "illegal or missing ' or \""));
11610Sstevel@tonic-gate if (c == L'\\') {
11620Sstevel@tonic-gate c = getwc(finput);
11630Sstevel@tonic-gate tokname[i] = L'\\';
11640Sstevel@tonic-gate if (++i >= toksize)
11650Sstevel@tonic-gate exp_tokname();
11660Sstevel@tonic-gate } else if (c == match) break;
11670Sstevel@tonic-gate tokname[i] = c;
11680Sstevel@tonic-gate if (++i >= toksize)
11690Sstevel@tonic-gate exp_tokname();
11700Sstevel@tonic-gate }
11710Sstevel@tonic-gate break;
11720Sstevel@tonic-gate
11730Sstevel@tonic-gate case L'%':
11740Sstevel@tonic-gate case L'\\':
11750Sstevel@tonic-gate
11760Sstevel@tonic-gate switch (c = getwc(finput)) {
11770Sstevel@tonic-gate
11780Sstevel@tonic-gate case L'0': return (TERM);
11790Sstevel@tonic-gate case L'<': return (LEFT);
11800Sstevel@tonic-gate case L'2': return (BINARY);
11810Sstevel@tonic-gate case L'>': return (RIGHT);
11820Sstevel@tonic-gate case L'%':
11830Sstevel@tonic-gate case L'\\': return (MARK);
11840Sstevel@tonic-gate case L'=': return (PREC);
11850Sstevel@tonic-gate case L'{': return (LCURLY);
11860Sstevel@tonic-gate default: reserve = 1;
11870Sstevel@tonic-gate }
11880Sstevel@tonic-gate
11890Sstevel@tonic-gate default:
11900Sstevel@tonic-gate
11910Sstevel@tonic-gate if (iswdigit(c)) { /* number */
11920Sstevel@tonic-gate numbval = c - L'0';
11930Sstevel@tonic-gate base = (c == L'0') ? 8 : 10;
11940Sstevel@tonic-gate for (c = getwc(finput);
11954538Sdamico iswdigit(c);
11964538Sdamico c = getwc(finput)) {
11970Sstevel@tonic-gate numbval = numbval*base + c - L'0';
11980Sstevel@tonic-gate }
11990Sstevel@tonic-gate (void) ungetwc(c, finput);
12000Sstevel@tonic-gate return (NUMBER);
12010Sstevel@tonic-gate } else if (iswlower(c) || iswupper(c) ||
12024538Sdamico c == L'_' || c == L'.' ||
12034538Sdamico c == L'$') {
12040Sstevel@tonic-gate i = 0;
12050Sstevel@tonic-gate while (iswlower(c) || iswupper(c) ||
12064538Sdamico iswdigit(c) || c == L'_' ||
12074538Sdamico c == L'.' || c == L'$') {
12080Sstevel@tonic-gate tokname[i] = c;
12090Sstevel@tonic-gate if (reserve && iswupper(c))
12100Sstevel@tonic-gate tokname[i] = towlower(c);
12110Sstevel@tonic-gate if (++i >= toksize)
12120Sstevel@tonic-gate exp_tokname();
12130Sstevel@tonic-gate c = getwc(finput);
12140Sstevel@tonic-gate }
12150Sstevel@tonic-gate }
12160Sstevel@tonic-gate else
12170Sstevel@tonic-gate return (c);
12180Sstevel@tonic-gate
12190Sstevel@tonic-gate (void) ungetwc(c, finput);
12200Sstevel@tonic-gate }
12210Sstevel@tonic-gate
12220Sstevel@tonic-gate tokname[i] = 0;
12230Sstevel@tonic-gate
12240Sstevel@tonic-gate if (reserve) { /* find a reserved word */
12250Sstevel@tonic-gate if (!wscmp(tokname, L"term"))
12260Sstevel@tonic-gate return (TERM);
12270Sstevel@tonic-gate if (!wscmp(tokname, L"token"))
12280Sstevel@tonic-gate return (TERM);
12290Sstevel@tonic-gate if (!wscmp(tokname, L"left"))
12300Sstevel@tonic-gate return (LEFT);
12310Sstevel@tonic-gate if (!wscmp(tokname, L"nonassoc"))
12320Sstevel@tonic-gate return (BINARY);
12330Sstevel@tonic-gate if (!wscmp(tokname, L"binary"))
12340Sstevel@tonic-gate return (BINARY);
12350Sstevel@tonic-gate if (!wscmp(tokname, L"right"))
12360Sstevel@tonic-gate return (RIGHT);
12370Sstevel@tonic-gate if (!wscmp(tokname, L"prec"))
12380Sstevel@tonic-gate return (PREC);
12390Sstevel@tonic-gate if (!wscmp(tokname, L"start"))
12400Sstevel@tonic-gate return (START);
12410Sstevel@tonic-gate if (!wscmp(tokname, L"type"))
12420Sstevel@tonic-gate return (TYPEDEF);
12430Sstevel@tonic-gate if (!wscmp(tokname, L"union"))
12440Sstevel@tonic-gate return (UNION);
12450Sstevel@tonic-gate error(gettext(
12464538Sdamico "invalid escape, or illegal reserved word: %ws"),
12474538Sdamico tokname);
12480Sstevel@tonic-gate }
12490Sstevel@tonic-gate
12500Sstevel@tonic-gate /* look ahead to distinguish IDENTIFIER from C_IDENTIFIER */
12510Sstevel@tonic-gate
12520Sstevel@tonic-gate c = getwc(finput);
12530Sstevel@tonic-gate /*
12540Sstevel@tonic-gate * while (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '/')
12550Sstevel@tonic-gate * {
12560Sstevel@tonic-gate */
12570Sstevel@tonic-gate while (iswspace(c) || c == L'/') {
12580Sstevel@tonic-gate if (c == L'\n') {
12590Sstevel@tonic-gate ++peekline;
12600Sstevel@tonic-gate } else if (c == L'/') { /* look for comments */
12610Sstevel@tonic-gate peekline += skipcom();
12620Sstevel@tonic-gate }
12630Sstevel@tonic-gate c = getwc(finput);
12640Sstevel@tonic-gate }
12650Sstevel@tonic-gate if (c == L':')
12660Sstevel@tonic-gate return (C_IDENTIFIER);
12670Sstevel@tonic-gate (void) ungetwc(c, finput);
12680Sstevel@tonic-gate return (IDENTIFIER);
12690Sstevel@tonic-gate }
12700Sstevel@tonic-gate
1271100Smike_s static int
fdtype(int t)1272100Smike_s fdtype(int t)
12730Sstevel@tonic-gate {
12740Sstevel@tonic-gate /* determine the type of a symbol */
1275100Smike_s int v;
12760Sstevel@tonic-gate if (t >= NTBASE)
12770Sstevel@tonic-gate v = nontrst[t-NTBASE].tvalue;
12780Sstevel@tonic-gate else
12790Sstevel@tonic-gate v = TYPE(toklev[t]);
12800Sstevel@tonic-gate if (v <= 0)
12810Sstevel@tonic-gate error(gettext(
12824538Sdamico "must specify type for %ws"),
12834538Sdamico (t >= NTBASE) ? nontrst[t-NTBASE].name:
12844538Sdamico tokset[t].name);
12850Sstevel@tonic-gate return (v);
12860Sstevel@tonic-gate }
12870Sstevel@tonic-gate
1288100Smike_s static int
chfind(int t,wchar_t * s)1289100Smike_s chfind(int t, wchar_t *s)
12900Sstevel@tonic-gate {
12910Sstevel@tonic-gate int i;
12920Sstevel@tonic-gate
12930Sstevel@tonic-gate if (s[0] == ' ')
12940Sstevel@tonic-gate t = 0;
12950Sstevel@tonic-gate TLOOP(i) {
12960Sstevel@tonic-gate if (!wscmp(s, tokset[i].name)) {
12970Sstevel@tonic-gate return (i);
12980Sstevel@tonic-gate }
12990Sstevel@tonic-gate }
13000Sstevel@tonic-gate NTLOOP(i) {
13010Sstevel@tonic-gate if (!wscmp(s, nontrst[i].name)) {
13020Sstevel@tonic-gate return (i + NTBASE);
13030Sstevel@tonic-gate }
13040Sstevel@tonic-gate }
13050Sstevel@tonic-gate /* cannot find name */
13060Sstevel@tonic-gate if (t > 1)
13070Sstevel@tonic-gate error(gettext(
13080Sstevel@tonic-gate "%ws should have been defined earlier"), s);
13090Sstevel@tonic-gate return (defin(t, s));
13100Sstevel@tonic-gate }
13110Sstevel@tonic-gate
13120Sstevel@tonic-gate static void
cpyunion()13130Sstevel@tonic-gate cpyunion()
13140Sstevel@tonic-gate {
13150Sstevel@tonic-gate /*
13160Sstevel@tonic-gate * copy the union declaration to the output,
13170Sstevel@tonic-gate * and the define file if present
13180Sstevel@tonic-gate */
13190Sstevel@tonic-gate int level, c;
13200Sstevel@tonic-gate if (gen_lines)
13210Sstevel@tonic-gate (void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
13220Sstevel@tonic-gate (void) fprintf(ftable, "typedef union\n");
13230Sstevel@tonic-gate if (fdefine)
13240Sstevel@tonic-gate (void) fprintf(fdefine, "\ntypedef union\n");
13250Sstevel@tonic-gate (void) fprintf(ftable, "#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
13260Sstevel@tonic-gate if (fdefine)
13270Sstevel@tonic-gate (void) fprintf(fdefine,
13284538Sdamico "#ifdef __cplusplus\n\tYYSTYPE\n#endif\n");
13290Sstevel@tonic-gate
13300Sstevel@tonic-gate level = 0;
13310Sstevel@tonic-gate for (;;) {
13320Sstevel@tonic-gate if ((c = getwc(finput)) == EOF)
13330Sstevel@tonic-gate /*
13340Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
13350Sstevel@tonic-gate * This message is passed to error() function.
13360Sstevel@tonic-gate * EOF - End Of File.
13370Sstevel@tonic-gate * Do not translate %%union.
13380Sstevel@tonic-gate */
13390Sstevel@tonic-gate error(gettext(
13400Sstevel@tonic-gate "EOF encountered while processing %%union"));
13410Sstevel@tonic-gate (void) putwc(c, ftable);
13420Sstevel@tonic-gate if (fdefine)
13430Sstevel@tonic-gate (void) putwc(c, fdefine);
13440Sstevel@tonic-gate
13450Sstevel@tonic-gate switch (c) {
13460Sstevel@tonic-gate
13470Sstevel@tonic-gate case L'\n':
13480Sstevel@tonic-gate ++lineno;
13490Sstevel@tonic-gate break;
13500Sstevel@tonic-gate
13510Sstevel@tonic-gate case L'{':
13520Sstevel@tonic-gate ++level;
13530Sstevel@tonic-gate break;
13540Sstevel@tonic-gate
13550Sstevel@tonic-gate case L'}':
13560Sstevel@tonic-gate --level;
13570Sstevel@tonic-gate if (level == 0) { /* we are finished copying */
13580Sstevel@tonic-gate (void) fprintf(ftable, " YYSTYPE;\n");
13590Sstevel@tonic-gate if (fdefine)
13600Sstevel@tonic-gate (void) fprintf(fdefine,
13610Sstevel@tonic-gate " YYSTYPE;\nextern YYSTYPE yylval;\n");
13620Sstevel@tonic-gate return;
13630Sstevel@tonic-gate }
13640Sstevel@tonic-gate }
13650Sstevel@tonic-gate }
13660Sstevel@tonic-gate }
13670Sstevel@tonic-gate
13680Sstevel@tonic-gate static void
cpycode()13690Sstevel@tonic-gate cpycode()
13700Sstevel@tonic-gate {
13710Sstevel@tonic-gate /* copies code between \{ and \} */
13720Sstevel@tonic-gate
13730Sstevel@tonic-gate int c;
13740Sstevel@tonic-gate c = getwc(finput);
13750Sstevel@tonic-gate if (c == L'\n') {
13760Sstevel@tonic-gate c = getwc(finput);
13770Sstevel@tonic-gate lineno++;
13780Sstevel@tonic-gate }
13790Sstevel@tonic-gate if (gen_lines)
13800Sstevel@tonic-gate (void) fprintf(ftable, "\n# line %d \"%s\"\n", lineno, infile);
13810Sstevel@tonic-gate while (c != EOF) {
13820Sstevel@tonic-gate if (c == L'\\') {
13830Sstevel@tonic-gate if ((c = getwc(finput)) == L'}')
13840Sstevel@tonic-gate return;
13850Sstevel@tonic-gate else
13860Sstevel@tonic-gate (void) putwc(L'\\', ftable);
13870Sstevel@tonic-gate } else if (c == L'%') {
13880Sstevel@tonic-gate if ((c = getwc(finput)) == L'}')
13890Sstevel@tonic-gate return;
13900Sstevel@tonic-gate else
13910Sstevel@tonic-gate (void) putwc(L'%', ftable);
13920Sstevel@tonic-gate }
13930Sstevel@tonic-gate (void) putwc(c, ftable);
13940Sstevel@tonic-gate if (c == L'\n')
13950Sstevel@tonic-gate ++lineno;
13960Sstevel@tonic-gate c = getwc(finput);
13970Sstevel@tonic-gate }
13980Sstevel@tonic-gate /*
13990Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
14000Sstevel@tonic-gate * This message is passed to error() function.
14010Sstevel@tonic-gate * Do not translate %%}.
14020Sstevel@tonic-gate */
14030Sstevel@tonic-gate error(gettext(
14040Sstevel@tonic-gate "eof before %%}"));
14050Sstevel@tonic-gate }
14060Sstevel@tonic-gate
1407100Smike_s static int
skipcom()14080Sstevel@tonic-gate skipcom()
14090Sstevel@tonic-gate {
14100Sstevel@tonic-gate /* skip over comments */
1411100Smike_s int c, i = 0; /* i is the number of lines skipped */
14120Sstevel@tonic-gate
14130Sstevel@tonic-gate /* skipcom is called after reading a / */
14140Sstevel@tonic-gate
14150Sstevel@tonic-gate if (getwc(finput) != L'*')
14160Sstevel@tonic-gate error(gettext(
14170Sstevel@tonic-gate "illegal comment"));
14180Sstevel@tonic-gate c = getwc(finput);
14190Sstevel@tonic-gate while (c != EOF) {
14200Sstevel@tonic-gate while (c == L'*') {
14210Sstevel@tonic-gate if ((c = getwc(finput)) == L'/')
14220Sstevel@tonic-gate return (i);
14230Sstevel@tonic-gate }
14240Sstevel@tonic-gate if (c == L'\n')
14250Sstevel@tonic-gate ++i;
14260Sstevel@tonic-gate c = getwc(finput);
14270Sstevel@tonic-gate }
14280Sstevel@tonic-gate /*
14290Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
14300Sstevel@tonic-gate * This message is passed to error() function.
14310Sstevel@tonic-gate * EOF -- End Of File.
14320Sstevel@tonic-gate */
14330Sstevel@tonic-gate error(gettext(
14340Sstevel@tonic-gate "EOF inside comment"));
14350Sstevel@tonic-gate /* NOTREACHED */
1436100Smike_s return (0);
14370Sstevel@tonic-gate }
14380Sstevel@tonic-gate
14390Sstevel@tonic-gate static void
cpyact(int offset)1440100Smike_s cpyact(int offset)
14410Sstevel@tonic-gate {
14420Sstevel@tonic-gate /* copy C action to the next ; or closing } */
14430Sstevel@tonic-gate int brac, c, match, i, t, j, s, tok, argument, m;
14440Sstevel@tonic-gate wchar_t id_name[NAMESIZE+1];
14450Sstevel@tonic-gate int id_idx = 0;
14460Sstevel@tonic-gate
14470Sstevel@tonic-gate if (gen_lines) {
14480Sstevel@tonic-gate (void) fprintf(faction, "\n# line %d \"%s\"\n", lineno, infile);
14490Sstevel@tonic-gate act_lines++;
14500Sstevel@tonic-gate }
14510Sstevel@tonic-gate brac = 0;
14520Sstevel@tonic-gate id_name[0] = 0;
14530Sstevel@tonic-gate loop:
14540Sstevel@tonic-gate c = getwc(finput);
14550Sstevel@tonic-gate swt:
14560Sstevel@tonic-gate switch (c) {
14570Sstevel@tonic-gate case L';':
14580Sstevel@tonic-gate if (brac == 0) {
14590Sstevel@tonic-gate (void) putwc(c, faction);
14600Sstevel@tonic-gate return;
14610Sstevel@tonic-gate }
14620Sstevel@tonic-gate goto lcopy;
14630Sstevel@tonic-gate case L'{':
14640Sstevel@tonic-gate brac++;
14650Sstevel@tonic-gate goto lcopy;
14660Sstevel@tonic-gate case L'$':
14670Sstevel@tonic-gate s = 1;
14680Sstevel@tonic-gate tok = -1;
14690Sstevel@tonic-gate argument = 1;
14704538Sdamico while ((c = getwc(finput)) == L' ' || c == L'\t')
14714538Sdamico /* NULL */;
14720Sstevel@tonic-gate if (c == L'<') { /* type description */
14730Sstevel@tonic-gate (void) ungetwc(c, finput);
14740Sstevel@tonic-gate if (gettok() != TYPENAME)
14750Sstevel@tonic-gate /*
14760Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
14770Sstevel@tonic-gate * This message is passed to error() function.
14780Sstevel@tonic-gate * Do not translate $<ident>
14790Sstevel@tonic-gate */
14800Sstevel@tonic-gate error(gettext(
14810Sstevel@tonic-gate "bad syntax on $<ident> clause"));
14820Sstevel@tonic-gate tok = numbval;
14830Sstevel@tonic-gate c = getwc(finput);
14840Sstevel@tonic-gate }
14850Sstevel@tonic-gate if (c == L'$') {
14860Sstevel@tonic-gate (void) fprintf(faction, "yyval");
14870Sstevel@tonic-gate if (ntypes) { /* put out the proper tag... */
14880Sstevel@tonic-gate if (tok < 0)
14890Sstevel@tonic-gate tok = fdtype(*prdptr[nprod]);
14900Sstevel@tonic-gate (void) fprintf(faction,
1491*6951Sab196087 WSFMT(".%ws"), typeset[tok]);
14920Sstevel@tonic-gate }
14930Sstevel@tonic-gate goto loop;
14940Sstevel@tonic-gate }
14950Sstevel@tonic-gate if (iswalpha(c)) {
14960Sstevel@tonic-gate int same = 0;
14970Sstevel@tonic-gate int id_sw = 0;
14980Sstevel@tonic-gate (void) ungetwc(c, finput);
14990Sstevel@tonic-gate if (gettok() != IDENTIFIER)
15000Sstevel@tonic-gate /*
15010Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
15020Sstevel@tonic-gate * This message is passed to error() function.
15030Sstevel@tonic-gate * Check how action is translated in yacc man page/document.
15040Sstevel@tonic-gate */
15050Sstevel@tonic-gate error(gettext(
15060Sstevel@tonic-gate "bad action format"));
15070Sstevel@tonic-gate /*
15080Sstevel@tonic-gate * Save the number of non-terminal
15090Sstevel@tonic-gate */
15100Sstevel@tonic-gate id_sw = nnonter;
15110Sstevel@tonic-gate t = chfind(1, tokname);
15120Sstevel@tonic-gate /*
15130Sstevel@tonic-gate * Check if the identifier is added as a non-terminal
15140Sstevel@tonic-gate */
15150Sstevel@tonic-gate if (id_sw != nnonter)
15160Sstevel@tonic-gate id_sw = 1;
15170Sstevel@tonic-gate else
15180Sstevel@tonic-gate id_sw = 0;
15190Sstevel@tonic-gate while ((c = getwc(finput)) == L' ' ||
15204538Sdamico c == L'\t')
15214538Sdamico /* NULL */;
15220Sstevel@tonic-gate if (c == L'#') {
15230Sstevel@tonic-gate while ((c = getwc(finput)) == L' ' ||
15244538Sdamico c == L'\t')
15254538Sdamico /* NULL */;
15260Sstevel@tonic-gate if (iswdigit(c)) {
15270Sstevel@tonic-gate m = 0;
15280Sstevel@tonic-gate while (iswdigit(c)) {
15290Sstevel@tonic-gate m = m*10+c-L'0';
15300Sstevel@tonic-gate c = getwc(finput);
15310Sstevel@tonic-gate }
15320Sstevel@tonic-gate argument = m;
15330Sstevel@tonic-gate } else
15340Sstevel@tonic-gate error(gettext(
15350Sstevel@tonic-gate "illegal character \"#\""));
15360Sstevel@tonic-gate }
15370Sstevel@tonic-gate if (argument < 1)
15380Sstevel@tonic-gate /*
15390Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
15400Sstevel@tonic-gate * This message is passed to error() function.
15410Sstevel@tonic-gate * Check how action is translated in yacc man page/document.
15420Sstevel@tonic-gate */
15430Sstevel@tonic-gate error(gettext(
15440Sstevel@tonic-gate "illegal action argument no."));
15450Sstevel@tonic-gate for (i = 1; i <= offset; ++i)
15460Sstevel@tonic-gate if (prdptr[nprod][i] == t)
15470Sstevel@tonic-gate if (++same == argument) {
15480Sstevel@tonic-gate (void) fprintf(faction,
15494538Sdamico "yypvt[-%d]", offset-i);
15500Sstevel@tonic-gate if (ntypes) {
15510Sstevel@tonic-gate if (tok < 0)
15520Sstevel@tonic-gate tok =
15530Sstevel@tonic-gate /* CSTYLED */
15540Sstevel@tonic-gate fdtype(prdptr[nprod][i]);
15550Sstevel@tonic-gate (void) fprintf(faction,
1556*6951Sab196087 WSFMT(".%ws"),
1557*6951Sab196087 typeset[tok]);
15580Sstevel@tonic-gate }
15590Sstevel@tonic-gate goto swt;
15600Sstevel@tonic-gate }
15610Sstevel@tonic-gate /*
15620Sstevel@tonic-gate * This used to be handled as error.
15630Sstevel@tonic-gate * Treat this as a valid C statement.
15640Sstevel@tonic-gate * (Likely id with $ in.)
15650Sstevel@tonic-gate * If non-terminal is added, remove it from the list.
15660Sstevel@tonic-gate */
1567*6951Sab196087 (void) fprintf(faction, WSFMT("$%ws"), tokname);
15680Sstevel@tonic-gate /*
15690Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
15700Sstevel@tonic-gate * This message is passed to warning() function.
15710Sstevel@tonic-gate * Do not translate Ansi C.
15720Sstevel@tonic-gate */
15730Sstevel@tonic-gate warning(1, gettext(
15740Sstevel@tonic-gate "Illegal character '$' in Ansi C symbol: %ws$%ws."),
15754538Sdamico id_name, tokname);
15760Sstevel@tonic-gate
15770Sstevel@tonic-gate if (id_sw == 1)
15780Sstevel@tonic-gate --nnonter;
15790Sstevel@tonic-gate goto swt;
15800Sstevel@tonic-gate }
15810Sstevel@tonic-gate if (c == '-') {
15820Sstevel@tonic-gate s = -s;
15830Sstevel@tonic-gate c = getwc(finput);
15840Sstevel@tonic-gate }
15850Sstevel@tonic-gate if (iswdigit(c)) {
15860Sstevel@tonic-gate j = 0;
15870Sstevel@tonic-gate while (iswdigit(c)) {
15880Sstevel@tonic-gate j = j*10 + c - L'0';
15890Sstevel@tonic-gate c = getwc(finput);
15900Sstevel@tonic-gate }
15910Sstevel@tonic-gate j = j*s - offset;
15920Sstevel@tonic-gate if (j > 0) {
15930Sstevel@tonic-gate /*
15940Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
15950Sstevel@tonic-gate * This message is passed to error() function.
15960Sstevel@tonic-gate * Do not translate $%d.
15970Sstevel@tonic-gate */
15980Sstevel@tonic-gate error(gettext(
15994538Sdamico "Illegal use of $%d"),
16004538Sdamico j + offset);
16010Sstevel@tonic-gate }
16020Sstevel@tonic-gate (void) fprintf(faction, "yypvt[-%d]", -j);
16030Sstevel@tonic-gate if (ntypes) { /* put out the proper tag */
16040Sstevel@tonic-gate if (j + offset <= 0 && tok < 0)
16050Sstevel@tonic-gate /*
16060Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
16070Sstevel@tonic-gate * This message is passed to error() function.
16080Sstevel@tonic-gate * Do not translate $%d.
16090Sstevel@tonic-gate */
16100Sstevel@tonic-gate error(gettext(
16114538Sdamico "must specify type of $%d"),
16124538Sdamico j + offset);
16130Sstevel@tonic-gate if (tok < 0)
16140Sstevel@tonic-gate tok = fdtype(prdptr[nprod][j+offset]);
16150Sstevel@tonic-gate (void) fprintf(faction,
1616*6951Sab196087 WSFMT(".%ws"), typeset[tok]);
16170Sstevel@tonic-gate }
16180Sstevel@tonic-gate goto swt;
16190Sstevel@tonic-gate }
16200Sstevel@tonic-gate (void) putwc(L'$', faction);
16210Sstevel@tonic-gate if (s < 0)
16220Sstevel@tonic-gate (void) putwc(L'-', faction);
16230Sstevel@tonic-gate goto swt;
16240Sstevel@tonic-gate case L'}':
16250Sstevel@tonic-gate if (--brac)
16260Sstevel@tonic-gate goto lcopy;
16270Sstevel@tonic-gate (void) putwc(c, faction);
16280Sstevel@tonic-gate return;
16290Sstevel@tonic-gate case L'/': /* look for comments */
16300Sstevel@tonic-gate (void) putwc(c, faction);
16310Sstevel@tonic-gate c = getwc(finput);
16320Sstevel@tonic-gate if (c != L'*')
16330Sstevel@tonic-gate goto swt;
16340Sstevel@tonic-gate /* it really is a comment */
16350Sstevel@tonic-gate (void) putwc(c, faction);
16360Sstevel@tonic-gate c = getwc(finput);
16370Sstevel@tonic-gate while (c != EOF) {
16380Sstevel@tonic-gate while (c == L'*') {
16390Sstevel@tonic-gate (void) putwc(c, faction);
16400Sstevel@tonic-gate if ((c = getwc(finput)) == L'/')
16410Sstevel@tonic-gate goto lcopy;
16420Sstevel@tonic-gate }
16430Sstevel@tonic-gate (void) putwc(c, faction);
16440Sstevel@tonic-gate if (c == L'\n')
16450Sstevel@tonic-gate ++lineno;
16460Sstevel@tonic-gate c = getwc(finput);
16470Sstevel@tonic-gate }
16480Sstevel@tonic-gate error("EOF inside comment");
16490Sstevel@tonic-gate /* FALLTHRU */
16500Sstevel@tonic-gate case L'\'': /* character constant */
16510Sstevel@tonic-gate case L'"': /* character string */
16520Sstevel@tonic-gate match = c;
16530Sstevel@tonic-gate (void) putwc(c, faction);
16540Sstevel@tonic-gate while ((c = getwc(finput)) != EOF) {
16550Sstevel@tonic-gate if (c == L'\\') {
16560Sstevel@tonic-gate (void) putwc(c, faction);
16570Sstevel@tonic-gate c = getwc(finput);
16580Sstevel@tonic-gate if (c == L'\n')
16590Sstevel@tonic-gate ++lineno;
16600Sstevel@tonic-gate } else if (c == match)
16610Sstevel@tonic-gate goto lcopy;
16620Sstevel@tonic-gate else if (c == L'\n')
16630Sstevel@tonic-gate /*
16640Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
16650Sstevel@tonic-gate * This message is passed to error() function.
16660Sstevel@tonic-gate * This error message is issued when
16670Sstevel@tonic-gate * quoted string has multiple lines.
16680Sstevel@tonic-gate */
16690Sstevel@tonic-gate error(gettext(
16700Sstevel@tonic-gate "newline in string or char. const."));
16710Sstevel@tonic-gate (void) putwc(c, faction);
16720Sstevel@tonic-gate }
16730Sstevel@tonic-gate error(gettext(
16740Sstevel@tonic-gate "EOF in string or character constant"));
16750Sstevel@tonic-gate /* FALLTHRU */
16760Sstevel@tonic-gate case EOF:
16770Sstevel@tonic-gate /*
16780Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
16790Sstevel@tonic-gate * This message is passed to error() function.
16800Sstevel@tonic-gate * Check how 'action' is translated in yacc mapage/document.
16810Sstevel@tonic-gate */
16820Sstevel@tonic-gate error(gettext(
16830Sstevel@tonic-gate "action does not terminate"));
16840Sstevel@tonic-gate /* FALLTHRU */
16850Sstevel@tonic-gate case L'\n':
16860Sstevel@tonic-gate ++lineno;
16870Sstevel@tonic-gate goto lcopy;
16880Sstevel@tonic-gate }
16890Sstevel@tonic-gate lcopy:
16900Sstevel@tonic-gate (void) putwc(c, faction);
16910Sstevel@tonic-gate /*
16920Sstevel@tonic-gate * Save the possible identifier name.
16930Sstevel@tonic-gate * Used to print out a warning message.
16940Sstevel@tonic-gate */
16950Sstevel@tonic-gate if (id_idx >= NAMESIZE) {
16960Sstevel@tonic-gate /*
16970Sstevel@tonic-gate * Error. Silently ignore.
16980Sstevel@tonic-gate */
1699100Smike_s /* EMPTY */;
17000Sstevel@tonic-gate }
17010Sstevel@tonic-gate /*
17020Sstevel@tonic-gate * If c has a possibility to be a
17030Sstevel@tonic-gate * part of identifier, save it.
17040Sstevel@tonic-gate */
17050Sstevel@tonic-gate else if (iswalnum(c) || c == L'_') {
17060Sstevel@tonic-gate id_name[id_idx++] = c;
17070Sstevel@tonic-gate id_name[id_idx] = 0;
17080Sstevel@tonic-gate } else {
17090Sstevel@tonic-gate id_idx = 0;
17100Sstevel@tonic-gate id_name[id_idx] = 0;
17110Sstevel@tonic-gate }
17120Sstevel@tonic-gate goto loop;
17130Sstevel@tonic-gate }
17140Sstevel@tonic-gate
17150Sstevel@tonic-gate static void
lhsfill(s)17160Sstevel@tonic-gate lhsfill(s) /* new rule, dump old (if exists), restart strings */
17170Sstevel@tonic-gate wchar_t *s;
17180Sstevel@tonic-gate {
17190Sstevel@tonic-gate static int lhs_len = LHS_TEXT_LEN;
17200Sstevel@tonic-gate int s_lhs = wslen(s);
17210Sstevel@tonic-gate if (s_lhs >= lhs_len) {
17220Sstevel@tonic-gate lhs_len = s_lhs + 2;
17230Sstevel@tonic-gate lhstext = (wchar_t *)
17240Sstevel@tonic-gate realloc((char *)lhstext, sizeof (wchar_t)*lhs_len);
17250Sstevel@tonic-gate if (lhstext == NULL)
17260Sstevel@tonic-gate /*
17270Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
17280Sstevel@tonic-gate * This message is passed to error() function.
17290Sstevel@tonic-gate * LHS -- Left Hand Side.
17300Sstevel@tonic-gate */
17310Sstevel@tonic-gate error(gettext(
17320Sstevel@tonic-gate "couldn't expanded LHS length"));
17330Sstevel@tonic-gate }
17340Sstevel@tonic-gate rhsfill((wchar_t *)0);
17350Sstevel@tonic-gate (void) wscpy(lhstext, s); /* don't worry about too long of a name */
17360Sstevel@tonic-gate }
17370Sstevel@tonic-gate
17380Sstevel@tonic-gate static void
rhsfill(s)17390Sstevel@tonic-gate rhsfill(s)
17400Sstevel@tonic-gate wchar_t *s; /* either name or 0 */
17410Sstevel@tonic-gate {
17420Sstevel@tonic-gate static wchar_t *loc; /* next free location in rhstext */
17430Sstevel@tonic-gate static int rhs_len = RHS_TEXT_LEN;
17440Sstevel@tonic-gate static int used = 0;
17450Sstevel@tonic-gate int s_rhs = (s == NULL ? 0 : wslen(s));
17460Sstevel@tonic-gate register wchar_t *p;
17470Sstevel@tonic-gate
17480Sstevel@tonic-gate if (!s) /* print out and erase old text */
17490Sstevel@tonic-gate {
17500Sstevel@tonic-gate if (*lhstext) /* there was an old rule - dump it */
17510Sstevel@tonic-gate lrprnt();
17520Sstevel@tonic-gate (loc = rhstext)[0] = 0;
17530Sstevel@tonic-gate return;
17540Sstevel@tonic-gate }
17550Sstevel@tonic-gate /* add to stuff in rhstext */
17560Sstevel@tonic-gate p = s;
17570Sstevel@tonic-gate
17580Sstevel@tonic-gate used = loc - rhstext;
17590Sstevel@tonic-gate if ((s_rhs + 3) >= (rhs_len - used)) {
17600Sstevel@tonic-gate static wchar_t *textbase;
17610Sstevel@tonic-gate textbase = rhstext;
17620Sstevel@tonic-gate rhs_len += s_rhs + RHS_TEXT_LEN;
17630Sstevel@tonic-gate rhstext = (wchar_t *)
17640Sstevel@tonic-gate realloc((char *)rhstext, sizeof (wchar_t)*rhs_len);
17650Sstevel@tonic-gate if (rhstext == NULL)
17660Sstevel@tonic-gate /*
17670Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
17680Sstevel@tonic-gate * This message is passed to error() function.
17690Sstevel@tonic-gate * RHS -- Right Hand Side.
17700Sstevel@tonic-gate */
17710Sstevel@tonic-gate error(gettext(
17720Sstevel@tonic-gate "couldn't expanded RHS length"));
17730Sstevel@tonic-gate loc = loc - textbase + rhstext;
17740Sstevel@tonic-gate }
17750Sstevel@tonic-gate
17760Sstevel@tonic-gate *loc++ = L' ';
17770Sstevel@tonic-gate if (*s == L' ') /* special quoted symbol */
17780Sstevel@tonic-gate {
17790Sstevel@tonic-gate *loc++ = L'\''; /* add first quote */
17800Sstevel@tonic-gate p++;
17810Sstevel@tonic-gate }
17820Sstevel@tonic-gate while (*loc = *p++)
17830Sstevel@tonic-gate if (loc++ > &rhstext[ RHS_TEXT_LEN ] - 3)
17840Sstevel@tonic-gate break;
17850Sstevel@tonic-gate
17860Sstevel@tonic-gate if (*s == L' ')
17870Sstevel@tonic-gate *loc++ = L'\'';
17880Sstevel@tonic-gate *loc = 0; /* terminate the string */
17890Sstevel@tonic-gate }
17900Sstevel@tonic-gate
17910Sstevel@tonic-gate static void
lrprnt()17920Sstevel@tonic-gate lrprnt() /* print out the left and right hand sides */
17930Sstevel@tonic-gate {
17940Sstevel@tonic-gate wchar_t *rhs;
17950Sstevel@tonic-gate wchar_t *m_rhs = NULL;
17960Sstevel@tonic-gate
17970Sstevel@tonic-gate if (!*rhstext) /* empty rhs - print usual comment */
17980Sstevel@tonic-gate rhs = L" /* empty */";
17990Sstevel@tonic-gate else {
18000Sstevel@tonic-gate int idx1; /* tmp idx used to find if there are d_quotes */
18010Sstevel@tonic-gate int idx2; /* tmp idx used to generate escaped string */
18020Sstevel@tonic-gate wchar_t *p;
18030Sstevel@tonic-gate /*
18040Sstevel@tonic-gate * Check if there are any double quote in RHS.
18050Sstevel@tonic-gate */
18060Sstevel@tonic-gate for (idx1 = 0; rhstext[idx1] != 0; idx1++) {
18070Sstevel@tonic-gate if (rhstext[idx1] == L'"') {
18080Sstevel@tonic-gate /*
18090Sstevel@tonic-gate * A double quote is found.
18100Sstevel@tonic-gate */
18110Sstevel@tonic-gate idx2 = wslen(rhstext)*2;
18120Sstevel@tonic-gate p = m_rhs = (wchar_t *)
18134538Sdamico malloc((idx2 + 1)*sizeof (wchar_t));
18140Sstevel@tonic-gate if (m_rhs == NULL)
18150Sstevel@tonic-gate /*
18160Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
18170Sstevel@tonic-gate * This message is passed to error() function.
18180Sstevel@tonic-gate * RHS - Right Hand Side.
18190Sstevel@tonic-gate *
18200Sstevel@tonic-gate * You may just translate this as:
18210Sstevel@tonic-gate * 'Could not allocate internally used memory.'
18220Sstevel@tonic-gate */
18230Sstevel@tonic-gate error(gettext(
18240Sstevel@tonic-gate "Couldn't allocate memory for RHS."));
18250Sstevel@tonic-gate /*
18260Sstevel@tonic-gate * Copy string
18270Sstevel@tonic-gate */
18280Sstevel@tonic-gate for (idx2 = 0; rhstext[idx2] != 0; idx2++) {
18290Sstevel@tonic-gate /*
18300Sstevel@tonic-gate * Check if this quote is escaped or not
18310Sstevel@tonic-gate */
18320Sstevel@tonic-gate if (rhstext[idx2] == L'"') {
18330Sstevel@tonic-gate int tmp_l = idx2-1;
18340Sstevel@tonic-gate int cnt = 0;
18350Sstevel@tonic-gate while (tmp_l >= 0 &&
18364538Sdamico rhstext[tmp_l] == '\\') {
18370Sstevel@tonic-gate cnt++;
18380Sstevel@tonic-gate tmp_l--;
18390Sstevel@tonic-gate }
18400Sstevel@tonic-gate /*
18410Sstevel@tonic-gate * If quote is not escaped,
18420Sstevel@tonic-gate * then escape it.
18430Sstevel@tonic-gate */
18440Sstevel@tonic-gate if (cnt%2 == 0)
18450Sstevel@tonic-gate *p++ = L'\\';
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate *p++ = rhstext[idx2];
18480Sstevel@tonic-gate }
18490Sstevel@tonic-gate *p = 0;
18500Sstevel@tonic-gate /*
18510Sstevel@tonic-gate * Break from the loop
18520Sstevel@tonic-gate */
18530Sstevel@tonic-gate break;
18540Sstevel@tonic-gate }
18550Sstevel@tonic-gate }
18560Sstevel@tonic-gate if (m_rhs == NULL)
18570Sstevel@tonic-gate rhs = rhstext;
18580Sstevel@tonic-gate else
18590Sstevel@tonic-gate rhs = m_rhs;
18600Sstevel@tonic-gate }
1861*6951Sab196087 (void) fprintf(fdebug, WSFMT("\t\"%ws :%ws\",\n"), lhstext, rhs);
18620Sstevel@tonic-gate if (m_rhs)
18630Sstevel@tonic-gate free(m_rhs);
18640Sstevel@tonic-gate }
18650Sstevel@tonic-gate
18660Sstevel@tonic-gate
18670Sstevel@tonic-gate static void
beg_debug()18680Sstevel@tonic-gate beg_debug() /* dump initial sequence for fdebug file */
18690Sstevel@tonic-gate {
18700Sstevel@tonic-gate (void) fprintf(fdebug,
18714538Sdamico "typedef struct\n");
18720Sstevel@tonic-gate (void) fprintf(fdebug,
18734538Sdamico "#ifdef __cplusplus\n\tyytoktype\n");
18740Sstevel@tonic-gate (void) fprintf(fdebug, "#endif\n{\n");
18750Sstevel@tonic-gate (void) fprintf(fdebug,
18764538Sdamico "#ifdef __cplusplus\nconst\n#endif\n");
18770Sstevel@tonic-gate (void) fprintf(fdebug, "char *t_name; int t_val; } yytoktype;\n");
18780Sstevel@tonic-gate (void) fprintf(fdebug,
18794538Sdamico "#ifndef YYDEBUG\n#\tdefine YYDEBUG\t%d", gen_testing);
18800Sstevel@tonic-gate (void) fprintf(fdebug, "\t/*%sallow debugging */\n#endif\n\n",
18814538Sdamico gen_testing ? " " : " don't ");
18820Sstevel@tonic-gate (void) fprintf(fdebug, "#if YYDEBUG\n\nyytoktype yytoks[] =\n{\n");
18830Sstevel@tonic-gate }
18840Sstevel@tonic-gate
18850Sstevel@tonic-gate
18860Sstevel@tonic-gate static void
end_toks()18870Sstevel@tonic-gate end_toks() /* finish yytoks array, get ready for yyred's strings */
18880Sstevel@tonic-gate {
18890Sstevel@tonic-gate (void) fprintf(fdebug, "\t\"-unknown-\",\t-1\t/* ends search */\n");
18900Sstevel@tonic-gate (void) fprintf(fdebug, "};\n\n");
18910Sstevel@tonic-gate (void) fprintf(fdebug,
18924538Sdamico "#ifdef __cplusplus\nconst\n#endif\n");
18930Sstevel@tonic-gate (void) fprintf(fdebug, "char * yyreds[] =\n{\n");
18940Sstevel@tonic-gate (void) fprintf(fdebug, "\t\"-no such reduction-\",\n");
18950Sstevel@tonic-gate }
18960Sstevel@tonic-gate
18970Sstevel@tonic-gate
18980Sstevel@tonic-gate static void
end_debug()18990Sstevel@tonic-gate end_debug() /* finish yyred array, close file */
19000Sstevel@tonic-gate {
19010Sstevel@tonic-gate lrprnt(); /* dump last lhs, rhs */
19020Sstevel@tonic-gate (void) fprintf(fdebug, "};\n#endif /* YYDEBUG */\n");
19030Sstevel@tonic-gate (void) fclose(fdebug);
19040Sstevel@tonic-gate }
19050Sstevel@tonic-gate
19060Sstevel@tonic-gate
19070Sstevel@tonic-gate /*
19080Sstevel@tonic-gate * 2/29/88 -
19090Sstevel@tonic-gate * The normal length for token sizes is NAMESIZE - If a token is
19100Sstevel@tonic-gate * seen that has a longer length, expand "tokname" by NAMESIZE.
19110Sstevel@tonic-gate */
19120Sstevel@tonic-gate static void
exp_tokname()19130Sstevel@tonic-gate exp_tokname()
19140Sstevel@tonic-gate {
19150Sstevel@tonic-gate toksize += NAMESIZE;
19160Sstevel@tonic-gate tokname = (wchar_t *)
19174538Sdamico realloc((char *)tokname, sizeof (wchar_t) * toksize);
19180Sstevel@tonic-gate }
19190Sstevel@tonic-gate
19200Sstevel@tonic-gate
19210Sstevel@tonic-gate /*
19220Sstevel@tonic-gate * 2/29/88 -
19230Sstevel@tonic-gate *
19240Sstevel@tonic-gate */
19250Sstevel@tonic-gate static void
exp_prod()19260Sstevel@tonic-gate exp_prod()
19270Sstevel@tonic-gate {
19280Sstevel@tonic-gate int i;
19290Sstevel@tonic-gate nprodsz += NPROD;
19300Sstevel@tonic-gate
19310Sstevel@tonic-gate prdptr = (int **) realloc((char *)prdptr, sizeof (int *) * (nprodsz+2));
19320Sstevel@tonic-gate levprd = (int *) realloc((char *)levprd, sizeof (int) * (nprodsz+2));
19330Sstevel@tonic-gate had_act = (wchar_t *)
19344538Sdamico realloc((char *)had_act, sizeof (wchar_t) * (nprodsz+2));
19350Sstevel@tonic-gate for (i = nprodsz-NPROD; i < nprodsz+2; ++i)
19360Sstevel@tonic-gate had_act[i] = 0;
19370Sstevel@tonic-gate
19380Sstevel@tonic-gate if ((*prdptr == NULL) || (levprd == NULL) || (had_act == NULL))
19390Sstevel@tonic-gate /*
19400Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
19410Sstevel@tonic-gate * This message is passed to error() function.
19420Sstevel@tonic-gate *
19430Sstevel@tonic-gate * You may just translate this as:
19440Sstevel@tonic-gate * 'Could not allocate internally used memory.'
19450Sstevel@tonic-gate */
19460Sstevel@tonic-gate error(gettext(
19470Sstevel@tonic-gate "couldn't expand productions"));
19480Sstevel@tonic-gate }
19490Sstevel@tonic-gate
19500Sstevel@tonic-gate /*
19510Sstevel@tonic-gate * 2/29/88 -
19520Sstevel@tonic-gate * Expand the number of terminals. Initially there are NTERMS;
19530Sstevel@tonic-gate * each time space runs out, the size is increased by NTERMS.
19540Sstevel@tonic-gate * The total size, however, cannot exceed MAXTERMS because of
19550Sstevel@tonic-gate * the way LOOKSETS(struct looksets) is set up.
19560Sstevel@tonic-gate * Tables affected:
19570Sstevel@tonic-gate * tokset, toklev : increased to ntoksz
19580Sstevel@tonic-gate *
19590Sstevel@tonic-gate * tables with initial dimensions of TEMPSIZE must be changed if
19600Sstevel@tonic-gate * (ntoksz + NNONTERM) >= TEMPSIZE : temp1[]
19610Sstevel@tonic-gate */
19620Sstevel@tonic-gate static void
exp_ntok()19630Sstevel@tonic-gate exp_ntok()
19640Sstevel@tonic-gate {
19650Sstevel@tonic-gate ntoksz += NTERMS;
19660Sstevel@tonic-gate
19670Sstevel@tonic-gate tokset = (TOKSYMB *) realloc((char *)tokset, sizeof (TOKSYMB) * ntoksz);
19680Sstevel@tonic-gate toklev = (int *) realloc((char *)toklev, sizeof (int) * ntoksz);
19690Sstevel@tonic-gate
19700Sstevel@tonic-gate if ((tokset == NULL) || (toklev == NULL))
19710Sstevel@tonic-gate /*
19720Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
19730Sstevel@tonic-gate * This message is passed to error() function.
19740Sstevel@tonic-gate * Do not translate NTERMS.
19750Sstevel@tonic-gate *
19760Sstevel@tonic-gate * You may just translate this as:
19770Sstevel@tonic-gate * 'Could not allocate internally used memory.'
19780Sstevel@tonic-gate */
19790Sstevel@tonic-gate error(gettext(
19800Sstevel@tonic-gate "couldn't expand NTERMS"));
19810Sstevel@tonic-gate }
19820Sstevel@tonic-gate
19830Sstevel@tonic-gate
19840Sstevel@tonic-gate static void
exp_nonterm()19850Sstevel@tonic-gate exp_nonterm()
19860Sstevel@tonic-gate {
19870Sstevel@tonic-gate nnontersz += NNONTERM;
19880Sstevel@tonic-gate
19890Sstevel@tonic-gate nontrst = (NTSYMB *)
19904538Sdamico realloc((char *)nontrst, sizeof (TOKSYMB) * nnontersz);
19910Sstevel@tonic-gate if (nontrst == NULL)
19920Sstevel@tonic-gate /*
19930Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
19940Sstevel@tonic-gate * This message is passed to error() function.
19950Sstevel@tonic-gate * Do not translate NTERMS.
19960Sstevel@tonic-gate *
19970Sstevel@tonic-gate * You may just translate this as:
19980Sstevel@tonic-gate * 'Could not allocate internally used memory.'
19990Sstevel@tonic-gate */
20000Sstevel@tonic-gate error(gettext(
20010Sstevel@tonic-gate "couldn't expand NNONTERM"));
20020Sstevel@tonic-gate }
20030Sstevel@tonic-gate
20040Sstevel@tonic-gate void
exp_mem(flag)20050Sstevel@tonic-gate exp_mem(flag)
20060Sstevel@tonic-gate int flag;
20070Sstevel@tonic-gate {
20080Sstevel@tonic-gate int i;
20090Sstevel@tonic-gate static int *membase;
20100Sstevel@tonic-gate new_memsize += MEMSIZE;
20110Sstevel@tonic-gate
20120Sstevel@tonic-gate membase = tracemem;
20130Sstevel@tonic-gate tracemem = (int *)
20140Sstevel@tonic-gate realloc((char *)tracemem, sizeof (int) * new_memsize);
20150Sstevel@tonic-gate if (tracemem == NULL)
20160Sstevel@tonic-gate /*
20170Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
20180Sstevel@tonic-gate * This message is passed to error() function.
20190Sstevel@tonic-gate *
20200Sstevel@tonic-gate * You may just translate this as:
20210Sstevel@tonic-gate * 'Could not allocate internally used memory.'
20220Sstevel@tonic-gate */
20230Sstevel@tonic-gate error(gettext(
20240Sstevel@tonic-gate "couldn't expand mem table"));
20250Sstevel@tonic-gate if (flag) {
20260Sstevel@tonic-gate for (i = 0; i <= nprod; ++i)
20270Sstevel@tonic-gate prdptr[i] = prdptr[i] - membase + tracemem;
20280Sstevel@tonic-gate mem = mem - membase + tracemem;
20290Sstevel@tonic-gate } else {
20300Sstevel@tonic-gate size += MEMSIZE;
20310Sstevel@tonic-gate temp1 = (int *)realloc((char *)temp1, sizeof (int)*size);
20320Sstevel@tonic-gate optimmem = optimmem - membase + tracemem;
20330Sstevel@tonic-gate }
20340Sstevel@tonic-gate }
20350Sstevel@tonic-gate
20360Sstevel@tonic-gate static int
findchtok(chlit)20370Sstevel@tonic-gate findchtok(chlit)
20380Sstevel@tonic-gate int chlit;
20390Sstevel@tonic-gate /*
20400Sstevel@tonic-gate * findchtok(chlit) returns the token number for a character literal
20410Sstevel@tonic-gate * chlit that is "bigger" than 255 -- the max char value that the
20420Sstevel@tonic-gate * original yacc was build for. This yacc treate them as though
20430Sstevel@tonic-gate * an ordinary token.
20440Sstevel@tonic-gate */
20450Sstevel@tonic-gate {
20460Sstevel@tonic-gate int i;
20470Sstevel@tonic-gate
20480Sstevel@tonic-gate if (chlit < 0xff)
20490Sstevel@tonic-gate return (chlit); /* single-byte char */
20500Sstevel@tonic-gate for (i = 0; i < nmbchars; ++i) {
20510Sstevel@tonic-gate if (mbchars->character == chlit)
20520Sstevel@tonic-gate return (mbchars->tvalue);
20530Sstevel@tonic-gate }
20540Sstevel@tonic-gate
20550Sstevel@tonic-gate /* Not found. Register it! */
20560Sstevel@tonic-gate if (++nmbchars > nmbcharsz) { /* Make sure there's enough space */
20570Sstevel@tonic-gate nmbcharsz += NMBCHARSZ;
20580Sstevel@tonic-gate mbchars = (MBCLIT *)
20590Sstevel@tonic-gate realloc((char *)mbchars, sizeof (MBCLIT)*nmbcharsz);
20600Sstevel@tonic-gate if (mbchars == NULL)
20610Sstevel@tonic-gate error(gettext(
20620Sstevel@tonic-gate "too many character literals"));
20630Sstevel@tonic-gate }
20640Sstevel@tonic-gate mbchars[nmbchars-1].character = chlit;
20650Sstevel@tonic-gate return (mbchars[nmbchars-1].tvalue = extval++);
20660Sstevel@tonic-gate /* Return the newly assigned token. */
20670Sstevel@tonic-gate }
20680Sstevel@tonic-gate
20690Sstevel@tonic-gate /*
20700Sstevel@tonic-gate * When -p is specified, symbol prefix for
20710Sstevel@tonic-gate * yy{parse, lex, error}(),
20720Sstevel@tonic-gate * yy{lval, val, char, debug, errflag, nerrs}
20730Sstevel@tonic-gate * are defined to the specified name.
20740Sstevel@tonic-gate */
20750Sstevel@tonic-gate static void
put_prefix_define(char * pre)20760Sstevel@tonic-gate put_prefix_define(char *pre)
20770Sstevel@tonic-gate {
20780Sstevel@tonic-gate char *syms[] = {
20790Sstevel@tonic-gate /* Functions */
20800Sstevel@tonic-gate "parse",
20810Sstevel@tonic-gate "lex",
20820Sstevel@tonic-gate "error",
20830Sstevel@tonic-gate /* Variables */
20840Sstevel@tonic-gate "lval",
20850Sstevel@tonic-gate "val",
20860Sstevel@tonic-gate "char",
20870Sstevel@tonic-gate "debug",
20880Sstevel@tonic-gate "errflag",
20890Sstevel@tonic-gate "nerrs",
20900Sstevel@tonic-gate NULL};
20910Sstevel@tonic-gate int i;
20920Sstevel@tonic-gate
20930Sstevel@tonic-gate for (i = 0; syms[i]; i++)
2094*6951Sab196087 (void) fprintf(ftable, "#define\tyy%s\t%s%s\n",
20954538Sdamico syms[i], pre, syms[i]);
20960Sstevel@tonic-gate }
2097