1 /* output from Ox version G1.04 */ 2 #line 1 "expr.Y" 3 #line 4 "expr.oxout.y" 4 %{ 5 #include <stdlib.h> 6 #include <string.h> 7 %} 8 #line 1 "expr.Y" 9 /* Y-file for translation of infix expressions to prefix and postfix */ 10 %token ID CONST 11 %start yyyAugNonterm 12 %left '+' '-' 13 %left '*' '/' 14 %nonassoc '*' 15 16 %{ 17 #include "expr.oxout.h" 18 #include <stdio.h> 19 20 extern int yylex(void); 21 extern void yyerror(const char *); 22 %} 23 24 #line 25 "expr.oxout.y" 25 26 %{ 27 #include <limits.h> 28 #define yyyR USHRT_MAX 29 %} 30 %type <yyyOxAttrbs> yyyAugNonterm 31 %union { 32 struct yyyOxAttrbs { 33 struct yyyStackItem *yyyOxStackItem; 34 } yyyOxAttrbs; 35 } 36 37 %{ 38 #include <stdio.h> 39 #include <stdarg.h> 40 41 static int yyyYok = 1; 42 43 extern yyyFT yyyRCIL[]; 44 45 void yyyExecuteRRsection(yyyGNT *rootNode); 46 void yyyYoxInit(void); 47 void yyyDecorate(void); 48 struct yyyOxAttrbs; /* hack required to compensate for 'msta' behavior */ 49 void yyyGenIntNode(long yyyProdNum, int yyyRHSlength, int yyyNattrbs, struct yyyOxAttrbs *yyval_OxAttrbs, ...); 50 void yyyAdjustINRC(long yyyProdNum, int yyyRHSlength, long startP, long stopP, struct yyyOxAttrbs *yyval_OxAttrbs, ...); 51 void yyyCheckUnsolvedInstTrav(yyyGNT *rootNode,long *nNZrc,long *cycleSum); 52 void yyyUnsolvedInstSearchTrav(yyyGNT *pNode); 53 void yyyUnsolvedInstSearchTravAux(yyyGNT *pNode); 54 void yyyabort(void); 55 56 %} 57 58 59 #line 20 "expr.Y" 60 %% 61 62 #line 63 "expr.oxout.y" 63 yyyAugNonterm 64 : {yyyYoxInit();} 65 s 66 { 67 yyyDecorate(); yyyExecuteRRsection($<yyyOxAttrbs>2.yyyOxStackItem->node); 68 } 69 ; 70 #line 21 "expr.Y" 71 s : expr 72 #line 73 "expr.oxout.y" 73 {if(yyyYok){ 74 yyyGenIntNode(1,1,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1); 75 yyyAdjustINRC(1,1,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1);}} 76 77 #line 27 "expr.Y" 78 expr : expr '*' expr 79 #line 80 "expr.oxout.y" 80 {if(yyyYok){ 81 yyyGenIntNode(2,3,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3); 82 yyyAdjustINRC(2,3,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3);}} 83 84 #line 31 "expr.Y" 85 | expr '+' expr 86 #line 87 "expr.oxout.y" 87 {if(yyyYok){ 88 yyyGenIntNode(3,3,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3); 89 yyyAdjustINRC(3,3,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3);}} 90 91 #line 35 "expr.Y" 92 | expr '/' expr 93 #line 94 "expr.oxout.y" 94 {if(yyyYok){ 95 yyyGenIntNode(4,3,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3); 96 yyyAdjustINRC(4,3,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3);}} 97 98 #line 39 "expr.Y" 99 | expr '-' expr 100 #line 101 "expr.oxout.y" 101 {if(yyyYok){ 102 yyyGenIntNode(5,3,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3); 103 yyyAdjustINRC(5,3,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3);}} 104 105 #line 43 "expr.Y" 106 | '(' expr ')' 107 #line 108 "expr.oxout.y" 108 {if(yyyYok){ 109 yyyGenIntNode(6,3,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3); 110 yyyAdjustINRC(6,3,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1,&$<yyyOxAttrbs>2,&$<yyyOxAttrbs>3);}} 111 #line 44 "expr.Y" 112 | ID 113 #line 114 "expr.oxout.y" 114 {if(yyyYok){ 115 yyyGenIntNode(7,1,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1); 116 yyyAdjustINRC(7,1,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1);}} 117 118 #line 48 "expr.Y" 119 | CONST 120 #line 121 "expr.oxout.y" 121 {if(yyyYok){ 122 yyyGenIntNode(8,1,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1); 123 yyyAdjustINRC(8,1,0,0,&$<yyyOxAttrbs>$,&$<yyyOxAttrbs>1);}} 124 125 #line 52 "expr.Y" 126 ; 127 %% 128 129 int yyparse(void); 130 131 int main() 132 {yyparse(); 133 } 134 135 136 137 #line 138 "expr.oxout.y" 138 long yyySSALspaceSize = 20000; 139 long yyyRSmaxSize = 1000; 140 long yyyTravStackMaxSize = 2000; 141 142 struct yyySolvedSAlistCell {yyyWAT attrbNum; 143 long next; 144 }; 145 146 #define yyyLambdaSSAL 0 147 long yyySSALCfreeList = yyyLambdaSSAL; 148 long yyyNewSSALC = 1; 149 150 struct yyySolvedSAlistCell *yyySSALspace; 151 152 long yyyNbytesStackStg; 153 154 155 156 yyyFT yyyRCIL[1]; 157 158 short yyyIIIEL[] = {0, 159 0,2,6,10,14,18,22,24, 160 }; 161 162 long yyyIIEL[] = { 163 0,0,0,0,0,0,0,0,0,0,0,0, 164 0,0,0,0,0,0,0,0,0,0,0,0, 165 1,1, 166 }; 167 168 long yyyIEL[] = { 169 0,0,0, 170 }; 171 172 yyyFT yyyEntL[1]; 173 174 void yyyfatal(char *msg) 175 {fputs(msg,stderr);exit(-1);} 176 177 178 179 #define yyySSALof 'S' 180 #define yyyRSof 'q' 181 #define yyyTSof 't' 182 183 184 185 void yyyHandleOverflow(char which) 186 {char *msg1 = "?", *msg2; 187 long oldSize = 0, newSize; 188 switch(which) 189 { 190 case yyySSALof : 191 msg1 = "SSAL overflow: "; 192 oldSize = yyySSALspaceSize; 193 break; 194 case yyyRSof : 195 msg1 = "ready set overflow: "; 196 oldSize = yyyRSmaxSize; 197 break; 198 case yyyTSof : 199 msg1 = "traversal stack overflow: "; 200 oldSize = yyyTravStackMaxSize; 201 break; 202 default :; 203 } 204 newSize = (3*oldSize)/2; 205 if (newSize < 100) newSize = 100; 206 fputs(msg1,stderr); 207 fprintf(stderr,"size was %ld.\n",oldSize); 208 msg2 = " Have to modify evaluator: -Y%c%ld.\n"; 209 fprintf(stderr,msg2,which,newSize); 210 exit(-1); 211 } 212 213 214 215 void yyySignalEnts(yyyGNT *node,long startP,long stopP) 216 {yyyGNT *dumNode; 217 218 while (startP < stopP) 219 { 220 if (!yyyEntL[startP]) dumNode = node; 221 else dumNode = (node->cL)[yyyEntL[startP]-1]; 222 if (!(--((dumNode->refCountList)[yyyEntL[startP+1]] 223 ) 224 ) 225 ) 226 { 227 if (++yyyRSTop == yyyAfterRS) 228 {yyyHandleOverflow(yyyRSof); 229 break; 230 } 231 yyyRSTop->node = dumNode; 232 yyyRSTop->whichSym = yyyEntL[startP]; 233 yyyRSTop->wa = yyyEntL[startP+1]; 234 } 235 startP += 2; 236 } 237 } 238 239 240 241 242 243 244 void yyySolveAndSignal() { 245 long yyyiDum,*yyypL; 246 int yyyws,yyywa; 247 yyyGNT *yyyRSTopN,*yyyRefN; 248 yyyParent yyyRSTopNp; 249 250 251 yyyRSTopNp = (yyyRSTopN = yyyRSTop->node)->parent; 252 yyyRefN= (yyyws = (yyyRSTop->whichSym))?yyyRSTopNp.noderef:yyyRSTopN; 253 yyywa = yyyRSTop->wa; 254 yyyRSTop--; 255 switch(yyyRefN->prodNum) { 256 case 1: /***yacc rule 1***/ 257 switch (yyyws) { 258 } 259 break; 260 case 2: /***yacc rule 2***/ 261 switch (yyyws) { 262 } 263 break; 264 case 3: /***yacc rule 3***/ 265 switch (yyyws) { 266 } 267 break; 268 case 4: /***yacc rule 4***/ 269 switch (yyyws) { 270 } 271 break; 272 case 5: /***yacc rule 5***/ 273 switch (yyyws) { 274 } 275 break; 276 case 6: /***yacc rule 6***/ 277 switch (yyyws) { 278 } 279 break; 280 case 7: /***yacc rule 7***/ 281 switch (yyyws) { 282 case 1: /**/ 283 switch (yyywa) { 284 } 285 break; 286 } 287 break; 288 case 8: /***yacc rule 8***/ 289 switch (yyyws) { 290 case 1: /**/ 291 switch (yyywa) { 292 } 293 break; 294 } 295 break; 296 } /* switch */ 297 298 if (yyyws) /* the just-solved instance was inherited. */ 299 {if (yyyRSTopN->prodNum) 300 {yyyiDum = yyyIIEL[yyyIIIEL[yyyRSTopN->prodNum]] + yyywa; 301 yyySignalEnts(yyyRSTopN,yyyIEL[yyyiDum], 302 yyyIEL[yyyiDum+1] 303 ); 304 } 305 } 306 else /* the just-solved instance was synthesized. */ 307 {if (!(yyyRSTopN->parentIsStack)) /* node has a parent. */ 308 {yyyiDum = yyyIIEL[yyyIIIEL[yyyRSTopNp.noderef->prodNum] + 309 yyyRSTopN->whichSym 310 ] + 311 yyywa; 312 yyySignalEnts(yyyRSTopNp.noderef, 313 yyyIEL[yyyiDum], 314 yyyIEL[yyyiDum+1] 315 ); 316 } 317 else /* node is still on the stack--it has no parent yet. */ 318 {yyypL = &(yyyRSTopNp.stackref->solvedSAlist); 319 if (yyySSALCfreeList == yyyLambdaSSAL) 320 {yyySSALspace[yyyNewSSALC].next = *yyypL; 321 if ((*yyypL = yyyNewSSALC++) == yyySSALspaceSize) 322 yyyHandleOverflow(yyySSALof); 323 } 324 else 325 {yyyiDum = yyySSALCfreeList; 326 yyySSALCfreeList = yyySSALspace[yyySSALCfreeList].next; 327 yyySSALspace[yyyiDum].next = *yyypL; 328 *yyypL = yyyiDum; 329 } 330 yyySSALspace[*yyypL].attrbNum = yyywa; 331 } 332 } 333 334 } /* yyySolveAndSignal */ 335 336 337 338 339 340 341 #define condStg unsigned int conds; 342 #define yyyClearConds {yyyTST->conds = 0;} 343 #define yyySetCond(n) {yyyTST->conds += (1<<(n));} 344 #define yyyCond(n) ((yyyTST->conds & (1<<(n)))?1:0) 345 346 347 348 struct yyyTravStackItem {yyyGNT *node; 349 char isReady; 350 condStg 351 }; 352 353 354 355 void yyyDoTraversals(yyyGNT *rootNode) 356 {struct yyyTravStackItem *yyyTravStack,*yyyTST,*yyyAfterTravStack; 357 yyyGNT *yyyTSTn,**yyyCLptr2; 358 int yyyi,yyyRL,yyyPass; 359 int i; 360 361 if (!yyyYok) return; 362 if ((yyyTravStack = 363 ((struct yyyTravStackItem *) 364 calloc((size_t)yyyTravStackMaxSize, 365 (size_t)sizeof(struct yyyTravStackItem) 366 ) 367 ) 368 ) 369 == 370 (struct yyyTravStackItem *)NULL 371 ) 372 {fputs("malloc error in traversal stack allocation\n",stderr); 373 exit(-1); 374 } 375 376 yyyAfterTravStack = yyyTravStack + yyyTravStackMaxSize; 377 yyyTravStack++; 378 379 380 for (yyyi=0; yyyi<2; yyyi++) { 381 yyyTST = yyyTravStack; 382 yyyTST->node = rootNode; 383 yyyTST->isReady = 0; 384 yyyClearConds 385 386 while(yyyTST >= yyyTravStack) 387 {yyyTSTn = yyyTST->node; 388 if (yyyTST->isReady) 389 {yyyPass = 1; 390 goto yyyTravSwitch; 391 yyyTpop: 392 yyyTST--; 393 } 394 else 395 {yyyPass = 0; 396 goto yyyTravSwitch; 397 yyyTpush: 398 yyyTST->isReady = 1; 399 if (yyyTSTn->prodNum) 400 {if (yyyRL) 401 {yyyCLptr2 = yyyTSTn->cL; 402 i = yyyTSTn->cLlen; 403 while (i--) 404 {if (++yyyTST == yyyAfterTravStack) 405 yyyHandleOverflow(yyyTSof); 406 else 407 {yyyTST->node = *yyyCLptr2; 408 yyyTST->isReady = 0; 409 yyyClearConds 410 } 411 yyyCLptr2++; 412 } 413 } /* right to left */ 414 else /* left to right */ 415 {i = yyyTSTn->cLlen; 416 yyyCLptr2 = yyyTSTn->cL + i; 417 while (i--) 418 {yyyCLptr2--; 419 if (++yyyTST == yyyAfterTravStack) 420 yyyHandleOverflow(yyyTSof); 421 else 422 {yyyTST->node = *yyyCLptr2; 423 yyyTST->isReady = 0; 424 yyyClearConds 425 } 426 } 427 } /* left to right */ 428 } 429 } /* else */ 430 continue; 431 yyyTravSwitch: 432 switch(yyyTSTn->prodNum) { 433 case 1: 434 switch(yyyi) { 435 case 0: 436 switch(yyyPass) { 437 case 0: 438 yyyRL = 0;yyySetCond(0) 439 440 if (! 441 #line 24 "expr.Y" 442 (1) 443 #line 444 "expr.oxout.y" 444 ) yyySetCond(1) 445 yyySetCond(2) 446 447 case 1: 448 449 if (yyyCond(0) != yyyPass) { 450 #line 24 "expr.Y" 451 452 #line 453 "expr.oxout.y" 453 } 454 if (yyyCond(1) != yyyPass) { 455 #line 24 "expr.Y" 456 printf("\n"); 457 458 #line 459 "expr.oxout.y" 459 } 460 if (yyyCond(2) != yyyPass) { 461 #line 25 "expr.Y" 462 printf("prefix: "); 463 464 #line 465 "expr.oxout.y" 465 } 466 break; 467 } 468 break; 469 case 1: 470 switch(yyyPass) { 471 case 0: 472 yyyRL = 0; 473 if ( 474 #line 23 "expr.Y" 475 (1) 476 #line 477 "expr.oxout.y" 477 ) yyySetCond(2) 478 479 case 1: 480 481 if (yyyCond(0) != yyyPass) { 482 #line 22 "expr.Y" 483 printf("\n"); 484 485 #line 486 "expr.oxout.y" 486 } 487 if (yyyCond(1) != yyyPass) { 488 #line 23 "expr.Y" 489 490 #line 491 "expr.oxout.y" 491 } 492 if (yyyCond(2) != yyyPass) { 493 #line 23 "expr.Y" 494 printf("postfix: "); 495 496 #line 497 "expr.oxout.y" 497 } 498 break; 499 } 500 break; 501 } 502 503 break; 504 case 2: 505 switch(yyyi) { 506 case 0: 507 switch(yyyPass) { 508 case 0: 509 yyyRL = 0;yyySetCond(0) 510 511 case 1: 512 513 if (yyyCond(0) != yyyPass) { 514 #line 29 "expr.Y" 515 printf(" * "); 516 517 #line 518 "expr.oxout.y" 518 } 519 break; 520 } 521 break; 522 case 1: 523 switch(yyyPass) { 524 case 0: 525 yyyRL = 0; 526 case 1: 527 528 if (yyyCond(0) != yyyPass) { 529 #line 28 "expr.Y" 530 printf(" * "); 531 532 #line 533 "expr.oxout.y" 533 } 534 break; 535 } 536 break; 537 } 538 539 break; 540 case 3: 541 switch(yyyi) { 542 case 0: 543 switch(yyyPass) { 544 case 0: 545 yyyRL = 0;yyySetCond(0) 546 547 case 1: 548 549 if (yyyCond(0) != yyyPass) { 550 #line 32 "expr.Y" 551 printf(" + "); 552 553 #line 554 "expr.oxout.y" 554 } 555 break; 556 } 557 break; 558 case 1: 559 switch(yyyPass) { 560 case 0: 561 yyyRL = 0; 562 case 1: 563 564 if (yyyCond(0) != yyyPass) { 565 #line 33 "expr.Y" 566 printf(" + "); 567 568 #line 569 "expr.oxout.y" 569 } 570 break; 571 } 572 break; 573 } 574 575 break; 576 case 4: 577 switch(yyyi) { 578 case 0: 579 switch(yyyPass) { 580 case 0: 581 yyyRL = 0;yyySetCond(0) 582 583 case 1: 584 585 if (yyyCond(0) != yyyPass) { 586 #line 37 "expr.Y" 587 printf(" / "); 588 589 #line 590 "expr.oxout.y" 590 } 591 break; 592 } 593 break; 594 case 1: 595 switch(yyyPass) { 596 case 0: 597 yyyRL = 0; 598 case 1: 599 600 if (yyyCond(0) != yyyPass) { 601 #line 36 "expr.Y" 602 printf(" / "); 603 604 #line 605 "expr.oxout.y" 605 } 606 break; 607 } 608 break; 609 } 610 611 break; 612 case 5: 613 switch(yyyi) { 614 case 0: 615 switch(yyyPass) { 616 case 0: 617 yyyRL = 0;yyySetCond(0) 618 619 case 1: 620 621 if (yyyCond(0) != yyyPass) { 622 #line 41 "expr.Y" 623 printf(" - "); 624 625 #line 626 "expr.oxout.y" 626 } 627 break; 628 } 629 break; 630 case 1: 631 switch(yyyPass) { 632 case 0: 633 yyyRL = 0; 634 case 1: 635 636 if (yyyCond(0) != yyyPass) { 637 #line 40 "expr.Y" 638 printf(" - "); 639 640 #line 641 "expr.oxout.y" 641 } 642 break; 643 } 644 break; 645 } 646 647 break; 648 case 6: 649 switch(yyyi) { 650 case 0: 651 switch(yyyPass) { 652 case 0: 653 yyyRL = 0; 654 case 1: 655 656 break; 657 } 658 break; 659 case 1: 660 switch(yyyPass) { 661 case 0: 662 yyyRL = 0; 663 case 1: 664 665 break; 666 } 667 break; 668 } 669 670 break; 671 case 7: 672 switch(yyyi) { 673 case 0: 674 switch(yyyPass) { 675 case 0: 676 yyyRL = 0;yyySetCond(0) 677 678 case 1: 679 680 if (yyyCond(0) != yyyPass) { 681 #line 46 "expr.Y" 682 printf(" %s ",yyyTSTn->cL[0]->yyyAttrbs.yyyAttrb1.lexeme); 683 684 #line 685 "expr.oxout.y" 685 } 686 break; 687 } 688 break; 689 case 1: 690 switch(yyyPass) { 691 case 0: 692 yyyRL = 0; 693 case 1: 694 695 if (yyyCond(0) != yyyPass) { 696 #line 45 "expr.Y" 697 printf(" %s ",yyyTSTn->cL[0]->yyyAttrbs.yyyAttrb1.lexeme); 698 699 #line 700 "expr.oxout.y" 700 } 701 break; 702 } 703 break; 704 } 705 706 break; 707 case 8: 708 switch(yyyi) { 709 case 0: 710 switch(yyyPass) { 711 case 0: 712 yyyRL = 0;yyySetCond(0) 713 714 case 1: 715 716 if (yyyCond(0) != yyyPass) { 717 #line 50 "expr.Y" 718 printf(" %s ",yyyTSTn->cL[0]->yyyAttrbs.yyyAttrb1.lexeme); 719 720 #line 721 "expr.oxout.y" 721 } 722 break; 723 } 724 break; 725 case 1: 726 switch(yyyPass) { 727 case 0: 728 yyyRL = 0; 729 case 1: 730 731 if (yyyCond(0) != yyyPass) { 732 #line 49 "expr.Y" 733 printf(" %s ",yyyTSTn->cL[0]->yyyAttrbs.yyyAttrb1.lexeme); 734 735 #line 736 "expr.oxout.y" 736 } 737 break; 738 } 739 break; 740 } 741 742 break; 743 } /* switch */ 744 if (yyyPass) goto yyyTpop; else goto yyyTpush; 745 } /* while */ 746 } /* for */ 747 } /* yyyDoTraversals */ 748 749 void yyyExecuteRRsection(yyyGNT *rootNode) { 750 int yyyi; 751 long cycleSum = 0; 752 long nNZrc = 0; 753 754 if (!yyyYok) return; 755 yyyCheckUnsolvedInstTrav(rootNode,&nNZrc,&cycleSum); 756 if (nNZrc) 757 { 758 fputs("\n\n\n**********\n",stderr); 759 fputs("cycle detected in completed parse tree",stderr); 760 fputs(" after decoration.\n",stderr); 761 #if CYCLE_VERBOSE 762 fprintf(stderr, 763 "number of unsolved attribute instances == %ld.\n", 764 nNZrc 765 ); 766 fprintf(stderr, 767 "total number of remaining dependencies == %ld.\n", 768 cycleSum 769 ); 770 fputs("average number of remaining dependencies\n",stderr); 771 fprintf(stderr," per unsolved instance == %f.\n", 772 ((float)(cycleSum)/(float)(nNZrc)) 773 ); 774 #endif 775 fprintf(stderr, 776 "searching parse tree for %ld unsolved instances:\n", 777 nNZrc 778 ); 779 yyyUnsolvedInstSearchTravAux(rootNode); 780 } 781 yyyDoTraversals(rootNode); 782 } /* yyyExecuteRRsection */ 783 784 785 786 yyyWAT yyyLRCIL[2] = {0,0, 787 }; 788 789 790 791 void yyyYoxInit(void) 792 { 793 static int yyyInitDone = 0; 794 if (yyyInitDone) return; 795 796 if ((yyyRS = (yyyRSitem *) 797 calloc((size_t)(yyyRSmaxSize+1), (size_t)sizeof(yyyRSitem)) 798 ) 799 == 800 ((yyyRSitem *) NULL) 801 ) 802 yyyfatal("malloc error in ox ready set space allocation\n"); 803 yyyRS++; 804 yyyAfterRS = yyyRS + yyyRSmaxSize; 805 806 807 if ((yyySSALspace = (struct yyySolvedSAlistCell *) 808 calloc((size_t)(yyySSALspaceSize+1), (size_t)sizeof(struct yyySolvedSAlistCell)) 809 ) 810 == 811 ((struct yyySolvedSAlistCell *) NULL) 812 ) 813 yyyfatal("malloc error in stack solved list space allocation\n"); 814 yyyInitDone = 1; 815 816 yyyRSTop = yyyRS - 1; 817 } /* yyyYoxInit */ 818 819 820 821 void yyyDecorate(void) 822 { 823 while (yyyRSTop >= yyyRS) 824 yyySolveAndSignal(); 825 } 826 827 828 829 void yyyGenIntNode(long yyyProdNum, int yyyRHSlength, int yyyNattrbs, struct yyyOxAttrbs *yyval_OxAttrbs, ...) 830 {yyyWST i; 831 yyySIT **yyyOxStackItem = &yyval_OxAttrbs->yyyOxStackItem; 832 yyyGNT *gnpDum; 833 va_list ap; 834 835 *yyyOxStackItem = (yyySIT *) malloc((size_t)sizeof(yyySIT)); 836 if (*yyyOxStackItem == (yyySIT *) NULL) 837 yyyfatal("malloc error in ox yacc semantic stack space allocation\n"); 838 (*yyyOxStackItem)->node = 839 (yyyGNT *) malloc((size_t)sizeof(yyyGNT)); 840 if ((*yyyOxStackItem)->node == (yyyGNT *) NULL) 841 yyyfatal("malloc error in ox node space allocation\n"); 842 (*yyyOxStackItem)->solvedSAlist = yyyLambdaSSAL; 843 (*yyyOxStackItem)->node->parent.stackref = *yyyOxStackItem; 844 (*yyyOxStackItem)->node->parentIsStack = 1; 845 (*yyyOxStackItem)->node->cLlen = yyyRHSlength; 846 (*yyyOxStackItem)->node->cL = 847 (yyyGNT **) calloc((size_t)yyyRHSlength, (size_t)sizeof(yyyGNT *)); 848 if ((*yyyOxStackItem)->node->cL == (yyyGNT **) NULL) 849 yyyfatal("malloc error in ox child list space allocation\n"); 850 (*yyyOxStackItem)->node->refCountListLen = yyyNattrbs; 851 (*yyyOxStackItem)->node->refCountList = 852 (yyyRCT *) calloc((size_t)yyyNattrbs, (size_t)sizeof(yyyRCT)); 853 if ((*yyyOxStackItem)->node->refCountList == (yyyRCT *) NULL) 854 yyyfatal("malloc error in ox reference count list space allocation\n"); 855 (*yyyOxStackItem)->node->prodNum = (int) yyyProdNum; 856 va_start(ap, yyval_OxAttrbs); 857 for (i=1;i<=yyyRHSlength;i++) 858 {yyySIT *yaccStDum = va_arg(ap,struct yyyOxAttrbs *)->yyyOxStackItem; 859 gnpDum = (*yyyOxStackItem)->node->cL[i-1] = yaccStDum->node; 860 gnpDum->whichSym = i; 861 gnpDum->parent.noderef = (*yyyOxStackItem)->node; 862 gnpDum->parentIsStack = 0; 863 } 864 va_end(ap); 865 } 866 867 868 869 #define yyyDECORfREQ 50 870 871 872 873 void yyyAdjustINRC(long yyyProdNum, int yyyRHSlength, long startP, long stopP, struct yyyOxAttrbs *yyval_OxAttrbs, ...) 874 {yyyWST i; 875 yyySIT *yyyOxStackItem = yyval_OxAttrbs->yyyOxStackItem; 876 long SSALptr,SSALptrHead,*cPtrPtr; 877 long *pL; 878 yyyGNT *gnpDum; 879 long iTemp; 880 long nextP; 881 static unsigned short intNodeCount = yyyDECORfREQ; 882 va_list ap; 883 884 nextP = startP; 885 while (nextP < stopP) 886 {if (yyyRCIL[nextP] == yyyR) 887 {(yyyOxStackItem->node->refCountList)[yyyRCIL[nextP+1]] = yyyRCIL[nextP+2]; 888 } 889 else 890 {(((yyyOxStackItem->node->cL)[yyyRCIL[nextP]])->refCountList)[yyyRCIL[nextP+1]] = yyyRCIL[nextP+2]; 891 } 892 nextP += 3; 893 } 894 pL = yyyIIEL + yyyIIIEL[yyyProdNum]; 895 va_start(ap, yyval_OxAttrbs); 896 for (i=1;i<=yyyRHSlength;i++) 897 {yyySIT *yaccStDum = va_arg(ap,struct yyyOxAttrbs *)->yyyOxStackItem; 898 pL++; 899 SSALptrHead = SSALptr = *(cPtrPtr = &(yaccStDum->solvedSAlist)); 900 if (SSALptr != yyyLambdaSSAL) 901 {*cPtrPtr = yyyLambdaSSAL; 902 do 903 { 904 iTemp = (*pL+yyySSALspace[SSALptr].attrbNum); 905 yyySignalEnts(yyyOxStackItem->node, 906 yyyIEL[iTemp], 907 yyyIEL[iTemp+1] 908 ); 909 SSALptr = *(cPtrPtr = &(yyySSALspace[SSALptr].next)); 910 } 911 while (SSALptr != yyyLambdaSSAL); 912 *cPtrPtr = yyySSALCfreeList; 913 yyySSALCfreeList = SSALptrHead; 914 } 915 } 916 va_end(ap); 917 nextP = startP + 2; 918 while (nextP < stopP) 919 {if (!yyyRCIL[nextP]) 920 {if (yyyRCIL[nextP-2] == yyyR) 921 {pL = &(yyyOxStackItem->solvedSAlist); 922 if (yyySSALCfreeList == yyyLambdaSSAL) 923 {yyySSALspace[yyyNewSSALC].next = *pL; 924 if ((*pL = yyyNewSSALC++) == yyySSALspaceSize) 925 yyyHandleOverflow(yyySSALof); 926 } 927 else 928 {iTemp = yyySSALCfreeList; 929 yyySSALCfreeList = yyySSALspace[yyySSALCfreeList].next; 930 yyySSALspace[iTemp].next = *pL; 931 *pL = iTemp; 932 } 933 yyySSALspace[*pL].attrbNum = yyyRCIL[nextP-1]; 934 } 935 else 936 {if ((gnpDum = (yyyOxStackItem->node->cL)[yyyRCIL[nextP-2]])->prodNum != 0) 937 { 938 iTemp = yyyIIEL[yyyIIIEL[gnpDum->prodNum]] + yyyRCIL[nextP-1]; 939 yyySignalEnts(gnpDum, 940 yyyIEL[iTemp], 941 yyyIEL[iTemp+1] 942 ); 943 } 944 } 945 } 946 nextP += 3; 947 } 948 if (!--intNodeCount) 949 {intNodeCount = yyyDECORfREQ; 950 yyyDecorate(); 951 } 952 } 953 954 955 956 void yyyGenLeaf(int nAttrbs,int typeNum,long startP,long stopP,YYSTYPE *mylval) 957 {yyyRCT *rcPdum; 958 yyySIT **yyyOxStackItem = &mylval->yyyOxAttrbs.yyyOxStackItem; 959 (*yyyOxStackItem) = (yyySIT *) malloc((size_t)sizeof(yyySIT)); 960 if ((*yyyOxStackItem) == (yyySIT *) NULL) 961 yyyfatal("malloc error in ox yacc semantic stack space allocation\n"); 962 (*yyyOxStackItem)->node = 963 (yyyGNT *) malloc((size_t)sizeof(yyyGNT)) 964 ; 965 if ((*yyyOxStackItem)->node == (yyyGNT *) NULL) 966 yyyfatal("malloc error in ox node space allocation\n"); 967 (*yyyOxStackItem)->solvedSAlist = yyyLambdaSSAL; 968 (*yyyOxStackItem)->node->parent.stackref = *yyyOxStackItem; 969 (*yyyOxStackItem)->node->parentIsStack = 1; 970 (*yyyOxStackItem)->node->cLlen = 0; 971 (*yyyOxStackItem)->node->cL = (yyyGNT **)NULL; 972 (*yyyOxStackItem)->node->refCountListLen = nAttrbs; 973 rcPdum = (*yyyOxStackItem)->node->refCountList = 974 (yyyRCT *) calloc((size_t)nAttrbs, (size_t)sizeof(yyyRCT)); 975 if (rcPdum == (yyyRCT *) NULL) 976 yyyfatal("malloc error in ox reference count list space allocation\n"); 977 while (startP < stopP) rcPdum[yyyLRCIL[startP++]] = 0; 978 (*yyyOxStackItem)->node->prodNum = 0; 979 (*yyyOxStackItem)->node->whichSym = 0; 980 } 981 982 983 984 void yyyabort(void) 985 {yyyYok = 0; 986 } 987 988 989 990 991 992 #define yyyLastProdNum 8 993 994 995 #define yyyNsorts 1 996 997 998 int yyyProdsInd[] = { 999 0, 1000 0, 2, 6, 10, 14, 18, 22, 24, 1001 26, 1002 }; 1003 1004 1005 int yyyProds[][2] = { 1006 { 116, 0},{ 462, 0},{ 462, 0},{ 462, 0},{ 412, 0}, 1007 { 462, 0},{ 462, 0},{ 462, 0},{ 420, 0},{ 462, 0}, 1008 { 462, 0},{ 462, 0},{ 452, 0},{ 462, 0},{ 462, 0}, 1009 { 462, 0},{ 436, 0},{ 462, 0},{ 462, 0},{ 396, 0}, 1010 { 462, 0},{ 404, 0},{ 462, 0},{ 619, 1},{ 462, 0}, 1011 { 567, 1}, 1012 }; 1013 1014 1015 int yyySortsInd[] = { 1016 0, 1017 0, 1018 1, 1019 }; 1020 1021 1022 int yyySorts[] = { 1023 413, 1024 }; 1025 1026 1027 1028 char *yyyStringTab[] = { 1029 0,0,0,0,0, 1030 0,0,0,0,0, 1031 0,0,0,0,0, 1032 0,0,0,0,0, 1033 0,0,0,0,0, 1034 0,0,0,0,0, 1035 0,0,0,0,0, 1036 0,0,0,0,0, 1037 0,0,0,0,0, 1038 0,0,0,0,0, 1039 0,0,0,0,0, 1040 0,0,0,0,0, 1041 0,0,0,0,0, 1042 0,0,0,0,0, 1043 0,0,0,0,0, 1044 0,0,0,0,0, 1045 0,0,0,0,0, 1046 0,0,0,0,0, 1047 0,0,0,0,0, 1048 0,0,0,0,0, 1049 0,0,0,0,0, 1050 0,0,0,0,0, 1051 0,0,0,0,0, 1052 0,"s",0,0,0, 1053 0,0,"y",0,0, 1054 0,0,0,0,0, 1055 0,0,0,0,0, 1056 0,0,0,0,0, 1057 0,0,0,0,0, 1058 0,0,0,0,0, 1059 0,0,0,0,0, 1060 0,0,0,0,0, 1061 0,0,0,0,0, 1062 0,0,0,0,0, 1063 0,0,0,0,0, 1064 0,0,0,0,0, 1065 0,0,0,0,0, 1066 0,0,0,0,0, 1067 0,0,0,0,0, 1068 0,0,0,0,0, 1069 0,0,0,0,0, 1070 0,0,0,0,0, 1071 0,0,0,0,0, 1072 0,0,0,0,0, 1073 0,0,0,0,0, 1074 0,0,0,0,0, 1075 0,0,0,0,0, 1076 0,0,0,0,0, 1077 0,0,0,0,0, 1078 0,0,0,0,0, 1079 0,0,0,0,0, 1080 0,0,0,0,0, 1081 0,0,0,0,0, 1082 0,0,0,0,0, 1083 0,0,0,0,0, 1084 0,0,0,0,0, 1085 0,0,0,0,0, 1086 0,0,0,0,0, 1087 0,0,0,0,0, 1088 0,0,0,0,0, 1089 0,0,0,0,0, 1090 0,0,0,0,0, 1091 0,0,0,0,0, 1092 0,0,0,0,0, 1093 0,0,0,0,0, 1094 0,"LRpre",0,0,0, 1095 0,0,0,0,0, 1096 0,0,0,0,0, 1097 0,0,0,0,0, 1098 0,0,0,0,0, 1099 0,0,0,0,0, 1100 0,0,0,0,0, 1101 0,0,0,0,0, 1102 0,0,0,0,0, 1103 0,0,0,0,0, 1104 0,0,0,0,0, 1105 0,0,0,0,0, 1106 0,0,0,0,0, 1107 0,0,0,0,0, 1108 0,"'('",0,0,0, 1109 0,0,0,0,"')'", 1110 0,0,0,0,0, 1111 0,0,"'*'","lexeme",0, 1112 0,0,0,0,0, 1113 "'+'",0,0,0,0, 1114 0,0,0,0,0, 1115 0,0,0,0,0, 1116 0,"'-'",0,0,0, 1117 0,0,0,0,0, 1118 0,0,0,0,0, 1119 0,0,"'/'",0,0, 1120 0,0,0,0,0, 1121 0,0,"expr",0,0, 1122 0,0,0,0,0, 1123 0,0,0,0,0, 1124 0,"printf",0,0,0, 1125 0,0,0,0,0, 1126 0,0,0,0,0, 1127 0,0,0,0,0, 1128 0,0,0,0,0, 1129 0,0,0,0,0, 1130 0,0,0,0,0, 1131 0,0,0,0,0, 1132 0,0,0,0,0, 1133 0,0,0,0,0, 1134 0,0,0,0,0, 1135 0,0,0,0,0, 1136 0,0,0,0,0, 1137 0,0,0,0,0, 1138 0,0,0,0,0, 1139 0,0,0,0,0, 1140 0,0,0,0,0, 1141 0,0,0,0,0, 1142 0,0,"CONST","LRpost",0, 1143 0,0,0,0,0, 1144 0,0,0,0,0, 1145 0,0,0,0,0, 1146 0,0,0,0,0, 1147 0,0,0,0,0, 1148 0,0,0,0,0, 1149 0,0,0,0,0, 1150 0,0,0,0,0, 1151 0,0,0,0,0, 1152 0,0,0,0,"ID", 1153 0,0,0,0,0, 1154 0,0,0,0,0, 1155 0,0,0,0,0, 1156 0,0,0,0,0, 1157 0,0,0,0,0, 1158 0,0,0,0,0, 1159 0,0,0,0,0, 1160 0,0,0,0,0, 1161 0,0,0,0,0, 1162 0,0,0,0,0, 1163 0,0,0,0,0, 1164 0,0,0,0,0, 1165 0,0,0,0,0, 1166 0,0,0,0,0, 1167 0,0,0,0,0, 1168 0,0,0,0,0, 1169 0,0,0,0,0, 1170 0,0,0,0,0, 1171 0,0,0,0,0, 1172 0,0,0,0,0, 1173 0,0,0,0,0, 1174 0,0,0,0,0, 1175 0,0,0,0,0, 1176 0,0,0,0,0, 1177 0,0,0,0,0, 1178 0,0,0,0,0, 1179 0,0,0,0,0, 1180 0,0,0,0,0, 1181 0,0,0,0,0, 1182 0,0,0,0,0, 1183 0,0,0,0,0, 1184 0,0,0,0,0, 1185 0,0,0,0,0, 1186 0,0,0,0,0, 1187 0,0,0,0,0, 1188 0,0,0,0,0, 1189 0,0,0,0,0, 1190 0,0,0,0,0, 1191 0,0,0,0,0, 1192 0,0,0,0,0, 1193 0,0,0,0,0, 1194 0,0,0,0,0, 1195 0,0,0,0,0, 1196 0,0,0,0,0, 1197 0,0,0,0,0, 1198 0,0,0,0,0, 1199 0,0,0,0,0, 1200 0,0,0,0,0, 1201 0,0,0,0,0, 1202 0,0,0,0,0, 1203 0,0,0,0,0, 1204 0,0,0,0,0, 1205 0,0,0,0,0, 1206 0,0,0,0,0, 1207 0,0,0,0,0, 1208 0,0,0,0,0, 1209 0,0,0,0,0, 1210 0,0,0,0,0, 1211 0,0,0,0,0, 1212 0,0,0,0,0, 1213 0,0,0,0,0, 1214 0,0,0,0,0, 1215 0,0,0,0,0, 1216 0,0,0,0,0, 1217 0,0,0,0,0, 1218 0,0,0,0,0, 1219 0,0,0,0,0, 1220 0,0,0,0,0, 1221 0,0,0,0,0, 1222 0,0,0,0,0, 1223 0,0,0,0,0, 1224 0,0,0,0,0, 1225 0,0,0,0,0, 1226 0,0,0,0,0, 1227 0,0,0,0,0, 1228 0,0,0,0,0, 1229 0,0,0,0,0, 1230 0,0,0,0,0, 1231 0,0,0,0,0, 1232 0,0,0,0,0, 1233 0,0,0,0,0, 1234 0,0,0,0,0, 1235 0,0,0,0,0, 1236 0,0,0,0,0, 1237 0,0,0,0,0, 1238 0,0,0,0,0, 1239 0,0,0,0,0, 1240 0,0,0,0,0, 1241 0,0,0,0,0, 1242 0,0,0,0,0, 1243 0,0,0,0,0, 1244 0,0,0,0,0, 1245 0,0,0,0,0, 1246 0,0,0,0,0, 1247 0,0,0,0,0, 1248 0,0,0,0,0, 1249 0,0,0,0,0, 1250 0,0,0,0,0, 1251 0,0,0,0,0, 1252 0,0,0,0,0, 1253 0,0,0,0,0, 1254 0,0,0,0,0, 1255 0,0,0,0,0, 1256 0,0,0,0,0, 1257 0,0,0,0,0, 1258 0,0,0,0,0, 1259 0,0,0,0,0, 1260 0,0,0,0,0, 1261 0,0,0,0,0, 1262 0,0,0,0,0, 1263 0,0,0,0,0, 1264 0,0,0,0,0, 1265 0,0,0,0,0, 1266 0,0,0,0,0, 1267 0,0,0,0,0, 1268 0,0,0,0,0, 1269 0,0,0,0,0, 1270 0,0,0,0,0, 1271 0,0,0,0,0, 1272 0,0,0,0,0, 1273 0,0,0,0,0, 1274 0,0,0,0,0, 1275 0, 1276 }; 1277 1278 1279 1280 #define yyySizeofProd(num) (yyyProdsInd[(num)+1] - yyyProdsInd[(num)]) 1281 1282 #define yyyGSoccurStr(prodNum,symPos) \ 1283 (yyyStringTab[yyyProds[yyyProdsInd[(prodNum)] + (symPos)][0]]) 1284 1285 #define yyySizeofSort(num) (yyySortsInd[(num)+1] - yyySortsInd[(num)]) 1286 1287 #define yyySortOf(prodNum,symPos) \ 1288 (yyyProds[yyyProdsInd[(prodNum)] + (symPos)][1]) 1289 1290 #define yyyAttrbStr(prodNum,symPos,attrbNum) \ 1291 (yyyStringTab[yyySorts[yyySortsInd[yyySortOf(prodNum,symPos)] + \ 1292 (attrbNum) \ 1293 ] \ 1294 ] \ 1295 ) 1296 1297 1298 1299 void yyyShowProd(int i) 1300 {int j,nSyms; 1301 1302 nSyms = yyySizeofProd(i); 1303 for (j=0; j<nSyms; j++) 1304 { 1305 fprintf(stderr,"%s",yyyGSoccurStr(i,j)); 1306 if (j == 0) fputs(" : ",stderr); else putc(' ',stderr); 1307 } 1308 fputs(";\n",stderr); 1309 } 1310 1311 1312 1313 void yyyShowProds() 1314 {int i; for (i=1; i<=yyyLastProdNum; i++) yyyShowProd(i);} 1315 1316 1317 1318 void yyyShowSymsAndSorts() 1319 {int i; 1320 1321 for (i=1; i<=yyyLastProdNum; i++) 1322 {int j, nSyms; 1323 1324 fprintf(stderr, 1325 "\n\n\n---------------------------------- %3.1d\n",i); 1326 /* yyyShowProd(i); */ 1327 nSyms = yyySizeofProd(i); 1328 for (j=0; j<nSyms; j++) 1329 {int k, sortSize; 1330 1331 fprintf(stderr,"%s\n",yyyGSoccurStr(i,j)); 1332 sortSize = yyySizeofSort(yyySortOf(i,j)); 1333 for (k=0; k<sortSize; k++) 1334 fprintf(stderr," %s\n",yyyAttrbStr(i,j,k)); 1335 if (j == 0) fputs("->\n",stderr); 1336 else 1337 putc('\n',stderr); 1338 } 1339 } 1340 } 1341 1342 1343 1344 void yyyCheckNodeInstancesSolved(yyyGNT *np) 1345 {int mysort,sortSize,i,prodNum,symPos,inTerminalNode; 1346 int nUnsolvedInsts = 0; 1347 1348 if (np->prodNum != 0) 1349 {inTerminalNode = 0; 1350 prodNum = np->prodNum; 1351 symPos = 0; 1352 } 1353 else 1354 {inTerminalNode = 1; 1355 prodNum = np->parent.noderef->prodNum; 1356 symPos = np->whichSym; 1357 } 1358 mysort = yyySortOf(prodNum,symPos); 1359 sortSize = yyySizeofSort(mysort); 1360 for (i=0; i<sortSize; i++) 1361 if ((np->refCountList)[i] != 0) nUnsolvedInsts += 1; 1362 if (nUnsolvedInsts) 1363 {fprintf(stderr, 1364 "\nFound node that has %d unsolved attribute instance(s).\n", 1365 nUnsolvedInsts 1366 ); 1367 fprintf(stderr,"Node is labeled \"%s\".\n", 1368 yyyGSoccurStr(prodNum,symPos)); 1369 if (inTerminalNode) 1370 {fputs("Node is terminal. Its parent production is:\n ",stderr); 1371 yyyShowProd(prodNum); 1372 } 1373 else 1374 {fputs("Node is nonterminal. ",stderr); 1375 if (!(np->parentIsStack)) 1376 {fprintf(stderr, 1377 "Node is %dth child in its parent production:\n ", 1378 np->whichSym 1379 ); 1380 yyyShowProd(np->parent.noderef->prodNum); 1381 } 1382 fputs("Node is on left hand side of this production:\n ",stderr); 1383 yyyShowProd(np->prodNum); 1384 } 1385 fputs("The following instances are unsolved:\n",stderr); 1386 for (i=0; i<sortSize; i++) 1387 if ((np->refCountList)[i] != 0) 1388 fprintf(stderr," %-16s still has %1d dependencies.\n", 1389 yyyAttrbStr(prodNum,symPos,i),(np->refCountList)[i]); 1390 } 1391 } 1392 1393 1394 1395 void yyyCheckUnsolvedInstTrav(yyyGNT *pNode,long *nNZrc,long *cycleSum) 1396 {yyyGNT **yyyCLpdum; 1397 yyyRCT *rcp; 1398 int i; 1399 1400 /* visit the refCountList of each node in the tree, and sum the non-zero refCounts */ 1401 rcp = pNode->refCountList; 1402 i = pNode->refCountListLen; 1403 while (i--) 1404 if (*rcp++) {*cycleSum += *(rcp - 1); (*nNZrc)++;} 1405 yyyCLpdum = pNode->cL; 1406 i = pNode->cLlen; 1407 while (i--) 1408 { 1409 yyyCheckUnsolvedInstTrav(*yyyCLpdum,nNZrc,cycleSum); 1410 yyyCLpdum++; 1411 } 1412 } 1413 1414 1415 1416 void yyyUnsolvedInstSearchTravAux(yyyGNT *pNode) 1417 {yyyGNT **yyyCLpdum; 1418 int i; 1419 1420 yyyCheckNodeInstancesSolved(pNode); 1421 yyyCLpdum = pNode->cL; 1422 i = pNode->cLlen; 1423 while (i--) 1424 { 1425 yyyUnsolvedInstSearchTravAux(*yyyCLpdum); 1426 yyyCLpdum++; 1427 } 1428 } 1429 1430 1431 1432 void yyyUnsolvedInstSearchTrav(yyyGNT *pNode) 1433 {yyyGNT **yyyCLpdum; 1434 int i; 1435 1436 yyyCLpdum = pNode->cL; 1437 i = pNode->cLlen; 1438 while (i--) 1439 { 1440 yyyUnsolvedInstSearchTravAux(*yyyCLpdum); 1441 yyyCLpdum++; 1442 } 1443 } 1444 1445 1446 1447