114493Ssam #ifndef lint 2*46777Sbostic static char sccsid[] = "@(#)sub1.c 4.5 (Berkeley) 02/28/91"; 314493Ssam #endif 414493Ssam 514493Ssam # include "ldefs.c" 6*46777Sbostic # include <stdarg.h> 7*46777Sbostic 814493Ssam char * 914493Ssam getl(p) /* return next line of input, throw away trailing '\n' */ 1014493Ssam /* returns 0 if eof is had immediately */ 1114493Ssam char *p; 1214493Ssam { 1314493Ssam register int c; 1414493Ssam register char *s, *t; 1514493Ssam t = s = p; 1614493Ssam while(((c = gch()) != 0) && c != '\n') 1714493Ssam *t++ = c; 1814493Ssam *t = 0; 1914493Ssam if(c == 0 && s == t) return(0); 2014493Ssam prev = '\n'; 2114493Ssam pres = '\n'; 2214493Ssam return(s); 2314493Ssam } 2414493Ssam space(ch) 2514493Ssam { 2614493Ssam switch(ch) 2714493Ssam { 2814493Ssam case ' ': 2914493Ssam case '\t': 3014493Ssam case '\n': 3114493Ssam return(1); 3214493Ssam } 3314493Ssam return(0); 3414493Ssam } 3514493Ssam 3614493Ssam digit(c) 3714493Ssam { 3814493Ssam return(c>='0' && c <= '9'); 3914493Ssam } 40*46777Sbostic 41*46777Sbostic error(s) 42*46777Sbostic char *s; 43*46777Sbostic { 44*46777Sbostic va_list ap; 45*46777Sbostic 4618033Sserge fprintf(errorf,"\"%s\", line %d: (Error) ", 4718033Sserge fptr > 0 ? sargv[fptr] : "<stdin>", yyline); 48*46777Sbostic va_start(ap, s); 49*46777Sbostic vfprintf(errorf, s, ap); 50*46777Sbostic va_end(ap); 51*46777Sbostic putc('\n', errorf); 5214493Ssam # ifdef DEBUG 5314493Ssam if(debug && sect != ENDSECTION) { 5414493Ssam sect1dump(); 5514493Ssam sect2dump(); 5614493Ssam } 5714493Ssam # endif 5814493Ssam if( 5914493Ssam # ifdef DEBUG 6014493Ssam debug || 6114493Ssam # endif 6214493Ssam report == 1) statistics(); 6314493Ssam exit(1); /* error return code */ 6414493Ssam } 6514493Ssam 66*46777Sbostic warning(s) 67*46777Sbostic char *s; 68*46777Sbostic { 69*46777Sbostic va_list ap; 70*46777Sbostic 7118033Sserge fprintf(errorf,"\"%s\", line %d: (Warning) ", 7218033Sserge fptr > 0 ? sargv[fptr] : "<stdin>", yyline); 73*46777Sbostic va_start(ap, s); 74*46777Sbostic vfprintf(errorf, s, ap); 75*46777Sbostic va_end(ap); 7614493Ssam putc('\n',errorf); 7714493Ssam fflush(errorf); 7814493Ssam fflush(fout); 7914493Ssam fflush(stdout); 8014493Ssam } 8114493Ssam index(a,s) 8214493Ssam char *s; 8314493Ssam { 8414493Ssam register int k; 8514493Ssam for(k=0; s[k]; k++) 8614493Ssam if (s[k]== a) 8714493Ssam return(k); 8814493Ssam return(-1); 8914493Ssam } 9014493Ssam 9114493Ssam alpha(c) 9214493Ssam int c; { 9314493Ssam # ifdef ASCII 9414493Ssam return('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z'); 9514493Ssam # endif 9614493Ssam # ifdef EBCDIC 9714493Ssam return(index(c,"abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") >= 0); 9814493Ssam # endif 9914493Ssam } 10014493Ssam printable(c) 10114493Ssam { 10214493Ssam # ifdef ASCII 10314493Ssam return( c>040 && c < 0177); 10414493Ssam # endif 10514493Ssam # ifdef EBCDIC 10614493Ssam return(index(c, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;:><+*)('&%!-=\"")>=0); 10714493Ssam # endif 10814493Ssam } 10914493Ssam lgate() 11014493Ssam { 11114493Ssam char fname[20]; 11214493Ssam if (lgatflg) return; 11314493Ssam lgatflg=1; 11414493Ssam if(fout == NULL){ 11514493Ssam sprintf(fname, "lex.yy.%c", ratfor ? 'r' : 'c' ); 11614493Ssam fout = fopen(fname, "w"); 11714493Ssam } 11814493Ssam if(fout == NULL) error("Can't open %s",fname); 11914493Ssam if(ratfor) fprintf( fout, "#\n"); 12014493Ssam phead1(); 12114493Ssam } 12214493Ssam /* scopy(ptr to str, ptr to str) - copy first arg str to second */ 12314493Ssam /* returns ptr to second arg */ 12414493Ssam scopy(s,t) 12514493Ssam char *s, *t; { 12614493Ssam register char *i; 12714493Ssam i = t; 12814493Ssam while(*i++ = *s++); 12914493Ssam return; 13014493Ssam } 13114493Ssam siconv(t) /* convert string t, return integer value */ 13214493Ssam char *t; { 13314493Ssam register int i,sw; 13414493Ssam register char *s; 13514493Ssam s = t; 13614493Ssam while(!(('0' <= *s && *s <= '9') || *s == '-') && *s) s++; 13714493Ssam sw = 0; 13814493Ssam if(*s == '-'){ /* neg */ 13914493Ssam sw = 1; 14014493Ssam s++; 14114493Ssam } 14214493Ssam i = 0; 14314493Ssam while('0' <= *s && *s <= '9') 14414493Ssam i = i * 10 + (*(s++)-'0'); 14514493Ssam return(sw ? -i : i); 14614493Ssam } 14714493Ssam /* slength(ptr to str) - return integer length of string arg */ 14814493Ssam /* excludes '\0' terminator */ 14914493Ssam slength(s) 15014493Ssam char *s; { 15114493Ssam register int n; 15214493Ssam register char *t; 15314493Ssam t = s; 15414493Ssam for (n = 0; *t++; n++); 15514493Ssam return(n); 15614493Ssam } 15714493Ssam /* scomp(x,y) - return -1 if x < y, 15814493Ssam 0 if x == y, 15914493Ssam return 1 if x > y, all lexicographically */ 16014493Ssam scomp(x,y) 16114493Ssam char *x,*y; { 16214493Ssam register char *a,*d; 16314493Ssam a = x; 16414493Ssam d = y; 16514493Ssam while(*a || *d){ 16614493Ssam if(*a > *d) 16714493Ssam return(1); /* greater */ 16814493Ssam if(*a < *d) 16914493Ssam return(-1); /* less */ 17014493Ssam a++; 17114493Ssam d++; 17214493Ssam } 17314493Ssam return(0); /* equal */ 17414493Ssam } 17514493Ssam ctrans(ss) 17614493Ssam char **ss; 17714493Ssam { 17814493Ssam register int c, k; 17914493Ssam if ((c = **ss) != '\\') 18014493Ssam return(c); 18114493Ssam switch(c= *++*ss) 18214493Ssam { 18314493Ssam case 'n': c = '\n'; break; 18414493Ssam case 't': c = '\t'; break; 18514493Ssam case 'r': c = '\r'; break; 18614493Ssam case 'b': c = '\b'; break; 18714493Ssam case 'f': c = 014; break; /* form feed for ascii */ 18814493Ssam case '\\': c = '\\'; break; 18914493Ssam case '0': case '1': case '2': case '3': 19014493Ssam case '4': case '5': case '6': case '7': 19114493Ssam c -= '0'; 19214493Ssam while ((k = *(*ss+1)) >= '0' && k <= '7') 19314493Ssam { 19414493Ssam c = c*8 + k - '0'; 19514493Ssam (*ss)++; 19614493Ssam } 19714493Ssam break; 19814493Ssam } 19914493Ssam return(c); 20014493Ssam } 20114493Ssam cclinter(sw) 20214493Ssam int sw; { 20314493Ssam /* sw = 1 ==> ccl */ 20414493Ssam register int i, j, k; 20514493Ssam int m; 20614493Ssam if(!sw){ /* is NCCL */ 20714493Ssam for(i=1;i<NCH;i++) 20814493Ssam symbol[i] ^= 1; /* reverse value */ 20914493Ssam } 21014493Ssam for(i=1;i<NCH;i++) 21114493Ssam if(symbol[i]) break; 21214493Ssam if(i >= NCH) return; 21314493Ssam i = cindex[i]; 21414493Ssam /* see if ccl is already in our table */ 21514493Ssam j = 0; 21614493Ssam if(i){ 21714493Ssam for(j=1;j<NCH;j++){ 21814493Ssam if((symbol[j] && cindex[j] != i) || 21914493Ssam (!symbol[j] && cindex[j] == i)) break; 22014493Ssam } 22114493Ssam } 22214493Ssam if(j >= NCH) return; /* already in */ 22314493Ssam m = 0; 22414493Ssam k = 0; 22514493Ssam for(i=1;i<NCH;i++) 22614493Ssam if(symbol[i]){ 22714493Ssam if(!cindex[i]){ 22814493Ssam cindex[i] = ccount; 22914493Ssam symbol[i] = 0; 23014493Ssam m = 1; 23114493Ssam } 23214493Ssam else k = 1; 23314493Ssam } 23414493Ssam /* m == 1 implies last value of ccount has been used */ 23514493Ssam if(m)ccount++; 23614493Ssam if(k == 0) return; /* is now in as ccount wholly */ 23714493Ssam /* intersection must be computed */ 23814493Ssam for(i=1;i<NCH;i++){ 23914493Ssam if(symbol[i]){ 24014493Ssam m = 0; 24114493Ssam j = cindex[i]; /* will be non-zero */ 24214493Ssam for(k=1;k<NCH;k++){ 24314493Ssam if(cindex[k] == j){ 24414493Ssam if(symbol[k]) symbol[k] = 0; 24514493Ssam else { 24614493Ssam cindex[k] = ccount; 24714493Ssam m = 1; 24814493Ssam } 24914493Ssam } 25014493Ssam } 25114493Ssam if(m)ccount++; 25214493Ssam } 25314493Ssam } 25414493Ssam return; 25514493Ssam } 25614493Ssam usescape(c) 25714493Ssam int c; { 25814493Ssam register char d; 25914493Ssam switch(c){ 26014493Ssam case 'n': c = '\n'; break; 26114493Ssam case 'r': c = '\r'; break; 26214493Ssam case 't': c = '\t'; break; 26314493Ssam case 'b': c = '\b'; break; 26414493Ssam case 'f': c = 014; break; /* form feed for ascii */ 26514493Ssam case '0': case '1': case '2': case '3': 26614493Ssam case '4': case '5': case '6': case '7': 26714493Ssam c -= '0'; 26814493Ssam while('0' <= (d=gch()) && d <= '7'){ 26914493Ssam c = c * 8 + (d-'0'); 27014493Ssam if(!('0' <= peek && peek <= '7')) break; 27114493Ssam } 27214493Ssam break; 27314493Ssam } 27414493Ssam return(c); 27514493Ssam } 27614493Ssam lookup(s,t) 27714493Ssam char *s; 27814493Ssam char **t; { 27914493Ssam register int i; 28014493Ssam i = 0; 28114493Ssam while(*t){ 28214493Ssam if(scomp(s,*t) == 0) 28314493Ssam return(i); 28414493Ssam i++; 28514493Ssam t++; 28614493Ssam } 28714493Ssam return(-1); 28814493Ssam } 28914493Ssam cpyact(){ /* copy C action to the next ; or closing } */ 29014493Ssam register int brac, c, mth; 29114493Ssam int savline, sw; 29214493Ssam 29314493Ssam brac = 0; 29414493Ssam sw = TRUE; 29514493Ssam 29614493Ssam while(!eof){ 29714493Ssam c = gch(); 29814493Ssam swt: 29914493Ssam switch( c ){ 30014493Ssam 30114493Ssam case '|': if(brac == 0 && sw == TRUE){ 30214493Ssam if(peek == '|')gch(); /* eat up an extra '|' */ 30314493Ssam return(0); 30414493Ssam } 30514493Ssam break; 30614493Ssam 30714493Ssam case ';': 30814493Ssam if( brac == 0 ){ 30914493Ssam putc(c,fout); 31014493Ssam putc('\n',fout); 31114493Ssam return(1); 31214493Ssam } 31314493Ssam break; 31414493Ssam 31514493Ssam case '{': 31614493Ssam brac++; 31714493Ssam savline=yyline; 31814493Ssam break; 31914493Ssam 32014493Ssam case '}': 32114493Ssam brac--; 32214493Ssam if( brac == 0 ){ 32314493Ssam putc(c,fout); 32414493Ssam putc('\n',fout); 32514493Ssam return(1); 32614493Ssam } 32714493Ssam break; 32814493Ssam 32914493Ssam case '/': /* look for comments */ 33014493Ssam putc(c,fout); 33114493Ssam c = gch(); 33214493Ssam if( c != '*' ) goto swt; 33314493Ssam 33414493Ssam /* it really is a comment */ 33514493Ssam 33614493Ssam putc(c,fout); 33714493Ssam savline=yyline; 33814493Ssam while( c=gch() ){ 33914493Ssam if( c=='*' ){ 34014493Ssam putc(c,fout); 34114493Ssam if( (c=gch()) == '/' ) goto loop; 34214493Ssam } 34314493Ssam putc(c,fout); 34414493Ssam } 34514493Ssam yyline=savline; 34614493Ssam error( "EOF inside comment" ); 34714493Ssam 34814493Ssam case '\'': /* character constant */ 34914493Ssam mth = '\''; 35014493Ssam goto string; 35114493Ssam 35214493Ssam case '"': /* character string */ 35314493Ssam mth = '"'; 35414493Ssam 35514493Ssam string: 35614493Ssam 35714493Ssam putc(c,fout); 35814493Ssam while( c=gch() ){ 35914493Ssam if( c=='\\' ){ 36014493Ssam putc(c,fout); 36114493Ssam c=gch(); 36214493Ssam } 36314493Ssam else if( c==mth ) goto loop; 36414493Ssam putc(c,fout); 36514493Ssam if (c == '\n') 36614493Ssam { 36714493Ssam yyline--; 36814493Ssam error( "Non-terminated string or character constant"); 36914493Ssam } 37014493Ssam } 37114493Ssam error( "EOF in string or character constant" ); 37214493Ssam 37314493Ssam case '\0': 37414493Ssam yyline = savline; 37514493Ssam error("Action does not terminate"); 37614493Ssam default: 37714493Ssam break; /* usual character */ 37814493Ssam } 37914493Ssam loop: 38014493Ssam if(c != ' ' && c != '\t' && c != '\n') sw = FALSE; 38114493Ssam putc(c,fout); 38214493Ssam } 38314493Ssam error("Premature EOF"); 38414493Ssam } 38514493Ssam gch(){ 38614493Ssam register int c; 38718033Sserge static int hadeof; 38818033Sserge 38918033Sserge if (hadeof) { 39018033Sserge hadeof = 0; 39118033Sserge yyline = 0; 39218033Sserge } 39314493Ssam prev = pres; 39414493Ssam c = pres = peek; 39514493Ssam peek = pushptr > pushc ? *--pushptr : getc(fin); 39614493Ssam if(peek == EOF && sargc > 1){ 39718033Sserge hadeof = 1; 39814493Ssam fclose(fin); 39914493Ssam fin = fopen(sargv[++fptr],"r"); 40018033Sserge if(fin == NULL) { 40118033Sserge yyline = 0; 40214493Ssam error("Cannot open file %s",sargv[fptr]); 40318033Sserge } 40414493Ssam peek = getc(fin); 40514493Ssam sargc--; 40614493Ssam } 40714493Ssam if(c == EOF) { 40814493Ssam eof = TRUE; 40914493Ssam fclose(fin); 41014493Ssam return(0); 41114493Ssam } 41214493Ssam if(c == '\n')yyline++; 41314493Ssam return(c); 41414493Ssam } 41514493Ssam mn2(a,d,c) 41614493Ssam int a,d,c; 41714493Ssam { 41814493Ssam name[tptr] = a; 41914493Ssam left[tptr] = d; 42014493Ssam right[tptr] = c; 42114493Ssam parent[tptr] = 0; 42214493Ssam nullstr[tptr] = 0; 42314493Ssam switch(a){ 42414493Ssam case RSTR: 42514493Ssam parent[d] = tptr; 42614493Ssam break; 42714493Ssam case BAR: 42814493Ssam case RNEWE: 42914493Ssam if(nullstr[d] || nullstr[c]) nullstr[tptr] = TRUE; 43014493Ssam parent[d] = parent[c] = tptr; 43114493Ssam break; 43214493Ssam case RCAT: 43314493Ssam case DIV: 43414493Ssam if(nullstr[d] && nullstr[c])nullstr[tptr] = TRUE; 43514493Ssam parent[d] = parent[c] = tptr; 43614493Ssam break; 43714493Ssam case RSCON: 43814493Ssam parent[d] = tptr; 43914493Ssam nullstr[tptr] = nullstr[d]; 44014493Ssam break; 44114493Ssam # ifdef DEBUG 44214493Ssam default: 44314493Ssam warning("bad switch mn2 %d %d",a,d); 44414493Ssam break; 44514493Ssam # endif 44614493Ssam } 44714493Ssam if(tptr > treesize) 44814493Ssam error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":"")); 44914493Ssam return(tptr++); 45014493Ssam } 45114493Ssam mn1(a,d) 45214493Ssam int a,d; 45314493Ssam { 45414493Ssam name[tptr] = a; 45514493Ssam left[tptr] = d; 45614493Ssam parent[tptr] = 0; 45714493Ssam nullstr[tptr] = 0; 45814493Ssam switch(a){ 45914493Ssam case RCCL: 46014493Ssam case RNCCL: 46114493Ssam if(slength(d) == 0) nullstr[tptr] = TRUE; 46214493Ssam break; 46314493Ssam case STAR: 46414493Ssam case QUEST: 46514493Ssam nullstr[tptr] = TRUE; 46614493Ssam parent[d] = tptr; 46714493Ssam break; 46814493Ssam case PLUS: 46914493Ssam case CARAT: 47014493Ssam nullstr[tptr] = nullstr[d]; 47114493Ssam parent[d] = tptr; 47214493Ssam break; 47314493Ssam case S2FINAL: 47414493Ssam nullstr[tptr] = TRUE; 47514493Ssam break; 47614493Ssam # ifdef DEBUG 47714493Ssam case FINAL: 47814493Ssam case S1FINAL: 47914493Ssam break; 48014493Ssam default: 48114493Ssam warning("bad switch mn1 %d %d",a,d); 48214493Ssam break; 48314493Ssam # endif 48414493Ssam } 48514493Ssam if(tptr > treesize) 48614493Ssam error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":"")); 48714493Ssam return(tptr++); 48814493Ssam } 48914493Ssam mn0(a) 49014493Ssam int a; 49114493Ssam { 49214493Ssam name[tptr] = a; 49314493Ssam parent[tptr] = 0; 49414493Ssam nullstr[tptr] = 0; 49514493Ssam if(a >= NCH) switch(a){ 49614493Ssam case RNULLS: nullstr[tptr] = TRUE; break; 49714493Ssam # ifdef DEBUG 49814493Ssam default: 49914493Ssam warning("bad switch mn0 %d",a); 50014493Ssam break; 50114493Ssam # endif 50214493Ssam } 50314493Ssam if(tptr > treesize) 50414493Ssam error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":"")); 50514493Ssam return(tptr++); 50614493Ssam } 50714493Ssam munput(t,p) /* implementation dependent */ 50814493Ssam char *p; 50914493Ssam int t; { 51014493Ssam register int i,j; 51114493Ssam if(t == 'c'){ 51214493Ssam *pushptr++ = peek; /* watch out for this */ 51333342Sbostic peek = (int)p; 51414493Ssam } 51514493Ssam else if(t == 's'){ 51614493Ssam *pushptr++ = peek; 51714493Ssam peek = p[0]; 51814493Ssam i = slength(p); 51914493Ssam for(j = i-1; j>=1; j--) 52014493Ssam *pushptr++ = p[j]; 52114493Ssam } 52214493Ssam # ifdef DEBUG 52314493Ssam else error("Unrecognized munput option %c",t); 52414493Ssam # endif 52514493Ssam if(pushptr >= pushc+TOKENSIZE) 52614493Ssam error("Too many characters pushed"); 52714493Ssam return; 52814493Ssam } 52914493Ssam 53014493Ssam dupl(n) 53114493Ssam int n; { 53214493Ssam /* duplicate the subtree whose root is n, return ptr to it */ 53314493Ssam register int i; 53414493Ssam i = name[n]; 53514493Ssam if(i < NCH) return(mn0(i)); 53614493Ssam switch(i){ 53714493Ssam case RNULLS: 53814493Ssam return(mn0(i)); 53914493Ssam case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL: 54014493Ssam return(mn1(i,left[n])); 54114493Ssam case STAR: case QUEST: case PLUS: case CARAT: 54214493Ssam return(mn1(i,dupl(left[n]))); 54314493Ssam case RSTR: case RSCON: 54414493Ssam return(mn2(i,dupl(left[n]),right[n])); 54514493Ssam case BAR: case RNEWE: case RCAT: case DIV: 54614493Ssam return(mn2(i,dupl(left[n]),dupl(right[n]))); 54714493Ssam # ifdef DEBUG 54814493Ssam default: 54914493Ssam warning("bad switch dupl %d",n); 55014493Ssam # endif 55114493Ssam } 55214493Ssam return(0); 55314493Ssam } 55414493Ssam # ifdef DEBUG 55514493Ssam allprint(c) 55614493Ssam char c; { 55714493Ssam switch(c){ 55814493Ssam case 014: 55914493Ssam printf("\\f"); 56014493Ssam charc++; 56114493Ssam break; 56214493Ssam case '\n': 56314493Ssam printf("\\n"); 56414493Ssam charc++; 56514493Ssam break; 56614493Ssam case '\t': 56714493Ssam printf("\\t"); 56814493Ssam charc++; 56914493Ssam break; 57014493Ssam case '\b': 57114493Ssam printf("\\b"); 57214493Ssam charc++; 57314493Ssam break; 57414493Ssam case ' ': 57514493Ssam printf("\\\bb"); 57614493Ssam break; 57714493Ssam default: 57814493Ssam if(!printable(c)){ 57914493Ssam printf("\\%-3o",c); 58032766Sbostic charc += 3; 58114493Ssam } 58214493Ssam else 58314493Ssam putchar(c); 58414493Ssam break; 58514493Ssam } 58614493Ssam charc++; 58714493Ssam return; 58814493Ssam } 58914493Ssam strpt(s) 59014493Ssam char *s; { 59114493Ssam charc = 0; 59214493Ssam while(*s){ 59314493Ssam allprint(*s++); 59414493Ssam if(charc > LINESIZE){ 59514493Ssam charc = 0; 59614493Ssam printf("\n\t"); 59714493Ssam } 59814493Ssam } 59914493Ssam return; 60014493Ssam } 60114493Ssam sect1dump(){ 60214493Ssam register int i; 60314493Ssam printf("Sect 1:\n"); 60414493Ssam if(def[0]){ 60514493Ssam printf("str trans\n"); 60614493Ssam i = -1; 60714493Ssam while(def[++i]) 60814493Ssam printf("%s\t%s\n",def[i],subs[i]); 60914493Ssam } 61014493Ssam if(sname[0]){ 61114493Ssam printf("start names\n"); 61214493Ssam i = -1; 61314493Ssam while(sname[++i]) 61414493Ssam printf("%s\n",sname[i]); 61514493Ssam } 61614493Ssam if(chset == TRUE){ 61714493Ssam printf("char set changed\n"); 61814493Ssam for(i=1;i<NCH;i++){ 61914493Ssam if(i != ctable[i]){ 62014493Ssam allprint(i); 62114493Ssam putchar(' '); 62214493Ssam printable(ctable[i]) ? putchar(ctable[i]) : printf("%d",ctable[i]); 62314493Ssam putchar('\n'); 62414493Ssam } 62514493Ssam } 62614493Ssam } 62714493Ssam } 62814493Ssam sect2dump(){ 62914493Ssam printf("Sect 2:\n"); 63014493Ssam treedump(); 63114493Ssam } 63214493Ssam treedump() 63314493Ssam { 63414493Ssam register int t; 63514493Ssam register char *p; 63614493Ssam printf("treedump %d nodes:\n",tptr); 63714493Ssam for(t=0;t<tptr;t++){ 63814493Ssam printf("%4d ",t); 63914493Ssam parent[t] ? printf("p=%4d",parent[t]) : printf(" "); 64014493Ssam printf(" "); 64114493Ssam if(name[t] < NCH) { 64214493Ssam allprint(name[t]); 64314493Ssam } 64414493Ssam else switch(name[t]){ 64514493Ssam case RSTR: 64614493Ssam printf("%d ",left[t]); 64714493Ssam allprint(right[t]); 64814493Ssam break; 64914493Ssam case RCCL: 65014493Ssam printf("ccl "); 65114493Ssam strpt(left[t]); 65214493Ssam break; 65314493Ssam case RNCCL: 65414493Ssam printf("nccl "); 65514493Ssam strpt(left[t]); 65614493Ssam break; 65714493Ssam case DIV: 65814493Ssam printf("/ %d %d",left[t],right[t]); 65914493Ssam break; 66014493Ssam case BAR: 66114493Ssam printf("| %d %d",left[t],right[t]); 66214493Ssam break; 66314493Ssam case RCAT: 66414493Ssam printf("cat %d %d",left[t],right[t]); 66514493Ssam break; 66614493Ssam case PLUS: 66714493Ssam printf("+ %d",left[t]); 66814493Ssam break; 66914493Ssam case STAR: 67014493Ssam printf("* %d",left[t]); 67114493Ssam break; 67214493Ssam case CARAT: 67314493Ssam printf("^ %d",left[t]); 67414493Ssam break; 67514493Ssam case QUEST: 67614493Ssam printf("? %d",left[t]); 67714493Ssam break; 67814493Ssam case RNULLS: 67914493Ssam printf("nullstring"); 68014493Ssam break; 68114493Ssam case FINAL: 68214493Ssam printf("final %d",left[t]); 68314493Ssam break; 68414493Ssam case S1FINAL: 68514493Ssam printf("s1final %d",left[t]); 68614493Ssam break; 68714493Ssam case S2FINAL: 68814493Ssam printf("s2final %d",left[t]); 68914493Ssam break; 69014493Ssam case RNEWE: 69114493Ssam printf("new %d %d",left[t],right[t]); 69214493Ssam break; 69314493Ssam case RSCON: 69414493Ssam p = right[t]; 69514493Ssam printf("start %s",sname[*p++-1]); 69614493Ssam while(*p) 69714493Ssam printf(", %s",sname[*p++-1]); 69814493Ssam printf(" %d",left[t]); 69914493Ssam break; 70014493Ssam default: 70114493Ssam printf("unknown %d %d %d",name[t],left[t],right[t]); 70214493Ssam break; 70314493Ssam } 70414493Ssam if(nullstr[t])printf("\t(null poss.)"); 70514493Ssam putchar('\n'); 70614493Ssam } 70714493Ssam } 70814493Ssam # endif 709