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