USG_PG3/usr/source/lexgen1/cform.c
# include "../lexgen1/ldefs.c"
cform(nrule)
{
int cmin, cmax, maxst, j, j2, omin;
int crsiz, i, startup, c, ns, *pp, act[NCH], *pstop;
int *verify, *advance;
verify = calloc (crsiz=(count()+NCH+200), sizeof(i));
advance = calloc (crsiz,sizeof(i));
if (advance == -1)
error("no space for output table");
for(i=0; i<crsiz; i++ )
verify[i]=advance[i]=0;
for(omin=maxst=i=0; i <= nstate; i++)
{
if ((ns = used[i]) == 0) /* no machines this char */
continue;
for(c=0;c<NCH; c++)
act[c] = (pp=move(i,c,1,0)) ? used[pp[1]] : 0;
for(cmin=0; cmin < NCH; cmin++)
if (act[cmin])
break;
if (cmin >= NCH) /* no actions, only here for stops */
{
stoff[ns] = 0;
continue;
}
for(cmax = NCH-1; cmax>=0; cmax--)
if (act[cmax])
break;
while (verify[omin+NCH])
omin++;
startup = omin;
do
{
startup =+ 1;
if (startup > crsiz-NCH)
error("output table overflow (not your fault, see M. Lesk)");
for (c= cmin; c <= cmax; c++)
{
if (act[c]==0) continue;
if (startup+c < 0)
break;
else
if (verify[startup+c])
break;
}
}
while (c <= cmax);
for(c=cmin; c <= cmax; c++)
{
if (act[c] == 0) continue;
verify[startup+c] = ns;
advance[startup+c] = act[c];
}
stoff[ns] = startup;
if (startup> maxst) maxst= startup;
}
maxst =+ NCH;
if (ratfor)
{
rprint(verify, "verif", maxst);
rprint(advance, "advan", maxst);
outstp(pstop=xslide, verify);
rprint(stoff, "stoff", stnum);
rprint(other, "other", stnum);
rprint(pstop, "stops", stnum);
rprint(extra, "extra", nrule);
return;
}
printf(output, "struct %swork {int *verify, *advance;} %scrank[] {\n",
label, label, label);
for (i=0; i<maxst; i++)
{
if (verify[i])
printf(output,"%ssvec+%d, %ssvec+%d,\n",
label, verify[i], label, advance[i]);
else
printf(output, "0, 0,\n");
}
printf(output, "0};\n");
outstp(pstop=xslide, verify);
printf(output, "struct %ssvf {\n", label);
printf(output, "\tstruct %swork *%sstoff;\n", label,label);
printf(output, "\tstruct %ssvf *%sother;\n", label, label);
printf(output, "\tint *%sstops;} %ssvec []{\n",label,label);
printf(output, "0,0,0,\n");
for(i=1; i<stnum; i++)
{
if (stoff[i] > 0 || i<= 2)
printf(output, "%scrank+%d,",label,stoff[i]);
else printf(output, "0,");
if (other[i])
printf(output, " %ssvec+%d,", label, other[i]);
else
printf(output, " 0,");
if (pstop[i])
printf(output, "%svstop+%d,\n",label, pstop[i]);
else
printf(output, "0,\n");
}
printf(output, "0,0,0};\n");
printf(output, "int %sextra[] {\n",label);
for(i=0; i<nrule; i++)
printf(output, "%d,\n",extra[i]);
printf(output, "0};\n");
}
count()
{
int i, k, c;
for(k=i=0; i<=nstate; i++)
if (used[i])
for(c=0; c<NCH; c++)
if (move(i,c,1,0))
k++;
return(k);
}