lalr: offer more flexibility in debugging routines

* src/state.h, src/state.c (state_transitions_print): New, extracted
from...
(state_transitions_set): here.
This commit is contained in:
Akim Demaille
2019-04-03 07:24:56 +02:00
parent 18831f985c
commit 10175e4a65
2 changed files with 19 additions and 11 deletions

View File

@@ -189,6 +189,21 @@ state_free (state *s)
}
void
state_transitions_print (const state *s, FILE *out)
{
const transitions *trans = s->transitions;
fprintf (out, "transitions of %d (%d):\n",
s->number, trans->num);
for (int i = 0; i < trans->num; ++i)
fprintf (out, " %d: (%d, %s, %d)\n",
i,
s->number,
symbols[s->transitions->states[i]->accessing_symbol]->tag,
s->transitions->states[i]->number);
}
/*---------------------------.
| Set the transitions of S. |
`---------------------------*/
@@ -199,17 +214,7 @@ state_transitions_set (state *s, int num, state **dst)
aver (!s->transitions);
s->transitions = transitions_new (num, dst);
if (trace_flag & trace_automaton)
{
const transitions *trans = s->transitions;
fprintf (stderr, "transitions of %d (%d):\n",
s->number, trans->num);
for (int i = 0; i < trans->num; ++i)
fprintf (stderr, " %d: (%d, %s, %d)\n",
i,
s->number,
symbols[s->transitions->states[i]->accessing_symbol]->tag,
s->transitions->states[i]->number);
}
state_transitions_print (s, stderr);
}

View File

@@ -236,6 +236,9 @@ state *state_new_isocore (state const *s);
/* Record that from S we can reach all the DST states (NUM of them). */
void state_transitions_set (state *s, int num, state **dst);
/* Print the transitions of state s for debug. */
void state_transitions_print (const state *s, FILE *out);
/* Set the reductions of STATE. */
void state_reductions_set (state *s, int num, rule **reds);