multistart: introduce and use rule_is_initial

* src/gram.h (rule_is_initial): New.
* src/graphviz.c, src/print-xml.c, src/print.c, src/lalr.c: Use it.
Some of these occurrences were incorrect (checking whether this is
rule 0), and not behaving properly in the case of multistart.
This commit is contained in:
Akim Demaille
2020-11-08 17:50:46 +01:00
parent 4b0cd01fb7
commit a38d0b9145
6 changed files with 20 additions and 26 deletions

View File

@@ -233,9 +233,24 @@ item_rule (item_number const *item)
void item_print (item_number *item, rule const *previous_rule,
FILE *out);
/*--------.
| Rules. |
`--------*/
/* A function that selects a rule. */
typedef bool (*rule_filter) (rule const *);
/* Whether is an accepting rule (i.e., its reduction terminates
parsing with success). */
static inline bool
rule_is_initial (rule const *r)
{
/* In the case of multistart, we need to check whether the LHS is
$accept. In the case of "unistart", it would suffice to
check whether this is rule number 0. */
return r->lhs == acceptsymbol->content;
}
/* Whether the rule has a 'number' smaller than NRULES. That is, it
is useful in the grammar. */
bool rule_useful_in_grammar_p (rule const *r);