#
	int nar 0;
	int hflg, binflg;
# define BINARY 1
# define HASH 2
	extern char yytext[];
	int nrule 0;
	char ruleid[50], size[50], exist[50], length[50];
	int kind[100];
	int estimate, method;
# define name 257
# define number 258
# define Int 259
# define Char 260
# define String 261
# define Size 262
# define Exist 263
# define Method 264
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar, yyerrflag;

int yyval 0;
int *yypv;
int yylval 0;
yyactr(__np__){

switch(__np__){

case 2: {	nrule++;
		writeprog();
		nar = 0;
	  } break;
case 3: {	printf (-1, size, "%d", yypv[5]);
	  } break;
case 4: {
		printf(-1, size, "sizeof(%s)", length);
	 } break;
case 5: { printf(-1, size, "%d", sizeof(nrule));
	  } break;
case 6:{ estimate=0; method = BINARY;} break;
case 7:{estimate = yypv[2]; method = HASH;} break;
case 8:{method = yypv[2];} break;
case 9:{estimate= yypv[2]; method=yypv[3];} break;
case 10:{copy (ruleid,yytext);} break;
case 11:{copy(length, yytext);} break;
case 12: {	kind[nar++] = yypv[1];
	  } break;
case 13: {	kind[nar++] = yypv[3];
	  } break;
case 14:{yyval= 'i';} break;
case 15:{yyval = 'i';} break;
case 16: {yyval = 's';} break;
case 17: {yyval = 'z';} break;
case 18: {yyval = 'e';} break;
}
}
int yyerrval 256;

# include "lex.yy.c"
writeprog()
{
	int i, szflg, eflg, p1, p2, p3, fs;
	char * mname, root[20];
	szflg = eflg = -1;
	switch (method)
		{
		case BINARY: mname = "aabinary";
			binflg=1;
			printf(-1, root, "%d", nrule);
			break;
		case HASH: mname = "aahash";
			hflg=1;
			printf(-1, root, "aa%droot", nrule);
			p1 = nprime(estimate*3/2);
			p2 = nprime(p1);
			p3 = nprime(p2);
			printf("struct hnode{char *aakey, *aadata;} aa%droot[%d];\n",
				nrule, p3);
			printf("int aa%dtsize %d;\n", nrule, p3);
			printf("int aa%dp1 %d;\n", nrule,p1);
			printf("int aa%dp2 %d;\n", nrule, p2);
			break;
		}
	printf("%s",ruleid);
	printf( "(a0");
	for(i=1; i<nar; i++)
		printf(",a%d",i);
	printf(")\n\tchar *a0");
	for(i=1; i<nar; i++)
		printf(",*a%d",i);
	printf(";\n{\n\tchar keyc[100], *kcp;\n");
	printf("\tint keyi[10], *kip;\n");
	if(method==HASH) printf("\t\textern int aatsize, aapr1, aapr2;\n");
	printf("\tkip=keyi; kcp=keyc;\n");
	for (i=fs=0; i<nar; i++)
		switch(kind[i])
			{
			case 'i':
				printf("\t*kip++ = a%d;\n",i);
				break;
			case 's':
				if (fs)
					printf("\t*(kcp-1) = '|';\n");
				printf("\twhile(*kcp++= *a%d++);\n", i);
				fs=1;
				break;
			case 'z':
				szflg=i; break;
			case 'e':
				eflg = i; break;
			}
	printf("\t*kcp= 0;\n");
	if (szflg > 0) printf(-1, size, "a%d",szflg);
	printf(-1, exist, (eflg>0 ? "a%d" : "0"), eflg);
	if (method==HASH)
		{
		printf("\taatsize = aa%dtsize;\n", nrule);
		printf("\taapr1 = aa%dp1;\n", nrule);
		printf("\taapr2 = aa%dp2;\n", nrule);
		}
	printf("	return(%s(%s,keyi, kip-keyi, keyc, %s,%s));\n",
		mname, root, size,exist);
	printf("}\n");
}
copy (s,t)
	char *s, *t;
{
	while (*s++ = *t++);
}

# ifdef unix
char *binnam "/usr/source/agen/aabin.c";
char *hshnam "/usr/source/agen/aahash.c";
char *subnam "/usr/source/agen/aasub.c";
# endif
# ifdef gcos
char *binnam "pounce/aabin.c";
char *hshnam "pounce/aahash.c";
char *subnam "pounce/aasub.c";
# endif
main(argc,argv)
	char *argv[];
{
	extern int cin, cout;
	int c;
	cin = copen(argv[1], 'r');
	cout = copen("a.tab.c", 'w');
	printf("#\n");
	yyparse();
	while (c=cgetc(cin))
		cputc(c,cout);
	cclose(cin);
	printf("struct node {char *aakey, *aadata; struct node *lp, *rp;};\n");
	printf("struct node *aaroot[%d];\n",nrule+1);
	fcopy(subnam);
	if (binflg)
		fcopy(binnam);
	if (hflg)
		fcopy(hshnam);
	cexit();
}
fcopy(s)
	char *s;
{
int c;
extern int cin, cout;
cin = copen(s, 'r');
while (c=cgetc(cin))
	cputc(c,cout);
}
nprime(n)
{
while (!prime(++n));
return(n);
}
known[] {2,3,5,7,11,13,17,19,23,29,31,37,41,
43,47,53,59,61,67,
71,73,79,83,89,97,101,103,107,109,
113,127,131,137,139,149,151,157,163,
167,173,179,181,191,193,197,199,211,0};
prime(n)
{
int *p, k;
p=known;
while ((k= *p++) && (k*k <= n))
	if (n%k==0)
		return(0);
return(1);
}

int yyact[] {0,12289,4096,16384,4353,8197,0,12290,4136,8198
,0,4354,8199,4360,8200,12294,12298,4355,8203,4356
,8204,4357,8205,4358,8206,4359,8207,0,4360,8208
,12295,12296,4137,8209,4140,8210,0,12300,12302,12303
,12304,12305,12306,12297,4353,8214,4354,8211,4155,8213
,0,4355,8203,4356,8204,4357,8205,4358,8206,4359
,8207,0,4155,8216,0,4155,8217,0,12293,12299
,12301,12291,12292,-1};

int yypact[] {0,1,2,7,8,11,16,17,28,31
,32,37,38,39,40,41,42,43,44,51
,62,65,68,69,70,71,72,-1};

int yyr1[] {0,1,1,2,2,2,3,3,3,3
,6,5,4,4,7,7,7,7,7,-1};

int yyr2[] {0,0,2,6,6,5,1,2,2,3
,1,1,1,3,1,1,1,1,1,-1};

int yygo[] {0,-1,1,-1,2,-1,3,-1,9,-1
,20,-1,4,18,23,-1,10,-1};

int yypgo[] {0,1,3,5,7,9,11,13,-1};

int nterms 14;
int nnonter 7;
int nstate 26;
char *yysterm[] {
"error",
"name",
"number",
"Int",
"Char",
"String",
"Size",
"Exist",
"Method",
0 };

char *yysnter[] {
"$accept",
"S",
"thing",
"label",
"arglist",
"len",
"rname",
"type" };
