* src/reduce.c: Various comment/formatting changes.

(nonterminals_reduce): New, extracted from...
(reduce_grammar_tables): here.
(reduce_grammar): Call nonterminals_reduce.
This commit is contained in:
Akim Demaille
2001-11-30 10:47:56 +00:00
parent 396452de26
commit 002389585a
3 changed files with 84 additions and 68 deletions

View File

@@ -1,3 +1,10 @@
2001-11-30 Akim Demaille <akim@epita.fr>
* src/reduce.c: Various comment/formatting changes.
(nonterminals_reduce): New, extracted from...
(reduce_grammar_tables): here.
(reduce_grammar): Call nonterminals_reduce.
2001-11-29 Paul Eggert <eggert@twinsun.com> 2001-11-29 Paul Eggert <eggert@twinsun.com>
* src/bison.simple (YYSTACK_REALLOC): Remove. * src/bison.simple (YYSTACK_REALLOC): Remove.

View File

@@ -64,8 +64,7 @@ main (int argc, char *argv[])
if (complain_message_count) if (complain_message_count)
exit (1); exit (1);
/* Find useless nonterminals and productions and reduce the grammar. /* Find useless nonterminals and productions and reduce the grammar. */
In file reduce.c. */
reduce_grammar (); reduce_grammar ();
/* Record other info about the grammar. In files derives and /* Record other info about the grammar. In files derives and

View File

@@ -38,11 +38,18 @@ typedef unsigned *BSet;
typedef short *rule; typedef short *rule;
/* N is set of all nonterminals which are not useless. P is set of /* Set of all nonterminals which are not useless. */
all rules which have no useless nonterminals in their RHS. V is static BSet N;
the set of all accessible symbols. */
static BSet N, P, V, V1; /* Set of all rules which have no useless nonterminals in their RHS. */
static BSet P;
/* Set of all accessible symbols. */
static BSet V;
/* Set of symbols used to define rule precedence (so they are
`useless', but no warning should be issued). */
static BSet V1;
static int nuseful_productions; static int nuseful_productions;
static int nuseless_productions; static int nuseless_productions;
@@ -318,21 +325,23 @@ reduce_grammar_tables (void)
} }
} }
} }
}
/* remove useless symbols */
if (nuseless_nonterminals > 0)
{
/*------------------------------.
| Remove useless nonterminals. |
`------------------------------*/
static void
nonterminals_reduce (void)
{
int i, n; int i, n;
/* short j; JF unused */
short *nontermmap;
rule r; rule r;
/* Create a map of nonterminal number to new nonterminal /* Create a map of nonterminal number to new nonterminal number. -1
number. -1 in the map means it was useless and is being in the map means it was useless and is being eliminated. */
eliminated. */
nontermmap = XCALLOC (short, nvars) - ntokens; short *nontermmap = XCALLOC (short, nvars) - ntokens;
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
nontermmap[i] = -1; nontermmap[i] = -1;
@@ -376,13 +385,12 @@ reduce_grammar_tables (void)
nvars -= nuseless_nonterminals; nvars -= nuseless_nonterminals;
free (&nontermmap[ntokens]); free (&nontermmap[ntokens]);
}
} }
/*-----------------------------------------------------------------. /*------------------------------------------------------------------.
| Ouput the detailed results of the reductions. For FILE.output. | | Output the detailed results of the reductions. For FILE.output. |
`-----------------------------------------------------------------*/ `------------------------------------------------------------------*/
void void
reduce_output (FILE *out) reduce_output (FILE *out)
@@ -537,6 +545,8 @@ reduce_grammar (void)
tags[start_symbol]); tags[start_symbol]);
reduce_grammar_tables (); reduce_grammar_tables ();
if (nuseless_nonterminals > 0)
nonterminals_reduce ();
if (trace_flag) if (trace_flag)
{ {