mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +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>
|
2002-06-15 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
Copy BYacc's nice way to report the grammar.
|
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
|
static inline void
|
||||||
blanks_print (unsigned n, FILE *out)
|
blanks_print (unsigned n, FILE *out)
|
||||||
@@ -145,14 +146,15 @@ blanks_print (unsigned n, FILE *out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
grammar_rules_print (FILE *out)
|
grammar_rules_partial_print (FILE *out, const char *title,
|
||||||
|
int begin, int end)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
symbol_t *last_lhs = NULL;
|
symbol_t *last_lhs = NULL;
|
||||||
|
|
||||||
/* rule # : LHS -> RHS */
|
/* rule # : LHS -> RHS */
|
||||||
fprintf (out, "%s\n\n", _("Grammar"));
|
fprintf (out, "%s\n\n", title);
|
||||||
for (r = 1; r < nrules + 1; r++)
|
for (r = begin; r < end; r++)
|
||||||
{
|
{
|
||||||
if (last_lhs && last_lhs != rules[r].lhs)
|
if (last_lhs && last_lhs != rules[r].lhs)
|
||||||
fputc ('\n', out);
|
fputc ('\n', out);
|
||||||
@@ -173,6 +175,18 @@ grammar_rules_print (FILE *out)
|
|||||||
fputs ("\n\n", 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. |
|
| Dump the grammar. |
|
||||||
`-------------------*/
|
`-------------------*/
|
||||||
|
|||||||
@@ -183,6 +183,11 @@ void ritem_print PARAMS ((FILE *out));
|
|||||||
/* Return the size of the longest rule RHS. */
|
/* Return the size of the longest rule RHS. */
|
||||||
size_t ritem_longest_rhs PARAMS ((void));
|
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. */
|
/* Print the grammar's rules on OUT. */
|
||||||
void grammar_rules_print PARAMS ((FILE *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)
|
if (nuseless_productions > 0)
|
||||||
{
|
grammar_rules_partial_print (out, _("Useless rules"),
|
||||||
int i;
|
nrules + 1,
|
||||||
fprintf (out, "%s\n\n", _("Useless rules:"));
|
nuseless_productions + nrules + 1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Useless Rules])
|
AT_SETUP([Useless Rules])
|
||||||
|
|
||||||
|
AT_KEYWORDS([report])
|
||||||
|
|
||||||
AT_DATA([[input.y]],
|
AT_DATA([[input.y]],
|
||||||
[[%verbose
|
[[%verbose
|
||||||
%output="input.c"
|
%output="input.c"
|
||||||
@@ -184,16 +186,16 @@ Terminals which are not used:
|
|||||||
'7'
|
'7'
|
||||||
'8'
|
'8'
|
||||||
'9'
|
'9'
|
||||||
Useless rules:
|
Useless rules
|
||||||
#2 useless1: '1';
|
2 useless1: '1'
|
||||||
#3 useless2: '2';
|
3 useless2: '2'
|
||||||
#4 useless3: '3';
|
4 useless3: '3'
|
||||||
#5 useless4: '4';
|
5 useless4: '4'
|
||||||
#6 useless5: '5';
|
6 useless5: '5'
|
||||||
#7 useless6: '6';
|
7 useless6: '6'
|
||||||
#8 useless7: '7';
|
8 useless7: '7'
|
||||||
#9 useless8: '8';
|
9 useless8: '8'
|
||||||
#10 useless9: '9';
|
10 useless9: '9'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -209,6 +211,8 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Reduced Automaton])
|
AT_SETUP([Reduced Automaton])
|
||||||
|
|
||||||
|
AT_KEYWORDS([report])
|
||||||
|
|
||||||
# The non reduced grammar.
|
# The non reduced grammar.
|
||||||
# ------------------------
|
# ------------------------
|
||||||
AT_DATA([[not-reduced.y]],
|
AT_DATA([[not-reduced.y]],
|
||||||
@@ -249,10 +253,10 @@ AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
|
|||||||
non_productive
|
non_productive
|
||||||
Terminals which are not used:
|
Terminals which are not used:
|
||||||
useless_token
|
useless_token
|
||||||
Useless rules:
|
Useless rules
|
||||||
#2 exp: non_productive;
|
2 exp: non_productive
|
||||||
#3 not_reachable: useful;
|
3 not_reachable: useful
|
||||||
#4 non_productive: non_productive useless_token;
|
4 non_productive: non_productive useless_token
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# The reduced grammar.
|
# The reduced grammar.
|
||||||
@@ -296,6 +300,8 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Underivable Rules])
|
AT_SETUP([Underivable Rules])
|
||||||
|
|
||||||
|
AT_KEYWORDS([report])
|
||||||
|
|
||||||
AT_DATA([[input.y]],
|
AT_DATA([[input.y]],
|
||||||
[[%verbose
|
[[%verbose
|
||||||
%output="input.c"
|
%output="input.c"
|
||||||
@@ -319,10 +325,10 @@ AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
|
|||||||
[[Useless nonterminals:
|
[[Useless nonterminals:
|
||||||
underivable
|
underivable
|
||||||
indirection
|
indirection
|
||||||
Useless rules:
|
Useless rules
|
||||||
#2 exp: underivable;
|
2 exp: underivable
|
||||||
#3 underivable: indirection;
|
3 underivable: indirection
|
||||||
#4 indirection: underivable;
|
4 indirection: underivable
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user