1/* 2 * CDDL HEADER START 3 * 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. |
7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 26/* Copyright (c) 1988 AT&T */ 27/* All Rights Reserved */ 28 29#pragma ident "%Z%%M% %I% %E% SMI" 30 --- 71 unchanged lines hidden (view full) --- 102static int ***pres; /* vector of pointers to productions */ 103 /* yielding each nonterminal */ 104static LOOKSETS **pfirst; /* vector of pointers to first sets for */ 105 /* each nonterminal */ 106static int *pempty; /* vector of nonterminals nontrivially */ 107 /* deriving e */ 108extern int nprodsz; 109 |
110int 111main(int argc, char *argv[]) 112{ 113 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 */ 116#endif 117 (void) textdomain(TEXT_DOMAIN); 118 |
119 setup(argc, argv); /* initialize and read productions */ 120 TBITSET = NWORDS(ntoksz*LKFACTOR); 121 tbitset = NWORDS(ntokens*LKFACTOR); 122 mktbls(); 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 */ --- 37 unchanged lines hidden (view full) --- 164 zzmemsz = psmem; 165 memp = amem; 166 167 /* 168 * For lkst 169 */ 170#define INIT_LSIZE nnontersz*LKFACTOR 171 tmp_lset = (int *) |
172 calloc((size_t)(TBITSET * (INIT_LSIZE+1)), sizeof (int)); |
173 if (tmp_lset == NULL) 174/* 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'. 179 * 180 * You may just translate this as: --- 5 unchanged lines hidden (view full) --- 186 for (i = 0; i <= INIT_LSIZE; ++i) 187 lkst[i].lset = tmp_lset + TBITSET * i; 188 tmp_lset = NULL; 189 190 /* 191 * For wsets 192 */ 193 tmp_lset = (int *) |
194 calloc((size_t)(TBITSET * (nnontersz+1)), sizeof (int)); |
195 if (tmp_lset == NULL) 196 error(gettext( 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; 201 tmp_lset = NULL; 202 --- 36 unchanged lines hidden (view full) --- 239/* put out other arrays, copy the parsers */ 240static void 241others() 242{ 243 extern int gen_lines; 244 int c, i, j; 245 int tmpline; 246 |
247 finput = fopen(parser, "r"); 248 if (finput == NULL) 249/* 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. 254 */ 255 error(gettext( 256 "cannot find parser %s"), |
257 parser); |
258 259 warray(L"yyr1", levprd, nprod); 260 261 aryfil(temp1, nprod, 0); 262 /* had_act[i] is either 1 or 0 */ 263 PLOOP(1, i) 264 temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i]; 265 warray(L"yyr2", temp1, nprod); --- 40 unchanged lines hidden (view full) --- 306 */ 307 error(gettext( 308 "cannot open action tempfile")); 309 while ((c = getwc(faction)) != EOF) 310 (void) putwc(c, ftable); 311 (void) fclose(faction); 312 if (gen_lines) 313 fprintf(ftable, |
314 "\n# line\t%d \"%s\"", 315 tmpline, 316 parser); |
317 ZAPFILE(ACTNAME); 318 c = getwc(finput); 319 } 320 } 321 (void) putwc(c, ftable); 322 } 323 (void) fclose(ftable); 324} --- 101 unchanged lines hidden (view full) --- 426int zzrrconf = 0; 427 428/* output the summary on the tty */ 429static void 430summary() 431{ 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", |
441 zzsrconf, zzrrconf); |
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); |
459 } 460 if (zzsrconf != 0 || zzrrconf != 0) { 461/* 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. 467 */ 468 (void) fprintf(stderr, gettext( |
469 "\nconflicts: ")); |
470 if (zzsrconf) 471 (void) fprintf(stderr, "%d shift/reduce", zzsrconf); 472 if (zzsrconf && zzrrconf) 473 (void) fprintf(stderr, ", "); 474 if (zzrrconf) 475 (void) fprintf(stderr, "%d reduce/reduce", zzrrconf); 476 (void) fprintf(stderr, "\n"); 477 } --- 16 unchanged lines hidden (view full) --- 494 ++nerrors; 495 if (!lineno) 496/* 497 * TRANSLATION_NOTE -- This is a message from yacc. 498 * This message is a prefix to the error messages 499 * passed to error() function. 500 */ 501 (void) fprintf(stderr, gettext( |
502 "command line: fatal: ")); |
503 else { 504 (void) fprintf(stderr, "\"%s\", ", infile); 505/* 506 * TRANSLATION_NOTE -- This is a message from yacc. 507 * This message is a prefix to the error messages 508 * passed to error() function. 509 */ 510 (void) fprintf(stderr, gettext( |
511 "line %d: fatal: "), 512 lineno); |
513 } 514 (void) vfprintf(stderr, s, ap); 515 (void) fprintf(stderr, "\n"); 516 va_end(ap); 517 if (!fatfl) 518 return; 519 summary(); 520 exit(1); --- 15 unchanged lines hidden (view full) --- 536 */ 537 if (flag == 0) 538/* 539 * TRANSLATION_NOTE -- This is a message from yacc. 540 * This message is a prefix to the warning messages 541 * passed to warning() function. 542 */ 543 (void) fprintf(stderr, gettext( |
544 "warning: ")); |
545 else 546/* 547 * TRANSLATION_NOTE -- This is a message from yacc. 548 * This message is a prefix to the warning messages 549 * passed to warning() function. 550 */ 551 (void) fprintf(stderr, gettext( |
552 "line %d: warning: "), 553 lineno); |
554 (void) vfprintf(stderr, s, ap); 555 (void) fprintf(stderr, "\n"); 556 va_end(ap); 557} 558 559/* set elements 0 through n-1 to c */ 560void 561aryfil(v, n, c) --- 89 unchanged lines hidden (view full) --- 651/* 652 * TRANSLATION_NOTE -- This is a message from yacc. 653 * This message is passed to error() function. 654 * Ask somebody who knows yacc how to translate nonterminal or 655 * look at translated yacc document. 656 */ 657 error(gettext( 658 "undefined nonterminal: %ws"), |
659 nontrst[i].name); |
660 } 661 } 662 pres[i] = ptrpy; 663 fatfl = 1; 664 if (nerrors) { 665 summary(); 666 exit(1); 667 } --- 4 unchanged lines hidden (view full) --- 672 * This is an internal error message. 673 * Very little use to user. You may leave it 674 * un-translated. 675 * 676 * pyied is name of an array. Do not translate it. 677 */ 678 error(gettext( 679 "internal Yacc error: pyield %d"), |
680 ptrpy-&pyield[nprod]); |
681} 682 683static int indebug = 0; 684/* compute an array with the first of nonterminals */ 685static void 686cpfir() 687{ 688 int *p, **s, i, **t, ch, changes; --- 20 unchanged lines hidden (view full) --- 709 changes = 1; 710 while (changes) { 711 changes = 0; 712 NTLOOP(i) { 713 t = pres[i+1]; 714 for (s = pres[i]; s < t; ++s) { 715 for (p = *s; (ch = (*p-NTBASE)) >= 0; ++p) { 716 changes |= setunion(wsets[i].ws.lset, |
717 wsets[ch].ws.lset); |
718 if (!pempty[ch]) 719 break; 720 } 721 } 722 } 723 } 724 725 NTLOOP(i) --- 32 unchanged lines hidden (view full) --- 758 ss = k->look; 759 k->look = l->look; 760 l->look = ss; 761 } 762 } 763 size1 = p2 - p1; /* size of state */ 764 765 for (i = (c >= NTBASE) ? ntstates[c-NTBASE] : tstates[c]; |
766 i != 0; i = mstates[i]) { |
767 /* get ith state */ 768 q1 = pstate[i]; 769 q2 = pstate[i+1]; 770 size2 = q2 - q1; 771 if (size1 != size2) 772 continue; 773 k = p1; 774 for (l = q1; l < q2; l++) { --- 121 unchanged lines hidden (view full) --- 896 * TRANSLATION_NOTE -- This is a message from yacc. 897 * This message is passed to error() function. 898 * Ask somebody who knows yacc how to translate nonterminal or 899 * look at translated yacc document. Check how 'derive' is 900 * translated in these documents also. 901 */ 902 error(gettext( 903 "nonterminal %ws never derives any token string"), |
904 nontrst[i].name); |
905 } 906 } 907 908 if (nerrors) { 909 summary(); 910 exit(1); 911 } 912 --- 8 unchanged lines hidden (view full) --- 921 922 /* loop as long as we keep finding empty nonterminals */ 923 924again: 925 PLOOP(1, i) { 926 /* not known to be empty */ 927 if (pempty[*prdptr[i]-NTBASE] == WHOKNOWS) { 928 for (p = prdptr[i]+1; |
929 *p >= NTBASE && pempty[*p-NTBASE] == EMPTY; ++p) 930 /* EMPTY */; |
931 /* we have a nontrivially empty nonterminal */ 932 if (*p < 0) { 933 pempty[*prdptr[i]-NTBASE] = EMPTY; 934 goto again; /* got one ... try for another */ 935 } 936 } 937 } 938} --- 52 unchanged lines hidden (view full) --- 991 (void) state(c); /* register new state */ 992 else temp1[c-NTBASE] = state(c); 993 } 994 if (gsdebug && (foutput != NULL)) { 995 (void) fprintf(foutput, "%d: ", i); 996 NTLOOP(j) { 997 if (temp1[j]) 998 (void) fprintf(foutput, |
999 "%ws %d, ", nontrst[j].name, 1000 temp1[j]); |
1001 } 1002 (void) fprintf(foutput, "\n"); 1003 } 1004 indgo[i] = apack(&temp1[1], nnonter - 1) - 1; 1005 goto more; /* we have done one goto; do some more */ 1006 } 1007 /* no more to do... stop */ 1008} --- 59 unchanged lines hidden (view full) --- 1068 while ((ch = *++pi) > 0) { 1069 /* terminal symbol */ 1070 if (ch < NTBASE) { 1071 SETBIT(clset.lset, ch); 1072 break; 1073 } 1074 /* nonterminal symbol */ 1075 (void) setunion(clset.lset, |
1076 pfirst[ch-NTBASE]->lset); |
1077 if (!pempty[ch-NTBASE]) 1078 break; 1079 } 1080 if (ch <= 0) 1081 (void) setunion(clset.lset, |
1082 v->ws.lset); |
1083 } 1084 } 1085 1086 /* now loop over productions derived from c */ 1087 1088 c -= NTBASE; /* c is now nonterminal number */ 1089 1090 t = pres[c+1]; 1091 for (s = pres[c]; s < t; ++s) { 1092 /* put these items into the closure */ 1093 WSLOOP(wsets, v) { /* is the item there */ 1094 /* yes, it is there */ 1095 if (v->pitem == *s) { 1096 if (nolook) 1097 goto nexts; 1098 if (setunion(v->ws.lset, |
1099 clset.lset)) |
1100 v->flag = work = 1; 1101 goto nexts; 1102 } 1103 } 1104 1105 /* not there; make a new entry */ 1106 if (cwp + 1 >= wsetsz) 1107 exp_wsets(); 1108 1109 wsets[cwp].pitem = *s; 1110 wsets[cwp].flag = 1; 1111 if (!nolook) { 1112 work = 1; 1113 SETLOOP(k) 1114 wsets[cwp].ws.lset[k] = |
1115 clset.lset[k]; |
1116 } 1117 WSBUMP(cwp); 1118 nexts:; 1119 } 1120 } 1121 } 1122 1123 /* have computed closure; flags are reset; return */ --- 49 unchanged lines hidden (view full) --- 1173exp_lkst() 1174{ 1175 int i, j; 1176 static LOOKSETS *lookbase; 1177 1178 lookbase = lkst; 1179 lsetsize += LSETSIZE; 1180 tmp_lset = (int *) |
1181 calloc((size_t)(TBITSET * (lsetsize-LSETSIZE)), sizeof (int)); |
1182 if (tmp_lset == NULL) 1183/* 1184 * TRANSLATION_NOTE -- This is a message from yacc. 1185 * This message is passed to error() function. 1186 * Memory allocation error. Do not translate lookset. 1187 * 1188 * You may just translate this as: 1189 * 'Could not allocate internally used memory.' --- 27 unchanged lines hidden (view full) --- 1217 1218static void 1219exp_wsets() 1220{ 1221 int i, j; 1222 1223 wsetsz += WSETSIZE; 1224 tmp_lset = (int *) |
1225 calloc((size_t)(TBITSET * (wsetsz-WSETSIZE)), sizeof (int)); |
1226 if (tmp_lset == NULL) 1227/* 1228 * TRANSLATION_NOTE -- This is a message from yacc. 1229 * This message is passed to error() function. 1230 * Memory allocation error. Do not translate lookset. 1231 * 1232 * You may just translate this as: 1233 * 'Could not allocate internally used memory.' --- 19 unchanged lines hidden (view full) --- 1253} 1254 1255static void 1256exp_states() 1257{ 1258 nstatesz += NSTATES; 1259 1260 pstate = (ITEM **) |
1261 realloc((char *)pstate, sizeof (ITEM *)*(nstatesz+2)); |
1262 mstates = (int *)realloc((char *)mstates, sizeof (int)*nstatesz); 1263 defact = (int *)realloc((char *)defact, sizeof (int)*nstatesz); 1264 tystate = (int *)realloc((char *)tystate, sizeof (int)*nstatesz); 1265 indgo = (int *)realloc((char *)indgo, sizeof (int)*nstatesz); 1266 1267 if ((*pstate == NULL) || (tystate == NULL) || (defact == NULL) || |
1268 (indgo == NULL) || (mstates == NULL)) |
1269/* 1270 * TRANSLATION_NOTE -- This is a message from yacc. 1271 * This message is passed to error() function. 1272 * Memory allocation error. 1273 * 1274 * You may just translate this as: 1275 * 'Could not allocate internally used memory.' 1276 */ --- 28 unchanged lines hidden --- |