y1.c (e29394bd) | y1.c (67298654) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the | 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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. | 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. |
8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* | 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/* |
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. 25 */ 26 27/* Copyright (c) 1988 AT&T */ 28/* All Rights Reserved */ 29 30#pragma ident "%Z%%M% %I% %E% SMI" 31 --- 71 unchanged lines hidden (view full) --- 103static int ***pres; /* vector of pointers to productions */ 104 /* yielding each nonterminal */ 105static LOOKSETS **pfirst; /* vector of pointers to first sets for */ 106 /* each nonterminal */ 107static int *pempty; /* vector of nonterminals nontrivially */ 108 /* deriving e */ 109extern int nprodsz; 110 | 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 |
111static char *sav_argv0; 112char run_directory[MAXPATHLEN]; 113char current_work_directory[MAXPATHLEN]; 114extern int find_run_directory(char *, char *, char *, char **, char *); 115 | |
116int 117main(int argc, char *argv[]) 118{ 119 setlocale(LC_ALL, ""); 120#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 121#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 122#endif 123 (void) textdomain(TEXT_DOMAIN); 124 | 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 |
125 sav_argv0 = argv[0]; | |
126 setup(argc, argv); /* initialize and read productions */ 127 TBITSET = NWORDS(ntoksz*LKFACTOR); 128 tbitset = NWORDS(ntokens*LKFACTOR); 129 mktbls(); 130 cpres(); /* make table of which productions yield a */ 131 /* given nonterminal */ 132 cempty(); /* make a table of which nonterminals can match */ 133 /* the empty string */ --- 37 unchanged lines hidden (view full) --- 171 zzmemsz = psmem; 172 memp = amem; 173 174 /* 175 * For lkst 176 */ 177#define INIT_LSIZE nnontersz*LKFACTOR 178 tmp_lset = (int *) | 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 *) |
179 calloc((size_t)(TBITSET * (INIT_LSIZE+1)), sizeof (int)); | 172 calloc((size_t)(TBITSET * (INIT_LSIZE+1)), sizeof (int)); |
180 if (tmp_lset == NULL) 181/* 182 * TRANSLATION_NOTE -- This is a message from yacc. 183 * This message is passed to error() function. 184 * Yacc could not allocate memory for table named lookset. 185 * Do not translate 'lookset'. 186 * 187 * You may just translate this as: --- 5 unchanged lines hidden (view full) --- 193 for (i = 0; i <= INIT_LSIZE; ++i) 194 lkst[i].lset = tmp_lset + TBITSET * i; 195 tmp_lset = NULL; 196 197 /* 198 * For wsets 199 */ 200 tmp_lset = (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 *) |
201 calloc((size_t)(TBITSET * (nnontersz+1)), sizeof (int)); | 194 calloc((size_t)(TBITSET * (nnontersz+1)), sizeof (int)); |
202 if (tmp_lset == NULL) 203 error(gettext( 204 "could not allocate lookset array")); 205 wsets = (WSET *) malloc(sizeof (WSET) * (nnontersz + 1)); 206 for (i = 0; i <= nnontersz; ++i) 207 wsets[i].ws.lset = tmp_lset + TBITSET * i; 208 tmp_lset = NULL; 209 --- 36 unchanged lines hidden (view full) --- 246/* put out other arrays, copy the parsers */ 247static void 248others() 249{ 250 extern int gen_lines; 251 int c, i, j; 252 int tmpline; 253 | 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 |
254 /* This routine has been "stolen" from the driver */ 255 if (parser == NULL) { 256 current_work_directory[0] = '.'; 257 current_work_directory[1] = '\0'; 258 if (find_run_directory(sav_argv0, 259 current_work_directory, 260 run_directory, 261 (char **)0, 262 getenv("PATH")) != 0) { 263/* 264 * TRANSLATION_NOTE -- This is a message from yacc. 265 * This message is passed to warning() function. 266 * This warning is issued when yacc could not find 267 * the directory where the parser is. 268 */ 269 (void) warning(0, gettext( 270 "Error in finding run directory. Using default")); 271 parser = PARSER; 272 } else { 273 strcat(run_directory, "/yaccpar"); 274 parser = run_directory; 275 } 276 } 277 | |
278 finput = fopen(parser, "r"); 279 if (finput == NULL) 280/* 281 * TRANSLATION_NOTE -- This is a message from yacc. 282 * This message is passed to error() function. 283 * This error message is issued when yacc can not find 284 * the parser to be copied. 285 */ 286 error(gettext( 287 "cannot find parser %s"), | 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"), |
288 parser); | 257 parser); |
289 290 warray(L"yyr1", levprd, nprod); 291 292 aryfil(temp1, nprod, 0); 293 /* had_act[i] is either 1 or 0 */ 294 PLOOP(1, i) 295 temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i]; 296 warray(L"yyr2", temp1, nprod); --- 40 unchanged lines hidden (view full) --- 337 */ 338 error(gettext( 339 "cannot open action tempfile")); 340 while ((c = getwc(faction)) != EOF) 341 (void) putwc(c, ftable); 342 (void) fclose(faction); 343 if (gen_lines) 344 fprintf(ftable, | 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, |
345 "\n# line\t%d \"%s\"", 346 tmpline, 347 parser); | 314 "\n# line\t%d \"%s\"", 315 tmpline, 316 parser); |
348 ZAPFILE(ACTNAME); 349 c = getwc(finput); 350 } 351 } 352 (void) putwc(c, ftable); 353 } 354 (void) fclose(ftable); 355} --- 101 unchanged lines hidden (view full) --- 457int zzrrconf = 0; 458 459/* output the summary on the tty */ 460static void 461summary() 462{ 463 if (foutput != NULL) { 464 (void) fprintf(foutput, | 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, |
465 "\n%d/%d terminals, %d/%d nonterminals\n", 466 ntokens, ntoksz, nnonter, nnontersz); | 434 "\n%d/%d terminals, %d/%d nonterminals\n", 435 ntokens, ntoksz, nnonter, nnontersz); |
467 (void) fprintf(foutput, | 436 (void) fprintf(foutput, |
468 "%d/%d grammar rules, %d/%d states\n", 469 nprod, nprodsz, nstate, nstatesz); | 437 "%d/%d grammar rules, %d/%d states\n", 438 nprod, nprodsz, nstate, nstatesz); |
470 (void) fprintf(foutput, 471 "%d shift/reduce, %d reduce/reduce conflicts reported\n", | 439 (void) fprintf(foutput, 440 "%d shift/reduce, %d reduce/reduce conflicts reported\n", |
472 zzsrconf, zzrrconf); | 441 zzsrconf, zzrrconf); |
473 (void) fprintf(foutput, | 442 (void) fprintf(foutput, |
474 "%d/%d working sets used\n", zzcwp, wsetsz); | 443 "%d/%d working sets used\n", zzcwp, wsetsz); |
475 (void) fprintf(foutput, | 444 (void) fprintf(foutput, |
476 "memory: states,etc. %" PRIdPTR 477 "/%d, parser %" PRIdPTR "/%d\n", 478 mem-tracemem, new_memsize, 479 memp-amem, new_actsize); | 445 "memory: states,etc. %" PRIdPTR 446 "/%d, parser %" PRIdPTR "/%d\n", 447 mem-tracemem, new_memsize, 448 memp-amem, new_actsize); |
480 (void) fprintf(foutput, | 449 (void) fprintf(foutput, |
481 "%d/%d distinct lookahead sets\n", nlset, lsetsize); | 450 "%d/%d distinct lookahead sets\n", nlset, lsetsize); |
482 (void) fprintf(foutput, | 451 (void) fprintf(foutput, |
483 "%d extra closures\n", zzclose - 2*nstate); | 452 "%d extra closures\n", zzclose - 2*nstate); |
484 (void) fprintf(foutput, | 453 (void) fprintf(foutput, |
485 "%d shift entries, %d exceptions\n", zzacent, zzexcp); | 454 "%d shift entries, %d exceptions\n", zzacent, zzexcp); |
486 (void) fprintf(foutput, | 455 (void) fprintf(foutput, |
487 "%d goto entries\n", zzgoent); | 456 "%d goto entries\n", zzgoent); |
488 (void) fprintf(foutput, | 457 (void) fprintf(foutput, |
489 "%d entries saved by goto default\n", zzgobest); | 458 "%d entries saved by goto default\n", zzgobest); |
490 } 491 if (zzsrconf != 0 || zzrrconf != 0) { 492/* 493 * TRANSLATION_NOTE -- This is a message from yacc. 494 * You may just leave this message un-translated. 495 * This message only makes sense to those who knows 496 * how yacc works, and the person should know what 497 * this message means in English. 498 */ 499 (void) fprintf(stderr, gettext( | 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( |
500 "\nconflicts: ")); | 469 "\nconflicts: ")); |
501 if (zzsrconf) 502 (void) fprintf(stderr, "%d shift/reduce", zzsrconf); 503 if (zzsrconf && zzrrconf) 504 (void) fprintf(stderr, ", "); 505 if (zzrrconf) 506 (void) fprintf(stderr, "%d reduce/reduce", zzrrconf); 507 (void) fprintf(stderr, "\n"); 508 } --- 16 unchanged lines hidden (view full) --- 525 ++nerrors; 526 if (!lineno) 527/* 528 * TRANSLATION_NOTE -- This is a message from yacc. 529 * This message is a prefix to the error messages 530 * passed to error() function. 531 */ 532 (void) fprintf(stderr, gettext( | 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( |
533 "command line: fatal: ")); | 502 "command line: fatal: ")); |
534 else { 535 (void) fprintf(stderr, "\"%s\", ", infile); 536/* 537 * TRANSLATION_NOTE -- This is a message from yacc. 538 * This message is a prefix to the error messages 539 * passed to error() function. 540 */ 541 (void) fprintf(stderr, gettext( | 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( |
542 "line %d: fatal: "), 543 lineno); | 511 "line %d: fatal: "), 512 lineno); |
544 } 545 (void) vfprintf(stderr, s, ap); 546 (void) fprintf(stderr, "\n"); 547 va_end(ap); 548 if (!fatfl) 549 return; 550 summary(); 551 exit(1); --- 15 unchanged lines hidden (view full) --- 567 */ 568 if (flag == 0) 569/* 570 * TRANSLATION_NOTE -- This is a message from yacc. 571 * This message is a prefix to the warning messages 572 * passed to warning() function. 573 */ 574 (void) fprintf(stderr, gettext( | 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( |
575 "warning: ")); | 544 "warning: ")); |
576 else 577/* 578 * TRANSLATION_NOTE -- This is a message from yacc. 579 * This message is a prefix to the warning messages 580 * passed to warning() function. 581 */ 582 (void) fprintf(stderr, gettext( | 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( |
583 "line %d: warning: "), 584 lineno); | 552 "line %d: warning: "), 553 lineno); |
585 (void) vfprintf(stderr, s, ap); 586 (void) fprintf(stderr, "\n"); 587 va_end(ap); 588} 589 590/* set elements 0 through n-1 to c */ 591void 592aryfil(v, n, c) --- 89 unchanged lines hidden (view full) --- 682/* 683 * TRANSLATION_NOTE -- This is a message from yacc. 684 * This message is passed to error() function. 685 * Ask somebody who knows yacc how to translate nonterminal or 686 * look at translated yacc document. 687 */ 688 error(gettext( 689 "undefined nonterminal: %ws"), | 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"), |
690 nontrst[i].name); | 659 nontrst[i].name); |
691 } 692 } 693 pres[i] = ptrpy; 694 fatfl = 1; 695 if (nerrors) { 696 summary(); 697 exit(1); 698 } --- 4 unchanged lines hidden (view full) --- 703 * This is an internal error message. 704 * Very little use to user. You may leave it 705 * un-translated. 706 * 707 * pyied is name of an array. Do not translate it. 708 */ 709 error(gettext( 710 "internal Yacc error: pyield %d"), | 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"), |
711 ptrpy-&pyield[nprod]); | 680 ptrpy-&pyield[nprod]); |
712} 713 714static int indebug = 0; 715/* compute an array with the first of nonterminals */ 716static void 717cpfir() 718{ 719 int *p, **s, i, **t, ch, changes; --- 20 unchanged lines hidden (view full) --- 740 changes = 1; 741 while (changes) { 742 changes = 0; 743 NTLOOP(i) { 744 t = pres[i+1]; 745 for (s = pres[i]; s < t; ++s) { 746 for (p = *s; (ch = (*p-NTBASE)) >= 0; ++p) { 747 changes |= setunion(wsets[i].ws.lset, | 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, |
748 wsets[ch].ws.lset); | 717 wsets[ch].ws.lset); |
749 if (!pempty[ch]) 750 break; 751 } 752 } 753 } 754 } 755 756 NTLOOP(i) --- 32 unchanged lines hidden (view full) --- 789 ss = k->look; 790 k->look = l->look; 791 l->look = ss; 792 } 793 } 794 size1 = p2 - p1; /* size of state */ 795 796 for (i = (c >= NTBASE) ? ntstates[c-NTBASE] : tstates[c]; | 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]; |
797 i != 0; 798 i = mstates[i]) { | 766 i != 0; i = mstates[i]) { |
799 /* get ith state */ 800 q1 = pstate[i]; 801 q2 = pstate[i+1]; 802 size2 = q2 - q1; 803 if (size1 != size2) 804 continue; 805 k = p1; 806 for (l = q1; l < q2; l++) { --- 121 unchanged lines hidden (view full) --- 928 * TRANSLATION_NOTE -- This is a message from yacc. 929 * This message is passed to error() function. 930 * Ask somebody who knows yacc how to translate nonterminal or 931 * look at translated yacc document. Check how 'derive' is 932 * translated in these documents also. 933 */ 934 error(gettext( 935 "nonterminal %ws never derives any token string"), | 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"), |
936 nontrst[i].name); | 904 nontrst[i].name); |
937 } 938 } 939 940 if (nerrors) { 941 summary(); 942 exit(1); 943 } 944 --- 8 unchanged lines hidden (view full) --- 953 954 /* loop as long as we keep finding empty nonterminals */ 955 956again: 957 PLOOP(1, i) { 958 /* not known to be empty */ 959 if (pempty[*prdptr[i]-NTBASE] == WHOKNOWS) { 960 for (p = prdptr[i]+1; | 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; |
961 *p >= NTBASE && pempty[*p-NTBASE] == EMPTY; 962 ++p); | 929 *p >= NTBASE && pempty[*p-NTBASE] == EMPTY; ++p) 930 /* EMPTY */; |
963 /* we have a nontrivially empty nonterminal */ 964 if (*p < 0) { 965 pempty[*prdptr[i]-NTBASE] = EMPTY; 966 goto again; /* got one ... try for another */ 967 } 968 } 969 } 970} --- 52 unchanged lines hidden (view full) --- 1023 (void) state(c); /* register new state */ 1024 else temp1[c-NTBASE] = state(c); 1025 } 1026 if (gsdebug && (foutput != NULL)) { 1027 (void) fprintf(foutput, "%d: ", i); 1028 NTLOOP(j) { 1029 if (temp1[j]) 1030 (void) fprintf(foutput, | 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, |
1031 "%ws %d, ", nontrst[j].name, 1032 temp1[j]); | 999 "%ws %d, ", nontrst[j].name, 1000 temp1[j]); |
1033 } 1034 (void) fprintf(foutput, "\n"); 1035 } 1036 indgo[i] = apack(&temp1[1], nnonter - 1) - 1; 1037 goto more; /* we have done one goto; do some more */ 1038 } 1039 /* no more to do... stop */ 1040} --- 59 unchanged lines hidden (view full) --- 1100 while ((ch = *++pi) > 0) { 1101 /* terminal symbol */ 1102 if (ch < NTBASE) { 1103 SETBIT(clset.lset, ch); 1104 break; 1105 } 1106 /* nonterminal symbol */ 1107 (void) setunion(clset.lset, | 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, |
1108 pfirst[ch-NTBASE]->lset); | 1076 pfirst[ch-NTBASE]->lset); |
1109 if (!pempty[ch-NTBASE]) 1110 break; 1111 } 1112 if (ch <= 0) 1113 (void) setunion(clset.lset, | 1077 if (!pempty[ch-NTBASE]) 1078 break; 1079 } 1080 if (ch <= 0) 1081 (void) setunion(clset.lset, |
1114 v->ws.lset); | 1082 v->ws.lset); |
1115 } 1116 } 1117 1118 /* now loop over productions derived from c */ 1119 1120 c -= NTBASE; /* c is now nonterminal number */ 1121 1122 t = pres[c+1]; 1123 for (s = pres[c]; s < t; ++s) { 1124 /* put these items into the closure */ 1125 WSLOOP(wsets, v) { /* is the item there */ 1126 /* yes, it is there */ 1127 if (v->pitem == *s) { 1128 if (nolook) 1129 goto nexts; 1130 if (setunion(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, |
1131 clset.lset)) | 1099 clset.lset)) |
1132 v->flag = work = 1; 1133 goto nexts; 1134 } 1135 } 1136 1137 /* not there; make a new entry */ 1138 if (cwp + 1 >= wsetsz) 1139 exp_wsets(); 1140 1141 wsets[cwp].pitem = *s; 1142 wsets[cwp].flag = 1; 1143 if (!nolook) { 1144 work = 1; 1145 SETLOOP(k) 1146 wsets[cwp].ws.lset[k] = | 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] = |
1147 clset.lset[k]; | 1115 clset.lset[k]; |
1148 } 1149 WSBUMP(cwp); 1150 nexts:; 1151 } 1152 } 1153 } 1154 1155 /* have computed closure; flags are reset; return */ --- 49 unchanged lines hidden (view full) --- 1205exp_lkst() 1206{ 1207 int i, j; 1208 static LOOKSETS *lookbase; 1209 1210 lookbase = lkst; 1211 lsetsize += LSETSIZE; 1212 tmp_lset = (int *) | 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 *) |
1213 calloc((size_t)(TBITSET * (lsetsize-LSETSIZE)), sizeof (int)); | 1181 calloc((size_t)(TBITSET * (lsetsize-LSETSIZE)), sizeof (int)); |
1214 if (tmp_lset == NULL) 1215/* 1216 * TRANSLATION_NOTE -- This is a message from yacc. 1217 * This message is passed to error() function. 1218 * Memory allocation error. Do not translate lookset. 1219 * 1220 * You may just translate this as: 1221 * 'Could not allocate internally used memory.' --- 27 unchanged lines hidden (view full) --- 1249 1250static void 1251exp_wsets() 1252{ 1253 int i, j; 1254 1255 wsetsz += WSETSIZE; 1256 tmp_lset = (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 *) |
1257 calloc((size_t)(TBITSET * (wsetsz-WSETSIZE)), sizeof (int)); | 1225 calloc((size_t)(TBITSET * (wsetsz-WSETSIZE)), sizeof (int)); |
1258 if (tmp_lset == NULL) 1259/* 1260 * TRANSLATION_NOTE -- This is a message from yacc. 1261 * This message is passed to error() function. 1262 * Memory allocation error. Do not translate lookset. 1263 * 1264 * You may just translate this as: 1265 * 'Could not allocate internally used memory.' --- 19 unchanged lines hidden (view full) --- 1285} 1286 1287static void 1288exp_states() 1289{ 1290 nstatesz += NSTATES; 1291 1292 pstate = (ITEM **) | 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 **) |
1293 realloc((char *)pstate, sizeof (ITEM *)*(nstatesz+2)); | 1261 realloc((char *)pstate, sizeof (ITEM *)*(nstatesz+2)); |
1294 mstates = (int *)realloc((char *)mstates, sizeof (int)*nstatesz); 1295 defact = (int *)realloc((char *)defact, sizeof (int)*nstatesz); 1296 tystate = (int *)realloc((char *)tystate, sizeof (int)*nstatesz); 1297 indgo = (int *)realloc((char *)indgo, sizeof (int)*nstatesz); 1298 1299 if ((*pstate == NULL) || (tystate == NULL) || (defact == NULL) || | 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) || |
1300 (indgo == NULL) || (mstates == NULL)) | 1268 (indgo == NULL) || (mstates == NULL)) |
1301/* 1302 * TRANSLATION_NOTE -- This is a message from yacc. 1303 * This message is passed to error() function. 1304 * Memory allocation error. 1305 * 1306 * You may just translate this as: 1307 * 'Could not allocate internally used memory.' 1308 */ --- 28 unchanged lines hidden --- | 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 --- |