mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12: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:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2002-06-15 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* 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.
|
||||
|
||||
|
||||
2002-06-15 Akim Demaille <akim@epita.fr>
|
||||
|
||||
Copy BYacc's nice way to report the grammar.
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -124,6 +124,8 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([Useless Rules])
|
||||
|
||||
AT_KEYWORDS([report])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%verbose
|
||||
%output="input.c"
|
||||
@@ -184,16 +186,16 @@ Terminals which are not used:
|
||||
'7'
|
||||
'8'
|
||||
'9'
|
||||
Useless rules:
|
||||
#2 useless1: '1';
|
||||
#3 useless2: '2';
|
||||
#4 useless3: '3';
|
||||
#5 useless4: '4';
|
||||
#6 useless5: '5';
|
||||
#7 useless6: '6';
|
||||
#8 useless7: '7';
|
||||
#9 useless8: '8';
|
||||
#10 useless9: '9';
|
||||
Useless rules
|
||||
2 useless1: '1'
|
||||
3 useless2: '2'
|
||||
4 useless3: '3'
|
||||
5 useless4: '4'
|
||||
6 useless5: '5'
|
||||
7 useless6: '6'
|
||||
8 useless7: '7'
|
||||
9 useless8: '8'
|
||||
10 useless9: '9'
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
@@ -209,6 +211,8 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([Reduced Automaton])
|
||||
|
||||
AT_KEYWORDS([report])
|
||||
|
||||
# The non reduced grammar.
|
||||
# ------------------------
|
||||
AT_DATA([[not-reduced.y]],
|
||||
@@ -249,10 +253,10 @@ AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
|
||||
non_productive
|
||||
Terminals which are not used:
|
||||
useless_token
|
||||
Useless rules:
|
||||
#2 exp: non_productive;
|
||||
#3 not_reachable: useful;
|
||||
#4 non_productive: non_productive useless_token;
|
||||
Useless rules
|
||||
2 exp: non_productive
|
||||
3 not_reachable: useful
|
||||
4 non_productive: non_productive useless_token
|
||||
]])
|
||||
|
||||
# The reduced grammar.
|
||||
@@ -296,6 +300,8 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([Underivable Rules])
|
||||
|
||||
AT_KEYWORDS([report])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%verbose
|
||||
%output="input.c"
|
||||
@@ -319,10 +325,10 @@ AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
|
||||
[[Useless nonterminals:
|
||||
underivable
|
||||
indirection
|
||||
Useless rules:
|
||||
#2 exp: underivable;
|
||||
#3 underivable: indirection;
|
||||
#4 indirection: underivable;
|
||||
Useless rules
|
||||
2 exp: underivable
|
||||
3 underivable: indirection
|
||||
4 indirection: underivable
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user