mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
* src/gram.h, src/gram.c (grammar_rules_partial_print): New, eved
out of... (grammar_rules_print): here. * src/reduce.c (reduce_output): Use it. * tests/reduce.at (Useless Rules, Reduced Automaton) (Underivable Rules): Adjust.
This commit is contained in:
26
src/gram.c
26
src/gram.c
@@ -133,9 +133,10 @@ ritem_longest_rhs (void)
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------.
|
||||
| Print the grammar's rules on OUT. |
|
||||
`-----------------------------------*/
|
||||
/*----------------------------------------------------------------.
|
||||
| Print the grammar's rules numbers from BEGIN (inclusive) to END |
|
||||
| (exclusive) on OUT under TITLE. |
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
blanks_print (unsigned n, FILE *out)
|
||||
@@ -145,14 +146,15 @@ blanks_print (unsigned n, FILE *out)
|
||||
}
|
||||
|
||||
void
|
||||
grammar_rules_print (FILE *out)
|
||||
grammar_rules_partial_print (FILE *out, const char *title,
|
||||
int begin, int end)
|
||||
{
|
||||
int r;
|
||||
symbol_t *last_lhs = NULL;
|
||||
|
||||
/* rule # : LHS -> RHS */
|
||||
fprintf (out, "%s\n\n", _("Grammar"));
|
||||
for (r = 1; r < nrules + 1; r++)
|
||||
fprintf (out, "%s\n\n", title);
|
||||
for (r = begin; r < end; r++)
|
||||
{
|
||||
if (last_lhs && last_lhs != rules[r].lhs)
|
||||
fputc ('\n', out);
|
||||
@@ -173,6 +175,18 @@ grammar_rules_print (FILE *out)
|
||||
fputs ("\n\n", out);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------.
|
||||
| Print the grammar's useful rules on OUT. |
|
||||
`------------------------------------------*/
|
||||
|
||||
void
|
||||
grammar_rules_print (FILE *out)
|
||||
{
|
||||
grammar_rules_partial_print (out, _("Grammar"), 1, nrules + 1);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------.
|
||||
| Dump the grammar. |
|
||||
`-------------------*/
|
||||
|
||||
@@ -183,6 +183,11 @@ void ritem_print PARAMS ((FILE *out));
|
||||
/* Return the size of the longest rule RHS. */
|
||||
size_t ritem_longest_rhs PARAMS ((void));
|
||||
|
||||
/* Print the grammar's rules numbers from BEGIN (inclusive) to END
|
||||
(exclusive) on OUT under TITLE. */
|
||||
void grammar_rules_partial_print PARAMS ((FILE *out, const char *title,
|
||||
int begin, int end));
|
||||
|
||||
/* Print the grammar's rules on OUT. */
|
||||
void grammar_rules_print PARAMS ((FILE *out));
|
||||
|
||||
|
||||
17
src/reduce.c
17
src/reduce.c
@@ -371,20 +371,9 @@ reduce_output (FILE *out)
|
||||
}
|
||||
|
||||
if (nuseless_productions > 0)
|
||||
{
|
||||
int i;
|
||||
fprintf (out, "%s\n\n", _("Useless rules:"));
|
||||
for (i = nrules + 1; i < nuseless_productions + nrules + 1; i++)
|
||||
{
|
||||
item_number_t *r;
|
||||
fprintf (out, "#%-4d ", rules[i].user_number - 1);
|
||||
fprintf (out, "%s:", symbol_tag_get (rules[i].lhs));
|
||||
for (r = rules[i].rhs; *r >= 0; r++)
|
||||
fprintf (out, " %s", symbol_tag_get (symbols[*r]));
|
||||
fputs (";\n", out);
|
||||
}
|
||||
fputs ("\n\n", out);
|
||||
}
|
||||
grammar_rules_partial_print (out, _("Useless rules"),
|
||||
nrules + 1,
|
||||
nuseless_productions + nrules + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user