mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 02:03:03 +00:00
style: factor printing of rules
* src/gram.h, src/gram.c (rule_print): New. Use it.
This commit is contained in:
16
src/gram.c
16
src/gram.c
@@ -155,6 +155,13 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rule_print (rule const *r, rule const *prev_rule, FILE *out)
|
||||||
|
{
|
||||||
|
rule_lhs_print (r, prev_rule ? prev_rule->lhs : NULL, out);
|
||||||
|
rule_rhs_print (r, out);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ritem_print (FILE *out)
|
ritem_print (FILE *out)
|
||||||
{
|
{
|
||||||
@@ -186,7 +193,7 @@ grammar_rules_partial_print (FILE *out, const char *title,
|
|||||||
rule_filter filter)
|
rule_filter filter)
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
sym_content *previous_lhs = NULL;
|
rule *previous_rule = NULL;
|
||||||
|
|
||||||
/* rule # : LHS -> RHS */
|
/* rule # : LHS -> RHS */
|
||||||
for (rule_number r = 0; r < nrules + nuseless_productions; r++)
|
for (rule_number r = 0; r < nrules + nuseless_productions; r++)
|
||||||
@@ -195,13 +202,12 @@ grammar_rules_partial_print (FILE *out, const char *title,
|
|||||||
continue;
|
continue;
|
||||||
if (first)
|
if (first)
|
||||||
fprintf (out, "%s\n\n", title);
|
fprintf (out, "%s\n\n", title);
|
||||||
else if (previous_lhs && previous_lhs != rules[r].lhs)
|
else if (previous_rule && previous_rule->lhs != rules[r].lhs)
|
||||||
fputc ('\n', out);
|
fputc ('\n', out);
|
||||||
first = false;
|
first = false;
|
||||||
rule_lhs_print (&rules[r], previous_lhs, out);
|
rule_print (&rules[r], previous_rule, out);
|
||||||
rule_rhs_print (&rules[r], out);
|
|
||||||
fputc ('\n', out);
|
fputc ('\n', out);
|
||||||
previous_lhs = rules[r].lhs;
|
previous_rule = &rules[r];
|
||||||
}
|
}
|
||||||
if (!first)
|
if (!first)
|
||||||
fputs ("\n\n", out);
|
fputs ("\n\n", out);
|
||||||
|
|||||||
@@ -248,6 +248,9 @@ size_t rule_rhs_length (rule const *r);
|
|||||||
/* Print this rule's RHS on OUT. */
|
/* Print this rule's RHS on OUT. */
|
||||||
void rule_rhs_print (rule const *r, FILE *out);
|
void rule_rhs_print (rule const *r, FILE *out);
|
||||||
|
|
||||||
|
/* Print this rule on OUT. If a PREVIOUS_RULE was already displayed,
|
||||||
|
avoid useless repetitions of their LHS. */
|
||||||
|
void rule_print (rule const *r, rule const *prev_rule, FILE *out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,6 @@ build_relations (void)
|
|||||||
rp--;
|
rp--;
|
||||||
if (ISVAR (*rp))
|
if (ISVAR (*rp))
|
||||||
{
|
{
|
||||||
/* Downcasting from item_number to symbol_number. */
|
|
||||||
edge[nedges++] = map_goto (states1[--length],
|
edge[nedges++] = map_goto (states1[--length],
|
||||||
item_number_as_symbol_number (*rp));
|
item_number_as_symbol_number (*rp));
|
||||||
if (nullable[*rp - ntokens])
|
if (nullable[*rp - ntokens])
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ generate_states (void)
|
|||||||
closure (s->items, s->nitems);
|
closure (s->items, s->nitems);
|
||||||
/* Record the reductions allowed out of this state. */
|
/* Record the reductions allowed out of this state. */
|
||||||
save_reductions (s);
|
save_reductions (s);
|
||||||
/* Find the itemsets of the states that shifts can reach. */
|
/* Find the itemsets of the states that shifts/gotos can reach. */
|
||||||
new_itemsets (s);
|
new_itemsets (s);
|
||||||
/* Find or create the core structures for those states. */
|
/* Find or create the core structures for those states. */
|
||||||
append_states (s);
|
append_states (s);
|
||||||
|
|||||||
Reference in New Issue
Block a user