* src/reduce.c (nonterminals_reduce): Instead of throwing away

useless nonterminals, move them at the end of the symbol arrays.
(reduce_output): Adjust.
* tests/reduce.at (Useless Nonterminals): Adjust.
This commit is contained in:
Akim Demaille
2001-11-30 10:45:28 +00:00
parent 24b1e65f04
commit ea451a17d7
4 changed files with 41 additions and 18 deletions

View File

@@ -1,3 +1,10 @@
2001-11-30 Akim Demaille <akim@epita.fr>
* src/reduce.c (nonterminals_reduce): Instead of throwing away
useless nonterminals, move them at the end of the symbol arrays.
(reduce_output): Adjust.
* tests/reduce.at (Useless Nonterminals): Adjust.
2001-11-30 Akim Demaille <akim@epita.fr> 2001-11-30 Akim Demaille <akim@epita.fr>
* src/reduce.c: Various comment/formatting changes. * src/reduce.c: Various comment/formatting changes.

3
NEWS
View File

@@ -3,6 +3,9 @@ Bison News
Changes in version 1.30f: Changes in version 1.30f:
* Reduced Grammars
Fixed bugs when reporting useless nonterminals.
Changes in version 1.30e: Changes in version 1.30e:
* Error messages * Error messages

View File

@@ -342,26 +342,38 @@ nonterminals_reduce (void)
in the map means it was useless and is being eliminated. */ in the map means it was useless and is being eliminated. */
short *nontermmap = XCALLOC (short, nvars) - ntokens; short *nontermmap = XCALLOC (short, nvars) - ntokens;
for (i = ntokens; i < nsyms; i++)
nontermmap[i] = -1;
n = ntokens; n = ntokens;
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
if (BITISSET (V, i)) if (BITISSET (V, i))
nontermmap[i] = n++; nontermmap[i] = n++;
for (i = ntokens; i < nsyms; i++)
if (!BITISSET (V, i))
nontermmap[i] = n++;
/* Shuffle elements of tables indexed by symbol number. */ /* Shuffle elements of tables indexed by symbol number. */
{
short *sassoc_sorted = XMALLOC (short, nvars) - ntokens;
short *sprec_sorted = XMALLOC (short, nvars) - ntokens;
char **tags_sorted = XMALLOC (char *, nvars) - ntokens;
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
n = nontermmap[i]; n = nontermmap[i];
if (n >= 0) sassoc_sorted[n] = sassoc[i];
{ sprec_sorted[n] = sprec[i];
sassoc[n] = sassoc[i]; tags_sorted[n] = tags[i];
sprec[n] = sprec[i]; }
tags[n] = tags[i]; for (i = ntokens; i < nsyms; i++)
} {
} sassoc[i] = sassoc_sorted[i];
sprec[i] = sprec_sorted[i];
tags[i] = tags_sorted[i];
}
free (sassoc_sorted + ntokens);
free (sprec_sorted + ntokens);
free (tags_sorted + ntokens);
}
/* Replace all symbol numbers in valid data structures. */ /* Replace all symbol numbers in valid data structures. */
@@ -403,9 +415,8 @@ reduce_output (FILE *out)
{ {
fprintf (out, _("Useless nonterminals:")); fprintf (out, _("Useless nonterminals:"));
fprintf (out, "\n\n"); fprintf (out, "\n\n");
for (i = ntokens; i < nsyms; i++) for (i = 0; i < nuseless_nonterminals; ++i)
if (!BITISSET (V, i)) fprintf (out, " %s\n", tags[nsyms + i]);
fprintf (out, " %s\n", tags[i]);
} }
b = FALSE; b = FALSE;
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)

View File

@@ -88,10 +88,12 @@ AT_DATA([[input.y]],
exp: useful; exp: useful;
]]) ]])
AT_CHECK([[bison input.y]]) AT_CHECK([[bison input.y]], 0, [],
[[input.y contains 9 useless nonterminals
]])
AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0, AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
[[Terminals which are not used: [[Useless nonterminals:
useless1 useless1
useless2 useless2
useless3 useless3