From b09f4f48512c274a7574b6a22e4a1eac6a86fd61 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Mon, 7 May 2007 02:28:42 +0000 Subject: [PATCH] Minor code cleanup in parser table construction. * src/LR0.c (new_itemsets): Use item_number_is_symbol_number. (new_itemsets, save_reductions): Update for rename to nitemset. * src/closure.c (nritemset): Rename to... (nitemset): ... this since the "r" appears to meaningless and isn't used in the comments. (closure): Update for rename. * src/closure.h (nritemset): Update extern to... (nitemset): ... this. * src/lalr.c (LA): Fix a typo in comments. * src/print.c (print_core): Update for rename to nitemset. * src/print_graph.c (print_graph): Likewise. * src/state.h: Fix some typos in header comments. --- ChangeLog | 16 ++++++++++++++++ src/LR0.c | 6 +++--- src/closure.c | 18 +++++++++--------- src/closure.h | 2 +- src/lalr.c | 2 +- src/print.c | 2 +- src/print_graph.c | 2 +- src/state.h | 7 +++---- 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b0b8647..53361e3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-05-06 Joel E. Denny + + Minor code cleanup in parser table construction. + * src/LR0.c (new_itemsets): Use item_number_is_symbol_number. + (new_itemsets, save_reductions): Update for rename to nitemset. + * src/closure.c (nritemset): Rename to... + (nitemset): ... this since the "r" appears to meaningless and isn't + used in the comments. + (closure): Update for rename. + * src/closure.h (nritemset): Update extern to... + (nitemset): ... this. + * src/lalr.c (LA): Fix a typo in comments. + * src/print.c (print_core): Update for rename to nitemset. + * src/print_graph.c (print_graph): Likewise. + * src/state.h: Fix some typos in header comments. + 2007-04-04 Paul Eggert * THANKS: Use ASCII for Sebastien Fricker's name. Bison source diff --git a/src/LR0.c b/src/LR0.c index 945d41f8..f94f5ec9 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -183,8 +183,8 @@ new_itemsets (state *s) nshifts = 0; - for (i = 0; i < nritemset; ++i) - if (ritem[itemset[i]] >= 0) + for (i = 0; i < nitemset; ++i) + if (item_number_is_symbol_number (ritem[itemset[i]])) { symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]); if (!kernel_size[sym]) @@ -272,7 +272,7 @@ save_reductions (state *s) size_t i; /* Find and count the active items that represent ends of rules. */ - for (i = 0; i < nritemset; ++i) + for (i = 0; i < nitemset; ++i) { item_number item = ritem[itemset[i]]; if (item_number_is_rule_number (item)) diff --git a/src/closure.c b/src/closure.c index 001b8316..a12e9622 100644 --- a/src/closure.c +++ b/src/closure.c @@ -37,7 +37,7 @@ /* NITEMSET is the size of the array ITEMSET. */ item_number *itemset; -size_t nritemset; +size_t nitemset; static bitset ruleset; @@ -213,30 +213,30 @@ closure (item_number *core, size_t n) if (ISVAR (ritem[core[c]])) bitset_or (ruleset, ruleset, FDERIVES (ritem[core[c]])); - nritemset = 0; + nitemset = 0; c = 0; BITSET_FOR_EACH (iter, ruleset, ruleno, 0) { item_number itemno = rules[ruleno].rhs - ritem; while (c < n && core[c] < itemno) { - itemset[nritemset] = core[c]; - nritemset++; + itemset[nitemset] = core[c]; + nitemset++; c++; } - itemset[nritemset] = itemno; - nritemset++; + itemset[nitemset] = itemno; + nitemset++; }; while (c < n) { - itemset[nritemset] = core[c]; - nritemset++; + itemset[nitemset] = core[c]; + nitemset++; c++; } if (trace_flag & trace_sets) - print_closure ("output", itemset, nritemset); + print_closure ("output", itemset, nitemset); } diff --git a/src/closure.h b/src/closure.h index a2582e89..c170e645 100644 --- a/src/closure.h +++ b/src/closure.h @@ -54,6 +54,6 @@ void closure (item_number *items, size_t n); void free_closure (void); extern item_number *itemset; -extern size_t nritemset; +extern size_t nitemset; #endif /* !CLOSURE_H_ */ diff --git a/src/lalr.c b/src/lalr.c index f2bfa967..805797cf 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -56,7 +56,7 @@ typedef struct goto_list } goto_list; -/* LA is a LR by NTOKENS matrix of bits. LA[l, i] is 1 if the rule +/* LA is an NLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule LArule[l] is applicable in the appropriate state when the next token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j, it is a conflict. */ diff --git a/src/print.c b/src/print.c index 08feaafb..3fecc2a7 100644 --- a/src/print.c +++ b/src/print.c @@ -81,7 +81,7 @@ print_core (FILE *out, state *s) { closure (sitems, snritems); sitems = itemset; - snritems = nritemset; + snritems = nitemset; } if (!snritems) diff --git a/src/print_graph.c b/src/print_graph.c index aba69028..8898c9aa 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -56,7 +56,7 @@ print_core (struct obstack *oout, state *s) { closure (sitems, snritems); sitems = itemset; - snritems = nritemset; + snritems = nitemset; } obstack_fgrow1 (oout, "%d", s->number); diff --git a/src/state.h b/src/state.h index a2ae217f..28933e13 100644 --- a/src/state.h +++ b/src/state.h @@ -44,7 +44,7 @@ ACCESSING_SYMBOL of the core. Each core contains a vector of NITEMS items which are the indices - in the RITEMS vector of the items that are selected in this state. + in the RITEM vector of the items that are selected in this state. The two types of actions are shifts/gotos (push the lookahead token and read another/goto to the state designated by a nterm) and @@ -63,9 +63,8 @@ deletes transitions by having them point to zero. Each reductions structure describes the possible reductions at the - state whose number is in the number field. The data is a list of - nreds rules, represented by their rule numbers. first_reduction - points to the list of these structures. + state whose number is in the number field. rules is an array of + num rules. lookahead_tokens is an array of bitsets, one per rule. Conflict resolution can decide that certain tokens in certain states should explicitly be errors (for implementing %nonassoc). -- 2.47.2