4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/param.h>
33 #include <sys/errno.h>
36 #include <stdarg.h> /* For error() */
38 static void mktbls(void);
39 static void others(void);
40 static void summary(void);
41 static wchar_t *chcopy(wchar_t *, wchar_t *);
42 static int setunion(int *, int *);
43 static void prlook(LOOKSETS
*);
44 static void cpres(void);
45 static void cpfir(void);
46 static void cempty(void);
47 static void stagen(void);
48 static LOOKSETS
*flset(LOOKSETS
*);
49 static void exp_lkst(void);
50 static void exp_wsets(void);
51 static void exp_states(void);
52 static void exp_psmem(void);
54 /* lookahead computations */
57 static int tbitset
; /* size of lookahead sets */
61 static int nlset
= 0; /* next lookahead set index */
62 int nolook
= 0; /* flag to suppress lookahead computations */
63 static LOOKSETS clset
; /* temporary storage for lookahead computations */
65 static ITEM
*psmem
, *zzmemsz
;
66 static int new_pstsize
= PSTSIZE
;
68 /* working set computations */
72 static int wsetsz
= 0; /* number of WSET items in wsets block */
74 /* state information */
76 int nstate
= 0; /* number of states */
77 static int nstatesz
= NSTATES
; /* number of state space allocated */
78 ITEM
**pstate
; /* ptr to descriptions of the states */
79 int *tystate
; /* contains type info about the states */
80 int *indgo
; /* index to the stored goto table */
82 static int *tstates
; /* states generated by terminal gotos */
83 static int *ntstates
; /* states generated by non-term gotos */
84 static int *mstates
; /* chain of overflows of term/nonterm */
85 /* generation lists */
87 /* storage for the actions in the parser */
89 int *amem
, *memp
; /* next free action table position */
90 int new_actsize
= ACTSIZE
;
92 /* other storage areas */
94 int *temp1
; /* temp storate, indexed by terms+ntokens or states */
95 int lineno
= 0; /* current input line number */
97 static int fatfl
= 1; /* if on, error is fatal */
98 static int nerrors
= 0; /* number of errors */
100 /* storage for information about the nonterminals */
102 static int ***pres
; /* vector of pointers to productions */
103 /* yielding each nonterminal */
104 static LOOKSETS
**pfirst
; /* vector of pointers to first sets for */
105 /* each nonterminal */
106 static int *pempty
; /* vector of nonterminals nontrivially */
111 main(int argc
, char *argv
[])
113 (void) setlocale(LC_ALL
, "");
114 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
115 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
117 (void) textdomain(TEXT_DOMAIN
);
119 setup(argc
, argv
); /* initialize and read productions */
120 TBITSET
= NWORDS(ntoksz
*LKFACTOR
);
121 tbitset
= NWORDS(ntokens
*LKFACTOR
);
123 cpres(); /* make table of which productions yield a */
124 /* given nonterminal */
125 cempty(); /* make a table of which nonterminals can match */
126 /* the empty string */
127 cpfir(); /* make a table of firsts of nonterminals */
128 stagen(); /* generate the states */
129 output(); /* write the states and the tables */
144 size
= ntoksz
+ nnontersz
+1;
147 if (size
< new_memsize
)
150 amem
= (int *) malloc(sizeof (int) * new_actsize
);
151 psmem
= (ITEM
*) malloc(sizeof (ITEM
) * new_pstsize
);
152 if ((psmem
== NULL
) || (amem
== NULL
))
154 * TRANSLATION_NOTE -- This is a message from yacc.
155 * This message is passed to error() function.
156 * This error happens when yacc could not allocate
157 * initial memory to be used for internal tables.
159 * You may just translate this as:
160 * 'Could not allocate internally used memory.'
163 "couldn't allocate initial table"));
170 #define INIT_LSIZE nnontersz*LKFACTOR
172 calloc((size_t)(TBITSET
* (INIT_LSIZE
+1)), sizeof (int));
173 if (tmp_lset
== NULL
)
175 * TRANSLATION_NOTE -- This is a message from yacc.
176 * This message is passed to error() function.
177 * Yacc could not allocate memory for table named lookset.
178 * Do not translate 'lookset'.
180 * You may just translate this as:
181 * 'Could not allocate internally used memory.'
184 "could not allocate lookset array"));
185 lkst
= (LOOKSETS
*) malloc(sizeof (LOOKSETS
) * (INIT_LSIZE
+ 1));
186 for (i
= 0; i
<= INIT_LSIZE
; ++i
)
187 lkst
[i
].lset
= tmp_lset
+ TBITSET
* i
;
194 calloc((size_t)(TBITSET
* (nnontersz
+1)), sizeof (int));
195 if (tmp_lset
== NULL
)
197 "could not allocate lookset array"));
198 wsets
= (WSET
*) malloc(sizeof (WSET
) * (nnontersz
+ 1));
199 for (i
= 0; i
<= nnontersz
; ++i
)
200 wsets
[i
].ws
.lset
= tmp_lset
+ TBITSET
* i
;
203 clset
.lset
= (int *)malloc(sizeof (int)*TBITSET
);
204 tstates
= (int *)malloc(sizeof (int)*(ntoksz
+ 1));
205 ntstates
= (int *)malloc(sizeof (int)*(nnontersz
+ 1));
206 temp1
= (int *)malloc(sizeof (int)*size
);
207 pres
= (int ***)malloc(sizeof (int **)*(nnontersz
+ 2));
208 pfirst
= (LOOKSETS
**)malloc(sizeof (LOOKSETS
*)*(nnontersz
+ 2));
209 pempty
= (int *)malloc(sizeof (int)*(nnontersz
+ 1));
211 pstate
= (ITEM
**)malloc(sizeof (ITEM
*)*(nstatesz
+2));
212 tystate
= (int *)malloc(sizeof (int)*nstatesz
);
213 indgo
= (int *)malloc(sizeof (int)*nstatesz
);
214 mstates
= (int *)malloc(sizeof (int)*nstatesz
);
215 defact
= (int *)malloc(sizeof (int)*nstatesz
);
217 if ((lkst
== NULL
) || (wsets
== NULL
) || (tstates
== NULL
) ||
218 (ntstates
== NULL
) || (temp1
== NULL
) || (pres
== NULL
) ||
219 (pfirst
== NULL
) || (pempty
== NULL
) || (pstate
== NULL
) ||
220 (tystate
== NULL
) || (indgo
== NULL
) || (mstates
== NULL
) ||
221 (defact
== NULL
) || (clset
.lset
== NULL
))
223 * TRANSLATION_NOTE -- This is a message from yacc.
224 * This message is passed to error() function.
225 * Do not translate mktbls(). It is a function name.
227 * You may just translate this as:
228 * 'Could not allocate internally used memory.'
231 "cannot allocate tables in mktbls()"));
233 aryfil(ntstates
, nnontersz
+1, 0);
234 aryfil(tstates
, ntoksz
+1, 0);
235 wsetsz
= nnontersz
+ 1;
236 lsetsize
= INIT_LSIZE
+ 1;
239 /* put out other arrays, copy the parsers */
243 extern int gen_lines
;
247 finput
= fopen(parser
, "r");
250 * TRANSLATION_NOTE -- This is a message from yacc.
251 * This message is passed to error() function.
252 * This error message is issued when yacc can not find
253 * the parser to be copied.
256 "cannot find parser %s"),
259 warray(L
"yyr1", levprd
, nprod
);
261 aryfil(temp1
, nprod
, 0);
262 /* had_act[i] is either 1 or 0 */
264 temp1
[i
] = ((prdptr
[i
+1] - prdptr
[i
]-2) << 1) | had_act
[i
];
265 warray(L
"yyr2", temp1
, nprod
);
267 aryfil(temp1
, nstate
, -10000000);
269 for (j
= tstates
[i
]; j
!= 0; j
= mstates
[j
])
270 temp1
[j
] = tokset
[i
].value
;
272 for (j
= ntstates
[i
]; j
!= 0; j
= mstates
[j
])
274 warray(L
"yychk", temp1
, nstate
);
276 warray(L
"yydef", defact
, nstate
);
278 if ((fdebug
= fopen(DEBUGNAME
, "r")) == NULL
)
279 error("cannot open yacc.debug");
280 while ((c
= getwc(fdebug
)) != EOF
)
281 (void) putwc(c
, ftable
);
282 (void) fclose(fdebug
);
286 (void) fprintf(ftable
, "# line\t1 \"%s\"\n", parser
);
288 /* copy parser text */
289 while ((c
= getwc(finput
)) != EOF
) {
293 if ((c
= getwc(finput
)) != L
'A')
294 (void) putwc(L
'$', ftable
);
295 else { /* copy actions */
297 faction
= fopen(ACTNAME
, "r");
300 * TRANSLATION_NOTE -- This is a message from yacc.
301 * This message is passed to error() function.
302 * This error is issued when yacc can not open a
303 * temporary file to be used. You do not need to
304 * use the word 'tempfile'. You can translate it to
305 * mean 'temporary file'.
308 "cannot open action tempfile"));
309 while ((c
= getwc(faction
)) != EOF
)
310 (void) putwc(c
, ftable
);
311 (void) fclose(faction
);
313 (void) fprintf(ftable
,
314 "\n# line\t%d \"%s\"",
321 (void) putwc(c
, ftable
);
323 (void) fclose(ftable
);
327 /* copies string q into p, returning next free char ptr */
338 /* creates output string for item pointed to by pp */
344 static int isize
= ISIZE
;
345 static wchar_t *sarr
= NULL
;
349 sarr
= (wchar_t *)malloc(sizeof (wchar_t) * isize
);
352 * TRANSLATION_NOTE -- This is a message from yacc.
353 * This message is passed to error() function.
354 * This error is issued when yacc could not allocate
355 * memory for internally used array.
357 * You may just translate this as:
358 * 'Could not allocate internally used memory.'
361 "could not allocate output string array"));
362 for (i
= 0; i
< isize
; ++i
)
365 for (p
= pp
; *p
> 0; ++p
) /* NULL */;
367 q
= chcopy(sarr
, nontrst
[*p
-NTBASE
].name
);
368 q
= chcopy(q
, L
" : ");
371 *q
++ = ++p
== pp
? L
'_' : L
' ';
375 q
= chcopy(q
, symnam(i
));
376 while (q
> &sarr
[isize
-30]) {
377 static wchar_t *sarrbase
;
382 realloc((char *)sarr
, sizeof (*sarr
) * isize
);
385 * TRANSLATION_NOTE -- This is a message from yacc.
386 * This message is passed to error() function.
387 * This error is issued when yacc could not allocate
388 * memory for internally used array.
390 * You may just translate this as:
391 * 'Could not allocate internally used memory.'
394 "cannot expand sarr arrays"));
395 q
= q
- sarrbase
+ sarr
;
399 /* an item calling for a reduction */
401 q
= chcopy(q
, L
" (");
402 (void) wsprintf(q
, "%d)", -i
);
407 /* return a pointer to the name of symbol i */
413 cp
= (i
>= NTBASE
) ? nontrst
[i
-NTBASE
].name
: tokset
[i
].name
;
419 static int zzcwp
= 0;
420 static int zzclose
= 0;
428 /* output the summary on the tty */
432 if (foutput
!= NULL
) {
433 (void) fprintf(foutput
,
434 "\n%d/%d terminals, %d/%d nonterminals\n",
435 ntokens
, ntoksz
, nnonter
, nnontersz
);
436 (void) fprintf(foutput
,
437 "%d/%d grammar rules, %d/%d states\n",
438 nprod
, nprodsz
, nstate
, nstatesz
);
439 (void) fprintf(foutput
,
440 "%d shift/reduce, %d reduce/reduce conflicts reported\n",
442 (void) fprintf(foutput
,
443 "%d/%d working sets used\n", zzcwp
, wsetsz
);
444 (void) fprintf(foutput
,
445 "memory: states,etc. %" PRIdPTR
446 "/%d, parser %" PRIdPTR
"/%d\n",
447 mem
-tracemem
, new_memsize
,
448 memp
-amem
, new_actsize
);
449 (void) fprintf(foutput
,
450 "%d/%d distinct lookahead sets\n", nlset
, lsetsize
);
451 (void) fprintf(foutput
,
452 "%d extra closures\n", zzclose
- 2*nstate
);
453 (void) fprintf(foutput
,
454 "%d shift entries, %d exceptions\n", zzacent
, zzexcp
);
455 (void) fprintf(foutput
,
456 "%d goto entries\n", zzgoent
);
457 (void) fprintf(foutput
,
458 "%d entries saved by goto default\n", zzgobest
);
460 if (zzsrconf
!= 0 || zzrrconf
!= 0) {
462 * TRANSLATION_NOTE -- This is a message from yacc.
463 * You may just leave this message un-translated.
464 * This message only makes sense to those who knows
465 * how yacc works, and the person should know what
466 * this message means in English.
468 (void) fprintf(stderr
, gettext(
471 (void) fprintf(stderr
, "%d shift/reduce", zzsrconf
);
472 if (zzsrconf
&& zzrrconf
)
473 (void) fprintf(stderr
, ", ");
475 (void) fprintf(stderr
, "%d reduce/reduce", zzrrconf
);
476 (void) fprintf(stderr
, "\n");
480 (void) fclose(ftemp
);
482 (void) fclose(fdefine
);
485 /* write out error comment */
498 * TRANSLATION_NOTE -- This is a message from yacc.
499 * This message is a prefix to the error messages
500 * passed to error() function.
502 (void) fprintf(stderr
, gettext(
503 "command line: fatal: "));
505 (void) fprintf(stderr
, "\"%s\", ", infile
);
507 * TRANSLATION_NOTE -- This is a message from yacc.
508 * This message is a prefix to the error messages
509 * passed to error() function.
511 (void) fprintf(stderr
, gettext(
515 (void) vfprintf(stderr
, s
, ap
);
516 (void) fprintf(stderr
, "\n");
525 * Print out a warning message.
529 warning(int flag
, char *s
, ...)
535 (void) fprintf(stderr
, "\"%s\", ", infile
);
537 * If flag, print lineno as well.
541 * TRANSLATION_NOTE -- This is a message from yacc.
542 * This message is a prefix to the warning messages
543 * passed to warning() function.
545 (void) fprintf(stderr
, gettext(
549 * TRANSLATION_NOTE -- This is a message from yacc.
550 * This message is a prefix to the warning messages
551 * passed to warning() function.
553 (void) fprintf(stderr
, gettext(
554 "line %d: warning: "),
556 (void) vfprintf(stderr
, s
, ap
);
557 (void) fprintf(stderr
, "\n");
561 /* set elements 0 through n-1 to c */
567 for (i
= 0; i
< n
; ++i
)
571 /* set a to the union of a and b */
572 /* return 1 if b is not a subset of a, 0 otherwise */
581 *a
= (x
= *a
) | *b
++;
595 (void) fprintf(foutput
, "\tNULL");
597 (void) fprintf(foutput
, " { ");
600 (void) fprintf(foutput
, WSFMT("%ws "),
603 (void) fprintf(foutput
, "}");
608 * compute an array with the beginnings of productions yielding
610 * The array pres points to these lists
611 * the array pyield has the lists: the total size is only NPROD+1
622 * nprodsz is the size of the tables describing the productions.
623 * Normally this will be NPROD unless the production tables have
624 * been expanded, in which case the tables will be NPROD * N(where
625 * N is the number of times the tables had to be expanded.)
627 if ((pyield
= (int **) malloc(sizeof (int *) * nprodsz
)) == NULL
)
629 * TRANSLATION_NOTE -- This is a message from yacc.
630 * This message is passed to error() function.
631 * This error is issued when yacc could not allocate
632 * memory for internally used array.
634 * pyield is name of an array. You should not try to translate
637 * You may just translate this as:
638 * 'Could not allocate internally used memory.'
641 "cannot allocate space for pyield array"));
648 fatfl
= 0; /* make undefined symbols nonfatal */
650 if (*prdptr
[j
] == c
) /* linear search for all c's */
651 *ptrpy
++ = prdptr
[j
] + 1;
653 if (pres
[i
] == ptrpy
) { /* c not found */
655 * TRANSLATION_NOTE -- This is a message from yacc.
656 * This message is passed to error() function.
657 * Ask somebody who knows yacc how to translate nonterminal or
658 * look at translated yacc document.
661 "undefined nonterminal: %ws"),
671 if (ptrpy
!= &pyield
[nprod
])
673 * TRANSLATION_NOTE -- This is a message from yacc.
674 * This message is passed to error() function.
675 * This is an internal error message.
676 * Very little use to user. You may leave it
679 * pyied is name of an array. Do not translate it.
682 "internal Yacc error: pyield %d"),
683 ptrpy
-&pyield
[nprod
]);
686 static int indebug
= 0;
687 /* compute an array with the first of nonterminals */
691 int *p
, **s
, i
, **t
, ch
, changes
;
695 aryfil(wsets
[i
].ws
.lset
, tbitset
, 0);
697 /* initially fill the sets */
698 for (s
= pres
[i
]; s
< t
; ++s
) {
699 /* check if ch is non-terminal */
700 for (p
= *s
; (ch
= *p
) > 0; ++p
) {
701 if (ch
< NTBASE
) { /* should be token */
702 SETBIT(wsets
[i
].ws
.lset
, ch
);
704 } else if (!pempty
[ch
-NTBASE
])
710 /* now, reflect transitivity */
717 for (s
= pres
[i
]; s
< t
; ++s
) {
718 for (p
= *s
; (ch
= (*p
-NTBASE
)) >= 0; ++p
) {
719 changes
|= setunion(wsets
[i
].ws
.lset
,
729 pfirst
[i
] = flset(&wsets
[i
].ws
);
732 if ((foutput
!= NULL
)) {
734 (void) fprintf(foutput
, WSFMT("\n%ws: "),
737 (void) fprintf(foutput
, " %d\n", pempty
[i
]);
742 /* sorts last state,and sees if it equals earlier ones. returns state number */
748 ITEM
*p1
, *p2
, *k
, *l
, *q1
, *q2
;
750 p2
= pstate
[nstate
+1];
752 return (0); /* null state */
754 for (k
= p2
- 1; k
> p1
; k
--) { /* make k the biggest */
755 for (l
= k
-1; l
>= p1
; --l
)
756 if (l
->pitem
> k
->pitem
) {
767 size1
= p2
- p1
; /* size of state */
769 for (i
= (c
>= NTBASE
) ? ntstates
[c
-NTBASE
] : tstates
[c
];
770 i
!= 0; i
= mstates
[i
]) {
778 for (l
= q1
; l
< q2
; l
++) {
779 if (l
->pitem
!= k
->pitem
)
786 pstate
[nstate
+1] = pstate
[nstate
]; /* delete last state */
787 /* fix up lookaheads */
790 for (l
= q1
, k
= p1
; l
< q2
; ++l
, ++k
) {
793 clset
.lset
[s
] = l
->look
->lset
[s
];
794 if (setunion(clset
.lset
, k
->look
->lset
)) {
796 /* register the new set */
797 l
->look
= flset(&clset
);
805 * TRANSLATION_NOTE -- This is a message from yacc.
806 * This message is passed to error() function.
807 * You may leave this untranslated. Leave
808 * state/nolook un-translated.
811 "yacc state/nolook error"));
812 pstate
[nstate
+2] = p2
;
813 if (nstate
+1 >= nstatesz
)
816 mstates
[nstate
] = ntstates
[c
- NTBASE
];
817 ntstates
[c
- NTBASE
] = nstate
;
819 mstates
[nstate
] = tstates
[c
];
822 tystate
[nstate
] = MUSTDO
;
826 static int pidebug
= 0;
835 if (pidebug
&& (foutput
!= NULL
))
836 (void) fprintf(foutput
,
837 WSFMT("putitem(%ws), state %d\n"), writem(ptr
), nstate
);
838 j
= pstate
[nstate
+1];
841 j
->look
= flset(lptr
);
842 pstate
[nstate
+1] = ++j
;
845 if (zzmemsz
>= &psmem
[new_pstsize
])
847 /* error("out of state space"); */
852 * mark nonterminals which derive the empty string
853 * also, look for nonterminals which don't derive any token strings
864 * first, use the array pempty to detect productions
865 * that can never be reduced
868 /* set pempty to WHONOWS */
869 aryfil(pempty
, nnonter
+1, WHOKNOWS
);
872 * now, look at productions, marking nonterminals which
877 if (pempty
[*prdptr
[i
] - NTBASE
])
879 for (p
= prdptr
[i
] + 1; *p
>= 0; ++p
)
880 if (*p
>= NTBASE
&& pempty
[*p
-NTBASE
] == WHOKNOWS
)
882 if (*p
< 0) { /* production can be derived */
883 pempty
[*prdptr
[i
]-NTBASE
] = OK
;
888 /* now, look at the nonterminals, to see if they are all OK */
892 * the added production rises or falls as the
897 if (pempty
[i
] != OK
) {
900 * TRANSLATION_NOTE -- This is a message from yacc.
901 * This message is passed to error() function.
902 * Ask somebody who knows yacc how to translate nonterminal or
903 * look at translated yacc document. Check how 'derive' is
904 * translated in these documents also.
907 "nonterminal %ws never derives any token string"),
918 * now, compute the pempty array, to see which nonterminals
919 * derive the empty string
922 /* set pempty to WHOKNOWS */
924 aryfil(pempty
, nnonter
+1, WHOKNOWS
);
926 /* loop as long as we keep finding empty nonterminals */
930 /* not known to be empty */
931 if (pempty
[*prdptr
[i
]-NTBASE
] == WHOKNOWS
) {
932 for (p
= prdptr
[i
]+1;
933 *p
>= NTBASE
&& pempty
[*p
-NTBASE
] == EMPTY
; ++p
)
935 /* we have a nontrivially empty nonterminal */
937 pempty
[*prdptr
[i
]-NTBASE
] = EMPTY
;
938 goto again
; /* got one ... try for another */
944 /* generate the states */
945 static int gsdebug
= 0;
951 register WSET
*p
, *q
;
957 pstate
[0] = pstate
[1] = psmem
;
958 aryfil(clset
.lset
, tbitset
, 0);
959 putitem(prdptr
[0] + 1, &clset
);
962 pstate
[2] = pstate
[1];
964 aryfil(amem
, new_actsize
, 0);
966 /* now, the main state generation loop */
970 if (tystate
[i
] != MUSTDO
)
973 aryfil(temp1
, nnonter
+ 1, 0);
974 /* take state i, close it, and do gotos */
976 WSLOOP(wsets
, p
) { /* generate goto's */
982 if (pstate
[i
+1]-pstate
[i
] <= p
-wsets
)
983 tystate
[i
] = MUSTLOOKAHEAD
;
988 /* this item contributes to the goto */
989 if (c
== *(q
->pitem
)) {
990 putitem(q
->pitem
+ 1, &q
->ws
);
995 (void) state(c
); /* register new state */
996 else temp1
[c
-NTBASE
] = state(c
);
998 if (gsdebug
&& (foutput
!= NULL
)) {
999 (void) fprintf(foutput
, "%d: ", i
);
1002 (void) fprintf(foutput
,
1003 WSFMT("%ws %d, "), nontrst
[j
].name
,
1006 (void) fprintf(foutput
, "\n");
1008 indgo
[i
] = apack(&temp1
[1], nnonter
- 1) - 1;
1009 goto more
; /* we have done one goto; do some more */
1011 /* no more to do... stop */
1014 /* generate the closure of state i */
1015 static int cldebug
= 0; /* debugging flag for closure */
1021 register WSET
*u
, *v
;
1030 /* first, copy kernel of state i to wsets */
1033 wsets
[cwp
].pitem
= p
->pitem
;
1034 wsets
[cwp
].flag
= 1; /* this item must get closed */
1036 wsets
[cwp
].ws
.lset
[k
] = p
->look
->lset
[k
];
1040 /* now, go through the loop, closing each item */
1046 * WSLOOP(wsets, u) {
1048 for (idx1
= 0; idx1
< cwp
; idx1
++) {
1052 c
= *(u
->pitem
); /* dot is before c */
1056 * only interesting case is where . is
1057 * before nonterminal
1062 /* compute the lookahead */
1063 aryfil(clset
.lset
, tbitset
, 0);
1065 /* find items involving c */
1068 if (v
->flag
== 1 && *(pi
= v
->pitem
) == c
) {
1072 while ((ch
= *++pi
) > 0) {
1073 /* terminal symbol */
1075 SETBIT(clset
.lset
, ch
);
1078 /* nonterminal symbol */
1079 (void) setunion(clset
.lset
,
1080 pfirst
[ch
-NTBASE
]->lset
);
1081 if (!pempty
[ch
-NTBASE
])
1085 (void) setunion(clset
.lset
,
1090 /* now loop over productions derived from c */
1092 c
-= NTBASE
; /* c is now nonterminal number */
1095 for (s
= pres
[c
]; s
< t
; ++s
) {
1096 /* put these items into the closure */
1097 WSLOOP(wsets
, v
) { /* is the item there */
1098 /* yes, it is there */
1099 if (v
->pitem
== *s
) {
1102 if (setunion(v
->ws
.lset
,
1109 /* not there; make a new entry */
1110 if (cwp
+ 1 >= wsetsz
)
1113 wsets
[cwp
].pitem
= *s
;
1114 wsets
[cwp
].flag
= 1;
1118 wsets
[cwp
].ws
.lset
[k
] =
1127 /* have computed closure; flags are reset; return */
1129 if (&wsets
[cwp
] > &wsets
[zzcwp
])
1131 if (cldebug
&& (foutput
!= NULL
)) {
1132 (void) fprintf(foutput
, "\nState %d, nolook = %d\n", i
, nolook
);
1135 (void) fprintf(foutput
, "flag set!\n");
1137 (void) fprintf(foutput
, WSFMT("\t%ws"),
1140 (void) fprintf(foutput
, "\n");
1149 /* decide if the lookahead set pointed to by p is known */
1150 /* return pointer to a perminent location for the set */
1154 register LOOKSETS
*q
;
1156 for (q
= &lkst
[nlset
]; q
-- > lkst
; ) {
1163 /* we have matched */
1169 if (nlset
>= lsetsize
) {
1173 SETLOOP(j
) q
->lset
[j
] = p
->lset
[j
];
1181 static LOOKSETS
*lookbase
;
1184 lsetsize
+= LSETSIZE
;
1186 calloc((size_t)(TBITSET
* (lsetsize
-LSETSIZE
)), sizeof (int));
1187 if (tmp_lset
== NULL
)
1189 * TRANSLATION_NOTE -- This is a message from yacc.
1190 * This message is passed to error() function.
1191 * Memory allocation error. Do not translate lookset.
1193 * You may just translate this as:
1194 * 'Could not allocate internally used memory.'
1197 "could not expand lookset array"));
1198 lkst
= (LOOKSETS
*) realloc((char *)lkst
, sizeof (LOOKSETS
) * lsetsize
);
1199 for (i
= lsetsize
-LSETSIZE
, j
= 0; i
< lsetsize
; ++i
, ++j
)
1200 lkst
[i
].lset
= tmp_lset
+ TBITSET
* j
;
1204 * TRANSLATION_NOTE -- This is a message from yacc.
1205 * This message is passed to error() function.
1206 * Memory allocation error. Do not translate lookset.
1208 * You may just translate this as:
1209 * 'Could not allocate internally used memory.'
1212 "could not expand lookahead sets"));
1213 for (i
= 0; i
<= nnonter
; ++i
)
1214 pfirst
[i
] = pfirst
[i
] - lookbase
+ lkst
;
1215 for (i
= 0; i
<= nstate
+1; ++i
) {
1217 psmem
[i
].look
= psmem
[i
].look
- lookbase
+ lkst
;
1218 if (pstate
[i
]->look
)
1219 pstate
[i
]->look
= pstate
[i
]->look
- lookbase
+ lkst
;
1230 calloc((size_t)(TBITSET
* (wsetsz
-WSETSIZE
)), sizeof (int));
1231 if (tmp_lset
== NULL
)
1233 * TRANSLATION_NOTE -- This is a message from yacc.
1234 * This message is passed to error() function.
1235 * Memory allocation error. Do not translate lookset.
1237 * You may just translate this as:
1238 * 'Could not allocate internally used memory.'
1241 "could not expand lookset array"));
1242 wsets
= (WSET
*) realloc((char *)wsets
, sizeof (WSET
) * wsetsz
);
1243 for (i
= wsetsz
-WSETSIZE
, j
= 0; i
< wsetsz
; ++i
, ++j
)
1244 wsets
[i
].ws
.lset
= tmp_lset
+ TBITSET
* j
;
1248 * TRANSLATION_NOTE -- This is a message from yacc.
1249 * This message is passed to error() function.
1250 * Memory allocation error. You may just transltate
1251 * this as 'Could not allocate internally used memory.'
1253 * You may just translate this as:
1254 * 'Could not allocate internally used memory.'
1257 "could not expand working sets"));
1263 nstatesz
+= NSTATES
;
1266 realloc((char *)pstate
, sizeof (ITEM
*)*(nstatesz
+2));
1267 mstates
= (int *)realloc((char *)mstates
, sizeof (int)*nstatesz
);
1268 defact
= (int *)realloc((char *)defact
, sizeof (int)*nstatesz
);
1269 tystate
= (int *)realloc((char *)tystate
, sizeof (int)*nstatesz
);
1270 indgo
= (int *)realloc((char *)indgo
, sizeof (int)*nstatesz
);
1272 if ((*pstate
== NULL
) || (tystate
== NULL
) || (defact
== NULL
) ||
1273 (indgo
== NULL
) || (mstates
== NULL
))
1275 * TRANSLATION_NOTE -- This is a message from yacc.
1276 * This message is passed to error() function.
1277 * Memory allocation error.
1279 * You may just translate this as:
1280 * 'Could not allocate internally used memory.'
1283 "cannot expand table of states"));
1291 new_pstsize
+= PSTSIZE
;
1292 psmem
= (ITEM
*) realloc((char *)psmem
, sizeof (ITEM
) * new_pstsize
);
1295 * TRANSLATION_NOTE -- This is a message from yacc.
1296 * This message is passed to error() function.
1297 * Memory allocation error.
1299 * You may just translate this as:
1300 * 'Could not allocate internally used memory.'
1303 "cannot expand pstate memory"));
1305 zzmemsz
= zzmemsz
- pstate
[0] + psmem
;
1306 for (i
= 1; i
<= nstate
+1; ++i
)
1307 pstate
[i
] = pstate
[i
] - pstate
[0] + psmem
;