mirror of
https://github.com/python/cpython.git
synced 2024-12-01 11:15:56 +01:00
32dde22186
svn+ssh://pythondev@svn.python.org/python/trunk ........ r62323 | brett.cannon | 2008-04-13 10:09:43 -0700 (Sun, 13 Apr 2008) | 3 lines Add an explicit check for output in a test to try to diagnose a failure on Windows. ........ r62324 | brett.cannon | 2008-04-13 10:41:31 -0700 (Sun, 13 Apr 2008) | 3 lines Fix spliting on colons on Windows machines with a file path by limiting the number of splits. ........ r62329 | benjamin.peterson | 2008-04-13 13:35:56 -0700 (Sun, 13 Apr 2008) | 2 lines #2627 Let it be known what pgen generates ........ r62330 | benjamin.peterson | 2008-04-13 13:40:03 -0700 (Sun, 13 Apr 2008) | 2 lines Added an ignore file for Bazaar #2510 ........ r62331 | georg.brandl | 2008-04-13 13:50:29 -0700 (Sun, 13 Apr 2008) | 2 lines Improve -X error message. ........ r62334 | andrew.kuchling | 2008-04-13 15:39:12 -0700 (Sun, 13 Apr 2008) | 1 line Add example ........ r62340 | amaury.forgeotdarc | 2008-04-14 12:55:40 -0700 (Mon, 14 Apr 2008) | 2 lines Update project files for all Windows supported compilers ........ r62341 | amaury.forgeotdarc | 2008-04-14 13:07:48 -0700 (Mon, 14 Apr 2008) | 6 lines Correct a refleak found by "regrtest.py -R:: test_structmembers" Some other minor updates in _warnings.c: - make a function static - rename a shadowing local variable ........ r62347 | andrew.kuchling | 2008-04-14 19:24:15 -0700 (Mon, 14 Apr 2008) | 1 line Various items; begin writing the SSL section ........ r62348 | neal.norwitz | 2008-04-14 20:46:21 -0700 (Mon, 14 Apr 2008) | 1 line Prevent namespace pollution, add static for internal functions ........
117 lines
2.5 KiB
C
117 lines
2.5 KiB
C
|
|
/* Print a bunch of C initializers that represent a grammar */
|
|
|
|
#include "pgenheaders.h"
|
|
#include "grammar.h"
|
|
|
|
/* Forward */
|
|
static void printarcs(int, dfa *, FILE *);
|
|
static void printstates(grammar *, FILE *);
|
|
static void printdfas(grammar *, FILE *);
|
|
static void printlabels(grammar *, FILE *);
|
|
|
|
void
|
|
printgrammar(grammar *g, FILE *fp)
|
|
{
|
|
fprintf(fp, "/* Generated by Parser/pgen */\n\n");
|
|
fprintf(fp, "#include \"pgenheaders.h\"\n");
|
|
fprintf(fp, "#include \"grammar.h\"\n");
|
|
printdfas(g, fp);
|
|
printlabels(g, fp);
|
|
fprintf(fp, "grammar _PyParser_Grammar = {\n");
|
|
fprintf(fp, "\t%d,\n", g->g_ndfas);
|
|
fprintf(fp, "\tdfas,\n");
|
|
fprintf(fp, "\t{%d, labels},\n", g->g_ll.ll_nlabels);
|
|
fprintf(fp, "\t%d\n", g->g_start);
|
|
fprintf(fp, "};\n");
|
|
}
|
|
|
|
void
|
|
printnonterminals(grammar *g, FILE *fp)
|
|
{
|
|
dfa *d;
|
|
int i;
|
|
|
|
fprintf(fp, "/* Generated by Parser/pgen */\n\n");
|
|
|
|
d = g->g_dfa;
|
|
for (i = g->g_ndfas; --i >= 0; d++)
|
|
fprintf(fp, "#define %s %d\n", d->d_name, d->d_type);
|
|
}
|
|
|
|
static void
|
|
printarcs(int i, dfa *d, FILE *fp)
|
|
{
|
|
arc *a;
|
|
state *s;
|
|
int j, k;
|
|
|
|
s = d->d_state;
|
|
for (j = 0; j < d->d_nstates; j++, s++) {
|
|
fprintf(fp, "static arc arcs_%d_%d[%d] = {\n",
|
|
i, j, s->s_narcs);
|
|
a = s->s_arc;
|
|
for (k = 0; k < s->s_narcs; k++, a++)
|
|
fprintf(fp, "\t{%d, %d},\n", a->a_lbl, a->a_arrow);
|
|
fprintf(fp, "};\n");
|
|
}
|
|
}
|
|
|
|
static void
|
|
printstates(grammar *g, FILE *fp)
|
|
{
|
|
state *s;
|
|
dfa *d;
|
|
int i, j;
|
|
|
|
d = g->g_dfa;
|
|
for (i = 0; i < g->g_ndfas; i++, d++) {
|
|
printarcs(i, d, fp);
|
|
fprintf(fp, "static state states_%d[%d] = {\n",
|
|
i, d->d_nstates);
|
|
s = d->d_state;
|
|
for (j = 0; j < d->d_nstates; j++, s++)
|
|
fprintf(fp, "\t{%d, arcs_%d_%d},\n",
|
|
s->s_narcs, i, j);
|
|
fprintf(fp, "};\n");
|
|
}
|
|
}
|
|
|
|
static void
|
|
printdfas(grammar *g, FILE *fp)
|
|
{
|
|
dfa *d;
|
|
int i, j;
|
|
|
|
printstates(g, fp);
|
|
fprintf(fp, "static dfa dfas[%d] = {\n", g->g_ndfas);
|
|
d = g->g_dfa;
|
|
for (i = 0; i < g->g_ndfas; i++, d++) {
|
|
fprintf(fp, "\t{%d, \"%s\", %d, %d, states_%d,\n",
|
|
d->d_type, d->d_name, d->d_initial, d->d_nstates, i);
|
|
fprintf(fp, "\t \"");
|
|
for (j = 0; j < NBYTES(g->g_ll.ll_nlabels); j++)
|
|
fprintf(fp, "\\%03o", d->d_first[j] & 0xff);
|
|
fprintf(fp, "\"},\n");
|
|
}
|
|
fprintf(fp, "};\n");
|
|
}
|
|
|
|
static void
|
|
printlabels(grammar *g, FILE *fp)
|
|
{
|
|
label *l;
|
|
int i;
|
|
|
|
fprintf(fp, "static label labels[%d] = {\n", g->g_ll.ll_nlabels);
|
|
l = g->g_ll.ll_label;
|
|
for (i = g->g_ll.ll_nlabels; --i >= 0; l++) {
|
|
if (l->lb_str == NULL)
|
|
fprintf(fp, "\t{%d, 0},\n", l->lb_type);
|
|
else
|
|
fprintf(fp, "\t{%d, \"%s\"},\n",
|
|
l->lb_type, l->lb_str);
|
|
}
|
|
fprintf(fp, "};\n");
|
|
}
|