From 6c0ba6089a6f42be85c47aec16fad37ca2b8c215 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 9 Nov 2020 08:49:11 +0100 Subject: [PATCH] ielr: more comments and logs * src/ielr.c: More comments. (state_list_print): New. --- src/ielr.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ielr.c b/src/ielr.c index 91fccaa4..f4766dab 100644 --- a/src/ielr.c +++ b/src/ielr.c @@ -83,19 +83,22 @@ ielr_compute_ritem_sees_lookahead_set (void) while (0 < i) { --i; + // Walk the RHS right to left, as long as it's symbol, + // nonterminal, nullable. while (!item_number_is_rule_number (ritem[i]) && ISVAR (ritem[i]) && nullable [item_number_as_symbol_number (ritem[i]) - ntokens]) bitset_set (result, i--); if (!item_number_is_rule_number (ritem[i]) && ISVAR (ritem[i])) bitset_set (result, i--); + // Flush the remainder of the RHS. while (!item_number_is_rule_number (ritem[i]) && 0 < i) --i; } if (trace_flag & trace_ielr) { - fprintf (stderr, "ritem_sees_lookahead_set:\n"); - debug_bitset (result); + fprintf (stderr, "ritem_sees_lookahead_set (indexes of ritems): "); + bitset_dump (stderr, result); fprintf (stderr, "\n"); } return result; @@ -569,6 +572,24 @@ typedef struct state_list struct state_list *nextIsocore; } state_list; +MAYBE_UNUSED static void +state_list_print_ (const state_list *s, FILE *out, const char *sep) +{ + if (s) + { + fprintf (out, "%s%d", sep, s->state->number); + state_list_print_ (s->next, out, " "); + } +} + +MAYBE_UNUSED static void +state_list_print (const state_list *s, FILE *out) +{ + fprintf (out, "{"); + state_list_print_ (s, out, ""); + fprintf (out, "}"); +} + /** * \pre * - \c follow_kernel_items and \c always_follows were computed by