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>
+
+ * 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.
}
-/*-----------------------------------.
-| 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)
}
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);
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. |
`-------------------*/
/* 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));
}
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);
}
\f
AT_SETUP([Useless Rules])
+AT_KEYWORDS([report])
+
AT_DATA([[input.y]],
[[%verbose
%output="input.c"
'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
AT_SETUP([Reduced Automaton])
+AT_KEYWORDS([report])
+
# The non reduced grammar.
# ------------------------
AT_DATA([[not-reduced.y]],
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.
AT_SETUP([Underivable Rules])
+AT_KEYWORDS([report])
+
AT_DATA([[input.y]],
[[%verbose
%output="input.c"
[[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