summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2015-03-02 19:07:03 -0500
committerQuentin Carbonneaux2015-03-02 19:07:03 -0500
commit77e6f3a27f34b8196e6b90409f036714a62f58dd (patch)
treea17584bbd959a5e7444b401da45c575bc14467e3
parent5d3f70c41f059ab20c50e7aa984f9efde838432d (diff)
add token translation function
-rw-r--r--miniyacc.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/miniyacc.c b/miniyacc.c
index 3a36059..4cd7eff 100644
--- a/miniyacc.c
+++ b/miniyacc.c
@@ -655,7 +655,7 @@ aout(char *name, int *t, int n)
void
tblout()
{
- int *o, n;
+ int *o, n, m;
fprintf(fout, "short yyini = %d;\n", ini->id-1);
fprintf(fout, "short yyntoks = %d;\n", ntk);
@@ -685,6 +685,21 @@ tblout()
}
aout("yyact", act, actsz);
aout("yychk", chk, actsz);
+ for (n=0; n<128; n++) {
+ o[n] = 0;
+ for (m=0; m<ntk; m++)
+ if (is[m].name[0]=='\'')
+ if (is[m].name[1]==n)
+ assert(!o[n]), o[n] = m;
+ }
+ m = 128;
+ for (n=1; n<ntk; n++) {
+ if (is[n].name[0]=='\'')
+ continue;
+ fprintf(fout, "#define %s %d\n", is[n].name, m);
+ o[m++] = n;
+ }
+ aout("yytrns", o, m);
free(o);
}
@@ -1273,7 +1288,7 @@ char *code0[] = {
" tk = -1;\n",
"loop:\n",
" if (tk <= 0) {\n",
-" tk = lex();\n",
+" tk = yytrns[yylex()];\n",
" vl = yylval;\n",
" }\n",
" n = yyadsp[s] + tk;\n",