From b4c4ccc2b3b546a665f65a619af0a60e0dbacf50 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 7 Apr 2002 17:38:37 +0000 Subject: [PATCH] * src/LR0.c (allocate_itemsets): Don't loop over ritem: loop over the RHS of the rules. * src/output.c (output_gram): Likewise. --- ChangeLog | 6 ++++++ src/LR0.c | 9 +++++---- src/output.c | 18 +++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf4d384e..8a8721a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-04-07 Akim Demaille + + * src/LR0.c (allocate_itemsets): Don't loop over ritem: loop over + the RHS of the rules. + * src/output.c (output_gram): Likewise. + 2002-04-07 Akim Demaille * src/gram.h (rule_t): `lhs' is now a pointer to the symbol's diff --git a/src/LR0.c b/src/LR0.c index 02798cd9..15b29f30 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -68,7 +68,8 @@ static state_t **state_hash = NULL; static void allocate_itemsets (void) { - int i; + int i, r; + short *rhsp; /* Count the number of occurrences of all the symbols in RITEMS. Note that useless productions (hence useless nonterminals) are @@ -77,11 +78,11 @@ allocate_itemsets (void) int count = 0; short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals); - for (i = 0; i < nritems; ++i) - if (ritem[i] >= 0) + for (r = 1; r < nrules + 1; ++r) + for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) { count++; - symbol_count[ritem[i]]++; + symbol_count[*rhsp]++; } /* See comments before new_itemsets. All the vectors of items diff --git a/src/output.c b/src/output.c index acb453c6..4018fba3 100644 --- a/src/output.c +++ b/src/output.c @@ -202,14 +202,18 @@ output_gram (void) muscle_insert ("prhs", obstack_finish (&format_obstack)); { - short *yyrhs; - int i; - - yyrhs = XMALLOC (short, nritems); - - for (i = 1; i < nritems; ++i) - yyrhs[i] = ritem[i] >= 0 ? ritem[i] : -1; + short *rhsp; + int r; + int i = 0; + short *yyrhs = XMALLOC (short, nritems); + for (r = 1; r < nrules + 1; ++r) + { + for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) + yyrhs[i++] = *rhsp; + yyrhs[i++] = -1; + } + assert (i == nritems); output_table_data (&format_obstack, yyrhs, ritem[0], 1, nritems); muscle_insert ("rhs", obstack_finish (&format_obstack)); -- 2.45.2