mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
"Compiling" version
This commit is contained in:
parent
226d79eb4a
commit
3f5da24ea3
72 changed files with 3363 additions and 2061 deletions
|
@ -1,11 +1,52 @@
|
|||
/* Parser accelerator module */
|
||||
|
||||
#include <stdio.h>
|
||||
/* The parser as originally conceived had disappointing performance.
|
||||
This module does some precomputation that speeds up the selection
|
||||
of a DFA based upon a token, turning a search through an array
|
||||
into a simple indexing operation. The parser now cannot work
|
||||
without the accelerators installed. Note that the accelerators
|
||||
are installed dynamically when the parser is initialized, they
|
||||
are not part of the static data structure written on graminit.[ch]
|
||||
by the parser generator. */
|
||||
|
||||
#include "PROTO.h"
|
||||
#include "pgenheaders.h"
|
||||
#include "grammar.h"
|
||||
#include "token.h"
|
||||
#include "malloc.h"
|
||||
#include "parser.h"
|
||||
|
||||
/* Forward references */
|
||||
static void fixdfa PROTO((grammar *, dfa *));
|
||||
static void fixstate PROTO((grammar *, dfa *, state *));
|
||||
|
||||
void
|
||||
addaccelerators(g)
|
||||
grammar *g;
|
||||
{
|
||||
dfa *d;
|
||||
int i;
|
||||
#ifdef DEBUG
|
||||
printf("Adding parser accellerators ...\n");
|
||||
#endif
|
||||
d = g->g_dfa;
|
||||
for (i = g->g_ndfas; --i >= 0; d++)
|
||||
fixdfa(g, d);
|
||||
g->g_accel = 1;
|
||||
#ifdef DEBUG
|
||||
printf("Done.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
fixdfa(g, d)
|
||||
grammar *g;
|
||||
dfa *d;
|
||||
{
|
||||
state *s;
|
||||
int j;
|
||||
s = d->d_state;
|
||||
for (j = 0; j < d->d_nstates; j++, s++)
|
||||
fixstate(g, d, s);
|
||||
}
|
||||
|
||||
static void
|
||||
fixstate(g, d, s)
|
||||
|
@ -69,33 +110,3 @@ fixstate(g, d, s)
|
|||
}
|
||||
DEL(accel);
|
||||
}
|
||||
|
||||
static void
|
||||
fixdfa(g, d)
|
||||
grammar *g;
|
||||
dfa *d;
|
||||
{
|
||||
state *s;
|
||||
int j;
|
||||
s = d->d_state;
|
||||
for (j = 0; j < d->d_nstates; j++, s++)
|
||||
fixstate(g, d, s);
|
||||
}
|
||||
|
||||
void
|
||||
addaccelerators(g)
|
||||
grammar *g;
|
||||
{
|
||||
dfa *d;
|
||||
int i;
|
||||
#ifdef DEBUG
|
||||
printf("Adding parser accellerators ...\n");
|
||||
#endif
|
||||
d = g->g_dfa;
|
||||
for (i = g->g_ndfas; --i >= 0; d++)
|
||||
fixdfa(g, d);
|
||||
g->g_accel = 1;
|
||||
#ifdef DEBUG
|
||||
printf("Done.\n");
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue