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