diff options
author | Guido van Rossum <guido@python.org> | 1990-12-20 15:06:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1990-12-20 15:06:42 (GMT) |
commit | 3f5da24ea304e674a9abbdcffc4d671e32aa70f1 (patch) | |
tree | e932e31cb9381f40b7c87c377638216c043b5cfc /Parser/acceler.c | |
parent | 226d79eb4a776dd54c9e4544b17deaf928bcef3a (diff) | |
download | cpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.zip cpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.tar.gz cpython-3f5da24ea304e674a9abbdcffc4d671e32aa70f1.tar.bz2 |
"Compiling" version
Diffstat (limited to 'Parser/acceler.c')
-rw-r--r-- | Parser/acceler.c | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/Parser/acceler.c b/Parser/acceler.c index 7ff10b2..ce16711 100644 --- a/Parser/acceler.c +++ b/Parser/acceler.c @@ -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 -} |