/* lain4.c (lain.c) - Don Yang (uguu.org) Preprocess 4: Evaluate constants 08/11/00 */ int i, j, k, e, s, length = 183, leaf = 4, length0, leaf0, template[512], tindex, charcount; char code[9999] = "Zenum" "{" "x=Y127,y,z" "};" "Zchar t[z];" "Yint i,j,k;" "Zmain(Yint c,Zchar**a)" "{" "Yfor(i=j=t[x]=t[y]=0;i 0; j = getchar()) { e = (j - 10) ? j > 32 ? template[tindex] > 0 ? ++template[tindex] | charcount++ : (template[++tindex] = 1) | charcount++ : template[tindex] < 0 ? template[tindex]-- : (template[++tindex] = -1) : (template[++tindex] = 0); } for(template[++tindex] = 9999; length < charcount;) { k = rand() % leaf; for(i = j = 0; j <= k; i++) { if( code[i] == 64 ) j++; } i--; length0 = length--; leaf0 = leaf--; do { e = rand() & 7; length0 = length; leaf0 = leaf; for(j = 0; expr[e][j]; j++) { if( expr[e][j] == 64 ) leaf0++; length0++; } } while( length0 > charcount + 1 ); length = length0; leaf = leaf0; for(s = k = 0; code[s]; s++); for(; s >= i; code[s-- + j - 1] = code[s]); for(; expr[e][k]; code[i + k++] = expr[e][k]); } for(i = 0; code[i]; i++) { if( code[i] == 64 ) code[i] = terminal[rand() & 15]; } for(tindex = i = k = 0; code[i]; tindex++) { if( template[tindex] ) { if( template[tindex] > 0 ) { for( j = (code[i] > 87 && code[i] < 91) ? code[i++] - 86 : 1; j-- > 0; template[tindex]--) e = k ? k-- : putchar(code[i++]); e = template[tindex] > 0 ? tindex-- : (k = -template[tindex]); } else { for(; template[tindex]; template[tindex]++) e = k ? k-- : putchar(32); } } else { k = !putchar(10); } } putchar(10); }