|
|
1.1 ! root 1: # define CHAR 257 ! 2: # define CCL 258 ! 3: # define NCCL 259 ! 4: # define STR 260 ! 5: # define DELIM 261 ! 6: # define SCON 262 ! 7: # define ITER 263 ! 8: # define NEWE 264 ! 9: # define NULLS 265 ! 10: # define CAT 266 ! 11: ! 12: # line 11 "parser.y" ! 13: #ifndef lint ! 14: static char sccsid[] = "@(#)parser.y 4.1 (Berkeley) 8/11/83"; ! 15: #endif ! 16: ! 17: # include "ldefs.c" ! 18: #define yyclearin yychar = -1 ! 19: #define yyerrok yyerrflag = 0 ! 20: extern int yychar; ! 21: extern short yyerrflag; ! 22: #ifndef YYMAXDEPTH ! 23: #define YYMAXDEPTH 150 ! 24: #endif ! 25: #ifndef YYSTYPE ! 26: #define YYSTYPE int ! 27: #endif ! 28: YYSTYPE yylval, yyval; ! 29: ! 30: # line 19 "parser.y" ! 31: int i; ! 32: int j,k; ! 33: int g; ! 34: char *p; ! 35: # define YYERRCODE 256 ! 36: ! 37: # line 215 "parser.y" ! 38: ! 39: yylex(){ ! 40: register char *p; ! 41: register int c, i; ! 42: char *t, *xp; ! 43: int n, j, k, x; ! 44: static int sectbegin; ! 45: static char token[TOKENSIZE]; ! 46: static int iter; ! 47: ! 48: # ifdef DEBUG ! 49: yylval = 0; ! 50: # endif ! 51: ! 52: if(sect == DEFSECTION) { /* definitions section */ ! 53: while(!eof) { ! 54: if(prev == '\n'){ /* next char is at beginning of line */ ! 55: getl(p=buf); ! 56: switch(*p){ ! 57: case '%': ! 58: switch(c= *(p+1)){ ! 59: case '%': ! 60: lgate(); ! 61: if(!ratfor)fprintf(fout,"# "); ! 62: fprintf(fout,"define YYNEWLINE %d\n",ctable['\n']); ! 63: if(!ratfor)fprintf(fout,"yylex(){\nint nstr; extern int yyprevious;\n"); ! 64: sectbegin = TRUE; ! 65: i = treesize*(sizeof(*name)+sizeof(*left)+ ! 66: sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA; ! 67: c = myalloc(i,1); ! 68: if(c == 0) ! 69: error("Too little core for parse tree"); ! 70: p = c; ! 71: cfree(p,i,1); ! 72: name = myalloc(treesize,sizeof(*name)); ! 73: left = myalloc(treesize,sizeof(*left)); ! 74: right = myalloc(treesize,sizeof(*right)); ! 75: nullstr = myalloc(treesize,sizeof(*nullstr)); ! 76: parent = myalloc(treesize,sizeof(*parent)); ! 77: if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0) ! 78: error("Too little core for parse tree"); ! 79: return(freturn(DELIM)); ! 80: case 'p': case 'P': /* has overridden number of positions */ ! 81: while(*p && !digit(*p))p++; ! 82: maxpos = siconv(p); ! 83: # ifdef DEBUG ! 84: if (debug) printf("positions (%%p) now %d\n",maxpos); ! 85: # endif ! 86: if(report == 2)report = 1; ! 87: continue; ! 88: case 'n': case 'N': /* has overridden number of states */ ! 89: while(*p && !digit(*p))p++; ! 90: nstates = siconv(p); ! 91: # ifdef DEBUG ! 92: if(debug)printf( " no. states (%%n) now %d\n",nstates); ! 93: # endif ! 94: if(report == 2)report = 1; ! 95: continue; ! 96: case 'e': case 'E': /* has overridden number of tree nodes */ ! 97: while(*p && !digit(*p))p++; ! 98: treesize = siconv(p); ! 99: # ifdef DEBUG ! 100: if (debug) printf("treesize (%%e) now %d\n",treesize); ! 101: # endif ! 102: if(report == 2)report = 1; ! 103: continue; ! 104: case 'o': case 'O': ! 105: while (*p && !digit(*p))p++; ! 106: outsize = siconv(p); ! 107: if (report ==2) report=1; ! 108: continue; ! 109: case 'a': case 'A': /* has overridden number of transitions */ ! 110: while(*p && !digit(*p))p++; ! 111: if(report == 2)report = 1; ! 112: ntrans = siconv(p); ! 113: # ifdef DEBUG ! 114: if (debug)printf("N. trans (%%a) now %d\n",ntrans); ! 115: # endif ! 116: continue; ! 117: case 'k': case 'K': /* overriden packed char classes */ ! 118: while (*p && !digit(*p))p++; ! 119: if (report==2) report=1; ! 120: cfree(pchar, pchlen, sizeof(*pchar)); ! 121: pchlen = siconv(p); ! 122: # ifdef DEBUG ! 123: if (debug) printf( "Size classes (%%k) now %d\n",pchlen); ! 124: # endif ! 125: pchar=pcptr=myalloc(pchlen, sizeof(*pchar)); ! 126: continue; ! 127: case 't': case 'T': /* character set specifier */ ! 128: ZCH = atoi(p+2); ! 129: if (ZCH < NCH) ZCH = NCH; ! 130: if (ZCH > 2*NCH) error("ch table needs redeclaration"); ! 131: chset = TRUE; ! 132: for(i = 0; i<ZCH; i++) ! 133: ctable[i] = 0; ! 134: while(getl(p) && scomp(p,"%T") != 0 && scomp(p,"%t") != 0){ ! 135: if((n = siconv(p)) <= 0 || n > ZCH){ ! 136: warning("Character value %d out of range",n); ! 137: continue; ! 138: } ! 139: while(!space(*p) && *p) p++; ! 140: while(space(*p)) p++; ! 141: t = p; ! 142: while(*t){ ! 143: c = ctrans(&t); ! 144: if(ctable[c]){ ! 145: if (printable(c)) ! 146: warning("Character '%c' used twice",c); ! 147: else ! 148: warning("Character %o used twice",c); ! 149: } ! 150: else ctable[c] = n; ! 151: t++; ! 152: } ! 153: p = buf; ! 154: } ! 155: { ! 156: char chused[2*NCH]; int kr; ! 157: for(i=0; i<ZCH; i++) ! 158: chused[i]=0; ! 159: for(i=0; i<NCH; i++) ! 160: chused[ctable[i]]=1; ! 161: for(kr=i=1; i<NCH; i++) ! 162: if (ctable[i]==0) ! 163: { ! 164: while (chused[kr] == 0) ! 165: kr++; ! 166: ctable[i]=kr; ! 167: chused[kr]=1; ! 168: } ! 169: } ! 170: lgate(); ! 171: continue; ! 172: case 'r': case 'R': ! 173: c = 'r'; ! 174: case 'c': case 'C': ! 175: if(lgatflg) ! 176: error("Too late for language specifier"); ! 177: ratfor = (c == 'r'); ! 178: continue; ! 179: case '{': ! 180: lgate(); ! 181: while(getl(p) && scomp(p,"%}") != 0) ! 182: fprintf(fout, "%s\n",p); ! 183: if(p[0] == '%') continue; ! 184: error("Premature eof"); ! 185: case 's': case 'S': /* start conditions */ ! 186: lgate(); ! 187: while(*p && index(*p," \t,") < 0) p++; ! 188: n = TRUE; ! 189: while(n){ ! 190: while(*p && index(*p," \t,") >= 0) p++; ! 191: t = p; ! 192: while(*p && index(*p," \t,") < 0)p++; ! 193: if(!*p) n = FALSE; ! 194: *p++ = 0; ! 195: if (*t == 0) continue; ! 196: i = sptr*2; ! 197: if(!ratfor)fprintf(fout,"# "); ! 198: fprintf(fout,"define %s %d\n",t,i); ! 199: scopy(t,sp); ! 200: sname[sptr++] = sp; ! 201: sname[sptr] = 0; /* required by lookup */ ! 202: if(sptr >= STARTSIZE) ! 203: error("Too many start conditions"); ! 204: sp += slength(sp) + 1; ! 205: if(sp >= schar+STARTCHAR) ! 206: error("Start conditions too long"); ! 207: } ! 208: continue; ! 209: default: ! 210: warning("Invalid request %s",p); ! 211: continue; ! 212: } /* end of switch after seeing '%' */ ! 213: case ' ': case '\t': /* must be code */ ! 214: lgate(); ! 215: fprintf(fout, "%s\n",p); ! 216: continue; ! 217: default: /* definition */ ! 218: while(*p && !space(*p)) p++; ! 219: if(*p == 0) ! 220: continue; ! 221: prev = *p; ! 222: *p = 0; ! 223: bptr = p+1; ! 224: yylval = buf; ! 225: if(digit(buf[0])) ! 226: warning("Substitution strings may not begin with digits"); ! 227: return(freturn(STR)); ! 228: } ! 229: } ! 230: /* still sect 1, but prev != '\n' */ ! 231: else { ! 232: p = bptr; ! 233: while(*p && space(*p)) p++; ! 234: if(*p == 0) ! 235: warning("No translation given - null string assumed"); ! 236: scopy(p,token); ! 237: yylval = token; ! 238: prev = '\n'; ! 239: return(freturn(STR)); ! 240: } ! 241: } ! 242: /* end of section one processing */ ! 243: } ! 244: else if(sect == RULESECTION){ /* rules and actions */ ! 245: while(!eof){ ! 246: switch(c=gch()){ ! 247: case '\0': ! 248: return(freturn(0)); ! 249: case '\n': ! 250: if(prev == '\n') continue; ! 251: x = NEWE; ! 252: break; ! 253: case ' ': ! 254: case '\t': ! 255: if(sectbegin == TRUE){ ! 256: cpyact(); ! 257: while((c=gch()) && c != '\n'); ! 258: continue; ! 259: } ! 260: if(!funcflag)phead2(); ! 261: funcflag = TRUE; ! 262: if(ratfor)fprintf(fout,"%d\n",30000+casecount); ! 263: else fprintf(fout,"case %d:\n",casecount); ! 264: if(cpyact()){ ! 265: if(ratfor)fprintf(fout,"goto 30997\n"); ! 266: else fprintf(fout,"break;\n"); ! 267: } ! 268: while((c=gch()) && c != '\n'); ! 269: if(peek == ' ' || peek == '\t' || sectbegin == TRUE){ ! 270: warning("Executable statements should occur right after %%"); ! 271: continue; ! 272: } ! 273: x = NEWE; ! 274: break; ! 275: case '%': ! 276: if(prev != '\n') goto character; ! 277: if(peek == '{'){ /* included code */ ! 278: getl(buf); ! 279: while(!eof && getl(buf) && scomp("%}",buf) != 0) ! 280: fprintf(fout,"%s\n",buf); ! 281: continue; ! 282: } ! 283: if(peek == '%'){ ! 284: c = gch(); ! 285: c = gch(); ! 286: x = DELIM; ! 287: break; ! 288: } ! 289: goto character; ! 290: case '|': ! 291: if(peek == ' ' || peek == '\t' || peek == '\n'){ ! 292: if(ratfor)fprintf(fout,"%d\n",30000+casecount++); ! 293: else fprintf(fout,"case %d:\n",casecount++); ! 294: continue; ! 295: } ! 296: x = '|'; ! 297: break; ! 298: case '$': ! 299: if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){ ! 300: x = c; ! 301: break; ! 302: } ! 303: goto character; ! 304: case '^': ! 305: if(prev != '\n' && scon != TRUE) goto character; /* valid only at line begin */ ! 306: x = c; ! 307: break; ! 308: case '?': ! 309: case '+': ! 310: case '.': ! 311: case '*': ! 312: case '(': ! 313: case ')': ! 314: case ',': ! 315: case '/': ! 316: x = c; ! 317: break; ! 318: case '}': ! 319: iter = FALSE; ! 320: x = c; ! 321: break; ! 322: case '{': /* either iteration or definition */ ! 323: if(digit(c=gch())){ /* iteration */ ! 324: iter = TRUE; ! 325: ieval: ! 326: i = 0; ! 327: while(digit(c)){ ! 328: token[i++] = c; ! 329: c = gch(); ! 330: } ! 331: token[i] = 0; ! 332: yylval = siconv(token); ! 333: munput('c',c); ! 334: x = ITER; ! 335: break; ! 336: } ! 337: else { /* definition */ ! 338: i = 0; ! 339: while(c && c!='}'){ ! 340: token[i++] = c; ! 341: c = gch(); ! 342: } ! 343: token[i] = 0; ! 344: i = lookup(token,def); ! 345: if(i < 0) ! 346: warning("Definition %s not found",token); ! 347: else ! 348: munput('s',subs[i]); ! 349: continue; ! 350: } ! 351: case '<': /* start condition ? */ ! 352: if(prev != '\n') /* not at line begin, not start */ ! 353: goto character; ! 354: t = slptr; ! 355: do { ! 356: i = 0; ! 357: c = gch(); ! 358: while(c != ',' && c && c != '>'){ ! 359: token[i++] = c; ! 360: c = gch(); ! 361: } ! 362: token[i] = 0; ! 363: if(i == 0) ! 364: goto character; ! 365: i = lookup(token,sname); ! 366: if(i < 0) { ! 367: warning("Undefined start condition %s",token); ! 368: continue; ! 369: } ! 370: *slptr++ = i+1; ! 371: } while(c && c != '>'); ! 372: *slptr++ = 0; ! 373: /* check if previous value re-usable */ ! 374: for (xp=slist; xp<t; ) ! 375: { ! 376: if (strcmp(xp, t)==0) ! 377: break; ! 378: while (*xp++); ! 379: } ! 380: if (xp<t) ! 381: { ! 382: /* re-use previous pointer to string */ ! 383: slptr=t; ! 384: t=xp; ! 385: } ! 386: if(slptr > slist+STARTSIZE) /* note not packed ! */ ! 387: error("Too many start conditions used"); ! 388: yylval = t; ! 389: x = SCON; ! 390: break; ! 391: case '"': ! 392: i = 0; ! 393: while((c=gch()) && c != '"' && c != '\n'){ ! 394: if(c == '\\') c = usescape(c=gch()); ! 395: token[i++] = c; ! 396: if(i > TOKENSIZE){ ! 397: warning("String too long"); ! 398: i = TOKENSIZE-1; ! 399: break; ! 400: } ! 401: } ! 402: if(c == '\n') { ! 403: yyline--; ! 404: warning("Non-terminated string"); ! 405: yyline++; ! 406: } ! 407: token[i] = 0; ! 408: if(i == 0)x = NULLS; ! 409: else if(i == 1){ ! 410: yylval = token[0]; ! 411: x = CHAR; ! 412: } ! 413: else { ! 414: yylval = token; ! 415: x = STR; ! 416: } ! 417: break; ! 418: case '[': ! 419: for(i=1;i<NCH;i++) symbol[i] = 0; ! 420: x = CCL; ! 421: if((c = gch()) == '^'){ ! 422: x = NCCL; ! 423: c = gch(); ! 424: } ! 425: while(c != ']' && c){ ! 426: if(c == '\\') c = usescape(c=gch()); ! 427: symbol[c] = 1; ! 428: j = c; ! 429: if((c=gch()) == '-' && peek != ']'){ /* range specified */ ! 430: c = gch(); ! 431: if(c == '\\') c = usescape(c=gch()); ! 432: k = c; ! 433: if(j > k) { ! 434: n = j; ! 435: j = k; ! 436: k = n; ! 437: } ! 438: if(!(('A' <= j && k <= 'Z') || ! 439: ('a' <= j && k <= 'z') || ! 440: ('0' <= j && k <= '9'))) ! 441: warning("Non-portable Character Class"); ! 442: for(n=j+1;n<=k;n++) ! 443: symbol[n] = 1; /* implementation dependent */ ! 444: c = gch(); ! 445: } ! 446: } ! 447: /* try to pack ccl's */ ! 448: i = 0; ! 449: for(j=0;j<NCH;j++) ! 450: if(symbol[j])token[i++] = j; ! 451: token[i] = 0; ! 452: p = ccptr; ! 453: if(optim){ ! 454: p = ccl; ! 455: while(p <ccptr && scomp(token,p) != 0)p++; ! 456: } ! 457: if(p < ccptr) /* found it */ ! 458: yylval = p; ! 459: else { ! 460: yylval = ccptr; ! 461: scopy(token,ccptr); ! 462: ccptr += slength(token) + 1; ! 463: if(ccptr >= ccl+CCLSIZE) ! 464: error("Too many large character classes"); ! 465: } ! 466: cclinter(x==CCL); ! 467: break; ! 468: case '\\': ! 469: c = usescape(c=gch()); ! 470: default: ! 471: character: ! 472: if(iter){ /* second part of an iteration */ ! 473: iter = FALSE; ! 474: if('0' <= c && c <= '9') ! 475: goto ieval; ! 476: } ! 477: if(alpha(peek)){ ! 478: i = 0; ! 479: yylval = token; ! 480: token[i++] = c; ! 481: while(alpha(peek)) ! 482: token[i++] = gch(); ! 483: if(peek == '?' || peek == '*' || peek == '+') ! 484: munput('c',token[--i]); ! 485: token[i] = 0; ! 486: if(i == 1){ ! 487: yylval = token[0]; ! 488: x = CHAR; ! 489: } ! 490: else x = STR; ! 491: } ! 492: else { ! 493: yylval = c; ! 494: x = CHAR; ! 495: } ! 496: } ! 497: scon = FALSE; ! 498: if(x == SCON)scon = TRUE; ! 499: sectbegin = FALSE; ! 500: return(freturn(x)); ! 501: } ! 502: } ! 503: /* section three */ ! 504: ptail(); ! 505: # ifdef DEBUG ! 506: if(debug) ! 507: fprintf(fout,"\n/*this comes from section three - debug */\n"); ! 508: # endif ! 509: while(getl(buf) && !eof) ! 510: fprintf(fout,"%s\n",buf); ! 511: return(freturn(0)); ! 512: } ! 513: /* end of yylex */ ! 514: # ifdef DEBUG ! 515: freturn(i) ! 516: int i; { ! 517: if(yydebug) { ! 518: printf("now return "); ! 519: if(i < NCH) allprint(i); ! 520: else printf("%d",i); ! 521: printf(" yylval = "); ! 522: switch(i){ ! 523: case STR: case CCL: case NCCL: ! 524: strpt(yylval); ! 525: break; ! 526: case CHAR: ! 527: allprint(yylval); ! 528: break; ! 529: default: ! 530: printf("%d",yylval); ! 531: break; ! 532: } ! 533: putchar('\n'); ! 534: } ! 535: return(i); ! 536: } ! 537: # endif ! 538: short yyexca[] ={ ! 539: -1, 1, ! 540: 0, -1, ! 541: -2, 0, ! 542: }; ! 543: # define YYNPROD 33 ! 544: # define YYLAST 291 ! 545: short yyact[]={ ! 546: ! 547: 34, 45, 35, 23, 21, 43, 27, 28, 4, 34, ! 548: 16, 32, 41, 21, 46, 27, 28, 10, 34, 16, ! 549: 32, 8, 21, 9, 27, 28, 25, 29, 16, 6, ! 550: 7, 3, 24, 34, 27, 28, 29, 21, 11, 27, ! 551: 28, 2, 5, 16, 1, 29, 21, 0, 27, 28, ! 552: 0, 0, 16, 0, 0, 29, 21, 0, 20, 0, ! 553: 29, 0, 16, 0, 0, 21, 0, 20, 0, 29, ! 554: 0, 16, 0, 0, 31, 0, 20, 0, 0, 0, ! 555: 12, 0, 0, 12, 0, 0, 0, 0, 30, 0, ! 556: 0, 20, 0, 42, 36, 37, 38, 30, 0, 0, ! 557: 0, 0, 0, 0, 0, 39, 30, 40, 0, 0, ! 558: 20, 0, 0, 0, 0, 0, 0, 0, 0, 20, ! 559: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 560: 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, ! 561: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 562: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 563: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 564: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 565: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 566: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 567: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 568: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ! 569: 0, 14, 17, 18, 15, 0, 19, 33, 0, 22, ! 570: 14, 17, 18, 15, 0, 19, 33, 26, 22, 14, ! 571: 17, 18, 15, 0, 0, 33, 0, 22, 0, 0, ! 572: 0, 0, 0, 0, 14, 17, 18, 15, 0, 0, ! 573: 33, 0, 22, 14, 17, 18, 15, 0, 0, 33, ! 574: 0, 22, 13, 14, 17, 18, 15, 7, 19, 0, ! 575: 0, 22, 14, 17, 18, 15, 0, 19, 0, 0, ! 576: 22 }; ! 577: short yypact[]={ ! 578: ! 579: -248,-1000,-1000,-231,-1000, 16,-257,-1000, 16,-1000, ! 580: -1000,-1000, -27,-262,-1000,-1000,-1000,-1000,-1000, 25, ! 581: 25, 25,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, ! 582: 25, -8, 25, -32,-1000,-1000, -18, 6, -36, -3, ! 583: -18,-124,-1000,-1000,-111,-1000,-1000 }; ! 584: short yypgo[]={ ! 585: ! 586: 0, 44, 41, 31, 38, 21, 23, 17, 74 }; ! 587: short yyr1[]={ ! 588: ! 589: 0, 1, 2, 2, 2, 6, 6, 3, 3, 4, ! 590: 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, ! 591: 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ! 592: 8, 8, 8 }; ! 593: short yyr2[]={ ! 594: ! 595: 0, 1, 4, 3, 1, 1, 0, 3, 0, 1, ! 596: 2, 1, 2, 2, 1, 1, 1, 1, 1, 2, ! 597: 2, 2, 3, 2, 3, 5, 3, 4, 2, 2, ! 598: 2, 3, 1 }; ! 599: short yychk[]={ ! 600: ! 601: -1000, -1, -2, -3, 256, -4, 260, 261, -5, -6, ! 602: -7, -4, -8, 256, 257, 260, 46, 258, 259, 262, ! 603: 94, 40, 265, 260, -6, -7, 264, 42, 43, 63, ! 604: 124, -8, 47, 263, 36, 264, -8, -8, -8, -8, ! 605: -8, 44, 125, 41, 263, 125, 125 }; ! 606: short yydef[]={ ! 607: ! 608: 8, -2, 1, 0, 4, 6, 0, 9, 6, 3, ! 609: 11, 5, 0, 0, 14, 15, 16, 17, 18, 0, ! 610: 0, 0, 32, 7, 2, 10, 12, 19, 20, 21, ! 611: 0, 23, 0, 0, 30, 13, 28, 29, 0, 22, ! 612: 24, 0, 26, 31, 0, 27, 25 }; ! 613: #ifndef lint ! 614: static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83"; ! 615: #endif not lint ! 616: ! 617: # ! 618: # define YYFLAG -1000 ! 619: # define YYERROR goto yyerrlab ! 620: # define YYACCEPT return(0) ! 621: # define YYABORT return(1) ! 622: ! 623: /* parser for yacc output */ ! 624: ! 625: #ifdef YYDEBUG ! 626: int yydebug = 0; /* 1 for debugging */ ! 627: #endif ! 628: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */ ! 629: int yychar = -1; /* current input token number */ ! 630: int yynerrs = 0; /* number of errors */ ! 631: short yyerrflag = 0; /* error recovery flag */ ! 632: ! 633: yyparse() { ! 634: ! 635: short yys[YYMAXDEPTH]; ! 636: short yyj, yym; ! 637: register YYSTYPE *yypvt; ! 638: register short yystate, *yyps, yyn; ! 639: register YYSTYPE *yypv; ! 640: register short *yyxi; ! 641: ! 642: yystate = 0; ! 643: yychar = -1; ! 644: yynerrs = 0; ! 645: yyerrflag = 0; ! 646: yyps= &yys[-1]; ! 647: yypv= &yyv[-1]; ! 648: ! 649: yystack: /* put a state and value onto the stack */ ! 650: ! 651: #ifdef YYDEBUG ! 652: if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); ! 653: #endif ! 654: if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } ! 655: *yyps = yystate; ! 656: ++yypv; ! 657: *yypv = yyval; ! 658: ! 659: yynewstate: ! 660: ! 661: yyn = yypact[yystate]; ! 662: ! 663: if( yyn<= YYFLAG ) goto yydefault; /* simple state */ ! 664: ! 665: if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; ! 666: if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; ! 667: ! 668: if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ ! 669: yychar = -1; ! 670: yyval = yylval; ! 671: yystate = yyn; ! 672: if( yyerrflag > 0 ) --yyerrflag; ! 673: goto yystack; ! 674: } ! 675: ! 676: yydefault: ! 677: /* default state action */ ! 678: ! 679: if( (yyn=yydef[yystate]) == -2 ) { ! 680: if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; ! 681: /* look through exception table */ ! 682: ! 683: for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ ! 684: ! 685: while( *(yyxi+=2) >= 0 ){ ! 686: if( *yyxi == yychar ) break; ! 687: } ! 688: if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ ! 689: } ! 690: ! 691: if( yyn == 0 ){ /* error */ ! 692: /* error ... attempt to resume parsing */ ! 693: ! 694: switch( yyerrflag ){ ! 695: ! 696: case 0: /* brand new error */ ! 697: ! 698: yyerror( "syntax error" ); ! 699: yyerrlab: ! 700: ++yynerrs; ! 701: ! 702: case 1: ! 703: case 2: /* incompletely recovered error ... try again */ ! 704: ! 705: yyerrflag = 3; ! 706: ! 707: /* find a state where "error" is a legal shift action */ ! 708: ! 709: while ( yyps >= yys ) { ! 710: yyn = yypact[*yyps] + YYERRCODE; ! 711: if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ ! 712: yystate = yyact[yyn]; /* simulate a shift of "error" */ ! 713: goto yystack; ! 714: } ! 715: yyn = yypact[*yyps]; ! 716: ! 717: /* the current yyps has no shift onn "error", pop stack */ ! 718: ! 719: #ifdef YYDEBUG ! 720: if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); ! 721: #endif ! 722: --yyps; ! 723: --yypv; ! 724: } ! 725: ! 726: /* there is no state on the stack with an error shift ... abort */ ! 727: ! 728: yyabort: ! 729: return(1); ! 730: ! 731: ! 732: case 3: /* no shift yet; clobber input char */ ! 733: ! 734: #ifdef YYDEBUG ! 735: if( yydebug ) printf( "error recovery discards char %d\n", yychar ); ! 736: #endif ! 737: ! 738: if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ ! 739: yychar = -1; ! 740: goto yynewstate; /* try again in the same state */ ! 741: ! 742: } ! 743: ! 744: } ! 745: ! 746: /* reduction by production yyn */ ! 747: ! 748: #ifdef YYDEBUG ! 749: if( yydebug ) printf("reduce %d\n",yyn); ! 750: #endif ! 751: yyps -= yyr2[yyn]; ! 752: yypvt = yypv; ! 753: yypv -= yyr2[yyn]; ! 754: yyval = yypv[1]; ! 755: yym=yyn; ! 756: /* consult goto table to find next state */ ! 757: yyn = yyr1[yyn]; ! 758: yyj = yypgo[yyn] + *yyps + 1; ! 759: if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; ! 760: switch(yym){ ! 761: ! 762: case 1: ! 763: # line 25 "parser.y" ! 764: { ! 765: # ifdef DEBUG ! 766: if(debug) sect2dump(); ! 767: # endif ! 768: } break; ! 769: case 3: ! 770: # line 33 "parser.y" ! 771: { ! 772: if(!funcflag)phead2(); ! 773: funcflag = TRUE; ! 774: } break; ! 775: case 4: ! 776: # line 38 "parser.y" ! 777: { ! 778: # ifdef DEBUG ! 779: if(debug) { ! 780: sect1dump(); ! 781: sect2dump(); ! 782: } ! 783: # endif ! 784: } break; ! 785: case 7: ! 786: # line 49 "parser.y" ! 787: { scopy(yypvt[-1],dp); ! 788: def[dptr] = dp; ! 789: dp += slength(yypvt[-1]) + 1; ! 790: scopy(yypvt[-0],dp); ! 791: subs[dptr++] = dp; ! 792: if(dptr >= DEFSIZE) ! 793: error("Too many definitions"); ! 794: dp += slength(yypvt[-0]) + 1; ! 795: if(dp >= dchar+DEFCHAR) ! 796: error("Definitions too long"); ! 797: subs[dptr]=def[dptr]=0; /* for lookup - require ending null */ ! 798: } break; ! 799: case 9: ! 800: # line 64 "parser.y" ! 801: { ! 802: # ifdef DEBUG ! 803: if(sect == DEFSECTION && debug) sect1dump(); ! 804: # endif ! 805: sect++; ! 806: } break; ! 807: case 10: ! 808: # line 72 "parser.y" ! 809: { yyval = mn2(RNEWE,yypvt[-1],yypvt[-0]); ! 810: } break; ! 811: case 11: ! 812: # line 75 "parser.y" ! 813: { yyval = yypvt[-0];} break; ! 814: case 12: ! 815: # line 78 "parser.y" ! 816: { ! 817: if(divflg == TRUE) ! 818: i = mn1(S1FINAL,casecount); ! 819: else i = mn1(FINAL,casecount); ! 820: yyval = mn2(RCAT,yypvt[-1],i); ! 821: divflg = FALSE; ! 822: casecount++; ! 823: } break; ! 824: case 13: ! 825: # line 87 "parser.y" ! 826: { ! 827: # ifdef DEBUG ! 828: if(debug) sect2dump(); ! 829: # endif ! 830: } break; ! 831: case 14: ! 832: # line 93 "parser.y" ! 833: { yyval = mn0(yypvt[-0]); } break; ! 834: case 15: ! 835: # line 95 "parser.y" ! 836: { ! 837: p = yypvt[-0]; ! 838: i = mn0(*p++); ! 839: while(*p) ! 840: i = mn2(RSTR,i,*p++); ! 841: yyval = i; ! 842: } break; ! 843: case 16: ! 844: # line 103 "parser.y" ! 845: { symbol['\n'] = 0; ! 846: if(psave == FALSE){ ! 847: p = ccptr; ! 848: psave = ccptr; ! 849: for(i=1;i<'\n';i++){ ! 850: symbol[i] = 1; ! 851: *ccptr++ = i; ! 852: } ! 853: for(i='\n'+1;i<NCH;i++){ ! 854: symbol[i] = 1; ! 855: *ccptr++ = i; ! 856: } ! 857: *ccptr++ = 0; ! 858: if(ccptr > ccl+CCLSIZE) ! 859: error("Too many large character classes"); ! 860: } ! 861: else ! 862: p = psave; ! 863: yyval = mn1(RCCL,p); ! 864: cclinter(1); ! 865: } break; ! 866: case 17: ! 867: # line 125 "parser.y" ! 868: { yyval = mn1(RCCL,yypvt[-0]); } break; ! 869: case 18: ! 870: # line 127 "parser.y" ! 871: { yyval = mn1(RNCCL,yypvt[-0]); } break; ! 872: case 19: ! 873: # line 129 "parser.y" ! 874: { yyval = mn1(STAR,yypvt[-1]); } break; ! 875: case 20: ! 876: # line 131 "parser.y" ! 877: { yyval = mn1(PLUS,yypvt[-1]); } break; ! 878: case 21: ! 879: # line 133 "parser.y" ! 880: { yyval = mn1(QUEST,yypvt[-1]); } break; ! 881: case 22: ! 882: # line 135 "parser.y" ! 883: { yyval = mn2(BAR,yypvt[-2],yypvt[-0]); } break; ! 884: case 23: ! 885: # line 137 "parser.y" ! 886: { yyval = mn2(RCAT,yypvt[-1],yypvt[-0]); } break; ! 887: case 24: ! 888: # line 139 "parser.y" ! 889: { if(!divflg){ ! 890: j = mn1(S2FINAL,-casecount); ! 891: i = mn2(RCAT,yypvt[-2],j); ! 892: yyval = mn2(DIV,i,yypvt[-0]); ! 893: } ! 894: else { ! 895: yyval = mn2(RCAT,yypvt[-2],yypvt[-0]); ! 896: warning("Extra slash removed"); ! 897: } ! 898: divflg = TRUE; ! 899: } break; ! 900: case 25: ! 901: # line 151 "parser.y" ! 902: { if(yypvt[-3] > yypvt[-1]){ ! 903: i = yypvt[-3]; ! 904: yypvt[-3] = yypvt[-1]; ! 905: yypvt[-1] = i; ! 906: } ! 907: if(yypvt[-1] <= 0) ! 908: warning("Iteration range must be positive"); ! 909: else { ! 910: j = yypvt[-4]; ! 911: for(k = 2; k<=yypvt[-3];k++) ! 912: j = mn2(RCAT,j,dupl(yypvt[-4])); ! 913: for(i = yypvt[-3]+1; i<=yypvt[-1]; i++){ ! 914: g = dupl(yypvt[-4]); ! 915: for(k=2;k<=i;k++) ! 916: g = mn2(RCAT,g,dupl(yypvt[-4])); ! 917: j = mn2(BAR,j,g); ! 918: } ! 919: yyval = j; ! 920: } ! 921: } break; ! 922: case 26: ! 923: # line 172 "parser.y" ! 924: { ! 925: if(yypvt[-1] < 0)warning("Can't have negative iteration"); ! 926: else if(yypvt[-1] == 0) yyval = mn0(RNULLS); ! 927: else { ! 928: j = yypvt[-2]; ! 929: for(k=2;k<=yypvt[-1];k++) ! 930: j = mn2(RCAT,j,dupl(yypvt[-2])); ! 931: yyval = j; ! 932: } ! 933: } break; ! 934: case 27: ! 935: # line 183 "parser.y" ! 936: { ! 937: /* from n to infinity */ ! 938: if(yypvt[-2] < 0)warning("Can't have negative iteration"); ! 939: else if(yypvt[-2] == 0) yyval = mn1(STAR,yypvt[-3]); ! 940: else if(yypvt[-2] == 1)yyval = mn1(PLUS,yypvt[-3]); ! 941: else { /* >= 2 iterations minimum */ ! 942: j = yypvt[-3]; ! 943: for(k=2;k<yypvt[-2];k++) ! 944: j = mn2(RCAT,j,dupl(yypvt[-3])); ! 945: k = mn1(PLUS,dupl(yypvt[-3])); ! 946: yyval = mn2(RCAT,j,k); ! 947: } ! 948: } break; ! 949: case 28: ! 950: # line 197 "parser.y" ! 951: { yyval = mn2(RSCON,yypvt[-0],yypvt[-1]); } break; ! 952: case 29: ! 953: # line 199 "parser.y" ! 954: { yyval = mn1(CARAT,yypvt[-0]); } break; ! 955: case 30: ! 956: # line 201 "parser.y" ! 957: { i = mn0('\n'); ! 958: if(!divflg){ ! 959: j = mn1(S2FINAL,-casecount); ! 960: k = mn2(RCAT,yypvt[-1],j); ! 961: yyval = mn2(DIV,k,i); ! 962: } ! 963: else yyval = mn2(RCAT,yypvt[-1],i); ! 964: divflg = TRUE; ! 965: } break; ! 966: case 31: ! 967: # line 211 "parser.y" ! 968: { yyval = yypvt[-1]; } break; ! 969: case 32: ! 970: # line 213 "parser.y" ! 971: { yyval = mn0(RNULLS); } break; ! 972: } ! 973: goto yystack; /* stack new state and value */ ! 974: ! 975: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.