|
|
1.1 root 1:
2: # line 1 "gram.y"
3: #include "defs"
4: static char *sccsid = "@(#)gram.y 8th Edition (Bell Labs) 85/05/14";
5:
6: # line 6 "gram.y"
7: typedef union
8: {
9: struct shblock *yshblock;
10: depblkp ydepblock;
11: nameblkp ynameblock;
12: } YYSTYPE;
13: # define NAME 257
14: # define SHELLINE 258
15: # define START 259
16: # define MACRODEF 260
17: # define COLON 261
18: # define DOUBLECOLON 262
19: # define GREATER 263
20: # define AMPER 264
21: # define AMPERAMPER 265
22: #define yyclearin yychar = -1
23: #define yyerrok yyerrflag = 0
24: extern int yychar;
25: extern short yyerrflag;
26: #ifndef YYMAXDEPTH
27: #define YYMAXDEPTH 150
28: #endif
29: YYSTYPE yylval, yyval;
30:
31: # line 21 "gram.y"
32: struct depblock *pp;
33: FSTATIC struct shblock *prevshp;
34:
35: FSTATIC struct nameblock *lefts[NLEFTS];
36: struct nameblock *leftp;
37: FSTATIC int nlefts;
38:
39: struct lineblock *lp, *lpp;
40: FSTATIC struct depblock *prevdep;
41: FSTATIC int sepc;
42: FSTATIC int allnowait;
43:
44: FSTATIC struct fstack
45: {
46: FILE *fin;
47: char *fname;
48: int lineno;
49: } filestack[MAXINCLUDE];
50: FSTATIC int ninclude = 0;
51: # define YYERRCODE 256
52:
53: # line 150 "gram.y"
54:
55:
56: FSTATIC char *zznextc; /* null if need another line;
57: otherwise points to next char */
58: FSTATIC int yylineno;
59: FSTATIC FILE * fin;
60:
61: parse(name)
62: char *name;
63: {
64: extern int yylineno;
65: FILE *stream;
66: extern char *zznextc;
67:
68: if(name == CHNULL)
69: {
70: stream = NULL;
71: name = "(builtin-rules)";
72: }
73: else if(equal(name, "-"))
74: {
75: stream = stdin;
76: name = "(stdin)";
77: }
78: else if( (stream = fopen(name, "r")) == NULL)
79: return NO;
80: filestack[0].fname = copys(name);
81: ninclude = 1;
82: fin = stream;
83: yylineno = 0;
84: zznextc = 0;
85:
86: if( yyparse() )
87: fatal("Description file error");
88:
89: if(fin)
90: fclose(fin);
91: return YES;
92: }
93:
94:
95: yylex()
96: {
97: register char *p;
98: register char *q;
99: char word[INMAX];
100:
101: if(! zznextc )
102: return nextlin() ;
103:
104: while( isspace(*zznextc) )
105: ++zznextc;
106: switch(*zznextc)
107: {
108: case '\0':
109: return nextlin() ;
110:
111: case '|':
112: if(zznextc[1]==':')
113: {
114: zznextc += 2;
115: return DOUBLECOLON;
116: }
117: break;
118: case ':':
119: if(*++zznextc == ':')
120: {
121: ++zznextc;
122: return DOUBLECOLON;
123: }
124: return COLON;
125: case '>':
126: ++zznextc;
127: return GREATER;
128: case '&':
129: if(*++zznextc == '&')
130: {
131: ++zznextc;
132: return AMPERAMPER;
133: }
134: return AMPER;
135: case ';':
136: return retsh(zznextc) ;
137: }
138:
139: p = zznextc;
140: q = word;
141:
142: while( ! ( funny[*p] & TERMINAL) )
143: *q++ = *p++;
144:
145: if(p != zznextc)
146: {
147: *q = '\0';
148: if((yylval.ynameblock=srchname(word))==0)
149: yylval.ynameblock = makename(word);
150: zznextc = p;
151: return NAME;
152: }
153:
154: else {
155: char junk[100];
156: sprintf(junk, "Bad character %c (octal %o), line %d of file %s",
157: *zznextc, *zznextc, yylineno, filestack[ninclude-1].fname);
158: fatal(junk);
159: }
160: return 0; /* never executed */
161: }
162:
163:
164:
165:
166:
167: retsh(q)
168: char *q;
169: {
170: register char *p;
171: struct shblock *sp;
172: char *copys();
173:
174: for(p=q+1 ; *p==' '||*p=='\t' ; ++p) ;
175:
176: sp = ALLOC(shblock);
177: sp->nxtshblock = NULL;
178: sp->shbp = (fin ? copys(p) : p );
179: yylval.yshblock = sp;
180: zznextc = 0;
181: return SHELLINE;
182: }
183:
184: nextlin()
185: {
186: static char yytext[INMAX];
187: static char *yytextl = yytext+INMAX;
188: char *text, templin[INMAX];
189: register char c;
190: register char *p, *t;
191: char lastch, *lastchp;
192: extern char **linesptr;
193: int incom;
194: int kc;
195:
196: again:
197:
198: incom = NO;
199: zznextc = 0;
200:
201: if(fin == NULL)
202: {
203: if( (text = *linesptr++) == 0)
204: return 0;
205: ++yylineno;
206: }
207:
208: else {
209: for(p = text = yytext ; p<yytextl ; *p++ = kc)
210: switch(kc = getc(fin))
211: {
212: case '\t':
213: if(p == yytext)
214: incom = YES;
215: break;
216:
217: case ';':
218: incom = YES;
219: break;
220:
221: case '#':
222: if(! incom)
223: kc = '\0';
224: break;
225:
226: case '\n':
227: ++yylineno;
228: if(p==yytext || p[-1]!='\\')
229: {
230: *p = '\0';
231: goto endloop;
232: }
233: p[-1] = ' ';
234: while( (kc=getc(fin))=='\t' || kc==' ' || kc=='\n')
235: if(kc == '\n')
236: ++yylineno;
237:
238: if(kc != EOF)
239: break;
240: case EOF:
241: *p = '\0';
242: if(ninclude > 1)
243: {
244: register struct fstack *stp;
245: fclose(fin);
246: --ninclude;
247: stp = filestack + ninclude;
248: fin = stp->fin;
249: yylineno = stp->lineno;
250: free(stp->fname);
251: goto again;
252: }
253: return 0;
254: }
255:
256: fatal("line too long");
257: }
258:
259: endloop:
260:
261: if((c = text[0]) == '\t')
262: return retsh(text) ;
263:
264: if(isalpha(c) || isdigit(c) || c==' ' || c=='.')
265: for(p=text+1; *p!='\0'; )
266: if(*p == ':')
267: break;
268: else if(*p++ == '=')
269: {
270: eqsign(text);
271: return MACRODEF;
272: }
273:
274:
275: if(!strncmp(text, "include", 7) && isinclude(text+7))
276: goto again;
277:
278: /* substitute for macros on dependency line up to the semicolon if any */
279:
280: for(t = yytext ; *t!='\0' && *t!=';' ; ++t)
281: ;
282:
283: lastchp = t;
284: lastch = *t;
285: *t = '\0'; /* replace the semi with a null so subst will stop */
286:
287: subst(yytext, templin); /* Substitute for macros on dependency lines */
288:
289: if(lastch) /* copy the stuff after the semicolon */
290: {
291: *lastchp = lastch;
292: strcat(templin, lastchp);
293: }
294:
295: strcpy(yytext, templin);
296:
297: for(p = zznextc = text ; *p ; ++p )
298: if(*p!=' ' && *p!='\t')
299: return START;
300: goto again;
301: }
302:
303:
304:
305: isinclude(s)
306: register char *s;
307: {
308: register char *t;
309: register struct fstack *p;
310:
311: for(t=s; *t==' ' || *t=='\t' ; ++t)
312: ;
313: if(t == s)
314: return NO;
315:
316: for(s = t; *s!='\n' && *s!='#' && *s!='\0' ; ++s)
317: if(*s == ':')
318: return NO;
319: *s = '\0';
320:
321: if(ninclude >= MAXINCLUDE)
322: fatal("include depth exceeded");
323: p = filestack + ninclude;
324: p->fin = fin;
325: p->lineno = yylineno;
326: p->fname = copys(t);
327: if( (fin = fopen(t, "r")) == NULL)
328: fatal1("Cannot open include file %s", t);
329: yylineno = 0;
330: ++ninclude;
331: return YES;
332: }
333:
334:
335:
336: yyerror(s)
337: char *s;
338: {
339: char buf[100];
340:
341: sprintf(buf, "line %d of file %s: %s",
342: yylineno, filestack[ninclude-1].fname, s);
343: fatal(buf);
344: }
345: short yyexca[] ={
346: -1, 1,
347: 0, -1,
348: -2, 0,
349: };
350: # define YYNPROD 22
351: # define YYLAST 21
352: short yyact[]={
353:
354: 17, 20, 21, 16, 7, 9, 11, 18, 19, 12,
355: 13, 5, 2, 1, 3, 4, 10, 8, 6, 14,
356: 15 };
357: short yypact[]={
358:
359: -1000,-245,-1000,-253,-1000,-1000,-252,-1000,-255,-1000,
360: -257,-263,-1000,-1000,-1000,-256,-1000,-1000,-1000,-1000,
361: -1000,-1000 };
362: short yypgo[]={
363:
364: 0, 20, 19, 18, 17, 16, 13, 12, 6 };
365: short yyr1[]={
366:
367: 0, 6, 6, 7, 7, 7, 7, 3, 3, 4,
368: 4, 5, 5, 5, 5, 5, 8, 8, 2, 2,
369: 1, 1 };
370: short yyr2[]={
371:
372: 0, 0, 2, 1, 1, 4, 1, 1, 2, 0,
373: 1, 1, 2, 2, 2, 2, 1, 1, 0, 1,
374: 1, 2 };
375: short yychk[]={
376:
377: -1000, -6, -7, 259, 260, 256, -3, 257, -4, 257,
378: -5, -8, 261, 262, -2, -1, 258, 257, 264, 265,
379: 264, 258 };
380: short yydef[]={
381:
382: 1, -2, 2, 3, 4, 6, 9, 7, 18, 8,
383: 10, 11, 16, 17, 5, 19, 20, 13, 14, 15,
384: 12, 21 };
385: # ifdef YYDEBUG
386: # include "y.debug"
387: # endif
388:
389: # define YYFLAG -1000
390: # define YYERROR goto yyerrlab
391: # define YYACCEPT return(0)
392: # define YYABORT return(1)
393:
394: /* parser for yacc output */
395:
396: #ifdef YYDEBUG
397: int yydebug = 0; /* 1 for debugging */
398: #endif
399: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
400: int yychar = -1; /* current input token number */
401: int yynerrs = 0; /* number of errors */
402: short yyerrflag = 0; /* error recovery flag */
403:
404: yyparse()
405: { short yys[YYMAXDEPTH];
406: int yyj, yym;
407: register YYSTYPE *yypvt;
408: register int yystate, yyn;
409: register short *yyps;
410: register YYSTYPE *yypv;
411: register short *yyxi;
412:
413: yystate = 0;
414: yychar = -1;
415: yynerrs = 0;
416: yyerrflag = 0;
417: yyps= &yys[-1];
418: yypv= &yyv[-1];
419:
420: yystack: /* put a state and value onto the stack */
421: #ifdef YYDEBUG
422: if(yydebug >= 3)
423: if(yychar < 0 || yytoknames[yychar] == 0)
424: printf("char %d in %s", yychar, yystates[yystate]);
425: else
426: printf("%s in %s", yytoknames[yychar], yystates[yystate]);
427: #endif
428: if( ++yyps >= &yys[YYMAXDEPTH] ) {
429: yyerror( "yacc stack overflow" );
430: return(1);
431: }
432: *yyps = yystate;
433: ++yypv;
434: *yypv = yyval;
435: yynewstate:
436: yyn = yypact[yystate];
437: if(yyn <= YYFLAG) goto yydefault; /* simple state */
438: if(yychar<0) {
439: yychar = yylex();
440: #ifdef YYDEBUG
441: if(yydebug >= 2) {
442: if(yychar <= 0)
443: printf("lex EOF\n");
444: else if(yytoknames[yychar])
445: printf("lex %s\n", yytoknames[yychar]);
446: else
447: printf("lex (%c)\n", yychar);
448: }
449: #endif
450: if(yychar < 0)
451: yychar = 0;
452: }
453: if((yyn += yychar) < 0 || yyn >= YYLAST)
454: goto yydefault;
455: if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
456: yychar = -1;
457: yyval = yylval;
458: yystate = yyn;
459: if( yyerrflag > 0 ) --yyerrflag;
460: goto yystack;
461: }
462: yydefault:
463: /* default state action */
464: if( (yyn=yydef[yystate]) == -2 ) {
465: if(yychar < 0) {
466: yychar = yylex();
467: #ifdef YYDEBUG
468: if(yydebug >= 2)
469: if(yychar < 0)
470: printf("lex EOF\n");
471: else
472: printf("lex %s\n", yytoknames[yychar]);
473: #endif
474: if(yychar < 0)
475: yychar = 0;
476: }
477: /* look through exception table */
478: for(yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate);
479: yyxi += 2 ) ; /* VOID */
480: while( *(yyxi+=2) >= 0 ){
481: if( *yyxi == yychar ) break;
482: }
483: if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
484: }
485: if( yyn == 0 ){ /* error */
486: /* error ... attempt to resume parsing */
487: switch( yyerrflag ){
488: case 0: /* brand new error */
489: #ifdef YYDEBUG
490: yyerror("syntax error\n%s", yystates[yystate]);
491: if(yytoknames[yychar])
492: yyerror("saw %s\n", yytoknames[yychar]);
493: else if(yychar >= ' ' && yychar < '\177')
494: yyerror("saw `%c'\n", yychar);
495: else if(yychar == 0)
496: yyerror("saw EOF\n");
497: else
498: yyerror("saw char 0%o\n", yychar);
499: #else
500: yyerror( "syntax error" );
501: #endif
502: yyerrlab:
503: ++yynerrs;
504: case 1:
505: case 2: /* incompletely recovered error ... try again */
506: yyerrflag = 3;
507: /* find a state where "error" is a legal shift action */
508: while ( yyps >= yys ) {
509: yyn = yypact[*yyps] + YYERRCODE;
510: if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
511: yystate = yyact[yyn]; /* simulate a shift of "error" */
512: goto yystack;
513: }
514: yyn = yypact[*yyps];
515: /* the current yyps has no shift onn "error", pop stack */
516: #ifdef YYDEBUG
517: if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
518: #endif
519: --yyps;
520: --yypv;
521: }
522: /* there is no state on the stack with an error shift ... abort */
523: yyabort:
524: return(1);
525: case 3: /* no shift yet; clobber input char */
526: #ifdef YYDEBUG
527: if( yydebug ) {
528: printf("error recovery discards ");
529: if(yytoknames[yychar])
530: printf("%s\n", yytoknames[yychar]);
531: else if(yychar >= ' ' && yychar < '\177')
532: printf("`%c'\n", yychar);
533: else if(yychar == 0)
534: printf("EOF\n");
535: else
536: printf("char 0%o\n", yychar);
537: }
538: #endif
539: if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
540: yychar = -1;
541: goto yynewstate; /* try again in the same state */
542: }
543: }
544: /* reduction by production yyn */
545: #ifdef YYDEBUG
546: if(yydebug) { char *s;
547: printf("reduce %d in:\n\t", yyn);
548: for(s = yystates[yystate]; *s; s++) {
549: putchar(*s);
550: if(*s == '\n' && *(s+1))
551: putchar('\t');
552: }
553: }
554: #endif
555: yyps -= yyr2[yyn];
556: yypvt = yypv;
557: yypv -= yyr2[yyn];
558: yyval = yypv[1];
559: yym=yyn;
560: /* consult goto table to find next state */
561: yyn = yyr1[yyn];
562: yyj = yypgo[yyn] + *yyps + 1;
563: if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
564: switch(yym){
565:
566: case 5:
567: # line 49 "gram.y"
568: {
569: while( --nlefts >= 0)
570: {
571: wildp iswild(), wp;
572:
573: leftp = lefts[nlefts];
574: if(wp = iswild(leftp->namep))
575: {
576: leftp->septype = SOMEDEPS;
577: if(lastwild)
578: lastwild->next = wp;
579: else
580: firstwild = wp;
581: lastwild = wp;
582: }
583:
584: if(leftp->septype == 0)
585: leftp->septype = sepc;
586: else if(leftp->septype != sepc)
587: {
588: if(! wp)
589: fprintf(stderr,
590: "Inconsistent rules lines for `%s'\n",
591: leftp->namep);
592: }
593: else if(sepc==ALLDEPS && leftp->namep[0]!='.' && yypvt[-0].yshblock!=0)
594: {
595: for(lp=leftp->linep; lp->nxtlineblock; lp=lp->nxtlineblock)
596: if(lp->shp)
597: fprintf(stderr,
598: "Multiple rules lines for `%s'\n",
599: leftp->namep);
600: }
601:
602: lp = ALLOC(lineblock);
603: lp->nxtlineblock = NULL;
604: lp->depp = yypvt[-1].ydepblock;
605: lp->shp = yypvt[-0].yshblock;
606: if(wp)
607: wp->linep = lp;
608:
609: if(equal(leftp->namep, ".SUFFIXES") && yypvt[-1].ydepblock==0)
610: leftp->linep = 0;
611: else if(leftp->linep == 0)
612: leftp->linep = lp;
613: else {
614: for(lpp = leftp->linep; lpp->nxtlineblock;
615: lpp = lpp->nxtlineblock) ;
616: if(sepc==ALLDEPS && leftp->namep[0]=='.')
617: lpp->shp = 0;
618: lpp->nxtlineblock = lp;
619: }
620: }
621: } break;
622: case 7:
623: # line 106 "gram.y"
624: { lefts[0] = yypvt[-0].ynameblock; nlefts = 1; } break;
625: case 8:
626: # line 107 "gram.y"
627: { lefts[nlefts++] = yypvt[-0].ynameblock;
628: if(nlefts>=NLEFTS) fatal("Too many lefts"); } break;
629: case 9:
630: # line 112 "gram.y"
631: {
632: char junk[10];
633: sprintf(junk, "%d", yylineno);
634: fatal1("Must be a separator on rules line %s", junk);
635: } break;
636: case 11:
637: # line 120 "gram.y"
638: { prevdep = 0; yyval.ydepblock = 0; allnowait = NO; } break;
639: case 12:
640: # line 121 "gram.y"
641: { prevdep = 0; yyval.ydepblock = 0; allnowait = YES; } break;
642: case 13:
643: # line 122 "gram.y"
644: {
645: pp = ALLOC(depblock);
646: pp->nxtdepblock = NULL;
647: pp->depname = yypvt[-0].ynameblock;
648: pp->nowait = allnowait;
649: if(prevdep == 0) yyval.ydepblock = pp;
650: else prevdep->nxtdepblock = pp;
651: prevdep = pp;
652: } break;
653: case 14:
654: # line 131 "gram.y"
655: { if(prevdep) prevdep->nowait = YES; } break;
656: case 16:
657: # line 135 "gram.y"
658: { sepc = ALLDEPS; } break;
659: case 17:
660: # line 136 "gram.y"
661: { sepc = SOMEDEPS; } break;
662: case 18:
663: # line 139 "gram.y"
664: {yyval.yshblock = 0; } break;
665: case 19:
666: # line 140 "gram.y"
667: { yyval.yshblock = yypvt[-0].yshblock; } break;
668: case 20:
669: # line 143 "gram.y"
670: { yyval.yshblock = yypvt[-0].yshblock; prevshp = yypvt[-0].yshblock; } break;
671: case 21:
672: # line 144 "gram.y"
673: { yyval.yshblock = yypvt[-1].yshblock;
674: prevshp->nxtshblock = yypvt[-0].yshblock;
675: prevshp = yypvt[-0].yshblock;
676: } break;
677: }
678: goto yystack; /* stack new state and value */
679: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.