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