mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
* src/reduce.c (print_results): Rename as...
(reduce_output): This. Output to OUT, passed as argument, instead of output_obstack. (dump_grammar): Likewise. (reduce_free): New. Also free V1. (reduce_grammar): No longer call reduce_output, since... * src/print.c (print_results): do it. * src/main.c (main): Call reduce_free;
This commit is contained in:
14
ChangeLog
14
ChangeLog
@@ -1,10 +1,21 @@
|
|||||||
|
2001-11-12 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/reduce.c (print_results): Rename as...
|
||||||
|
(reduce_output): This.
|
||||||
|
Output to OUT, passed as argument, instead of output_obstack.
|
||||||
|
(dump_grammar): Likewise.
|
||||||
|
(reduce_free): New.
|
||||||
|
Also free V1.
|
||||||
|
(reduce_grammar): No longer call reduce_output, since...
|
||||||
|
* src/print.c (print_results): do it.
|
||||||
|
* src/main.c (main): Call reduce_free;
|
||||||
|
|
||||||
2001-11-12 Akim Demaille <akim@epita.fr>
|
2001-11-12 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/conflicts.c (print_reductions): Accept OUT as argument.
|
* src/conflicts.c (print_reductions): Accept OUT as argument.
|
||||||
Output to it, not to output_obstack.
|
Output to it, not to output_obstack.
|
||||||
* src/print.c (print_actions): Adjust.
|
* src/print.c (print_actions): Adjust.
|
||||||
|
|
||||||
|
|
||||||
2001-11-12 Akim Demaille <akim@epita.fr>
|
2001-11-12 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/conflicts.c (count_sr_conflicts, count_rr_conflicts): Return
|
* src/conflicts.c (count_sr_conflicts, count_rr_conflicts): Return
|
||||||
@@ -24,7 +35,6 @@
|
|||||||
* tests/regression.at (Invalid input): Remove, duplicate with
|
* tests/regression.at (Invalid input): Remove, duplicate with
|
||||||
``Invalid input: 1''.
|
``Invalid input: 1''.
|
||||||
|
|
||||||
|
|
||||||
2001-11-12 Akim Demaille <akim@epita.fr>
|
2001-11-12 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* tests/torture.at (AT_DATA_STACK_TORTURE)
|
* tests/torture.at (AT_DATA_STACK_TORTURE)
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ main (int argc, char *argv[])
|
|||||||
/* Close the input files. */
|
/* Close the input files. */
|
||||||
close_files ();
|
close_files ();
|
||||||
|
|
||||||
|
reduce_free ();
|
||||||
free_conflicts ();
|
free_conflicts ();
|
||||||
free_nullable ();
|
free_nullable ();
|
||||||
free_derives ();
|
free_derives ();
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ print_results (void)
|
|||||||
size_t size = obstack_object_size (&output_obstack);
|
size_t size = obstack_object_size (&output_obstack);
|
||||||
fwrite (obstack_finish (&output_obstack), 1, size, out);
|
fwrite (obstack_finish (&output_obstack), 1, size, out);
|
||||||
|
|
||||||
|
reduce_output (out);
|
||||||
conflicts_output (out);
|
conflicts_output (out);
|
||||||
|
|
||||||
print_grammar (out);
|
print_grammar (out);
|
||||||
|
|||||||
110
src/reduce.c
110
src/reduce.c
@@ -1,5 +1,5 @@
|
|||||||
/* Grammar reduction for Bison.
|
/* Grammar reduction for Bison.
|
||||||
Copyright 1988, 1989, 2000 Free Software Foundation, Inc.
|
Copyright 1988, 1989, 2000, 2001 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -388,21 +388,25 @@ reduce_grammar_tables (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
print_results (void)
|
/*-----------------------------------------------------------------.
|
||||||
|
| Ouput the detailed results of the reductions. For FILE.output. |
|
||||||
|
`-----------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void
|
||||||
|
reduce_output (FILE *out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/* short j; JF unused */
|
|
||||||
rule r;
|
rule r;
|
||||||
bool b;
|
bool b;
|
||||||
|
|
||||||
if (nuseless_nonterminals > 0)
|
if (nuseless_nonterminals > 0)
|
||||||
{
|
{
|
||||||
obstack_sgrow (&output_obstack, _("Useless nonterminals:"));
|
fprintf (out, _("Useless nonterminals:"));
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
if (!BITISSET (V, i))
|
if (!BITISSET (V, i))
|
||||||
obstack_fgrow1 (&output_obstack, " %s\n", tags[i]);
|
fprintf (out, " %s\n", tags[i]);
|
||||||
}
|
}
|
||||||
b = FALSE;
|
b = FALSE;
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
@@ -411,81 +415,81 @@ print_results (void)
|
|||||||
{
|
{
|
||||||
if (!b)
|
if (!b)
|
||||||
{
|
{
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
obstack_sgrow (&output_obstack,
|
fprintf (out, _("Terminals which are not used:"));
|
||||||
_("Terminals which are not used:"));
|
fprintf (out, "\n\n");
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
|
||||||
b = TRUE;
|
b = TRUE;
|
||||||
}
|
}
|
||||||
obstack_fgrow1 (&output_obstack, " %s\n", tags[i]);
|
fprintf (out, " %s\n", tags[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nuseless_productions > 0)
|
if (nuseless_productions > 0)
|
||||||
{
|
{
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
obstack_sgrow (&output_obstack, _("Useless rules:"));
|
fprintf (out, _("Useless rules:"));
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
for (i = 1; i <= nrules; i++)
|
for (i = 1; i <= nrules; i++)
|
||||||
{
|
{
|
||||||
if (!BITISSET (P, i))
|
if (!BITISSET (P, i))
|
||||||
{
|
{
|
||||||
obstack_fgrow1 (&output_obstack, "#%-4d ", i);
|
fprintf (out, "#%-4d ", i);
|
||||||
obstack_fgrow1 (&output_obstack, "%s :\t", tags[rlhs[i]]);
|
fprintf (out, "%s :\t", tags[rlhs[i]]);
|
||||||
for (r = &ritem[rrhs[i]]; *r >= 0; r++)
|
for (r = &ritem[rrhs[i]]; *r >= 0; r++)
|
||||||
obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
|
fprintf (out, " %s", tags[*r]);
|
||||||
obstack_sgrow (&output_obstack, ";\n");
|
fprintf (out, ";\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
|
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 /* XXX currently unused. */
|
#if 0 /* XXX currently unused. */
|
||||||
static void
|
static void
|
||||||
dump_grammar (void)
|
dump_grammar (FILE *out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
rule r;
|
rule r;
|
||||||
|
|
||||||
obstack_fgrow5 (&output_obstack,
|
fprintf (out,
|
||||||
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
|
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
|
||||||
ntokens, nvars, nsyms, nrules, nitems);
|
ntokens, nvars, nsyms, nrules, nitems);
|
||||||
obstack_sgrow (&output_obstack,
|
fprintf (out, _("Variables\n---------\n\n"));
|
||||||
_("Variables\n---------\n\n"));
|
fprintf (out, _("Value Sprec Sassoc Tag\n"));
|
||||||
obstack_sgrow (&output_obstack,
|
|
||||||
_("Value Sprec Sassoc Tag\n"));
|
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
obstack_fgrow4 (&output_obstack,
|
fprintf (out, "%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]);
|
||||||
"%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]);
|
fprintf (out, "\n\n");
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, _("Rules\n-----\n\n"));
|
||||||
obstack_sgrow (&output_obstack, _("Rules\n-----\n\n"));
|
|
||||||
for (i = 1; i <= nrules; i++)
|
for (i = 1; i <= nrules; i++)
|
||||||
{
|
{
|
||||||
obstack_fgrow5 (&output_obstack, "%-5d(%5d%5d)%5d : (@%-5d)",
|
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
|
||||||
i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
|
i, rprec[i], rassoc[i], rlhs[i], rrhs[i]);
|
||||||
for (r = &ritem[rrhs[i]]; *r > 0; r++)
|
for (r = &ritem[rrhs[i]]; *r > 0; r++)
|
||||||
obstack_fgrow1 (&output_obstack, "%5d", *r);
|
fprintf (out, "%5d", *r);
|
||||||
obstack_fgrow1 (&output_obstack, " [%d]\n", -(*r));
|
fprintf (out, " [%d]\n", -(*r));
|
||||||
}
|
}
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
obstack_sgrow (&output_obstack,
|
fprintf (out, _("Rules interpreted\n-----------------\n\n"));
|
||||||
_("Rules interpreted\n-----------------\n\n"));
|
|
||||||
for (i = 1; i <= nrules; i++)
|
for (i = 1; i <= nrules; i++)
|
||||||
{
|
{
|
||||||
obstack_fgrow2 (&output_obstack, "%-5d %s :", i, tags[rlhs[i]]);
|
fprintf (out, "%-5d %s :", i, tags[rlhs[i]]);
|
||||||
for (r = &ritem[rrhs[i]]; *r > 0; r++)
|
for (r = &ritem[rrhs[i]]; *r > 0; r++)
|
||||||
obstack_fgrow1 (&output_obstack, " %s", tags[*r]);
|
fprintf (out, " %s", tags[*r]);
|
||||||
obstack_grow1 (&output_obstack, '\n');
|
fputc ('\n', out);
|
||||||
}
|
}
|
||||||
obstack_sgrow (&output_obstack, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------.
|
||||||
|
| Report the results to STDERR. |
|
||||||
|
`-------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_notices (void)
|
reduce_print (void)
|
||||||
{
|
{
|
||||||
if (yacc_flag && nuseless_productions)
|
if (yacc_flag && nuseless_productions)
|
||||||
fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions);
|
fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions);
|
||||||
@@ -527,13 +531,10 @@ reduce_grammar (void)
|
|||||||
|
|
||||||
reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0);
|
reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0);
|
||||||
|
|
||||||
if (verbose_flag)
|
if (!reduced)
|
||||||
print_results ();
|
return;
|
||||||
|
|
||||||
if (reduced == FALSE)
|
reduce_print ();
|
||||||
goto done_reducing;
|
|
||||||
|
|
||||||
print_notices ();
|
|
||||||
|
|
||||||
if (!BITISSET (N, start_symbol - ntokens))
|
if (!BITISSET (N, start_symbol - ntokens))
|
||||||
fatal (_("Start symbol %s does not derive any sentence"),
|
fatal (_("Start symbol %s does not derive any sentence"),
|
||||||
@@ -543,7 +544,7 @@ reduce_grammar (void)
|
|||||||
#if 0
|
#if 0
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
{
|
{
|
||||||
obstack_fgrow1 (&output_obstack, "REDUCED GRAMMAR\n\n");
|
fprintf (out, "REDUCED GRAMMAR\n\n");
|
||||||
dump_grammar ();
|
dump_grammar ();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -558,11 +559,18 @@ reduce_grammar (void)
|
|||||||
(nvars == 1 ? "" : "s"),
|
(nvars == 1 ? "" : "s"),
|
||||||
nrules,
|
nrules,
|
||||||
(nrules == 1 ? "" : "s"));
|
(nrules == 1 ? "" : "s"));
|
||||||
|
}
|
||||||
|
|
||||||
done_reducing:
|
|
||||||
/* Free the global sets used to compute the reduced grammar */
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------.
|
||||||
|
| Free the global sets used to compute the reduced grammar. |
|
||||||
|
`-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void
|
||||||
|
reduce_free (void)
|
||||||
|
{
|
||||||
XFREE (N);
|
XFREE (N);
|
||||||
XFREE (V);
|
XFREE (V);
|
||||||
|
XFREE (V1);
|
||||||
XFREE (P);
|
XFREE (P);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Grammar reduction for Bison.
|
/* Grammar reduction for Bison.
|
||||||
Copyright 2000 Free Software Foundation, Inc.
|
Copyright 2000, 2001 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -22,5 +22,6 @@
|
|||||||
# define REDUCE_H_
|
# define REDUCE_H_
|
||||||
|
|
||||||
void reduce_grammar PARAMS ((void));
|
void reduce_grammar PARAMS ((void));
|
||||||
|
void reduce_output PARAMS ((FILE *out));
|
||||||
|
void reduce_free PARAMS ((void));
|
||||||
#endif /* !REDUCE_H_ */
|
#endif /* !REDUCE_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user