gram: detect and report (in debug traces) useless chain rules

A rule is a useless chain iff it's a chain (aka unit, or injection)
rule (i.e., the RHS has length 1), and it's useless (it has no used
defined semantic action).

* src/gram.h, src/gram.c (rule_useless_chain_p): New.
(grammar_dump): Report useless chain rules.
* tests/sets.at: Check the traces.
This commit is contained in:
Akim Demaille
2019-01-29 18:53:35 +01:00
parent 8b5fc2143f
commit 781d2b02de
3 changed files with 17 additions and 7 deletions

View File

@@ -232,6 +232,9 @@ bool rule_useless_in_grammar_p (rule const *r);
grammar. In other words, it was discarded because of conflicts. */
bool rule_useless_in_parser_p (rule const *r);
/* Whether the rule has a single RHS, and no user action. */
bool rule_useless_chain_p (rule const *r);
/* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was
already displayed (by a previous call for another rule), avoid
useless repetitions. */