diff options
Diffstat (limited to 'lr0.c')
-rw-r--r-- | lr0.c | 84 |
1 files changed, 44 insertions, 40 deletions
@@ -1,4 +1,4 @@ -/* $Id: lr0.c,v 1.13 2012/05/26 00:40:47 tom Exp $ */ +/* $Id: lr0.c,v 1.16 2014/04/07 21:53:50 tom Exp $ */ #include "defs.h" @@ -28,7 +28,7 @@ static shifts *last_shift; static reductions *last_reduction; static int nshifts; -static short *shift_symbol; +static Value_t *shift_symbol; static Value_t *redset; static Value_t *shiftset; @@ -40,16 +40,16 @@ static Value_t *kernel_items; static void allocate_itemsets(void) { - short *itemp; - short *item_end; + Value_t *itemp; + Value_t *item_end; int symbol; int i; int count; int max; - short *symbol_count; + Value_t *symbol_count; count = 0; - symbol_count = NEW2(nsyms, short); + symbol_count = NEW2(nsyms, Value_t); item_end = ritem + nitems; for (itemp = ritem; itemp < item_end; itemp++) @@ -62,8 +62,8 @@ allocate_itemsets(void) } } - kernel_base = NEW2(nsyms, short *); - kernel_items = NEW2(count, short); + kernel_base = NEW2(nsyms, Value_t *); + kernel_items = NEW2(count, Value_t); count = 0; max = 0; @@ -76,15 +76,15 @@ allocate_itemsets(void) } shift_symbol = symbol_count; - kernel_end = NEW2(nsyms, short *); + kernel_end = NEW2(nsyms, Value_t *); } static void allocate_storage(void) { allocate_itemsets(); - shiftset = NEW2(nsyms, short); - redset = NEW2(nrules + 1, short); + shiftset = NEW2(nsyms, Value_t); + redset = NEW2(nrules + 1, Value_t); state_set = NEW2(nitems, core *); } @@ -133,7 +133,7 @@ static void generate_states(void) { allocate_storage(); - itemset = NEW2(nitems, short); + itemset = NEW2(nitems, Value_t); ruleset = NEW2(WORDSIZE(nrules), unsigned); set_first_derives(); initialize_states(); @@ -158,9 +158,9 @@ static Value_t get_state(int symbol) { int key; - short *isp1; - short *isp2; - short *iend; + Value_t *isp1; + Value_t *isp2; + Value_t *iend; core *sp; int found; int n; @@ -220,14 +220,14 @@ static void initialize_states(void) { unsigned i; - short *start_derives; + Value_t *start_derives; core *p; start_derives = derives[start_symbol]; for (i = 0; start_derives[i] >= 0; ++i) continue; - p = (core *)MALLOC(sizeof(core) + i * sizeof(short)); + p = (core *)MALLOC(sizeof(core) + i * sizeof(Value_t)); NO_SPACE(p); p->next = 0; @@ -248,8 +248,8 @@ new_itemsets(void) { Value_t i; int shiftcount; - short *isp; - short *ksp; + Value_t *isp; + Value_t *ksp; Value_t symbol; for (i = 0; i < nsyms; i++) @@ -283,22 +283,22 @@ new_state(int symbol) { unsigned n; core *p; - short *isp1; - short *isp2; - short *iend; + Value_t *isp1; + Value_t *isp2; + Value_t *iend; #ifdef TRACE fprintf(stderr, "Entering new_state(%d)\n", symbol); #endif - if (nstates >= MAXSHORT) + if (nstates >= MAXYYINT) fatal("too many states"); isp1 = kernel_base[symbol]; iend = kernel_end[symbol]; n = (unsigned)(iend - isp1); - p = (core *)allocate((sizeof(core) + (n - 1) * sizeof(short))); + p = (core *)allocate((sizeof(core) + (n - 1) * sizeof(Value_t))); p->accessing_symbol = (Value_t) symbol; p->number = (Value_t) nstates; p->nitems = (Value_t) n; @@ -316,7 +316,7 @@ new_state(int symbol) } /* show_cores is used for debugging */ - +#ifdef DEBUG void show_cores(void) { @@ -393,17 +393,18 @@ show_shifts(void) printf("\t%d\n", p->shift[i]); } } +#endif static void save_shifts(void) { shifts *p; - short *sp1; - short *sp2; - short *send; + Value_t *sp1; + Value_t *sp2; + Value_t *send; p = (shifts *)allocate((sizeof(shifts) + - (unsigned)(nshifts - 1) * sizeof(short))); + (unsigned)(nshifts - 1) * sizeof(Value_t))); p->number = this_state->number; p->nshifts = (Value_t) nshifts; @@ -430,13 +431,13 @@ save_shifts(void) static void save_reductions(void) { - short *isp; - short *rp1; - short *rp2; + Value_t *isp; + Value_t *rp1; + Value_t *rp2; int item; Value_t count; reductions *p; - short *rend; + Value_t *rend; count = 0; for (isp = itemset; isp < itemsetend; isp++) @@ -452,7 +453,7 @@ save_reductions(void) { p = (reductions *)allocate((sizeof(reductions) + (unsigned)(count - 1) * - sizeof(short))); + sizeof(Value_t))); p->number = this_state->number; p->nreds = count; @@ -482,10 +483,10 @@ set_derives(void) { Value_t i, k; int lhs; - short *rules; + Value_t *rules; - derives = NEW2(nsyms, short *); - rules = NEW2(nvars + nrules, short); + derives = NEW2(nsyms, Value_t *); + rules = NEW2(nvars + nrules, Value_t); k = 0; for (lhs = start_symbol; lhs < nsyms; lhs++) @@ -513,7 +514,7 @@ void print_derives(void) { int i; - short *sp; + Value_t *sp; printf("\nDERIVES\n\n"); @@ -592,8 +593,11 @@ lr0(void) void lr0_leaks(void) { - DO_FREE(derives[start_symbol]); - DO_FREE(derives); + if (derives) + { + DO_FREE(derives[start_symbol]); + DO_FREE(derives); + } DO_FREE(nullable); } #endif |