3 getl(uchar *p) /* return next line of input, throw away trailing '\n' */
4 /* returns 0 if eof is had immediately */
10 while(((c = gch()) != 0) && c != '\n')
13 if(c == 0 && s == t) return((uchar *)0);
20 printerr(char *type, char *fmt, va_list argl)
24 if(!eof)fprint(errorf,"%s:%d ", yyfile, yyline);
25 fprint(errorf,"(%s) ", type);
26 vseprint(buf, buf+sizeof(buf), fmt, argl);
27 fprint(errorf, "%s\n", buf);
37 printerr("Error", s, argl);
40 if(debug && sect != ENDSECTION) {
49 report == 1) statistics();
50 exits("error"); /* error return code */
59 printerr("Warning", s, argl);
72 fd = create("lex.yy.c", OWRITE, 0666);
74 error("Can't open lex.yy.c: %r");
75 Binit(&fout, fd, OWRITE);
87 if(!sw){ /* is NCCL */
89 symbol[i] ^= 1; /* reverse value */
95 /* see if ccl is already in our table */
99 if((symbol[j] && cindex[j] != i) ||
100 (!symbol[j] && cindex[j] == i)) break;
103 if(j >= NCH) return; /* already in */
114 /* m == 1 implies last value of ccount has been used */
116 if(k == 0) return; /* is now in as ccount wholly */
117 /* intersection must be computed */
121 j = cindex[i]; /* will be non-zero */
124 if(symbol[k]) symbol[k] = 0;
141 case 'n': c = '\n'; break;
142 case 'r': c = '\r'; break;
143 case 't': c = '\t'; break;
144 case 'b': c = '\b'; break;
145 case 'f': c = 014; break; /* form feed for ascii */
146 case '0': case '1': case '2': case '3':
147 case '4': case '5': case '6': case '7':
149 while('0' <= (d=gch()) && d <= '7'){
151 if(!('0' <= peek && peek <= '7')) break;
159 lookup(uchar *s, uchar **t)
164 if(strcmp((char *)s, *(char **)t) == 0)
174 { /* copy C action to the next ; or closing } */
189 case '|': if(brac == 0 && sw == TRUE){
190 if(peek == '|')gch(); /* eat up an extra '|' */
218 case '/': /* look for comments */
221 if( c != '*' ) goto swt;
223 /* it really is a comment */
231 if( (c=gch()) == '/' ) goto loop;
237 error( "EOF inside comment" );
239 case '\'': /* character constant */
243 case '"': /* character string */
254 else if( c==mth ) goto loop;
258 error( "Non-terminated string or character constant");
261 error( "EOF in string or character constant" );
266 error("Action does not terminate");
268 break; /* usual character */
271 if(c != ' ' && c != '\t' && c != '\n') sw = FALSE;
274 error("Premature EOF");
283 peek = pushptr > pushc ? *--pushptr : Bgetc(fin);
284 if(peek == Beof && sargc > 1){
286 yyfile = sargv[fptr++];
287 fin = Bopen(yyfile,OREAD);
289 error("%s - cannot open file: %r",yyfile);
300 if(c == '\n')yyline++;
305 mn2(int a, int d, int c)
318 if(nullstr[d] || nullstr[c]) nullstr[tptr] = TRUE;
319 parent[d] = parent[c] = tptr;
323 if(nullstr[d] && nullstr[c])nullstr[tptr] = TRUE;
324 parent[d] = parent[c] = tptr;
328 nullstr[tptr] = nullstr[d];
332 warning("bad switch mn2 %d %d",a,d);
337 error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
352 if(strlen(p) == 0) nullstr[tptr] = TRUE;
355 error("bad switch mnp %d %P", a, p);
359 error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
373 nullstr[tptr] = TRUE;
378 nullstr[tptr] = nullstr[d];
382 nullstr[tptr] = TRUE;
389 warning("bad switch mn1 %d %d",a,d);
394 error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
404 if(a >= NCH) switch(a){
405 case RNULLS: nullstr[tptr] = TRUE; break;
408 warning("bad switch mn0 %d",a);
413 error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
420 *pushptr++ = peek; /* watch out for this */
422 if(pushptr >= pushc+TOKENSIZE)
423 error("Too many characters pushed");
432 i = strlen((char*)p);
433 for(j = i-1; j>=1; j--)
435 if(pushptr >= pushc+TOKENSIZE)
436 error("Too many characters pushed");
442 /* duplicate the subtree whose root is n, return ptr to it */
446 if(i < NCH) return(mn0(i));
450 case RCCL: case RNCCL:
451 return(mnp(i,ptr[n]));
452 case FINAL: case S1FINAL: case S2FINAL:
453 return(mn1(i,left[n]));
454 case STAR: case QUEST: case PLUS: case CARAT:
455 return(mn1(i,dupl(left[n])));
456 case RSTR: case RSCON:
457 return(mn2(i,dupl(left[n]),right[n]));
458 case BAR: case RNEWE: case RCAT: case DIV:
459 return(mn2(i,dupl(left[n]),dupl(right[n])));
462 warning("bad switch dupl %d",n);
473 c += 256; /* signed char */
511 if(charc > LINESIZE){
525 print("str trans\n");
528 print("%s\t%s\n",def[i],subs[i]);
531 print("start names\n");
534 print("%s\n",sname[i]);
550 print("treedump %d nodes:\n",tptr);
553 parent[t] ? print("p=%4d",parent[t]) : print(" ");
557 else switch(name[t]){
559 print("%d ",left[t]);
571 print("/ %d %d",left[t],right[t]);
574 print("| %d %d",left[t],right[t]);
577 print("cat %d %d",left[t],right[t]);
580 print("+ %d",left[t]);
583 print("* %d",left[t]);
586 print("^ %d",left[t]);
589 print("? %d",left[t]);
595 print("final %d",left[t]);
598 print("s1final %d",left[t]);
601 print("s2final %d",left[t]);
604 print("new %d %d",left[t],right[t]);
607 p = (uchar *)right[t];
608 print("start %s",sname[*p++-1]);
610 print(", %s",sname[*p++-1]);
611 print(" %d",left[t]);
614 print("unknown %d %d %d",name[t],left[t],right[t]);
617 if(nullstr[t])print("\t(null poss.)");