Because useless nonterminals are now kept alive (instead of being

`destroyed'), we now sometimes examine them, and store information
related to them.  Hence we need to know their number, and adjust
memory allocations.
* src/reduce.c, src/reduce.h (nuseless_nonterminals): No longer
static.
* src/LR0.c (allocate_itemsets): The memory allocated to
`symbol_count' was used for two different purpose: once to count
the number of occurrences of each symbol, and later reassigned to
`shift_symbol', containing the symbol that can be shifted from a
given state.
Deobfuscate, i.e., allocate, use and free `symbol_count' here
only, and...
(new_itemsets): Allocate `shift_symbol' here.
(allocate_itemsets): symbol_count includes useless nonterminals.
Make room for them.
(free_storage): Use `free', not `XFREE', for pointers that cannot
be null.
This commit is contained in:
Akim Demaille
2001-12-05 09:16:37 +00:00
parent d854cc9e5a
commit fa7f94f217
5 changed files with 47 additions and 15 deletions

View File

@@ -28,6 +28,7 @@
#include "reader.h"
#include "types.h"
#include "gram.h"
#include "reduce.h"
#include "nullable.h"
char *nullable = NULL;
@@ -64,11 +65,14 @@ set_nullable (void)
s1 = s2 = squeue;
rcount = XCALLOC (short, nrules + 1);
rsets = XCALLOC (shorts *, nvars) - ntokens;
/* RITEM contains all the rules, including useless productions.
Hence we must allocate room for useless nonterminals too. */
rsets = XCALLOC (shorts *, nvars + nuseless_nonterminals) - ntokens;
/* This is said to be more elements than we actually use.
Supposedly nitems - nrules is enough.
But why take the risk? */
relts = XCALLOC (shorts, nitems + nvars + 1);
relts = XCALLOC (shorts, nitems + nvars + nuseless_nonterminals + 1);
p = relts;
for (r = ritem; *r; ++r)