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
577c478bd9Sstevel@tonic-gate char *infile; /* input file name */
587c478bd9Sstevel@tonic-gate 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 */
6167298654Sdamico 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
1687c478bd9Sstevel@tonic-gate void
setup(argc,argv)1697c478bd9Sstevel@tonic-gate setup(argc, argv)
1707c478bd9Sstevel@tonic-gate int argc;
1717c478bd9Sstevel@tonic-gate char *argv[];
1727c478bd9Sstevel@tonic-gate { int ii, i, j, lev, t, ty;
1737c478bd9Sstevel@tonic-gate /* ty is the sequencial number of token name in tokset */
1747c478bd9Sstevel@tonic-gate int c;
1757c478bd9Sstevel@tonic-gate int *p;
1767c478bd9Sstevel@tonic-gate char *cp;
1777c478bd9Sstevel@tonic-gate wchar_t actname[8];
1787c478bd9Sstevel@tonic-gate unsigned int options = 0;
1797c478bd9Sstevel@tonic-gate char *file_prefix = DEFAULT_PREFIX;
1807c478bd9Sstevel@tonic-gate char *sym_prefix = "";
1817c478bd9Sstevel@tonic-gate #define F_NAME_LENGTH 128
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)+
2407c478bd9Sstevel@tonic-gate 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) {
2731dd08564Sab (void) strncpy(fname,
2747c478bd9Sstevel@tonic-gate file_prefix,
2757c478bd9Sstevel@tonic-gate F_NAME_LENGTH-strlen(".output"));
2761dd08564Sab (void) strcat(fname, ".output");
2777c478bd9Sstevel@tonic-gate foutput = fopen(fname, "w");
2787c478bd9Sstevel@tonic-gate if (foutput == NULL)
2797c478bd9Sstevel@tonic-gate error(gettext(
2807c478bd9Sstevel@tonic-gate "cannot open y.output"));
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate * Open y.tab.h if -d is specified
2857c478bd9Sstevel@tonic-gate */
2867c478bd9Sstevel@tonic-gate if (options & d_FLAG) {
2871dd08564Sab (void) strncpy(fname,
2887c478bd9Sstevel@tonic-gate file_prefix,
2897c478bd9Sstevel@tonic-gate F_NAME_LENGTH-strlen(".tab.h"));
2901dd08564Sab (void) strcat(fname, ".tab.h");
2917c478bd9Sstevel@tonic-gate fdefine = fopen(fname, "w");
2927c478bd9Sstevel@tonic-gate if (fdefine == NULL)
2937c478bd9Sstevel@tonic-gate error(gettext(
2947c478bd9Sstevel@tonic-gate "cannot open y.tab.h"));
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate fdebug = fopen(DEBUGNAME, "w");
2987c478bd9Sstevel@tonic-gate if (fdebug == NULL)
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3017c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3027c478bd9Sstevel@tonic-gate * Do not translate yacc.debug.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate error(gettext(
3057c478bd9Sstevel@tonic-gate "cannot open yacc.debug"));
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate * Open y.tab.c
3087c478bd9Sstevel@tonic-gate */
3091dd08564Sab (void) strncpy(fname,
3107c478bd9Sstevel@tonic-gate file_prefix,
3117c478bd9Sstevel@tonic-gate F_NAME_LENGTH-strlen(".tab.c"));
3121dd08564Sab (void) strcat(fname, ".tab.c");
3137c478bd9Sstevel@tonic-gate ftable = fopen(fname, "w");
3147c478bd9Sstevel@tonic-gate if (ftable == NULL)
3157c478bd9Sstevel@tonic-gate error(gettext(
3167c478bd9Sstevel@tonic-gate "cannot open %s"), fname);
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate ftemp = fopen(TEMPNAME, "w");
3197c478bd9Sstevel@tonic-gate faction = fopen(ACTNAME, "w");
3207c478bd9Sstevel@tonic-gate if (ftemp == NULL || faction == NULL)
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3237c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3247c478bd9Sstevel@tonic-gate * The message means: "Could not open a temporary file."
3257c478bd9Sstevel@tonic-gate */
3267c478bd9Sstevel@tonic-gate error(gettext(
3277c478bd9Sstevel@tonic-gate "cannot open temp file"));
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate if ((finput = fopen(infile = argv[optind], "r")) == NULL)
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3327c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3337c478bd9Sstevel@tonic-gate */
3347c478bd9Sstevel@tonic-gate error(gettext(
3357c478bd9Sstevel@tonic-gate "cannot open input file"));
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate lineno = 1;
3387c478bd9Sstevel@tonic-gate cnamp = cnames;
3397c478bd9Sstevel@tonic-gate (void) defin(0, L"$end");
3407c478bd9Sstevel@tonic-gate extval = 0400;
3417c478bd9Sstevel@tonic-gate (void) defin(0, L"error");
3427c478bd9Sstevel@tonic-gate (void) defin(1, L"$accept");
3437c478bd9Sstevel@tonic-gate mem = mem0;
3447c478bd9Sstevel@tonic-gate lev = 0;
3457c478bd9Sstevel@tonic-gate ty = 0;
3467c478bd9Sstevel@tonic-gate i = 0;
3477c478bd9Sstevel@tonic-gate beg_debug(); /* initialize fdebug file */
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate * sorry -- no yacc parser here.....
3517c478bd9Sstevel@tonic-gate * we must bootstrap somehow...
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate t = gettok();
3557c478bd9Sstevel@tonic-gate if (*v_stmp == 'y')
3567c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#ident\t\"yacc: %s %s\"\n",
3577c478bd9Sstevel@tonic-gate (const char *)SGU_PKG, (const char *)SGU_REL);
3587c478bd9Sstevel@tonic-gate for (; t != MARK && t != ENDFILE; ) {
3597c478bd9Sstevel@tonic-gate int tok_in_line;
3607c478bd9Sstevel@tonic-gate switch (t) {
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate case L';':
3637c478bd9Sstevel@tonic-gate t = gettok();
3647c478bd9Sstevel@tonic-gate break;
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate case START:
3677c478bd9Sstevel@tonic-gate if ((t = gettok()) != IDENTIFIER) {
3687c478bd9Sstevel@tonic-gate error("bad %%start construction");
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate start = chfind(1, tokname);
3717c478bd9Sstevel@tonic-gate t = gettok();
3727c478bd9Sstevel@tonic-gate continue;
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate case TYPEDEF:
3757c478bd9Sstevel@tonic-gate tok_in_line = 0;
3767c478bd9Sstevel@tonic-gate if ((t = gettok()) != TYPENAME)
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3797c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3807c478bd9Sstevel@tonic-gate * Do not translate %%type.
3817c478bd9Sstevel@tonic-gate */
3827c478bd9Sstevel@tonic-gate error(gettext(
3837c478bd9Sstevel@tonic-gate "bad syntax in %%type"));
3847c478bd9Sstevel@tonic-gate ty = numbval;
3857c478bd9Sstevel@tonic-gate for (;;) {
3867c478bd9Sstevel@tonic-gate t = gettok();
3877c478bd9Sstevel@tonic-gate switch (t) {
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate case IDENTIFIER:
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate * The following lines are idented to left.
3927c478bd9Sstevel@tonic-gate */
3937c478bd9Sstevel@tonic-gate tok_in_line = 1;
3947c478bd9Sstevel@tonic-gate if ((t = chfind(1, tokname)) < NTBASE) {
3957c478bd9Sstevel@tonic-gate j = TYPE(toklev[t]);
3967c478bd9Sstevel@tonic-gate if (j != 0 && j != ty) {
3977c478bd9Sstevel@tonic-gate /*
3987c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3997c478bd9Sstevel@tonic-gate * This message is passed to error() function.
4007c478bd9Sstevel@tonic-gate */
4017c478bd9Sstevel@tonic-gate error(gettext(
4027c478bd9Sstevel@tonic-gate "type redeclaration of token %ws"),
4037c478bd9Sstevel@tonic-gate tokset[t].name);
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate else
4067c478bd9Sstevel@tonic-gate SETTYPE(toklev[t], ty);
4077c478bd9Sstevel@tonic-gate } else {
4087c478bd9Sstevel@tonic-gate j = nontrst[t-NTBASE].tvalue;
4097c478bd9Sstevel@tonic-gate if (j != 0 && j != ty) {
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4127c478bd9Sstevel@tonic-gate * This message is passed to error() function.
4137c478bd9Sstevel@tonic-gate * Check how nonterminal is translated in translated
4147c478bd9Sstevel@tonic-gate * yacc man page or yacc user's document.
4157c478bd9Sstevel@tonic-gate */
4167c478bd9Sstevel@tonic-gate error(gettext(
4177c478bd9Sstevel@tonic-gate "type redeclaration of nonterminal %ws"),
4187c478bd9Sstevel@tonic-gate nontrst[t-NTBASE].name);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate else
4217c478bd9Sstevel@tonic-gate nontrst[t-NTBASE].tvalue = ty;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate /* FALLTHRU */
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate * End Indentation
4267c478bd9Sstevel@tonic-gate */
4277c478bd9Sstevel@tonic-gate case L',':
4287c478bd9Sstevel@tonic-gate continue;
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate case L';':
4317c478bd9Sstevel@tonic-gate t = gettok();
4327c478bd9Sstevel@tonic-gate break;
4337c478bd9Sstevel@tonic-gate default:
4347c478bd9Sstevel@tonic-gate break;
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate if (!tok_in_line)
4377c478bd9Sstevel@tonic-gate /*
4387c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4397c478bd9Sstevel@tonic-gate * This message is passed to error() function.
4407c478bd9Sstevel@tonic-gate */
4417c478bd9Sstevel@tonic-gate error(gettext(
4427c478bd9Sstevel@tonic-gate "missing tokens or illegal tokens"));
4437c478bd9Sstevel@tonic-gate break;
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate continue;
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate case UNION:
4487c478bd9Sstevel@tonic-gate /* copy the union declaration to the output */
4497c478bd9Sstevel@tonic-gate cpyunion();
4507c478bd9Sstevel@tonic-gate defunion = 1;
4517c478bd9Sstevel@tonic-gate t = gettok();
4527c478bd9Sstevel@tonic-gate continue;
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate case LEFT:
4557c478bd9Sstevel@tonic-gate case BINARY:
4567c478bd9Sstevel@tonic-gate case RIGHT:
4577c478bd9Sstevel@tonic-gate i++;
4587c478bd9Sstevel@tonic-gate /* FALLTHRU */
4597c478bd9Sstevel@tonic-gate case TERM:
4607c478bd9Sstevel@tonic-gate tok_in_line = 0;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate /* nonzero means new prec. and assoc. */
4637c478bd9Sstevel@tonic-gate lev = (t-TERM) | 04;
4647c478bd9Sstevel@tonic-gate ty = 0;
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate /* get identifiers so defined */
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate t = gettok();
4697c478bd9Sstevel@tonic-gate if (t == TYPENAME) { /* there is a type defined */
4707c478bd9Sstevel@tonic-gate ty = numbval;
4717c478bd9Sstevel@tonic-gate t = gettok();
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate for (;;) {
4757c478bd9Sstevel@tonic-gate switch (t) {
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate case L',':
4787c478bd9Sstevel@tonic-gate t = gettok();
4797c478bd9Sstevel@tonic-gate continue;
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate case L';':
4827c478bd9Sstevel@tonic-gate break;
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate case IDENTIFIER:
4857c478bd9Sstevel@tonic-gate tok_in_line = 1;
4867c478bd9Sstevel@tonic-gate j = chfind(0, tokname);
4877c478bd9Sstevel@tonic-gate if (j > NTBASE) {
4887c478bd9Sstevel@tonic-gate /*
4897c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4907c478bd9Sstevel@tonic-gate * This message is passed to error() function.
4917c478bd9Sstevel@tonic-gate */
4927c478bd9Sstevel@tonic-gate error(gettext(
4937c478bd9Sstevel@tonic-gate "%ws is not a token."),
4947c478bd9Sstevel@tonic-gate tokname);
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate if (lev & ~04) {
4977c478bd9Sstevel@tonic-gate if (ASSOC(toklev[j]) & ~04)
4987c478bd9Sstevel@tonic-gate /*
4997c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5007c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5017c478bd9Sstevel@tonic-gate */
5027c478bd9Sstevel@tonic-gate error(gettext(
5037c478bd9Sstevel@tonic-gate "redeclaration of precedence of %ws"),
5047c478bd9Sstevel@tonic-gate tokname);
5057c478bd9Sstevel@tonic-gate SETASC(toklev[j], lev);
5067c478bd9Sstevel@tonic-gate SETPLEV(toklev[j], i);
5077c478bd9Sstevel@tonic-gate } else {
5087c478bd9Sstevel@tonic-gate if (ASSOC(toklev[j]))
5097c478bd9Sstevel@tonic-gate (void) warning(1, gettext(
5107c478bd9Sstevel@tonic-gate "redeclaration of precedence of %ws."),
5117c478bd9Sstevel@tonic-gate tokname);
5127c478bd9Sstevel@tonic-gate SETASC(toklev[j], lev);
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate if (ty) {
5157c478bd9Sstevel@tonic-gate if (TYPE(toklev[j]))
5167c478bd9Sstevel@tonic-gate error(gettext(
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5197c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5207c478bd9Sstevel@tonic-gate */
5217c478bd9Sstevel@tonic-gate "redeclaration of type of %ws"),
5227c478bd9Sstevel@tonic-gate tokname);
5237c478bd9Sstevel@tonic-gate SETTYPE(toklev[j], ty);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate if ((t = gettok()) == NUMBER) {
5267c478bd9Sstevel@tonic-gate tokset[j].value = numbval;
5277c478bd9Sstevel@tonic-gate if (j < ndefout && j > 2) {
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5307c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5317c478bd9Sstevel@tonic-gate */
5327c478bd9Sstevel@tonic-gate error(gettext(
5337c478bd9Sstevel@tonic-gate "type number of %ws should be defined earlier"),
5347c478bd9Sstevel@tonic-gate tokset[j].name);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate if (numbval >= -YYFLAG1) {
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5397c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5407c478bd9Sstevel@tonic-gate */
5417c478bd9Sstevel@tonic-gate error(gettext(
5427c478bd9Sstevel@tonic-gate "token numbers must be less than %d"),
5437c478bd9Sstevel@tonic-gate -YYFLAG1);
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate t = gettok();
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate continue;
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate if (!tok_in_line)
5517c478bd9Sstevel@tonic-gate /*
5527c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5537c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5547c478bd9Sstevel@tonic-gate */
5557c478bd9Sstevel@tonic-gate error(gettext(
5567c478bd9Sstevel@tonic-gate "missing tokens or illegal tokens"));
5577c478bd9Sstevel@tonic-gate break;
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate continue;
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate case LCURLY:
5627c478bd9Sstevel@tonic-gate defout();
5637c478bd9Sstevel@tonic-gate cpycode();
5647c478bd9Sstevel@tonic-gate t = gettok();
5657c478bd9Sstevel@tonic-gate continue;
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate default:
5687c478bd9Sstevel@tonic-gate error("syntax error");
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate if (t == ENDFILE) {
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5777c478bd9Sstevel@tonic-gate * This message is passed to error() function.
5787c478bd9Sstevel@tonic-gate * Do not translate %%%%.
5797c478bd9Sstevel@tonic-gate */
5807c478bd9Sstevel@tonic-gate error("unexpected EOF before %%%%");
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate /* t is MARK */
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate defout();
5867c478bd9Sstevel@tonic-gate end_toks(); /* all tokens dumped - get ready for reductions */
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "\n#include <inttypes.h>\n");
5897c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "\n#ifdef __STDC__\n");
5907c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#include <stdlib.h>\n");
5917c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#include <string.h>\n");
5927c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#define YYCONST const\n");
5937c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#else\n");
5947c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#include <malloc.h>\n");
5957c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#include <memory.h>\n");
5967c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#define YYCONST\n");
5977c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
5987c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "\n#include <values.h>\n");
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate if (sym_prefix[0] != '\0')
6017c478bd9Sstevel@tonic-gate put_prefix_define(sym_prefix);
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
6047c478bd9Sstevel@tonic-gate "\n#if defined(__cplusplus) || defined(__STDC__)\n");
6057c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
6067c478bd9Sstevel@tonic-gate "\n#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6077c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "extern \"C\" {\n");
6087c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6097c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#ifndef yyerror\n");
6107c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#if defined(__cplusplus)\n");
6117c478bd9Sstevel@tonic-gate (void) fprintf(ftable, " void yyerror(YYCONST char *);\n");
6127c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6137c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6147c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#ifndef yylex\n");
6157c478bd9Sstevel@tonic-gate (void) fprintf(ftable, " int yylex(void);\n");
6167c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6177c478bd9Sstevel@tonic-gate (void) fprintf(ftable, " int yyparse(void);\n");
6187c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
6197c478bd9Sstevel@tonic-gate "#if defined(__cplusplus) && defined(__EXTERN_C__)\n");
6207c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "}\n");
6217c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#endif\n");
6227c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "\n#endif\n\n");
6237c478bd9Sstevel@tonic-gate
6247c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#define yyclearin yychar = -1\n");
6257c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#define yyerrok yyerrflag = 0\n");
6267c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "extern int yychar;\nextern int yyerrflag;\n");
6277c478bd9Sstevel@tonic-gate if (!(defunion || ntypes))
6287c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
6297c478bd9Sstevel@tonic-gate "#ifndef YYSTYPE\n#define YYSTYPE int\n#endif\n");
6307c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yylval;\n");
6317c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yyval;\n");
6327c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "typedef int yytabelem;\n");
6337c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
6347c478bd9Sstevel@tonic-gate "#ifndef YYMAXDEPTH\n#define YYMAXDEPTH 150\n#endif\n");
6357c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#if YYMAXDEPTH > 0\n");
6367c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "int yy_yys[YYMAXDEPTH], *yys = yy_yys;\n");
6377c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv;\n");
6387c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "#else /* user does initial allocation */\n");
6397c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "int *yys;\nYYSTYPE *yyv;\n#endif\n");
6407c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "static int yymaxdepth = YYMAXDEPTH;\n");
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate prdptr[0] = mem;
6437c478bd9Sstevel@tonic-gate /* added production */
6447c478bd9Sstevel@tonic-gate *mem++ = NTBASE;
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate /* if start is 0, we will overwrite with the lhs of the first rule */
6477c478bd9Sstevel@tonic-gate *mem++ = start;
6487c478bd9Sstevel@tonic-gate *mem++ = 1;
6497c478bd9Sstevel@tonic-gate *mem++ = 0;
6507c478bd9Sstevel@tonic-gate prdptr[1] = mem;
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate while ((t = gettok()) == LCURLY)
6537c478bd9Sstevel@tonic-gate cpycode();
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate if (t != C_IDENTIFIER)
6567c478bd9Sstevel@tonic-gate error("bad syntax on first rule");
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate if (!start)
6597c478bd9Sstevel@tonic-gate prdptr[0][1] = chfind(1, tokname);
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate /* read rules */
6627c478bd9Sstevel@tonic-gate
6637c478bd9Sstevel@tonic-gate while (t != MARK && t != ENDFILE) {
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate /* process a rule */
6667c478bd9Sstevel@tonic-gate
6677c478bd9Sstevel@tonic-gate if (t == L'|') {
6687c478bd9Sstevel@tonic-gate rhsfill((wchar_t *)0); /* restart fill of rhs */
6697c478bd9Sstevel@tonic-gate *mem = *prdptr[nprod-1];
6707c478bd9Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
6717c478bd9Sstevel@tonic-gate exp_mem(1);
6727c478bd9Sstevel@tonic-gate } else if (t == C_IDENTIFIER) {
6737c478bd9Sstevel@tonic-gate *mem = chfind(1, tokname);
6747c478bd9Sstevel@tonic-gate if (*mem < NTBASE)
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6777c478bd9Sstevel@tonic-gate * This message is passed to error() function.
6787c478bd9Sstevel@tonic-gate * Check how nonterminal is translated.
6797c478bd9Sstevel@tonic-gate */
6807c478bd9Sstevel@tonic-gate error(gettext(
6817c478bd9Sstevel@tonic-gate "illegal nonterminal in grammar rule"));
6827c478bd9Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
6837c478bd9Sstevel@tonic-gate exp_mem(1);
6847c478bd9Sstevel@tonic-gate lhsfill(tokname); /* new rule: restart strings */
6857c478bd9Sstevel@tonic-gate } else
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6887c478bd9Sstevel@tonic-gate * This message is passed to error() function.
6897c478bd9Sstevel@tonic-gate */
6907c478bd9Sstevel@tonic-gate error(gettext(
6917c478bd9Sstevel@tonic-gate "illegal rule: missing semicolon or | ?"));
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate /* read rule body */
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate t = gettok();
6977c478bd9Sstevel@tonic-gate more_rule:
6987c478bd9Sstevel@tonic-gate while (t == IDENTIFIER) {
6997c478bd9Sstevel@tonic-gate *mem = chfind(1, tokname);
7007c478bd9Sstevel@tonic-gate if (*mem < NTBASE)
7017c478bd9Sstevel@tonic-gate levprd[nprod] = toklev[*mem]& ~04;
7027c478bd9Sstevel@tonic-gate if (++mem >= &tracemem[new_memsize])
7037c478bd9Sstevel@tonic-gate exp_mem(1);
7047c478bd9Sstevel@tonic-gate rhsfill(tokname); /* add to rhs string */
7057c478bd9Sstevel@tonic-gate t = gettok();
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate if (t == PREC) {
7097c478bd9Sstevel@tonic-gate if (gettok() != IDENTIFIER)
7107c478bd9Sstevel@tonic-gate /*
7117c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
7127c478bd9Sstevel@tonic-gate * This message is passed to error() function.
7137c478bd9Sstevel@tonic-gate * Do not translate %%prec.
7147c478bd9Sstevel@tonic-gate */
7157c478bd9Sstevel@tonic-gate error(gettext(
7167c478bd9Sstevel@tonic-gate "illegal %%prec syntax"));
7177c478bd9Sstevel@tonic-gate j = chfind(2, tokname);
7187c478bd9Sstevel@tonic-gate if (j >= NTBASE)
7197c478bd9Sstevel@tonic-gate /*
7207c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
7217c478bd9Sstevel@tonic-gate * This message is passed to error() function.
7227c478bd9Sstevel@tonic-gate * Do not translate %%prec.
7237c478bd9Sstevel@tonic-gate */
7247c478bd9Sstevel@tonic-gate error(gettext(
7257c478bd9Sstevel@tonic-gate "nonterminal %ws illegal after %%prec"),
7267c478bd9Sstevel@tonic-gate nontrst[j-NTBASE].name);
7277c478bd9Sstevel@tonic-gate levprd[nprod] = toklev[j] & ~04;
7287c478bd9Sstevel@tonic-gate t = gettok();
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate if (t == L'=') {
7327c478bd9Sstevel@tonic-gate had_act[nprod] = 1;
7337c478bd9Sstevel@tonic-gate levprd[nprod] |= ACTFLAG;
7347c478bd9Sstevel@tonic-gate (void) fprintf(faction, "\ncase %d:", nprod);
7357c478bd9Sstevel@tonic-gate cpyact(mem-prdptr[nprod] - 1);
7367c478bd9Sstevel@tonic-gate (void) fprintf(faction, " break;");
7377c478bd9Sstevel@tonic-gate if ((t = gettok()) == IDENTIFIER) {
7387c478bd9Sstevel@tonic-gate /* action within rule... */
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate lrprnt(); /* dump lhs, rhs */
7417c478bd9Sstevel@tonic-gate (void) wsprintf(actname, "$$%d", nprod);
7427c478bd9Sstevel@tonic-gate /*
7437c478bd9Sstevel@tonic-gate * make it nonterminal
7447c478bd9Sstevel@tonic-gate */
7457c478bd9Sstevel@tonic-gate j = chfind(1, actname);
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate * the current rule will become rule
7497c478bd9Sstevel@tonic-gate * number nprod+1 move the contents down,
7507c478bd9Sstevel@tonic-gate * and make room for the null
7517c478bd9Sstevel@tonic-gate */
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate if (mem + 2 >= &tracemem[new_memsize])
7547c478bd9Sstevel@tonic-gate exp_mem(1);
7557c478bd9Sstevel@tonic-gate for (p = mem; p >= prdptr[nprod]; --p)
7567c478bd9Sstevel@tonic-gate p[2] = *p;
7577c478bd9Sstevel@tonic-gate mem += 2;
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate /* enter null production for action */
7607c478bd9Sstevel@tonic-gate
7617c478bd9Sstevel@tonic-gate p = prdptr[nprod];
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate *p++ = j;
7647c478bd9Sstevel@tonic-gate *p++ = -nprod;
7657c478bd9Sstevel@tonic-gate
7667c478bd9Sstevel@tonic-gate /* update the production information */
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
7697c478bd9Sstevel@tonic-gate levprd[nprod] = ACTFLAG;
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate if (++nprod >= nprodsz)
7727c478bd9Sstevel@tonic-gate exp_prod();
7737c478bd9Sstevel@tonic-gate prdptr[nprod] = p;
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate /*
7767c478bd9Sstevel@tonic-gate * make the action appear in
7777c478bd9Sstevel@tonic-gate * the original rule
7787c478bd9Sstevel@tonic-gate */
7797c478bd9Sstevel@tonic-gate *mem++ = j;
7807c478bd9Sstevel@tonic-gate if (mem >= &tracemem[new_memsize])
7817c478bd9Sstevel@tonic-gate exp_mem(1);
7827c478bd9Sstevel@tonic-gate /* get some more of the rule */
7837c478bd9Sstevel@tonic-gate goto more_rule;
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate while (t == L';')
7877c478bd9Sstevel@tonic-gate t = gettok();
7887c478bd9Sstevel@tonic-gate *mem++ = -nprod;
7897c478bd9Sstevel@tonic-gate if (mem >= &tracemem[new_memsize])
7907c478bd9Sstevel@tonic-gate exp_mem(1);
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate /* check that default action is reasonable */
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate if (ntypes && !(levprd[nprod] & ACTFLAG) &&
7957c478bd9Sstevel@tonic-gate nontrst[*prdptr[nprod]-NTBASE].tvalue) {
7967c478bd9Sstevel@tonic-gate /* no explicit action, LHS has value */
797e29394bdSmike_s int tempty;
7987c478bd9Sstevel@tonic-gate tempty = prdptr[nprod][1];
7997c478bd9Sstevel@tonic-gate if (tempty < 0)
8007c478bd9Sstevel@tonic-gate /*
8017c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8027c478bd9Sstevel@tonic-gate * This message is passed to error() function.
8037c478bd9Sstevel@tonic-gate * LHS means Left Hand Side. It does not need to be translated.
8047c478bd9Sstevel@tonic-gate */
8057c478bd9Sstevel@tonic-gate error(gettext(
8067c478bd9Sstevel@tonic-gate "must return a value, since LHS has a type"));
8077c478bd9Sstevel@tonic-gate else if (tempty >= NTBASE)
8087c478bd9Sstevel@tonic-gate tempty = nontrst[tempty-NTBASE].tvalue;
8097c478bd9Sstevel@tonic-gate else
8107c478bd9Sstevel@tonic-gate tempty = TYPE(toklev[tempty]);
8117c478bd9Sstevel@tonic-gate if (tempty != nontrst[*prdptr[nprod]-NTBASE].tvalue) {
8127c478bd9Sstevel@tonic-gate /*
8137c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8147c478bd9Sstevel@tonic-gate * This message is passed to error() function.
8157c478bd9Sstevel@tonic-gate * Check how action is transltated in yacc man page or documents.
8167c478bd9Sstevel@tonic-gate */
8177c478bd9Sstevel@tonic-gate error(gettext(
8187c478bd9Sstevel@tonic-gate "default action causes potential type clash"));
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate if (++nprod >= nprodsz)
8237c478bd9Sstevel@tonic-gate exp_prod();
8247c478bd9Sstevel@tonic-gate prdptr[nprod] = mem;
8257c478bd9Sstevel@tonic-gate levprd[nprod] = 0;
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate /* end of all rules */
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate end_debug(); /* finish fdebug file's input */
8307c478bd9Sstevel@tonic-gate finact();
8317c478bd9Sstevel@tonic-gate if (t == MARK) {
8327c478bd9Sstevel@tonic-gate if (gen_lines)
8337c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "\n# line %d \"%s\"\n",
8347c478bd9Sstevel@tonic-gate lineno, infile);
8357c478bd9Sstevel@tonic-gate while ((c = getwc(finput)) != EOF)
8367c478bd9Sstevel@tonic-gate (void) putwc(c, ftable);
8377c478bd9Sstevel@tonic-gate }
8387c478bd9Sstevel@tonic-gate (void) fclose(finput);
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate static void
finact()8427c478bd9Sstevel@tonic-gate finact()
8437c478bd9Sstevel@tonic-gate {
8447c478bd9Sstevel@tonic-gate /* finish action routine */
8457c478bd9Sstevel@tonic-gate (void) fclose(faction);
8467c478bd9Sstevel@tonic-gate (void) fprintf(ftable, "# define YYERRCODE %d\n", tokset[2].value);
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate static wchar_t *
cstash(s)8507c478bd9Sstevel@tonic-gate cstash(s)
8517c478bd9Sstevel@tonic-gate register wchar_t *s;
8527c478bd9Sstevel@tonic-gate {
8537c478bd9Sstevel@tonic-gate wchar_t *temp;
8547c478bd9Sstevel@tonic-gate static int used = 0;
8557c478bd9Sstevel@tonic-gate static int used_save = 0;
8567c478bd9Sstevel@tonic-gate static int exp_cname = CNAMSZ;
8577c478bd9Sstevel@tonic-gate int len = wslen(s);
8587c478bd9Sstevel@tonic-gate
8597c478bd9Sstevel@tonic-gate /*
8607c478bd9Sstevel@tonic-gate * 2/29/88 -
8617c478bd9Sstevel@tonic-gate * Don't need to expand the table, just allocate new space.
8627c478bd9Sstevel@tonic-gate */
8637c478bd9Sstevel@tonic-gate used_save = used;
8647c478bd9Sstevel@tonic-gate while (len >= (exp_cname - used_save)) {
8657c478bd9Sstevel@tonic-gate exp_cname += CNAMSZ;
8667c478bd9Sstevel@tonic-gate if (!used)
8677c478bd9Sstevel@tonic-gate free((char *)cnames);
8687c478bd9Sstevel@tonic-gate if ((cnames = (wchar_t *)
8697c478bd9Sstevel@tonic-gate malloc(sizeof (wchar_t)*exp_cname)) == NULL)
8707c478bd9Sstevel@tonic-gate /*
8717c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8727c478bd9Sstevel@tonic-gate * This message is passed to error() function.
8737c478bd9Sstevel@tonic-gate *
8747c478bd9Sstevel@tonic-gate * You may just translate this as:
8757c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
8767c478bd9Sstevel@tonic-gate */
8777c478bd9Sstevel@tonic-gate error(gettext(
8787c478bd9Sstevel@tonic-gate "cannot expand string dump"));
8797c478bd9Sstevel@tonic-gate cnamp = cnames;
8807c478bd9Sstevel@tonic-gate used = 0;
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate temp = cnamp;
8847c478bd9Sstevel@tonic-gate do {
8857c478bd9Sstevel@tonic-gate *cnamp++ = *s;
8867c478bd9Sstevel@tonic-gate } while (*s++);
8877c478bd9Sstevel@tonic-gate used += cnamp - temp;
8887c478bd9Sstevel@tonic-gate return (temp);
8897c478bd9Sstevel@tonic-gate }
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate static int
defin(int t,wchar_t * s)892e29394bdSmike_s defin(int t, wchar_t *s)
8937c478bd9Sstevel@tonic-gate {
8947c478bd9Sstevel@tonic-gate /* define s to be a terminal if t=0 or a nonterminal if t=1 */
8957c478bd9Sstevel@tonic-gate
896*7879e8a6SToomas Soome int val = 0;
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate if (t) {
8997c478bd9Sstevel@tonic-gate if (++nnonter >= nnontersz)
9007c478bd9Sstevel@tonic-gate exp_nonterm();
9017c478bd9Sstevel@tonic-gate nontrst[nnonter].name = cstash(s);
9027c478bd9Sstevel@tonic-gate return (NTBASE + nnonter);
9037c478bd9Sstevel@tonic-gate }
9047c478bd9Sstevel@tonic-gate /* must be a token */
9057c478bd9Sstevel@tonic-gate if (++ntokens >= ntoksz)
9067c478bd9Sstevel@tonic-gate exp_ntok();
9077c478bd9Sstevel@tonic-gate tokset[ntokens].name = cstash(s);
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate /* establish value for token */
9107c478bd9Sstevel@tonic-gate
9117c478bd9Sstevel@tonic-gate if (s[0] == L' ' && s[2] == 0) { /* single character literal */
9127c478bd9Sstevel@tonic-gate val = findchtok(s[1]);
9137c478bd9Sstevel@tonic-gate } else if (s[0] == L' ' && s[1] == L'\\') { /* escape sequence */
9147c478bd9Sstevel@tonic-gate if (s[3] == 0) { /* single character escape sequence */
9157c478bd9Sstevel@tonic-gate switch (s[2]) {
9167c478bd9Sstevel@tonic-gate /* character which is escaped */
9177c478bd9Sstevel@tonic-gate case L'a':
9187c478bd9Sstevel@tonic-gate (void) warning(1, gettext(
9197c478bd9Sstevel@tonic-gate /*
9207c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9217c478bd9Sstevel@tonic-gate * This message is passed to warning() function.
9227c478bd9Sstevel@tonic-gate * Do not trasnlate ANSI C, \\a.
9237c478bd9Sstevel@tonic-gate */
9247c478bd9Sstevel@tonic-gate "\\a is ANSI C \"alert\" character"));
9257c478bd9Sstevel@tonic-gate #if __STDC__ - 1 == 0
9267c478bd9Sstevel@tonic-gate val = L'\a';
9277c478bd9Sstevel@tonic-gate break;
9287c478bd9Sstevel@tonic-gate #else
9297c478bd9Sstevel@tonic-gate val = L'\007';
9307c478bd9Sstevel@tonic-gate break;
9317c478bd9Sstevel@tonic-gate #endif
9327c478bd9Sstevel@tonic-gate case L'v': val = L'\v'; break;
9337c478bd9Sstevel@tonic-gate case L'n': val = L'\n'; break;
9347c478bd9Sstevel@tonic-gate case L'r': val = L'\r'; break;
9357c478bd9Sstevel@tonic-gate case L'b': val = L'\b'; break;
9367c478bd9Sstevel@tonic-gate case L't': val = L'\t'; break;
9377c478bd9Sstevel@tonic-gate case L'f': val = L'\f'; break;
9387c478bd9Sstevel@tonic-gate case L'\'': val = L'\''; break;
9397c478bd9Sstevel@tonic-gate case L'"': val = L'"'; break;
9407c478bd9Sstevel@tonic-gate case L'?': val = L'?'; break;
9417c478bd9Sstevel@tonic-gate case L'\\': val = L'\\'; break;
9427c478bd9Sstevel@tonic-gate /*
9437c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9447c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9457c478bd9Sstevel@tonic-gate */
9467c478bd9Sstevel@tonic-gate default: error(gettext(
9477c478bd9Sstevel@tonic-gate "invalid escape"));
9487c478bd9Sstevel@tonic-gate }
9497c478bd9Sstevel@tonic-gate } else if (s[2] <= L'7' && s[2] >= L'0') { /* \nnn sequence */
9507c478bd9Sstevel@tonic-gate int i = 3;
9517c478bd9Sstevel@tonic-gate val = s[2] - L'0';
9527c478bd9Sstevel@tonic-gate while (iswdigit(s[i]) && i <= 4) {
9537c478bd9Sstevel@tonic-gate if (s[i] >= L'0' && s[i] <= L'7')
9547c478bd9Sstevel@tonic-gate val = val * 8 + s[i] - L'0';
9557c478bd9Sstevel@tonic-gate else
9567c478bd9Sstevel@tonic-gate /*
9577c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9587c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9597c478bd9Sstevel@tonic-gate */
9607c478bd9Sstevel@tonic-gate error(gettext(
9617c478bd9Sstevel@tonic-gate "illegal octal number"));
9627c478bd9Sstevel@tonic-gate i++;
9637c478bd9Sstevel@tonic-gate }
9647c478bd9Sstevel@tonic-gate if (s[i] != 0)
9657c478bd9Sstevel@tonic-gate /*
9667c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9677c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9687c478bd9Sstevel@tonic-gate * Do not translate \\nnn.
9697c478bd9Sstevel@tonic-gate */
9707c478bd9Sstevel@tonic-gate error(gettext(
9717c478bd9Sstevel@tonic-gate "illegal \\nnn construction"));
9727c478bd9Sstevel@tonic-gate if (val > 255)
9737c478bd9Sstevel@tonic-gate /*
9747c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9757c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9767c478bd9Sstevel@tonic-gate * Do not translate
9777c478bd9Sstevel@tonic-gate * \\nnn, \\xnnnnnnnn.
9787c478bd9Sstevel@tonic-gate */
9797c478bd9Sstevel@tonic-gate error(
9807c478bd9Sstevel@tonic-gate "\\nnn exceed \\377; use \\xnnnnnnnn for wchar_t value of multibyte char");
9817c478bd9Sstevel@tonic-gate if (val == 0 && i >= 4)
9827c478bd9Sstevel@tonic-gate /*
9837c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9847c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9857c478bd9Sstevel@tonic-gate * Do not translate \\000.
9867c478bd9Sstevel@tonic-gate */
9877c478bd9Sstevel@tonic-gate error(gettext(
9887c478bd9Sstevel@tonic-gate "'\\000' is illegal"));
9897c478bd9Sstevel@tonic-gate } else if (s[2] == L'x') { /* hexadecimal \xnnn sequence */
9907c478bd9Sstevel@tonic-gate int i = 3;
9917c478bd9Sstevel@tonic-gate val = 0;
9927c478bd9Sstevel@tonic-gate /*
9937c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9947c478bd9Sstevel@tonic-gate * This message is passed to warning() function.
9957c478bd9Sstevel@tonic-gate * Do not translate \\x, ANSI C.
9967c478bd9Sstevel@tonic-gate */
9977c478bd9Sstevel@tonic-gate (void) warning(1, gettext(
99867298654Sdamico "\\x is ANSI C hex escape"));
9997c478bd9Sstevel@tonic-gate if (iswxdigit(s[i]))
10007c478bd9Sstevel@tonic-gate while (iswxdigit(s[i])) {
10017c478bd9Sstevel@tonic-gate int tmpval;
10027c478bd9Sstevel@tonic-gate if (iswdigit(s[i]))
10037c478bd9Sstevel@tonic-gate tmpval = s[i] - L'0';
10047c478bd9Sstevel@tonic-gate else if (s[i] >= L'a')
10057c478bd9Sstevel@tonic-gate tmpval = s[i] - L'a' + 10;
10067c478bd9Sstevel@tonic-gate else
10077c478bd9Sstevel@tonic-gate tmpval = s[i] - L'A' + 10;
10087c478bd9Sstevel@tonic-gate val = 16 * val + tmpval;
10097c478bd9Sstevel@tonic-gate i++;
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate else
10127c478bd9Sstevel@tonic-gate error(gettext(
10137c478bd9Sstevel@tonic-gate "illegal hexadecimal number"));
10147c478bd9Sstevel@tonic-gate if (s[i] != 0)
10157c478bd9Sstevel@tonic-gate /*
10167c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10177c478bd9Sstevel@tonic-gate * This message is passed to error() function.
10187c478bd9Sstevel@tonic-gate * Do not translate \\xnn.
10197c478bd9Sstevel@tonic-gate */
10207c478bd9Sstevel@tonic-gate error(gettext(
10217c478bd9Sstevel@tonic-gate "illegal \\xnn construction"));
10227c478bd9Sstevel@tonic-gate #define LWCHAR_MAX 0x7fffffff
10237c478bd9Sstevel@tonic-gate if ((unsigned)val > LWCHAR_MAX)
10247c478bd9Sstevel@tonic-gate /*
10257c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10267c478bd9Sstevel@tonic-gate * This message is passed to error() function.
10277c478bd9Sstevel@tonic-gate * Do not translate \\xnnnnnnnn and %#x.
10287c478bd9Sstevel@tonic-gate */
102967298654Sdamico error(gettext(
103067298654Sdamico " \\xnnnnnnnn exceed %#x"),
103167298654Sdamico LWCHAR_MAX);
10327c478bd9Sstevel@tonic-gate if (val == 0)
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
10357c478bd9Sstevel@tonic-gate * This message is passed to error() function.
10367c478bd9Sstevel@tonic-gate * Do not translate \\x00.
10377c478bd9Sstevel@tonic-gate */
10387c478bd9Sstevel@tonic-gate error(gettext(
10397c478bd9Sstevel@tonic-gate "'\\x00' is illegal"));
10407c478bd9Sstevel@tonic-gate val = findchtok(val);
10417c478bd9Sstevel@tonic-gate } else
10427c478bd9Sstevel@tonic-gate error(gettext(
10437c478bd9Sstevel@tonic-gate "invalid escape"));
10447c478bd9Sstevel@tonic-gate } else {
10457c478bd9Sstevel@tonic-gate val = extval++;
10467c478bd9Sstevel@tonic-gate }
10477c478bd9Sstevel@tonic-gate tokset[ntokens].value = val;
10487c478bd9Sstevel@tonic-gate toklev[ntokens] = 0;
10497c478bd9Sstevel@tonic-gate return (ntokens);
10507c478bd9Sstevel@tonic-gate }
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate static void
defout()10537c478bd9Sstevel@tonic-gate defout()
10547c478bd9Sstevel@tonic-gate {
10557c478bd9Sstevel@tonic-gate /* write out the defines (at the end of the declaration section) */
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate register int i, c;
10587c478bd9Sstevel@tonic-gate register wchar_t *cp;
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate for (i = ndefout; i <= ntokens; ++i) {
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate cp = tokset[i].name;
10637c478bd9Sstevel@tonic-gate if (*cp == L' ') /* literals */
10647c478bd9Sstevel@tonic-gate {
10651dd08564Sab (void) fprintf(fdebug, WSFMT("\t\"%ws\",\t%d,\n"),
106667298654Sdamico tokset[i].name + 1, tokset[i].value);
10677c478bd9Sstevel@tonic-gate continue; /* was cp++ */
10687c478bd9Sstevel@tonic-gate }
10697c478bd9Sstevel@tonic-gate
10707c478bd9Sstevel@tonic-gate for (; (c = *cp) != 0; ++cp) {
10717c478bd9Sstevel@tonic-gate if (iswlower(c) || iswupper(c) ||
107267298654Sdamico iswdigit(c) || c == L'_')
107367298654Sdamico /* EMPTY */;
10747c478bd9Sstevel@tonic-gate else
10757c478bd9Sstevel@tonic-gate goto nodef;
107667298654Sdamico }
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate (void) fprintf(fdebug,
10791dd08564Sab WSFMT("\t\"%ws\",\t%d,\n"), tokset[i].name,
108067298654Sdamico tokset[i].value);
10817c478bd9Sstevel@tonic-gate (void) fprintf(ftable,
10821dd08564Sab WSFMT("# define %ws %d\n"), tokset[i].name,
108367298654Sdamico tokset[i].value);
10847c478bd9Sstevel@tonic-gate if (fdefine != NULL)
10857c478bd9Sstevel@tonic-gate (void) fprintf(fdefine,
10861dd08564Sab WSFMT("# define %ws %d\n"),
108767298654Sdamico tokset[i].name,
108867298654Sdamico tokset[i].value);
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate nodef:;
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate ndefout = ntokens+1;
10937c478bd9Sstevel@tonic-gate }
10947c478bd9Sstevel@tonic-gate
1095e29394bdSmike_s static int
gettok()10967c478bd9Sstevel@tonic-gate gettok()
10977c478bd9Sstevel@tonic-gate {
1098e29394bdSmike_s int i, base;
10997c478bd9Sstevel@tonic-gate static int peekline; /* number of '\n' seen in lookahead */
1100e29394bdSmike_s int c, match, reserve;
11017c478bd9Sstevel@tonic-gate begin:
11027c478bd9Sstevel@tonic-gate reserve = 0;
11037c478bd9Sstevel@tonic-gate lineno += peekline;
11047c478bd9Sstevel@tonic-gate peekline = 0;
11057c478bd9Sstevel@tonic-gate c = getwc(finput);
11067c478bd9Sstevel@tonic-gate /*
11077c478bd9Sstevel@tonic-gate * while (c == ' ' || c == '\n' || c == '\t' || c == '\f') {
11087c478bd9Sstevel@tonic-gate */
11097c478bd9Sstevel@tonic-gate while (iswspace(c)) {
11107c478bd9Sstevel@tonic-gate if (c == L'\n')
11117c478bd9Sstevel@tonic-gate ++lineno;
11127c478bd9Sstevel@tonic-gate c = getwc(finput);
11137c478bd9Sstevel@tonic-gate }
11147c478bd9Sstevel@tonic-gate if (c == L'/') { /* skip comment */
11157c478bd9Sstevel@tonic-gate lineno += skipcom();
11167c478bd9Sstevel@tonic-gate goto begin;
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate switch (c) {
11207c478bd9Sstevel@tonic-gate
11217c478bd9Sstevel@tonic-gate case EOF:
11227c478bd9Sstevel@tonic-gate return (ENDFILE);
11237c478bd9Sstevel@tonic-gate case L'{':
11247c478bd9Sstevel@tonic-gate (void) ungetwc(c, finput);
11257c478bd9Sstevel@tonic-gate return (L'='); /* action ... */
11267c478bd9Sstevel@tonic-gate case L'<': /* get, and look up, a type name (union member name) */
11277c478bd9Sstevel@tonic-gate i = 0;
11287c478bd9Sstevel@tonic-gate while ((c = getwc(finput)) != L'>' &&
112967298654Sdamico c != EOF && c != L'\n') {
11307c478bd9Sstevel@tonic-gate tokname[i] = c;
11317c478bd9Sstevel@tonic-gate if (++i >= toksize)
11327c478bd9Sstevel@tonic-gate exp_tokname();
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate if (c != L'>')
11357c478bd9Sstevel@tonic-gate error(gettext(
11367c478bd9Sstevel@tonic-gate "unterminated < ... > clause"));
11377c478bd9Sstevel@tonic-gate tokname[i] = 0;
11387c478bd9Sstevel@tonic-gate if (i == 0)
11397c478bd9Sstevel@tonic-gate error("missing type name in < ... > clause");
11407c478bd9Sstevel@tonic-gate for (i = 1; i <= ntypes; ++i) {
11417c478bd9Sstevel@tonic-gate if (!wscmp(typeset[i], tokname)) {
11427c478bd9Sstevel@tonic-gate numbval = i;
11437c478bd9Sstevel@tonic-gate return (TYPENAME);
11447c478bd9Sstevel@tonic-gate }
11457c478bd9Sstevel@tonic-gate }
11467c478bd9Sstevel@tonic-gate typeset[numbval = ++ntypes] = cstash(tokname);
11477c478bd9Sstevel@tonic-gate return (TYPENAME);
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gate case L'"':
11507c478bd9Sstevel@tonic-gate case L'\'':
11517c478bd9Sstevel@tonic-gate match = c;
11527c478bd9Sstevel@tonic-gate tokname[0] = L' ';
11537c478bd9Sstevel@tonic-gate i = 1;
11547c478bd9Sstevel@tonic-gate for (;;) {
11557c478bd9Sstevel@tonic-gate c = getwc(finput);
11567c478bd9Sstevel@tonic-gate if (c == L'\n' || c == EOF)
11577c478bd9Sstevel@tonic-gate error(gettext(
11587c478bd9Sstevel@tonic-gate "illegal or missing ' or \""));
11597c478bd9Sstevel@tonic-gate if (c == L'\\') {
11607c478bd9Sstevel@tonic-gate c = getwc(finput);
11617c478bd9Sstevel@tonic-gate tokname[i] = L'\\';
11627c478bd9Sstevel@tonic-gate if (++i >= toksize)
11637c478bd9Sstevel@tonic-gate exp_tokname();
11647c478bd9Sstevel@tonic-gate } else if (c == match) break;
11657c478bd9Sstevel@tonic-gate tokname[i] = c;
11667c478bd9Sstevel@tonic-gate if (++i >= toksize)
11677c478bd9Sstevel@tonic-gate exp_tokname();
11687c478bd9Sstevel@tonic-gate }
11697c478bd9Sstevel@tonic-gate break;
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate case L'%':
11727c478bd9Sstevel@tonic-gate case L'\\':
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate switch (c = getwc(finput)) {
11757c478bd9Sstevel@tonic-gate
11767c478bd9Sstevel@tonic-gate case L'0': return (TERM);
11777c478bd9Sstevel@tonic-gate case L'<': return (LEFT);
11787c478bd9Sstevel@tonic-gate case L'2': return (BINARY);
11797c478bd9Sstevel@tonic-gate case L'>': return (RIGHT);
11807c478bd9Sstevel@tonic-gate case L'%':
11817c478bd9Sstevel@tonic-gate case L'\\': return (MARK);
11827c478bd9Sstevel@tonic-gate case L'=': return (PREC);
11837c478bd9Sstevel@tonic-gate case L'{': return (LCURLY);
11847c478bd9Sstevel@tonic-gate default: reserve = 1;
11851e819975SToomas Soome }
11861e819975SToomas Soome /* FALLTHROUGH */
11877c478bd9Sstevel@tonic-gate default:
11887c478bd9Sstevel@tonic-gate
11897c478bd9Sstevel@tonic-gate if (iswdigit(c)) { /* number */
11907c478bd9Sstevel@tonic-gate numbval = c - L'0';
11917c478bd9Sstevel@tonic-gate base = (c == L'0') ? 8 : 10;
11927c478bd9Sstevel@tonic-gate for (c = getwc(finput);
119367298654Sdamico iswdigit(c);
119467298654Sdamico c = getwc(finput)) {
11957c478bd9Sstevel@tonic-gate numbval = numbval*base + c - L'0';
11967c478bd9Sstevel@tonic-gate }
11977c478bd9Sstevel@tonic-gate (void) ungetwc(c, finput);
11987c478bd9Sstevel@tonic-gate return (NUMBER);
11997c478bd9Sstevel@tonic-gate } else if (iswlower(c) || iswupper(c) ||
120067298654Sdamico c == L'_' || c == L'.' ||
120167298654Sdamico c == L'$') {
12027c478bd9Sstevel@tonic-gate i = 0;
12037c478bd9Sstevel@tonic-gate while (iswlower(c) || iswupper(c) ||
120467298654Sdamico iswdigit(c) || c == L'_' ||
120567298654Sdamico c == L'.' || c == L'$') {
12067c478bd9Sstevel@tonic-gate tokname[i] = c;
12077c478bd9Sstevel@tonic-gate if (reserve && iswupper(c))
12087c478bd9Sstevel@tonic-gate tokname[i] = towlower(c);
12097c478bd9Sstevel@tonic-gate if (++i >= toksize)
12107c478bd9Sstevel@tonic-gate exp_tokname();
12117c478bd9