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 /*
22*1dd08564Sab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
307c478bd9Sstevel@tonic-gate
31e29394bdSmike_s #include "dextern.h"
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/errno.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <locale.h>
367c478bd9Sstevel@tonic-gate #include <stdarg.h> /* For error() */
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate static void mktbls(void);
397c478bd9Sstevel@tonic-gate static void others(void);
407c478bd9Sstevel@tonic-gate static void summary(void);
417c478bd9Sstevel@tonic-gate static wchar_t *chcopy(wchar_t *, wchar_t *);
42e29394bdSmike_s static int setunion(int *, int *);
437c478bd9Sstevel@tonic-gate static void prlook(LOOKSETS *);
447c478bd9Sstevel@tonic-gate static void cpres(void);
457c478bd9Sstevel@tonic-gate static void cpfir(void);
467c478bd9Sstevel@tonic-gate static void cempty(void);
477c478bd9Sstevel@tonic-gate static void stagen(void);
487c478bd9Sstevel@tonic-gate static LOOKSETS *flset(LOOKSETS *);
497c478bd9Sstevel@tonic-gate static void exp_lkst(void);
507c478bd9Sstevel@tonic-gate static void exp_wsets(void);
517c478bd9Sstevel@tonic-gate static void exp_states(void);
527c478bd9Sstevel@tonic-gate static void exp_psmem(void);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /* lookahead computations */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate int TBITSET;
577c478bd9Sstevel@tonic-gate static int tbitset; /* size of lookahead sets */
587c478bd9Sstevel@tonic-gate LOOKSETS *lkst;
597c478bd9Sstevel@tonic-gate static int lsetsize;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate static int nlset = 0; /* next lookahead set index */
627c478bd9Sstevel@tonic-gate int nolook = 0; /* flag to suppress lookahead computations */
637c478bd9Sstevel@tonic-gate static LOOKSETS clset; /* temporary storage for lookahead computations */
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate static ITEM *psmem, *zzmemsz;
667c478bd9Sstevel@tonic-gate static int new_pstsize = PSTSIZE;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /* working set computations */
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate WSET *wsets;
717c478bd9Sstevel@tonic-gate int cwp;
727c478bd9Sstevel@tonic-gate static int wsetsz = 0; /* number of WSET items in wsets block */
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate /* state information */
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate int nstate = 0; /* number of states */
777c478bd9Sstevel@tonic-gate static int nstatesz = NSTATES; /* number of state space allocated */
787c478bd9Sstevel@tonic-gate ITEM **pstate; /* ptr to descriptions of the states */
797c478bd9Sstevel@tonic-gate int *tystate; /* contains type info about the states */
807c478bd9Sstevel@tonic-gate int *indgo; /* index to the stored goto table */
817c478bd9Sstevel@tonic-gate static int *tmp_lset;
827c478bd9Sstevel@tonic-gate static int *tstates; /* states generated by terminal gotos */
837c478bd9Sstevel@tonic-gate static int *ntstates; /* states generated by non-term gotos */
847c478bd9Sstevel@tonic-gate static int *mstates; /* chain of overflows of term/nonterm */
857c478bd9Sstevel@tonic-gate /* generation lists */
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate /* storage for the actions in the parser */
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate int *amem, *memp; /* next free action table position */
907c478bd9Sstevel@tonic-gate int new_actsize = ACTSIZE;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /* other storage areas */
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate int *temp1; /* temp storate, indexed by terms+ntokens or states */
957c478bd9Sstevel@tonic-gate int lineno = 0; /* current input line number */
967c478bd9Sstevel@tonic-gate int size;
977c478bd9Sstevel@tonic-gate static int fatfl = 1; /* if on, error is fatal */
987c478bd9Sstevel@tonic-gate static int nerrors = 0; /* number of errors */
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /* storage for information about the nonterminals */
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate static int ***pres; /* vector of pointers to productions */
1037c478bd9Sstevel@tonic-gate /* yielding each nonterminal */
1047c478bd9Sstevel@tonic-gate static LOOKSETS **pfirst; /* vector of pointers to first sets for */
1057c478bd9Sstevel@tonic-gate /* each nonterminal */
1067c478bd9Sstevel@tonic-gate static int *pempty; /* vector of nonterminals nontrivially */
1077c478bd9Sstevel@tonic-gate /* deriving e */
1087c478bd9Sstevel@tonic-gate extern int nprodsz;
1097c478bd9Sstevel@tonic-gate
110e29394bdSmike_s int
main(int argc,char * argv[])111e29394bdSmike_s main(int argc, char *argv[])
1127c478bd9Sstevel@tonic-gate {
113*1dd08564Sab196087 (void) setlocale(LC_ALL, "");
1147c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
1157c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
1167c478bd9Sstevel@tonic-gate #endif
1177c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate setup(argc, argv); /* initialize and read productions */
1207c478bd9Sstevel@tonic-gate TBITSET = NWORDS(ntoksz*LKFACTOR);
1217c478bd9Sstevel@tonic-gate tbitset = NWORDS(ntokens*LKFACTOR);
1227c478bd9Sstevel@tonic-gate mktbls();
1237c478bd9Sstevel@tonic-gate cpres(); /* make table of which productions yield a */
1247c478bd9Sstevel@tonic-gate /* given nonterminal */
1257c478bd9Sstevel@tonic-gate cempty(); /* make a table of which nonterminals can match */
1267c478bd9Sstevel@tonic-gate /* the empty string */
1277c478bd9Sstevel@tonic-gate cpfir(); /* make a table of firsts of nonterminals */
1287c478bd9Sstevel@tonic-gate stagen(); /* generate the states */
1297c478bd9Sstevel@tonic-gate output(); /* write the states and the tables */
1307c478bd9Sstevel@tonic-gate go2out();
1317c478bd9Sstevel@tonic-gate hideprod();
1327c478bd9Sstevel@tonic-gate summary();
1337c478bd9Sstevel@tonic-gate callopt();
1347c478bd9Sstevel@tonic-gate others();
135e29394bdSmike_s return (0);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate static void
mktbls()1407c478bd9Sstevel@tonic-gate mktbls()
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate int i;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate size = ntoksz + nnontersz +1;
1457c478bd9Sstevel@tonic-gate if (size < nstatesz)
1467c478bd9Sstevel@tonic-gate size = nstatesz;
1477c478bd9Sstevel@tonic-gate if (size < new_memsize)
1487c478bd9Sstevel@tonic-gate size = new_memsize;
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate amem = (int *) malloc(sizeof (int) * new_actsize);
1517c478bd9Sstevel@tonic-gate psmem = (ITEM *) malloc(sizeof (ITEM) * new_pstsize);
1527c478bd9Sstevel@tonic-gate if ((psmem == NULL) || (amem == NULL))
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
1557c478bd9Sstevel@tonic-gate * This message is passed to error() function.
1567c478bd9Sstevel@tonic-gate * This error happens when yacc could not allocate
1577c478bd9Sstevel@tonic-gate * initial memory to be used for internal tables.
1587c478bd9Sstevel@tonic-gate *
1597c478bd9Sstevel@tonic-gate * You may just translate this as:
1607c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
1617c478bd9Sstevel@tonic-gate */
1627c478bd9Sstevel@tonic-gate error(gettext(
1637c478bd9Sstevel@tonic-gate "couldn't allocate initial table"));
1647c478bd9Sstevel@tonic-gate zzmemsz = psmem;
1657c478bd9Sstevel@tonic-gate memp = amem;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * For lkst
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate #define INIT_LSIZE nnontersz*LKFACTOR
1717c478bd9Sstevel@tonic-gate tmp_lset = (int *)
1727c478bd9Sstevel@tonic-gate calloc((size_t)(TBITSET * (INIT_LSIZE+1)), sizeof (int));
1737c478bd9Sstevel@tonic-gate if (tmp_lset == NULL)
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
1767c478bd9Sstevel@tonic-gate * This message is passed to error() function.
1777c478bd9Sstevel@tonic-gate * Yacc could not allocate memory for table named lookset.
1787c478bd9Sstevel@tonic-gate * Do not translate 'lookset'.
1797c478bd9Sstevel@tonic-gate *
1807c478bd9Sstevel@tonic-gate * You may just translate this as:
1817c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
1827c478bd9Sstevel@tonic-gate */
1837c478bd9Sstevel@tonic-gate error(gettext(
1847c478bd9Sstevel@tonic-gate "could not allocate lookset array"));
1857c478bd9Sstevel@tonic-gate lkst = (LOOKSETS *) malloc(sizeof (LOOKSETS) * (INIT_LSIZE + 1));
1867c478bd9Sstevel@tonic-gate for (i = 0; i <= INIT_LSIZE; ++i)
1877c478bd9Sstevel@tonic-gate lkst[i].lset = tmp_lset + TBITSET * i;
1887c478bd9Sstevel@tonic-gate tmp_lset = NULL;
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate * For wsets
1927c478bd9Sstevel@tonic-gate */
1937c478bd9Sstevel@tonic-gate tmp_lset = (int *)
1947c478bd9Sstevel@tonic-gate calloc((size_t)(TBITSET * (nnontersz+1)), sizeof (int));
1957c478bd9Sstevel@tonic-gate if (tmp_lset == NULL)
1967c478bd9Sstevel@tonic-gate error(gettext(
1977c478bd9Sstevel@tonic-gate "could not allocate lookset array"));
1987c478bd9Sstevel@tonic-gate wsets = (WSET *) malloc(sizeof (WSET) * (nnontersz + 1));
1997c478bd9Sstevel@tonic-gate for (i = 0; i <= nnontersz; ++i)
2007c478bd9Sstevel@tonic-gate wsets[i].ws.lset = tmp_lset + TBITSET * i;
2017c478bd9Sstevel@tonic-gate tmp_lset = NULL;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate clset.lset = (int *)malloc(sizeof (int)*TBITSET);
2047c478bd9Sstevel@tonic-gate tstates = (int *)malloc(sizeof (int)*(ntoksz + 1));
2057c478bd9Sstevel@tonic-gate ntstates = (int *)malloc(sizeof (int)*(nnontersz + 1));
2067c478bd9Sstevel@tonic-gate temp1 = (int *)malloc(sizeof (int)*size);
2077c478bd9Sstevel@tonic-gate pres = (int ***)malloc(sizeof (int **)*(nnontersz + 2));
2087c478bd9Sstevel@tonic-gate pfirst = (LOOKSETS **)malloc(sizeof (LOOKSETS *)*(nnontersz + 2));
2097c478bd9Sstevel@tonic-gate pempty = (int *)malloc(sizeof (int)*(nnontersz + 1));
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate pstate = (ITEM **)malloc(sizeof (ITEM *)*(nstatesz+2));
2127c478bd9Sstevel@tonic-gate tystate = (int *)malloc(sizeof (int)*nstatesz);
2137c478bd9Sstevel@tonic-gate indgo = (int *)malloc(sizeof (int)*nstatesz);
2147c478bd9Sstevel@tonic-gate mstates = (int *)malloc(sizeof (int)*nstatesz);
2157c478bd9Sstevel@tonic-gate defact = (int *)malloc(sizeof (int)*nstatesz);
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate if ((lkst == NULL) || (wsets == NULL) || (tstates == NULL) ||
2187c478bd9Sstevel@tonic-gate (ntstates == NULL) || (temp1 == NULL) || (pres == NULL) ||
2197c478bd9Sstevel@tonic-gate (pfirst == NULL) || (pempty == NULL) || (pstate == NULL) ||
2207c478bd9Sstevel@tonic-gate (tystate == NULL) || (indgo == NULL) || (mstates == NULL) ||
2217c478bd9Sstevel@tonic-gate (defact == NULL) || (clset.lset == NULL))
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
2247c478bd9Sstevel@tonic-gate * This message is passed to error() function.
2257c478bd9Sstevel@tonic-gate * Do not translate mktbls(). It is a function name.
2267c478bd9Sstevel@tonic-gate *
2277c478bd9Sstevel@tonic-gate * You may just translate this as:
2287c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
2297c478bd9Sstevel@tonic-gate */
2307c478bd9Sstevel@tonic-gate error(gettext(
2317c478bd9Sstevel@tonic-gate "cannot allocate tables in mktbls()"));
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate aryfil(ntstates, nnontersz+1, 0);
2347c478bd9Sstevel@tonic-gate aryfil(tstates, ntoksz+1, 0);
2357c478bd9Sstevel@tonic-gate wsetsz = nnontersz + 1;
2367c478bd9Sstevel@tonic-gate lsetsize = INIT_LSIZE + 1;
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /* put out other arrays, copy the parsers */
2407c478bd9Sstevel@tonic-gate static void
others()2417c478bd9Sstevel@tonic-gate others()
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate extern int gen_lines;
244e29394bdSmike_s int c, i, j;
2457c478bd9Sstevel@tonic-gate int tmpline;
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate finput = fopen(parser, "r");
2487c478bd9Sstevel@tonic-gate if (finput == NULL)
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
2517c478bd9Sstevel@tonic-gate * This message is passed to error() function.
2527c478bd9Sstevel@tonic-gate * This error message is issued when yacc can not find
2537c478bd9Sstevel@tonic-gate * the parser to be copied.
2547c478bd9Sstevel@tonic-gate */
2557c478bd9Sstevel@tonic-gate error(gettext(
2567c478bd9Sstevel@tonic-gate "cannot find parser %s"),
2577c478bd9Sstevel@tonic-gate parser);
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate warray(L"yyr1", levprd, nprod);
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate aryfil(temp1, nprod, 0);
2627c478bd9Sstevel@tonic-gate /* had_act[i] is either 1 or 0 */
2637c478bd9Sstevel@tonic-gate PLOOP(1, i)
2647c478bd9Sstevel@tonic-gate temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i];
2657c478bd9Sstevel@tonic-gate warray(L"yyr2", temp1, nprod);
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate aryfil(temp1, nstate, -10000000);
2687c478bd9Sstevel@tonic-gate TLOOP(i)
2697c478bd9Sstevel@tonic-gate for (j = tstates[i]; j != 0; j = mstates[j])
2707c478bd9Sstevel@tonic-gate temp1[j] = tokset[i].value;
2717c478bd9Sstevel@tonic-gate NTLOOP(i)
2727c478bd9Sstevel@tonic-gate for (j = ntstates[i]; j != 0; j = mstates[j])
2737c478bd9Sstevel@tonic-gate temp1[j] = -i;
2747c478bd9Sstevel@tonic-gate warray(L"yychk", temp1, nstate);
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate warray(L"yydef", defact, nstate);
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if ((fdebug = fopen(DEBUGNAME, "r")) == NULL)
2797c478bd9Sstevel@tonic-gate error("cannot open yacc.debug");
2807c478bd9Sstevel@tonic-gate while ((c = getwc(fdebug)) != EOF)
2817c478bd9Sstevel@tonic-gate (void) putwc(c, ftable);
2827c478bd9Sstevel@tonic-gate (void) fclose(fdebug);
2837c478bd9Sstevel@tonic-gate ZAPFILE(DEBUGNAME);
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (gen_lines)
286*1dd08564Sab196087 (void) fprintf(ftable, "# line\t1 \"%s\"\n", parser);
2877c478bd9Sstevel@tonic-gate tmpline = 1;
2887c478bd9Sstevel@tonic-gate /* copy parser text */
2897c478bd9Sstevel@tonic-gate while ((c = getwc(finput)) != EOF) {
2907c478bd9Sstevel@tonic-gate if (c == '\n')
2917c478bd9Sstevel@tonic-gate tmpline++;
2927c478bd9Sstevel@tonic-gate if (c == L'$') {
2937c478bd9Sstevel@tonic-gate if ((c = getwc(finput)) != L'A')
2947c478bd9Sstevel@tonic-gate (void) putwc(L'$', ftable);
2957c478bd9Sstevel@tonic-gate else { /* copy actions */
2967c478bd9Sstevel@tonic-gate tmpline++;
2977c478bd9Sstevel@tonic-gate faction = fopen(ACTNAME, "r");
2987c478bd9Sstevel@tonic-gate if (faction == 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 * This error is issued when yacc can not open a
3037c478bd9Sstevel@tonic-gate * temporary file to be used. You do not need to
3047c478bd9Sstevel@tonic-gate * use the word 'tempfile'. You can translate it to
3057c478bd9Sstevel@tonic-gate * mean 'temporary file'.
3067c478bd9Sstevel@tonic-gate */
3077c478bd9Sstevel@tonic-gate error(gettext(
3087c478bd9Sstevel@tonic-gate "cannot open action tempfile"));
3097c478bd9Sstevel@tonic-gate while ((c = getwc(faction)) != EOF)
3107c478bd9Sstevel@tonic-gate (void) putwc(c, ftable);
3117c478bd9Sstevel@tonic-gate (void) fclose(faction);
3127c478bd9Sstevel@tonic-gate if (gen_lines)
313*1dd08564Sab196087 (void) fprintf(ftable,
3147c478bd9Sstevel@tonic-gate "\n# line\t%d \"%s\"",
3157c478bd9Sstevel@tonic-gate tmpline,
3167c478bd9Sstevel@tonic-gate parser);
3177c478bd9Sstevel@tonic-gate ZAPFILE(ACTNAME);
3187c478bd9Sstevel@tonic-gate c = getwc(finput);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate (void) putwc(c, ftable);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate (void) fclose(ftable);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate /* copies string q into p, returning next free char ptr */
3287c478bd9Sstevel@tonic-gate static wchar_t *
chcopy(p,q)3297c478bd9Sstevel@tonic-gate chcopy(p, q)
3307c478bd9Sstevel@tonic-gate wchar_t *p, *q;
3317c478bd9Sstevel@tonic-gate {
3327c478bd9Sstevel@tonic-gate while (*p = *q++)
3337c478bd9Sstevel@tonic-gate ++p;
3347c478bd9Sstevel@tonic-gate return (p);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate #define ISIZE 400
3387c478bd9Sstevel@tonic-gate /* creates output string for item pointed to by pp */
3397c478bd9Sstevel@tonic-gate wchar_t *
writem(pp)3407c478bd9Sstevel@tonic-gate writem(pp)
3417c478bd9Sstevel@tonic-gate int *pp;
3427c478bd9Sstevel@tonic-gate {
3437c478bd9Sstevel@tonic-gate int i, *p;
3447c478bd9Sstevel@tonic-gate static int isize = ISIZE;
3457c478bd9Sstevel@tonic-gate static wchar_t *sarr = NULL;
3467c478bd9Sstevel@tonic-gate wchar_t *q;
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate if (sarr == NULL) {
3497c478bd9Sstevel@tonic-gate sarr = (wchar_t *)malloc(sizeof (wchar_t) * isize);
3507c478bd9Sstevel@tonic-gate if (sarr == NULL)
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3537c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3547c478bd9Sstevel@tonic-gate * This error is issued when yacc could not allocate
3557c478bd9Sstevel@tonic-gate * memory for internally used array.
3567c478bd9Sstevel@tonic-gate *
3577c478bd9Sstevel@tonic-gate * You may just translate this as:
3587c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
3597c478bd9Sstevel@tonic-gate */
3607c478bd9Sstevel@tonic-gate error(gettext(
3617c478bd9Sstevel@tonic-gate "could not allocate output string array"));
3627c478bd9Sstevel@tonic-gate for (i = 0; i < isize; ++i)
3637c478bd9Sstevel@tonic-gate sarr[i] = L' ';
3647c478bd9Sstevel@tonic-gate }
365e29394bdSmike_s for (p = pp; *p > 0; ++p) /* NULL */;
3667c478bd9Sstevel@tonic-gate p = prdptr[-*p];
3677c478bd9Sstevel@tonic-gate q = chcopy(sarr, nontrst[*p-NTBASE].name);
3687c478bd9Sstevel@tonic-gate q = chcopy(q, L" : ");
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate for (;;) {
3717c478bd9Sstevel@tonic-gate *q++ = ++p == pp ? L'_' : L' ';
3727c478bd9Sstevel@tonic-gate *q = 0;
3737c478bd9Sstevel@tonic-gate if ((i = *p) <= 0)
3747c478bd9Sstevel@tonic-gate break;
3757c478bd9Sstevel@tonic-gate q = chcopy(q, symnam(i));
3767c478bd9Sstevel@tonic-gate while (q > &sarr[isize-30]) {
3777c478bd9Sstevel@tonic-gate static wchar_t *sarrbase;
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate sarrbase = sarr;
3807c478bd9Sstevel@tonic-gate isize += ISIZE;
3817c478bd9Sstevel@tonic-gate sarr = (wchar_t *)
3827c478bd9Sstevel@tonic-gate realloc((char *)sarr, sizeof (*sarr) * isize);
3837c478bd9Sstevel@tonic-gate if (sarr == NULL)
3847c478bd9Sstevel@tonic-gate /*
3857c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
3867c478bd9Sstevel@tonic-gate * This message is passed to error() function.
3877c478bd9Sstevel@tonic-gate * This error is issued when yacc could not allocate
3887c478bd9Sstevel@tonic-gate * memory for internally used array.
3897c478bd9Sstevel@tonic-gate *
3907c478bd9Sstevel@tonic-gate * You may just translate this as:
3917c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
3927c478bd9Sstevel@tonic-gate */
3937c478bd9Sstevel@tonic-gate error(gettext(
3947c478bd9Sstevel@tonic-gate "cannot expand sarr arrays"));
3957c478bd9Sstevel@tonic-gate q = q - sarrbase + sarr;
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate /* an item calling for a reduction */
4007c478bd9Sstevel@tonic-gate if ((i = *pp) < 0) {
4017c478bd9Sstevel@tonic-gate q = chcopy(q, L" (");
4027c478bd9Sstevel@tonic-gate (void) wsprintf(q, "%d)", -i);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate return (sarr);
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate /* return a pointer to the name of symbol i */
4087c478bd9Sstevel@tonic-gate wchar_t *
symnam(int i)409e29394bdSmike_s symnam(int i)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate wchar_t *cp;
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate cp = (i >= NTBASE) ? nontrst[i-NTBASE].name : tokset[i].name;
4147c478bd9Sstevel@tonic-gate if (*cp == L' ')
4157c478bd9Sstevel@tonic-gate ++cp;
4167c478bd9Sstevel@tonic-gate return (cp);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate static int zzcwp = 0;
4207c478bd9Sstevel@tonic-gate static int zzclose = 0;
4217c478bd9Sstevel@tonic-gate int zzgoent = 0;
4227c478bd9Sstevel@tonic-gate int zzgobest = 0;
4237c478bd9Sstevel@tonic-gate int zzacent = 0;
4247c478bd9Sstevel@tonic-gate int zzexcp = 0;
4257c478bd9Sstevel@tonic-gate int zzsrconf = 0;
4267c478bd9Sstevel@tonic-gate int zzrrconf = 0;
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate /* output the summary on the tty */
4297c478bd9Sstevel@tonic-gate static void
summary()4307c478bd9Sstevel@tonic-gate summary()
4317c478bd9Sstevel@tonic-gate {
4327c478bd9Sstevel@tonic-gate if (foutput != NULL) {
4337c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4347c478bd9Sstevel@tonic-gate "\n%d/%d terminals, %d/%d nonterminals\n",
4357c478bd9Sstevel@tonic-gate ntokens, ntoksz, nnonter, nnontersz);
4367c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4377c478bd9Sstevel@tonic-gate "%d/%d grammar rules, %d/%d states\n",
4387c478bd9Sstevel@tonic-gate nprod, nprodsz, nstate, nstatesz);
4397c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4407c478bd9Sstevel@tonic-gate "%d shift/reduce, %d reduce/reduce conflicts reported\n",
4417c478bd9Sstevel@tonic-gate zzsrconf, zzrrconf);
4427c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4437c478bd9Sstevel@tonic-gate "%d/%d working sets used\n", zzcwp, wsetsz);
4447c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
445e29394bdSmike_s "memory: states,etc. %" PRIdPTR
446e29394bdSmike_s "/%d, parser %" PRIdPTR "/%d\n",
447e29394bdSmike_s mem-tracemem, new_memsize,
448e29394bdSmike_s memp-amem, new_actsize);
4497c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4507c478bd9Sstevel@tonic-gate "%d/%d distinct lookahead sets\n", nlset, lsetsize);
4517c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4527c478bd9Sstevel@tonic-gate "%d extra closures\n", zzclose - 2*nstate);
4537c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4547c478bd9Sstevel@tonic-gate "%d shift entries, %d exceptions\n", zzacent, zzexcp);
4557c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4567c478bd9Sstevel@tonic-gate "%d goto entries\n", zzgoent);
4577c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
4587c478bd9Sstevel@tonic-gate "%d entries saved by goto default\n", zzgobest);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate if (zzsrconf != 0 || zzrrconf != 0) {
4617c478bd9Sstevel@tonic-gate /*
4627c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4637c478bd9Sstevel@tonic-gate * You may just leave this message un-translated.
4647c478bd9Sstevel@tonic-gate * This message only makes sense to those who knows
4657c478bd9Sstevel@tonic-gate * how yacc works, and the person should know what
4667c478bd9Sstevel@tonic-gate * this message means in English.
4677c478bd9Sstevel@tonic-gate */
4687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
4697c478bd9Sstevel@tonic-gate "\nconflicts: "));
4707c478bd9Sstevel@tonic-gate if (zzsrconf)
4717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%d shift/reduce", zzsrconf);
4727c478bd9Sstevel@tonic-gate if (zzsrconf && zzrrconf)
4737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ", ");
4747c478bd9Sstevel@tonic-gate if (zzrrconf)
4757c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%d reduce/reduce", zzrrconf);
4767c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate if (ftemp != NULL)
4807c478bd9Sstevel@tonic-gate (void) fclose(ftemp);
4817c478bd9Sstevel@tonic-gate if (fdefine != NULL)
4827c478bd9Sstevel@tonic-gate (void) fclose(fdefine);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate /* write out error comment */
486*1dd08564Sab196087 /*PRINTFLIKE1*/
4877c478bd9Sstevel@tonic-gate void
error(char * s,...)4887c478bd9Sstevel@tonic-gate error(char *s, ...)
4897c478bd9Sstevel@tonic-gate {
4907c478bd9Sstevel@tonic-gate extern char *infile;
4917c478bd9Sstevel@tonic-gate va_list ap;
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate va_start(ap, s);
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate ++nerrors;
4967c478bd9Sstevel@tonic-gate if (!lineno)
4977c478bd9Sstevel@tonic-gate /*
4987c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
4997c478bd9Sstevel@tonic-gate * This message is a prefix to the error messages
5007c478bd9Sstevel@tonic-gate * passed to error() function.
5017c478bd9Sstevel@tonic-gate */
5027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5037c478bd9Sstevel@tonic-gate "command line: fatal: "));
5047c478bd9Sstevel@tonic-gate else {
5057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\"%s\", ", infile);
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5087c478bd9Sstevel@tonic-gate * This message is a prefix to the error messages
5097c478bd9Sstevel@tonic-gate * passed to error() function.
5107c478bd9Sstevel@tonic-gate */
5117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5127c478bd9Sstevel@tonic-gate "line %d: fatal: "),
5137c478bd9Sstevel@tonic-gate lineno);
5147c478bd9Sstevel@tonic-gate }
5157c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, s, ap);
5167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
5177c478bd9Sstevel@tonic-gate va_end(ap);
5187c478bd9Sstevel@tonic-gate if (!fatfl)
5197c478bd9Sstevel@tonic-gate return;
5207c478bd9Sstevel@tonic-gate summary();
5217c478bd9Sstevel@tonic-gate exit(1);
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate * Print out a warning message.
5267c478bd9Sstevel@tonic-gate */
527*1dd08564Sab196087 /*PRINTFLIKE2*/
5287c478bd9Sstevel@tonic-gate void
warning(int flag,char * s,...)5297c478bd9Sstevel@tonic-gate warning(int flag, char *s, ...)
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate extern char *infile;
5327c478bd9Sstevel@tonic-gate va_list ap;
5337c478bd9Sstevel@tonic-gate va_start(ap, s);
5347c478bd9Sstevel@tonic-gate
5357c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\"%s\", ", infile);
5367c478bd9Sstevel@tonic-gate /*
5377c478bd9Sstevel@tonic-gate * If flag, print lineno as well.
5387c478bd9Sstevel@tonic-gate */
5397c478bd9Sstevel@tonic-gate if (flag == 0)
5407c478bd9Sstevel@tonic-gate /*
5417c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5427c478bd9Sstevel@tonic-gate * This message is a prefix to the warning messages
5437c478bd9Sstevel@tonic-gate * passed to warning() function.
5447c478bd9Sstevel@tonic-gate */
5457c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5467c478bd9Sstevel@tonic-gate "warning: "));
5477c478bd9Sstevel@tonic-gate else
5487c478bd9Sstevel@tonic-gate /*
5497c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
5507c478bd9Sstevel@tonic-gate * This message is a prefix to the warning messages
5517c478bd9Sstevel@tonic-gate * passed to warning() function.
5527c478bd9Sstevel@tonic-gate */
5537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5547c478bd9Sstevel@tonic-gate "line %d: warning: "),
5557c478bd9Sstevel@tonic-gate lineno);
5567c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, s, ap);
5577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
5587c478bd9Sstevel@tonic-gate va_end(ap);
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate /* set elements 0 through n-1 to c */
5627c478bd9Sstevel@tonic-gate void
aryfil(v,n,c)5637c478bd9Sstevel@tonic-gate aryfil(v, n, c)
5647c478bd9Sstevel@tonic-gate int *v, n, c;
5657c478bd9Sstevel@tonic-gate {
5667c478bd9Sstevel@tonic-gate int i;
5677c478bd9Sstevel@tonic-gate for (i = 0; i < n; ++i)
5687c478bd9Sstevel@tonic-gate v[i] = c;
5697c478bd9Sstevel@tonic-gate }
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate /* set a to the union of a and b */
5727c478bd9Sstevel@tonic-gate /* return 1 if b is not a subset of a, 0 otherwise */
573e29394bdSmike_s static int
setunion(a,b)5747c478bd9Sstevel@tonic-gate setunion(a, b)
575e29394bdSmike_s int *a, *b;
5767c478bd9Sstevel@tonic-gate {
577e29394bdSmike_s int i, x, sub;
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate sub = 0;
5807c478bd9Sstevel@tonic-gate SETLOOP(i) {
5817c478bd9Sstevel@tonic-gate *a = (x = *a) | *b++;
5827c478bd9Sstevel@tonic-gate if (*a++ != x)
5837c478bd9Sstevel@tonic-gate sub = 1;
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate return (sub);
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate static void
prlook(p)5897c478bd9Sstevel@tonic-gate prlook(p)
5907c478bd9Sstevel@tonic-gate LOOKSETS *p;
5917c478bd9Sstevel@tonic-gate {
592e29394bdSmike_s int j, *pp;
5937c478bd9Sstevel@tonic-gate pp = p->lset;
5947c478bd9Sstevel@tonic-gate if (pp == 0)
5957c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "\tNULL");
5967c478bd9Sstevel@tonic-gate else {
5977c478bd9Sstevel@tonic-gate (void) fprintf(foutput, " { ");
5987c478bd9Sstevel@tonic-gate TLOOP(j) {
5997c478bd9Sstevel@tonic-gate if (BIT(pp, j))
600*1dd08564Sab196087 (void) fprintf(foutput, WSFMT("%ws "),
601*1dd08564Sab196087 symnam(j));
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "}");
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate * compute an array with the beginnings of productions yielding
6097c478bd9Sstevel@tonic-gate * given nonterminals
6107c478bd9Sstevel@tonic-gate * The array pres points to these lists
6117c478bd9Sstevel@tonic-gate * the array pyield has the lists: the total size is only NPROD+1
6127c478bd9Sstevel@tonic-gate */
6137c478bd9Sstevel@tonic-gate static void
cpres()6147c478bd9Sstevel@tonic-gate cpres()
6157c478bd9Sstevel@tonic-gate {
616e29394bdSmike_s int **ptrpy;
6177c478bd9Sstevel@tonic-gate int **pyield;
618e29394bdSmike_s int c, j, i;
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate * 2/29/88 -
6227c478bd9Sstevel@tonic-gate * nprodsz is the size of the tables describing the productions.
6237c478bd9Sstevel@tonic-gate * Normally this will be NPROD unless the production tables have
6247c478bd9Sstevel@tonic-gate * been expanded, in which case the tables will be NPROD * N(where
6257c478bd9Sstevel@tonic-gate * N is the number of times the tables had to be expanded.)
6267c478bd9Sstevel@tonic-gate */
6277c478bd9Sstevel@tonic-gate if ((pyield = (int **) malloc(sizeof (int *) * nprodsz)) == NULL)
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6307c478bd9Sstevel@tonic-gate * This message is passed to error() function.
6317c478bd9Sstevel@tonic-gate * This error is issued when yacc could not allocate
6327c478bd9Sstevel@tonic-gate * memory for internally used array.
6337c478bd9Sstevel@tonic-gate *
6347c478bd9Sstevel@tonic-gate * pyield is name of an array. You should not try to translate
6357c478bd9Sstevel@tonic-gate * this word.
6367c478bd9Sstevel@tonic-gate *
6377c478bd9Sstevel@tonic-gate * You may just translate this as:
6387c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
6397c478bd9Sstevel@tonic-gate */
6407c478bd9Sstevel@tonic-gate error(gettext(
6417c478bd9Sstevel@tonic-gate "cannot allocate space for pyield array"));
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate ptrpy = pyield;
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate NTLOOP(i) {
6467c478bd9Sstevel@tonic-gate c = i+NTBASE;
6477c478bd9Sstevel@tonic-gate pres[i] = ptrpy;
6487c478bd9Sstevel@tonic-gate fatfl = 0; /* make undefined symbols nonfatal */
6497c478bd9Sstevel@tonic-gate PLOOP(0, j) {
6507c478bd9Sstevel@tonic-gate if (*prdptr[j] == c) /* linear search for all c's */
6517c478bd9Sstevel@tonic-gate *ptrpy++ = prdptr[j] + 1;
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate if (pres[i] == ptrpy) { /* c not found */
6547c478bd9Sstevel@tonic-gate /*
6557c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6567c478bd9Sstevel@tonic-gate * This message is passed to error() function.
6577c478bd9Sstevel@tonic-gate * Ask somebody who knows yacc how to translate nonterminal or
6587c478bd9Sstevel@tonic-gate * look at translated yacc document.
6597c478bd9Sstevel@tonic-gate */
6607c478bd9Sstevel@tonic-gate error(gettext(
6617c478bd9Sstevel@tonic-gate "undefined nonterminal: %ws"),
6627c478bd9Sstevel@tonic-gate nontrst[i].name);
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate pres[i] = ptrpy;
6667c478bd9Sstevel@tonic-gate fatfl = 1;
6677c478bd9Sstevel@tonic-gate if (nerrors) {
6687c478bd9Sstevel@tonic-gate summary();
6697c478bd9Sstevel@tonic-gate exit(1);
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate if (ptrpy != &pyield[nprod])
6727c478bd9Sstevel@tonic-gate /*
6737c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
6747c478bd9Sstevel@tonic-gate * This message is passed to error() function.
6757c478bd9Sstevel@tonic-gate * This is an internal error message.
6767c478bd9Sstevel@tonic-gate * Very little use to user. You may leave it
6777c478bd9Sstevel@tonic-gate * un-translated.
6787c478bd9Sstevel@tonic-gate *
6797c478bd9Sstevel@tonic-gate * pyied is name of an array. Do not translate it.
6807c478bd9Sstevel@tonic-gate */
6817c478bd9Sstevel@tonic-gate error(gettext(
6827c478bd9Sstevel@tonic-gate "internal Yacc error: pyield %d"),
6837c478bd9Sstevel@tonic-gate ptrpy-&pyield[nprod]);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate static int indebug = 0;
6877c478bd9Sstevel@tonic-gate /* compute an array with the first of nonterminals */
6887c478bd9Sstevel@tonic-gate static void
cpfir()6897c478bd9Sstevel@tonic-gate cpfir()
6907c478bd9Sstevel@tonic-gate {
691e29394bdSmike_s int *p, **s, i, **t, ch, changes;
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate zzcwp = nnonter;
6947c478bd9Sstevel@tonic-gate NTLOOP(i) {
6957c478bd9Sstevel@tonic-gate aryfil(wsets[i].ws.lset, tbitset, 0);
6967c478bd9Sstevel@tonic-gate t = pres[i+1];
6977c478bd9Sstevel@tonic-gate /* initially fill the sets */
6987c478bd9Sstevel@tonic-gate for (s = pres[i]; s < t; ++s) {
6997c478bd9Sstevel@tonic-gate /* check if ch is non-terminal */
7007c478bd9Sstevel@tonic-gate for (p = *s; (ch = *p) > 0; ++p) {
7017c478bd9Sstevel@tonic-gate if (ch < NTBASE) { /* should be token */
7027c478bd9Sstevel@tonic-gate SETBIT(wsets[i].ws.lset, ch);
7037c478bd9Sstevel@tonic-gate break;
7047c478bd9Sstevel@tonic-gate } else if (!pempty[ch-NTBASE])
7057c478bd9Sstevel@tonic-gate break;
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate }
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate /* now, reflect transitivity */
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate changes = 1;
7137c478bd9Sstevel@tonic-gate while (changes) {
7147c478bd9Sstevel@tonic-gate changes = 0;
7157c478bd9Sstevel@tonic-gate NTLOOP(i) {
7167c478bd9Sstevel@tonic-gate t = pres[i+1];
7177c478bd9Sstevel@tonic-gate for (s = pres[i]; s < t; ++s) {
7187c478bd9Sstevel@tonic-gate for (p = *s; (ch = (*p-NTBASE)) >= 0; ++p) {
7197c478bd9Sstevel@tonic-gate changes |= setunion(wsets[i].ws.lset,
7207c478bd9Sstevel@tonic-gate wsets[ch].ws.lset);
7217c478bd9Sstevel@tonic-gate if (!pempty[ch])
7227c478bd9Sstevel@tonic-gate break;
7237c478bd9Sstevel@tonic-gate }
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate }
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate NTLOOP(i)
7297c478bd9Sstevel@tonic-gate pfirst[i] = flset(&wsets[i].ws);
7307c478bd9Sstevel@tonic-gate if (!indebug)
7317c478bd9Sstevel@tonic-gate return;
7327c478bd9Sstevel@tonic-gate if ((foutput != NULL)) {
7337c478bd9Sstevel@tonic-gate NTLOOP(i) {
734*1dd08564Sab196087 (void) fprintf(foutput, WSFMT("\n%ws: "),
735*1dd08564Sab196087 nontrst[i].name);
7367c478bd9Sstevel@tonic-gate prlook(pfirst[i]);
7377c478bd9Sstevel@tonic-gate (void) fprintf(foutput, " %d\n", pempty[i]);
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate }
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate /* sorts last state,and sees if it equals earlier ones. returns state number */
7437c478bd9Sstevel@tonic-gate int
state(int c)7447c478bd9Sstevel@tonic-gate state(int c)
7457c478bd9Sstevel@tonic-gate {
7467c478bd9Sstevel@tonic-gate int size1, size2;
747e29394bdSmike_s int i;
7487c478bd9Sstevel@tonic-gate ITEM *p1, *p2, *k, *l, *q1, *q2;
7497c478bd9Sstevel@tonic-gate p1 = pstate[nstate];
7507c478bd9Sstevel@tonic-gate p2 = pstate[nstate+1];
7517c478bd9Sstevel@tonic-gate if (p1 == p2)
7527c478bd9Sstevel@tonic-gate return (0); /* null state */
7537c478bd9Sstevel@tonic-gate /* sort the items */
7547c478bd9Sstevel@tonic-gate for (k = p2 - 1; k > p1; k--) { /* make k the biggest */
7557c478bd9Sstevel@tonic-gate for (l = k-1; l >= p1; --l)
7567c478bd9Sstevel@tonic-gate if (l->pitem > k->pitem) {
7577c478bd9Sstevel@tonic-gate int *s;
7587c478bd9Sstevel@tonic-gate LOOKSETS *ss;
7597c478bd9Sstevel@tonic-gate s = k->pitem;
7607c478bd9Sstevel@tonic-gate k->pitem = l->pitem;
7617c478bd9Sstevel@tonic-gate l->pitem = s;
7627c478bd9Sstevel@tonic-gate ss = k->look;
7637c478bd9Sstevel@tonic-gate k->look = l->look;
7647c478bd9Sstevel@tonic-gate l->look = ss;
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate }
7677c478bd9Sstevel@tonic-gate size1 = p2 - p1; /* size of state */
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate for (i = (c >= NTBASE) ? ntstates[c-NTBASE] : tstates[c];
77067298654Sdamico i != 0; i = mstates[i]) {
7717c478bd9Sstevel@tonic-gate /* get ith state */
7727c478bd9Sstevel@tonic-gate q1 = pstate[i];
7737c478bd9Sstevel@tonic-gate q2 = pstate[i+1];
7747c478bd9Sstevel@tonic-gate size2 = q2 - q1;
7757c478bd9Sstevel@tonic-gate if (size1 != size2)
7767c478bd9Sstevel@tonic-gate continue;
7777c478bd9Sstevel@tonic-gate k = p1;
7787c478bd9Sstevel@tonic-gate for (l = q1; l < q2; l++) {
7797c478bd9Sstevel@tonic-gate if (l->pitem != k->pitem)
7807c478bd9Sstevel@tonic-gate break;
7817c478bd9Sstevel@tonic-gate ++k;
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate if (l != q2)
7847c478bd9Sstevel@tonic-gate continue;
7857c478bd9Sstevel@tonic-gate /* found it */
7867c478bd9Sstevel@tonic-gate pstate[nstate+1] = pstate[nstate]; /* delete last state */
7877c478bd9Sstevel@tonic-gate /* fix up lookaheads */
7887c478bd9Sstevel@tonic-gate if (nolook)
7897c478bd9Sstevel@tonic-gate return (i);
7907c478bd9Sstevel@tonic-gate for (l = q1, k = p1; l < q2; ++l, ++k) {
7917c478bd9Sstevel@tonic-gate int s;
7927c478bd9Sstevel@tonic-gate SETLOOP(s)
7937c478bd9Sstevel@tonic-gate clset.lset[s] = l->look->lset[s];
7947c478bd9Sstevel@tonic-gate if (setunion(clset.lset, k->look->lset)) {
7957c478bd9Sstevel@tonic-gate tystate[i] = MUSTDO;
7967c478bd9Sstevel@tonic-gate /* register the new set */
7977c478bd9Sstevel@tonic-gate l->look = flset(&clset);
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate return (i);
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate /* state is new */
8037c478bd9Sstevel@tonic-gate if (nolook)
8047c478bd9Sstevel@tonic-gate /*
8057c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
8067c478bd9Sstevel@tonic-gate * This message is passed to error() function.
8077c478bd9Sstevel@tonic-gate * You may leave this untranslated. Leave
8087c478bd9Sstevel@tonic-gate * state/nolook un-translated.
8097c478bd9Sstevel@tonic-gate */
8107c478bd9Sstevel@tonic-gate error(gettext(
8117c478bd9Sstevel@tonic-gate "yacc state/nolook error"));
8127c478bd9Sstevel@tonic-gate pstate[nstate+2] = p2;
8137c478bd9Sstevel@tonic-gate if (nstate+1 >= nstatesz)
8147c478bd9Sstevel@tonic-gate exp_states();
8157c478bd9Sstevel@tonic-gate if (c >= NTBASE) {
8167c478bd9Sstevel@tonic-gate mstates[nstate] = ntstates[c - NTBASE];
8177c478bd9Sstevel@tonic-gate ntstates[c - NTBASE] = nstate;
8187c478bd9Sstevel@tonic-gate } else {
8197c478bd9Sstevel@tonic-gate mstates[nstate] = tstates[c];
8207c478bd9Sstevel@tonic-gate tstates[c] = nstate;
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate tystate[nstate] = MUSTDO;
8237c478bd9Sstevel@tonic-gate return (nstate++);
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate static int pidebug = 0;
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate void
putitem(ptr,lptr)8297c478bd9Sstevel@tonic-gate putitem(ptr, lptr)
8307c478bd9Sstevel@tonic-gate int *ptr;
8317c478bd9Sstevel@tonic-gate LOOKSETS *lptr;
8327c478bd9Sstevel@tonic-gate {
8337c478bd9Sstevel@tonic-gate register ITEM *j;
8347c478bd9Sstevel@tonic-gate
8357c478bd9Sstevel@tonic-gate if (pidebug && (foutput != NULL))
8367c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
837*1dd08564Sab196087 WSFMT("putitem(%ws), state %d\n"), writem(ptr), nstate);
8387c478bd9Sstevel@tonic-gate j = pstate[nstate+1];
8397c478bd9Sstevel@tonic-gate j->pitem = ptr;
8407c478bd9Sstevel@tonic-gate if (!nolook)
8417c478bd9Sstevel@tonic-gate j->look = flset(lptr);
8427c478bd9Sstevel@tonic-gate pstate[nstate+1] = ++j;
8437c478bd9Sstevel@tonic-gate if (j > zzmemsz) {
8447c478bd9Sstevel@tonic-gate zzmemsz = j;
8457c478bd9Sstevel@tonic-gate if (zzmemsz >= &psmem[new_pstsize])
8467c478bd9Sstevel@tonic-gate exp_psmem();
8477c478bd9Sstevel@tonic-gate /* error("out of state space"); */
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate }
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate /*
8527c478bd9Sstevel@tonic-gate * mark nonterminals which derive the empty string
8537c478bd9Sstevel@tonic-gate * also, look for nonterminals which don't derive any token strings
8547c478bd9Sstevel@tonic-gate */
8557c478bd9Sstevel@tonic-gate static void
cempty()8567c478bd9Sstevel@tonic-gate cempty()
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate #define EMPTY 1
8597c478bd9Sstevel@tonic-gate #define WHOKNOWS 0
8607c478bd9Sstevel@tonic-gate #define OK 1
861e29394bdSmike_s int i, *p;
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate * first, use the array pempty to detect productions
8657c478bd9Sstevel@tonic-gate * that can never be reduced
8667c478bd9Sstevel@tonic-gate */
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate /* set pempty to WHONOWS */
8697c478bd9Sstevel@tonic-gate aryfil(pempty, nnonter+1, WHOKNOWS);
8707c478bd9Sstevel@tonic-gate
8717c478bd9Sstevel@tonic-gate /*
8727c478bd9Sstevel@tonic-gate * now, look at productions, marking nonterminals which
8737c478bd9Sstevel@tonic-gate * derive something
8747c478bd9Sstevel@tonic-gate */
8757c478bd9Sstevel@tonic-gate more:
8767c478bd9Sstevel@tonic-gate PLOOP(0, i) {
8777c478bd9Sstevel@tonic-gate if (pempty[*prdptr[i] - NTBASE])
8787c478bd9Sstevel@tonic-gate continue;
8797c478bd9Sstevel@tonic-gate for (p = prdptr[i] + 1; *p >= 0; ++p)
8807c478bd9Sstevel@tonic-gate if (*p >= NTBASE && pempty[*p-NTBASE] == WHOKNOWS)
8817c478bd9Sstevel@tonic-gate break;
8827c478bd9Sstevel@tonic-gate if (*p < 0) { /* production can be derived */
8837c478bd9Sstevel@tonic-gate pempty[*prdptr[i]-NTBASE] = OK;
8847c478bd9Sstevel@tonic-gate goto more;
8857c478bd9Sstevel@tonic-gate }
8867c478bd9Sstevel@tonic-gate }
8877c478bd9Sstevel@tonic-gate
8887c478bd9Sstevel@tonic-gate /* now, look at the nonterminals, to see if they are all OK */
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate NTLOOP(i) {
8917c478bd9Sstevel@tonic-gate /*
8927c478bd9Sstevel@tonic-gate * the added production rises or falls as the
8937c478bd9Sstevel@tonic-gate * start symbol ...
8947c478bd9Sstevel@tonic-gate */
8957c478bd9Sstevel@tonic-gate if (i == 0)
8967c478bd9Sstevel@tonic-gate continue;
8977c478bd9Sstevel@tonic-gate if (pempty[i] != OK) {
8987c478bd9Sstevel@tonic-gate fatfl = 0;
8997c478bd9Sstevel@tonic-gate /*
9007c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
9017c478bd9Sstevel@tonic-gate * This message is passed to error() function.
9027c478bd9Sstevel@tonic-gate * Ask somebody who knows yacc how to translate nonterminal or
9037c478bd9Sstevel@tonic-gate * look at translated yacc document. Check how 'derive' is
9047c478bd9Sstevel@tonic-gate * translated in these documents also.
9057c478bd9Sstevel@tonic-gate */
9067c478bd9Sstevel@tonic-gate error(gettext(
9077c478bd9Sstevel@tonic-gate "nonterminal %ws never derives any token string"),
9087c478bd9Sstevel@tonic-gate nontrst[i].name);
9097c478bd9Sstevel@tonic-gate }
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate if (nerrors) {
9137c478bd9Sstevel@tonic-gate summary();
9147c478bd9Sstevel@tonic-gate exit(1);
9157c478bd9Sstevel@tonic-gate }
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate /*
9187c478bd9Sstevel@tonic-gate * now, compute the pempty array, to see which nonterminals
9197c478bd9Sstevel@tonic-gate * derive the empty string
9207c478bd9Sstevel@tonic-gate */
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate /* set pempty to WHOKNOWS */
9237c478bd9Sstevel@tonic-gate
9247c478bd9Sstevel@tonic-gate aryfil(pempty, nnonter+1, WHOKNOWS);
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate /* loop as long as we keep finding empty nonterminals */
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate again:
9297c478bd9Sstevel@tonic-gate PLOOP(1, i) {
9307c478bd9Sstevel@tonic-gate /* not known to be empty */
9317c478bd9Sstevel@tonic-gate if (pempty[*prdptr[i]-NTBASE] == WHOKNOWS) {
9327c478bd9Sstevel@tonic-gate for (p = prdptr[i]+1;
93367298654Sdamico *p >= NTBASE && pempty[*p-NTBASE] == EMPTY; ++p)
934*1dd08564Sab196087 ;
9357c478bd9Sstevel@tonic-gate /* we have a nontrivially empty nonterminal */
9367c478bd9Sstevel@tonic-gate if (*p < 0) {
9377c478bd9Sstevel@tonic-gate pempty[*prdptr[i]-NTBASE] = EMPTY;
9387c478bd9Sstevel@tonic-gate goto again; /* got one ... try for another */
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate }
9417c478bd9Sstevel@tonic-gate }
9427c478bd9Sstevel@tonic-gate }
9437c478bd9Sstevel@tonic-gate
9447c478bd9Sstevel@tonic-gate /* generate the states */
9457c478bd9Sstevel@tonic-gate static int gsdebug = 0;
9467c478bd9Sstevel@tonic-gate static void
stagen()9477c478bd9Sstevel@tonic-gate stagen()
9487c478bd9Sstevel@tonic-gate {
9497c478bd9Sstevel@tonic-gate int i, j;
950e29394bdSmike_s int c;
9517c478bd9Sstevel@tonic-gate register WSET *p, *q;
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate /* initialize */
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate nstate = 0;
9567c478bd9Sstevel@tonic-gate
9577c478bd9Sstevel@tonic-gate pstate[0] = pstate[1] = psmem;
9587c478bd9Sstevel@tonic-gate aryfil(clset.lset, tbitset, 0);
9597c478bd9Sstevel@tonic-gate putitem(prdptr[0] + 1, &clset);
9607c478bd9Sstevel@tonic-gate tystate[0] = MUSTDO;
9617c478bd9Sstevel@tonic-gate nstate = 1;
9627c478bd9Sstevel@tonic-gate pstate[2] = pstate[1];
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate aryfil(amem, new_actsize, 0);
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate /* now, the main state generation loop */
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate more:
9697c478bd9Sstevel@tonic-gate SLOOP(i) {
9707c478bd9Sstevel@tonic-gate if (tystate[i] != MUSTDO)
9717c478bd9Sstevel@tonic-gate continue;
9727c478bd9Sstevel@tonic-gate tystate[i] = DONE;
9737c478bd9Sstevel@tonic-gate aryfil(temp1, nnonter + 1, 0);
9747c478bd9Sstevel@tonic-gate /* take state i, close it, and do gotos */
9757c478bd9Sstevel@tonic-gate closure(i);
9767c478bd9Sstevel@tonic-gate WSLOOP(wsets, p) { /* generate goto's */
9777c478bd9Sstevel@tonic-gate if (p->flag)
9787c478bd9Sstevel@tonic-gate continue;
9797c478bd9Sstevel@tonic-gate p->flag = 1;
9807c478bd9Sstevel@tonic-gate c = *(p->pitem);
9817c478bd9Sstevel@tonic-gate if (c <= 1) {
9827c478bd9Sstevel@tonic-gate if (pstate[i+1]-pstate[i] <= p-wsets)
9837c478bd9Sstevel@tonic-gate tystate[i] = MUSTLOOKAHEAD;
9847c478bd9Sstevel@tonic-gate continue;
9857c478bd9Sstevel@tonic-gate }
9867c478bd9Sstevel@tonic-gate /* do a goto on c */
9877c478bd9Sstevel@tonic-gate WSLOOP(p, q) {
9887c478bd9Sstevel@tonic-gate /* this item contributes to the goto */
9897c478bd9Sstevel@tonic-gate if (c == *(q->pitem)) {
9907c478bd9Sstevel@tonic-gate putitem(q->pitem + 1, &q->ws);
9917c478bd9Sstevel@tonic-gate q->flag = 1;
9927c478bd9Sstevel@tonic-gate }
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate if (c < NTBASE)
9957c478bd9Sstevel@tonic-gate (void) state(c); /* register new state */
9967c478bd9Sstevel@tonic-gate else temp1[c-NTBASE] = state(c);
9977c478bd9Sstevel@tonic-gate }
9987c478bd9Sstevel@tonic-gate if (gsdebug && (foutput != NULL)) {
9997c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "%d: ", i);
10007c478bd9Sstevel@tonic-gate NTLOOP(j) {
10017c478bd9Sstevel@tonic-gate if (temp1[j])
10027c478bd9Sstevel@tonic-gate (void) fprintf(foutput,
1003*1dd08564Sab196087 WSFMT("%ws %d, "), nontrst[j].name,
10047c478bd9Sstevel@tonic-gate temp1[j]);
10057c478bd9Sstevel@tonic-gate }
10067c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "\n");
10077c478bd9Sstevel@tonic-gate }
10087c478bd9Sstevel@tonic-gate indgo[i] = apack(&temp1[1], nnonter - 1) - 1;
10097c478bd9Sstevel@tonic-gate goto more; /* we have done one goto; do some more */
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate /* no more to do... stop */
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate /* generate the closure of state i */
10157c478bd9Sstevel@tonic-gate static int cldebug = 0; /* debugging flag for closure */
1016e29394bdSmike_s
10177c478bd9Sstevel@tonic-gate void
closure(int i)1018e29394bdSmike_s closure(int i)
10197c478bd9Sstevel@tonic-gate {
10207c478bd9Sstevel@tonic-gate int c, ch, work, k;
10217c478bd9Sstevel@tonic-gate register WSET *u, *v;
10227c478bd9Sstevel@tonic-gate int *pi;
10237c478bd9Sstevel@tonic-gate int **s, **t;
10247c478bd9Sstevel@tonic-gate ITEM *q;
10257c478bd9Sstevel@tonic-gate register ITEM *p;
10267c478bd9Sstevel@tonic-gate int idx1 = 0;
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate ++zzclose;
10297c478bd9Sstevel@tonic-gate
10307c478bd9Sstevel@tonic-gate /* first, copy kernel of state i to wsets */
10317c478bd9Sstevel@tonic-gate cwp = 0;
10327c478bd9Sstevel@tonic-gate ITMLOOP(i, p, q) {
10337c478bd9Sstevel@tonic-gate wsets[cwp].pitem = p->pitem;
10347c478bd9Sstevel@tonic-gate wsets[cwp].flag = 1; /* this item must get closed */
10357c478bd9Sstevel@tonic-gate SETLOOP(k)
10367c478bd9Sstevel@tonic-gate wsets[cwp].ws.lset[k] = p->look->lset[k];
10377c478bd9Sstevel@tonic-gate WSBUMP(cwp);
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate /* now, go through the loop, closing each item */
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate work = 1;
10437c478bd9Sstevel@tonic-gate while (work) {
10447c478bd9Sstevel@tonic-gate work = 0;
10457c478bd9Sstevel@tonic-gate /*
10467c478bd9Sstevel@tonic-gate * WSLOOP(wsets, u) {
10477c478bd9Sstevel@tonic-gate */
10487c478bd9Sstevel@tonic-gate for (idx1 = 0; idx1 < cwp; idx1++) {
10497c478bd9Sstevel@tonic-gate u = &wsets[idx1];
10507c478bd9Sstevel@tonic-gate if (u->flag == 0)
10517c478bd9Sstevel@tonic-gate continue;
10527c478bd9Sstevel@tonic-gate c = *(u->pitem); /* dot is before c */
10537c478bd9Sstevel@tonic-gate if (c < NTBASE) {
10547c478bd9Sstevel@tonic-gate u->flag = 0;
10557c478bd9Sstevel@tonic-gate /*
10567c478bd9Sstevel@tonic-gate * only interesting case is where . is
10577c478bd9Sstevel@tonic-gate * before nonterminal
10587c478bd9Sstevel@tonic-gate */
10597c478bd9Sstevel@tonic-gate continue;
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate /* compute the lookahead */
10637c478bd9Sstevel@tonic-gate aryfil(clset.lset, tbitset, 0);
10647c478bd9Sstevel@tonic-gate
10657c478bd9Sstevel@tonic-gate /* find items involving c */
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate WSLOOP(u, v) {
10687c478bd9Sstevel@tonic-gate if (v->flag == 1 && *(pi = v->pitem) == c) {
10697c478bd9Sstevel@tonic-gate v->flag = 0;
10707c478bd9Sstevel@tonic-gate if (nolook)
10717c478bd9Sstevel@tonic-gate continue;
10727c478bd9Sstevel@tonic-gate while ((ch = *++pi) > 0) {
10737c478bd9Sstevel@tonic-gate /* terminal symbol */
10747c478bd9Sstevel@tonic-gate if (ch < NTBASE) {
10757c478bd9Sstevel@tonic-gate SETBIT(clset.lset, ch);
10767c478bd9Sstevel@tonic-gate break;
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate /* nonterminal symbol */
10797c478bd9Sstevel@tonic-gate (void) setunion(clset.lset,
10807c478bd9Sstevel@tonic-gate pfirst[ch-NTBASE]->lset);
10817c478bd9Sstevel@tonic-gate if (!pempty[ch-NTBASE])
10827c478bd9Sstevel@tonic-gate break;
10837c478bd9Sstevel@tonic-gate }
10847c478bd9Sstevel@tonic-gate if (ch <= 0)
10857c478bd9Sstevel@tonic-gate (void) setunion(clset.lset,
10867c478bd9Sstevel@tonic-gate v->ws.lset);
10877c478bd9Sstevel@tonic-gate }
10887c478bd9Sstevel@tonic-gate }
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate /* now loop over productions derived from c */
10917c478bd9Sstevel@tonic-gate
10927c478bd9Sstevel@tonic-gate c -= NTBASE; /* c is now nonterminal number */
10937c478bd9Sstevel@tonic-gate
10947c478bd9Sstevel@tonic-gate t = pres[c+1];
10957c478bd9Sstevel@tonic-gate for (s = pres[c]; s < t; ++s) {
10967c478bd9Sstevel@tonic-gate /* put these items into the closure */
10977c478bd9Sstevel@tonic-gate WSLOOP(wsets, v) { /* is the item there */
10987c478bd9Sstevel@tonic-gate /* yes, it is there */
10997c478bd9Sstevel@tonic-gate if (v->pitem == *s) {
11007c478bd9Sstevel@tonic-gate if (nolook)
11017c478bd9Sstevel@tonic-gate goto nexts;
11027c478bd9Sstevel@tonic-gate if (setunion(v->ws.lset,
11037c478bd9Sstevel@tonic-gate clset.lset))
11047c478bd9Sstevel@tonic-gate v->flag = work = 1;
11057c478bd9Sstevel@tonic-gate goto nexts;
11067c478bd9Sstevel@tonic-gate }
11077c478bd9Sstevel@tonic-gate }
11087c478bd9Sstevel@tonic-gate
11097c478bd9Sstevel@tonic-gate /* not there; make a new entry */
11107c478bd9Sstevel@tonic-gate if (cwp + 1 >= wsetsz)
11117c478bd9Sstevel@tonic-gate exp_wsets();
11127c478bd9Sstevel@tonic-gate
11137c478bd9Sstevel@tonic-gate wsets[cwp].pitem = *s;
11147c478bd9Sstevel@tonic-gate wsets[cwp].flag = 1;
11157c478bd9Sstevel@tonic-gate if (!nolook) {
11167c478bd9Sstevel@tonic-gate work = 1;
11177c478bd9Sstevel@tonic-gate SETLOOP(k)
11187c478bd9Sstevel@tonic-gate wsets[cwp].ws.lset[k] =
11197c478bd9Sstevel@tonic-gate clset.lset[k];
11207c478bd9Sstevel@tonic-gate }
11217c478bd9Sstevel@tonic-gate WSBUMP(cwp);
11227c478bd9Sstevel@tonic-gate nexts:;
11237c478bd9Sstevel@tonic-gate }
11247c478bd9Sstevel@tonic-gate }
11257c478bd9Sstevel@tonic-gate }
11267c478bd9Sstevel@tonic-gate
11277c478bd9Sstevel@tonic-gate /* have computed closure; flags are reset; return */
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate if (&wsets[cwp] > &wsets[zzcwp])
11307c478bd9Sstevel@tonic-gate zzcwp = cwp;
11317c478bd9Sstevel@tonic-gate if (cldebug && (foutput != NULL)) {
11327c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "\nState %d, nolook = %d\n", i, nolook);
11337c478bd9Sstevel@tonic-gate WSLOOP(wsets, u) {
11347c478bd9Sstevel@tonic-gate if (u->flag)
11357c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "flag set!\n");
11367c478bd9Sstevel@tonic-gate u->flag = 0;
1137*1dd08564Sab196087 (void) fprintf(foutput, WSFMT("\t%ws"),
1138*1dd08564Sab196087 writem(u->pitem));
11397c478bd9Sstevel@tonic-gate prlook(&u->ws);
11407c478bd9Sstevel@tonic-gate (void) fprintf(foutput, "\n");
11417c478bd9Sstevel@tonic-gate }
11427c478bd9Sstevel@tonic-gate }
11437c478bd9Sstevel@tonic-gate }
11447c478bd9Sstevel@tonic-gate
11457c478bd9Sstevel@tonic-gate static LOOKSETS *
flset(p)11467c478bd9Sstevel@tonic-gate flset(p)
11477c478bd9Sstevel@tonic-gate LOOKSETS *p;
11487c478bd9Sstevel@tonic-gate {
11497c478bd9Sstevel@tonic-gate /* decide if the lookahead set pointed to by p is known */
11507c478bd9Sstevel@tonic-gate /* return pointer to a perminent location for the set */
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate int j, *w;
1153e29394bdSmike_s int *u, *v;
11547c478bd9Sstevel@tonic-gate register LOOKSETS *q;
11557c478bd9Sstevel@tonic-gate
11567c478bd9Sstevel@tonic-gate for (q = &lkst[nlset]; q-- > lkst; ) {
11577c478bd9Sstevel@tonic-gate u = p->lset;
11587c478bd9Sstevel@tonic-gate v = q->lset;
11597c478bd9Sstevel@tonic-gate w = & v[tbitset];
11607c478bd9Sstevel@tonic-gate while (v < w)
11617c478bd9Sstevel@tonic-gate if (*u++ != *v++)
11627c478bd9Sstevel@tonic-gate goto more;
11637c478bd9Sstevel@tonic-gate /* we have matched */
11647c478bd9Sstevel@tonic-gate return (q);
11657c478bd9Sstevel@tonic-gate more:;
11667c478bd9Sstevel@tonic-gate }
11677c478bd9Sstevel@tonic-gate /* add a new one */
11687c478bd9Sstevel@tonic-gate q = &lkst[nlset++];
11697c478bd9Sstevel@tonic-gate if (nlset >= lsetsize) {
11707c478bd9Sstevel@tonic-gate exp_lkst();
11717c478bd9Sstevel@tonic-gate q = &lkst[nlset++];
11727c478bd9Sstevel@tonic-gate }
11737c478bd9Sstevel@tonic-gate SETLOOP(j) q->lset[j] = p->lset[j];
11747c478bd9Sstevel@tonic-gate return (q);
11757c478bd9Sstevel@tonic-gate }
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate static void
exp_lkst()11787c478bd9Sstevel@tonic-gate exp_lkst()
11797c478bd9Sstevel@tonic-gate {
11807c478bd9Sstevel@tonic-gate int i, j;
11817c478bd9Sstevel@tonic-gate static LOOKSETS *lookbase;
11827c478bd9Sstevel@tonic-gate
11837c478bd9Sstevel@tonic-gate lookbase = lkst;
11847c478bd9Sstevel@tonic-gate lsetsize += LSETSIZE;
11857c478bd9Sstevel@tonic-gate tmp_lset = (int *)
11867c478bd9Sstevel@tonic-gate calloc((size_t)(TBITSET * (lsetsize-LSETSIZE)), sizeof (int));
11877c478bd9Sstevel@tonic-gate if (tmp_lset == NULL)
11887c478bd9Sstevel@tonic-gate /*
11897c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
11907c478bd9Sstevel@tonic-gate * This message is passed to error() function.
11917c478bd9Sstevel@tonic-gate * Memory allocation error. Do not translate lookset.
11927c478bd9Sstevel@tonic-gate *
11937c478bd9Sstevel@tonic-gate * You may just translate this as:
11947c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
11957c478bd9Sstevel@tonic-gate */
11967c478bd9Sstevel@tonic-gate error(gettext(
11977c478bd9Sstevel@tonic-gate "could not expand lookset array"));
11987c478bd9Sstevel@tonic-gate lkst = (LOOKSETS *) realloc((char *)lkst, sizeof (LOOKSETS) * lsetsize);
11997c478bd9Sstevel@tonic-gate for (i = lsetsize-LSETSIZE, j = 0; i < lsetsize; ++i, ++j)
12007c478bd9Sstevel@tonic-gate lkst[i].lset = tmp_lset + TBITSET * j;
12017c478bd9Sstevel@tonic-gate tmp_lset = NULL;
12027c478bd9Sstevel@tonic-gate if (lkst == NULL)
12037c478bd9Sstevel@tonic-gate /*
12047c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
12057c478bd9Sstevel@tonic-gate * This message is passed to error() function.
12067c478bd9Sstevel@tonic-gate * Memory allocation error. Do not translate lookset.
12077c478bd9Sstevel@tonic-gate *
12087c478bd9Sstevel@tonic-gate * You may just translate this as:
12097c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
12107c478bd9Sstevel@tonic-gate */
12117c478bd9Sstevel@tonic-gate error(gettext(
12127c478bd9Sstevel@tonic-gate "could not expand lookahead sets"));
12137c478bd9Sstevel@tonic-gate for (i = 0; i <= nnonter; ++i)
12147c478bd9Sstevel@tonic-gate pfirst[i] = pfirst[i] - lookbase + lkst;
12157c478bd9Sstevel@tonic-gate for (i = 0; i <= nstate+1; ++i) {
12167c478bd9Sstevel@tonic-gate if (psmem[i].look)
12177c478bd9Sstevel@tonic-gate psmem[i].look = psmem[i].look - lookbase + lkst;
12187c478bd9Sstevel@tonic-gate if (pstate[i]->look)
12197c478bd9Sstevel@tonic-gate pstate[i]->look = pstate[i]->look - lookbase + lkst;
12207c478bd9Sstevel@tonic-gate }
12217c478bd9Sstevel@tonic-gate }
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gate static void
exp_wsets()12247c478bd9Sstevel@tonic-gate exp_wsets()
12257c478bd9Sstevel@tonic-gate {
12267c478bd9Sstevel@tonic-gate int i, j;
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gate wsetsz += WSETSIZE;
12297c478bd9Sstevel@tonic-gate tmp_lset = (int *)
12307c478bd9Sstevel@tonic-gate calloc((size_t)(TBITSET * (wsetsz-WSETSIZE)), sizeof (int));
12317c478bd9Sstevel@tonic-gate if (tmp_lset == NULL)
12327c478bd9Sstevel@tonic-gate /*
12337c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
12347c478bd9Sstevel@tonic-gate * This message is passed to error() function.
12357c478bd9Sstevel@tonic-gate * Memory allocation error. Do not translate lookset.
12367c478bd9Sstevel@tonic-gate *
12377c478bd9Sstevel@tonic-gate * You may just translate this as:
12387c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
12397c478bd9Sstevel@tonic-gate */
12407c478bd9Sstevel@tonic-gate error(gettext(
12417c478bd9Sstevel@tonic-gate "could not expand lookset array"));
12427c478bd9Sstevel@tonic-gate wsets = (WSET *) realloc((char *)wsets, sizeof (WSET) * wsetsz);
12437c478bd9Sstevel@tonic-gate for (i = wsetsz-WSETSIZE, j = 0; i < wsetsz; ++i, ++j)
12447c478bd9Sstevel@tonic-gate wsets[i].ws.lset = tmp_lset + TBITSET * j;
12457c478bd9Sstevel@tonic-gate tmp_lset = NULL;
12467c478bd9Sstevel@tonic-gate if (wsets == NULL)
12477c478bd9Sstevel@tonic-gate /*
12487c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
12497c478bd9Sstevel@tonic-gate * This message is passed to error() function.
12507c478bd9Sstevel@tonic-gate * Memory allocation error. You may just transltate
12517c478bd9Sstevel@tonic-gate * this as 'Could not allocate internally used memory.'
12527c478bd9Sstevel@tonic-gate *
12537c478bd9Sstevel@tonic-gate * You may just translate this as:
12547c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
12557c478bd9Sstevel@tonic-gate */
12567c478bd9Sstevel@tonic-gate error(gettext(
12577c478bd9Sstevel@tonic-gate "could not expand working sets"));
12587c478bd9Sstevel@tonic-gate }
12597c478bd9Sstevel@tonic-gate
12607c478bd9Sstevel@tonic-gate static void
exp_states()12617c478bd9Sstevel@tonic-gate exp_states()
12627c478bd9Sstevel@tonic-gate {
12637c478bd9Sstevel@tonic-gate nstatesz += NSTATES;
12647c478bd9Sstevel@tonic-gate
12657c478bd9Sstevel@tonic-gate pstate = (ITEM **)
12667c478bd9Sstevel@tonic-gate realloc((char *)pstate, sizeof (ITEM *)*(nstatesz+2));
12677c478bd9Sstevel@tonic-gate mstates = (int *)realloc((char *)mstates, sizeof (int)*nstatesz);
12687c478bd9Sstevel@tonic-gate defact = (int *)realloc((char *)defact, sizeof (int)*nstatesz);
12697c478bd9Sstevel@tonic-gate tystate = (int *)realloc((char *)tystate, sizeof (int)*nstatesz);
12707c478bd9Sstevel@tonic-gate indgo = (int *)realloc((char *)indgo, sizeof (int)*nstatesz);
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gate if ((*pstate == NULL) || (tystate == NULL) || (defact == NULL) ||
12737c478bd9Sstevel@tonic-gate (indgo == NULL) || (mstates == NULL))
12747c478bd9Sstevel@tonic-gate /*
12757c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
12767c478bd9Sstevel@tonic-gate * This message is passed to error() function.
12777c478bd9Sstevel@tonic-gate * Memory allocation error.
12787c478bd9Sstevel@tonic-gate *
12797c478bd9Sstevel@tonic-gate * You may just translate this as:
12807c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
12817c478bd9Sstevel@tonic-gate */
12827c478bd9Sstevel@tonic-gate error(gettext(
12837c478bd9Sstevel@tonic-gate "cannot expand table of states"));
12847c478bd9Sstevel@tonic-gate }
12857c478bd9Sstevel@tonic-gate
12867c478bd9Sstevel@tonic-gate static void
exp_psmem()12877c478bd9Sstevel@tonic-gate exp_psmem()
12887c478bd9Sstevel@tonic-gate {
12897c478bd9Sstevel@tonic-gate int i;
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gate new_pstsize += PSTSIZE;
12927c478bd9Sstevel@tonic-gate psmem = (ITEM *) realloc((char *)psmem, sizeof (ITEM) * new_pstsize);
12937c478bd9Sstevel@tonic-gate if (psmem == NULL)
12947c478bd9Sstevel@tonic-gate /*
12957c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE -- This is a message from yacc.
12967c478bd9Sstevel@tonic-gate * This message is passed to error() function.
12977c478bd9Sstevel@tonic-gate * Memory allocation error.
12987c478bd9Sstevel@tonic-gate *
12997c478bd9Sstevel@tonic-gate * You may just translate this as:
13007c478bd9Sstevel@tonic-gate * 'Could not allocate internally used memory.'
13017c478bd9Sstevel@tonic-gate */
13027c478bd9Sstevel@tonic-gate error(gettext(
13037c478bd9Sstevel@tonic-gate "cannot expand pstate memory"));
13047c478bd9Sstevel@tonic-gate
13057c478bd9Sstevel@tonic-gate zzmemsz = zzmemsz - pstate[0] + psmem;
13067c478bd9Sstevel@tonic-gate for (i = 1; i <= nstate+1; ++i)
13077c478bd9Sstevel@tonic-gate pstate[i] = pstate[i] - pstate[0] + psmem;
13087c478bd9Sstevel@tonic-gate pstate[0] = psmem;
13097c478bd9Sstevel@tonic-gate }
1310