mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 06:43:03 +00:00
gram: factor the printing of items and the computation of their rule
There are several places where we need to recover the rule from an item, let's factor that into item_rule. We also want to print items in a nice way: we do it when generating the *output file, but it is also useful in debug messages. * src/gram.h, src/gram.c (item_rule, item_print): New. * src/print.c (print_core): Use them. * src/state.h, src/state.c: Propagate constness.
This commit is contained in:
29
src/gram.c
29
src/gram.c
@@ -48,6 +48,35 @@ int max_user_token_number = 256;
|
||||
|
||||
int required_version = 0;
|
||||
|
||||
rule const *
|
||||
item_rule (item_number const *item)
|
||||
{
|
||||
item_number const *sp = item;
|
||||
while (*sp >= 0)
|
||||
++sp;
|
||||
|
||||
rule_number r = item_number_as_rule_number (*sp);
|
||||
return &rules[r];
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
item_print (item_number *item, rule const *previous_rule, FILE *out)
|
||||
{
|
||||
rule const *r = item_rule (item);
|
||||
rule_lhs_print (r, previous_rule ? previous_rule->lhs : NULL, out);
|
||||
|
||||
for (item_number *sp = r->rhs; sp < item; sp++)
|
||||
fprintf (out, " %s", symbols[*sp]->tag);
|
||||
fputs (" .", out);
|
||||
if (0 <= *r->rhs)
|
||||
for (item_number *sp = item; 0 <= *sp; ++sp)
|
||||
fprintf (out, " %s", symbols[*sp]->tag);
|
||||
else
|
||||
fprintf (out, " %%empty");
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
rule_useful_in_grammar_p (rule const *r)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user