Upgraded to Berkeley's version 1.8
This commit is contained in:
parent
530ce78c37
commit
8eff53f8ea
|
@ -50,9 +50,7 @@ $(PROGRAM): $(OBJS) $(LIBS)
|
||||||
@$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
|
@$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
|
||||||
@echo "done"
|
@echo "done"
|
||||||
|
|
||||||
clean:; @rm -f $(OBJS)
|
clean:; @rm -f $(OBJS) $(PROGRAM)
|
||||||
|
|
||||||
clobber:; @rm -f $(OBJS) $(PROGRAM)
|
|
||||||
|
|
||||||
index:; @ctags -wx $(HDRS) $(SRCS)
|
index:; @ctags -wx $(HDRS) $(SRCS)
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@
|
||||||
|
|
||||||
#define SHIFT 1
|
#define SHIFT 1
|
||||||
#define REDUCE 2
|
#define REDUCE 2
|
||||||
#define ERROR 3
|
|
||||||
|
|
||||||
|
|
||||||
/* character macros */
|
/* character macros */
|
||||||
|
|
434
util/byacc/lr0.c
434
util/byacc/lr0.c
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
extern short *itemset;
|
extern short *itemset;
|
||||||
|
@ -31,124 +32,120 @@ static short *kernel_items;
|
||||||
|
|
||||||
allocate_itemsets()
|
allocate_itemsets()
|
||||||
{
|
{
|
||||||
register short *itemp;
|
register short *itemp;
|
||||||
register short *item_end;
|
register short *item_end;
|
||||||
register int symbol;
|
register int symbol;
|
||||||
register int i;
|
register int i;
|
||||||
register int count;
|
register int count;
|
||||||
register int max;
|
register int max;
|
||||||
register short *symbol_count;
|
register short *symbol_count;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
symbol_count = NEW2(nsyms, short);
|
symbol_count = NEW2(nsyms, short);
|
||||||
|
|
||||||
item_end = ritem + nitems;
|
item_end = ritem + nitems;
|
||||||
for (itemp = ritem; itemp < item_end; itemp++)
|
for (itemp = ritem; itemp < item_end; itemp++)
|
||||||
{
|
{
|
||||||
symbol = *itemp;
|
symbol = *itemp;
|
||||||
if (symbol >= 0)
|
if (symbol >= 0)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
symbol_count[symbol]++;
|
symbol_count[symbol]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel_base = NEW2(nsyms, short *);
|
kernel_base = NEW2(nsyms, short *);
|
||||||
kernel_items = NEW2(count, short);
|
kernel_items = NEW2(count, short);
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
max = 0;
|
max = 0;
|
||||||
for (i = 0; i < nsyms; i++)
|
for (i = 0; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
kernel_base[i] = kernel_items + count;
|
kernel_base[i] = kernel_items + count;
|
||||||
count += symbol_count[i];
|
count += symbol_count[i];
|
||||||
if (max < symbol_count[i])
|
if (max < symbol_count[i])
|
||||||
max = symbol_count[i];
|
max = symbol_count[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
shift_symbol = symbol_count;
|
shift_symbol = symbol_count;
|
||||||
kernel_end = NEW2(nsyms, short *);
|
kernel_end = NEW2(nsyms, short *);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
allocate_storage()
|
allocate_storage()
|
||||||
{
|
{
|
||||||
allocate_itemsets();
|
allocate_itemsets();
|
||||||
|
shiftset = NEW2(nsyms, short);
|
||||||
shiftset = NEW2(nsyms, short);
|
redset = NEW2(nrules + 1, short);
|
||||||
redset = NEW2(nrules + 1, short);
|
state_set = NEW2(nitems, core *);
|
||||||
state_set = NEW2(nitems, core *);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
append_states()
|
append_states()
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
register int j;
|
register int j;
|
||||||
register int symbol;
|
register int symbol;
|
||||||
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
fprintf(stderr, "Entering append_states\n");
|
fprintf(stderr, "Entering append_states()\n");
|
||||||
#endif
|
#endif
|
||||||
|
for (i = 1; i < nshifts; i++)
|
||||||
for (i = 1; i < nshifts; i++)
|
|
||||||
{
|
{
|
||||||
symbol = shift_symbol[i];
|
symbol = shift_symbol[i];
|
||||||
j = i;
|
j = i;
|
||||||
while (j > 0 && shift_symbol[j - 1] > symbol)
|
while (j > 0 && shift_symbol[j - 1] > symbol)
|
||||||
{
|
{
|
||||||
shift_symbol[j] = shift_symbol[j - 1];
|
shift_symbol[j] = shift_symbol[j - 1];
|
||||||
j--;
|
j--;
|
||||||
}
|
}
|
||||||
shift_symbol[j] = symbol;
|
shift_symbol[j] = symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nshifts; i++)
|
for (i = 0; i < nshifts; i++)
|
||||||
{
|
{
|
||||||
symbol = shift_symbol[i];
|
symbol = shift_symbol[i];
|
||||||
shiftset[i] = get_state(symbol);
|
shiftset[i] = get_state(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
free_storage()
|
free_storage()
|
||||||
{
|
{
|
||||||
FREE(shift_symbol);
|
FREE(shift_symbol);
|
||||||
FREE(redset);
|
FREE(redset);
|
||||||
FREE(shiftset);
|
FREE(shiftset);
|
||||||
FREE(kernel_base);
|
FREE(kernel_base);
|
||||||
FREE(kernel_end);
|
FREE(kernel_end);
|
||||||
FREE(kernel_items);
|
FREE(kernel_items);
|
||||||
FREE(state_set);
|
FREE(state_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generate_states()
|
generate_states()
|
||||||
{
|
{
|
||||||
allocate_storage();
|
allocate_storage();
|
||||||
itemset = NEW2(nitems, short);
|
itemset = NEW2(nitems, short);
|
||||||
ruleset = NEW2(WORDSIZE(nrules), unsigned);
|
ruleset = NEW2(WORDSIZE(nrules), unsigned);
|
||||||
set_first_derives();
|
set_first_derives();
|
||||||
initialize_states();
|
initialize_states();
|
||||||
|
|
||||||
while (this_state)
|
while (this_state)
|
||||||
{
|
{
|
||||||
closure(this_state->items, this_state->nitems);
|
closure(this_state->items, this_state->nitems);
|
||||||
save_reductions();
|
save_reductions();
|
||||||
new_itemsets();
|
new_itemsets();
|
||||||
append_states();
|
append_states();
|
||||||
|
|
||||||
if (nshifts > 0)
|
if (nshifts > 0)
|
||||||
save_shifts();
|
save_shifts();
|
||||||
|
|
||||||
this_state = this_state->next;
|
this_state = this_state->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize_closure();
|
finalize_closure();
|
||||||
free_storage();
|
free_storage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,64 +154,63 @@ int
|
||||||
get_state(symbol)
|
get_state(symbol)
|
||||||
int symbol;
|
int symbol;
|
||||||
{
|
{
|
||||||
register int key;
|
register int key;
|
||||||
register short *isp1;
|
register short *isp1;
|
||||||
register short *isp2;
|
register short *isp2;
|
||||||
register short *iend;
|
register short *iend;
|
||||||
register core *sp;
|
register core *sp;
|
||||||
register int found;
|
register int found;
|
||||||
|
register int n;
|
||||||
int n;
|
|
||||||
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
fprintf(stderr, "Entering get_state, symbol = %d\n", symbol);
|
fprintf(stderr, "Entering get_state(%d)\n", symbol);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
isp1 = kernel_base[symbol];
|
isp1 = kernel_base[symbol];
|
||||||
iend = kernel_end[symbol];
|
iend = kernel_end[symbol];
|
||||||
n = iend - isp1;
|
n = iend - isp1;
|
||||||
|
|
||||||
key = *isp1;
|
key = *isp1;
|
||||||
assert(0 <= key && key < nitems);
|
assert(0 <= key && key < nitems);
|
||||||
sp = state_set[key];
|
sp = state_set[key];
|
||||||
if (sp)
|
if (sp)
|
||||||
{
|
{
|
||||||
found = 0;
|
found = 0;
|
||||||
while (!found)
|
while (!found)
|
||||||
{
|
{
|
||||||
if (sp->nitems == n)
|
if (sp->nitems == n)
|
||||||
{
|
{
|
||||||
found = 1;
|
found = 1;
|
||||||
isp1 = kernel_base[symbol];
|
isp1 = kernel_base[symbol];
|
||||||
isp2 = sp->items;
|
isp2 = sp->items;
|
||||||
|
|
||||||
while (found && isp1 < iend)
|
while (found && isp1 < iend)
|
||||||
{
|
{
|
||||||
if (*isp1++ != *isp2++)
|
if (*isp1++ != *isp2++)
|
||||||
found = 0;
|
found = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
if (sp->link)
|
if (sp->link)
|
||||||
{
|
{
|
||||||
sp = sp->link;
|
sp = sp->link;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sp = sp->link = new_state(symbol);
|
sp = sp->link = new_state(symbol);
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state_set[key] = sp = new_state(symbol);
|
state_set[key] = sp = new_state(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sp->number);
|
return (sp->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,37 +244,36 @@ initialize_states()
|
||||||
|
|
||||||
new_itemsets()
|
new_itemsets()
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
register int shiftcount;
|
register int shiftcount;
|
||||||
register short *isp;
|
register short *isp;
|
||||||
register short *ksp;
|
register short *ksp;
|
||||||
register int symbol;
|
register int symbol;
|
||||||
|
|
||||||
for (i = 0; i < nsyms; i++)
|
for (i = 0; i < nsyms; i++)
|
||||||
kernel_end[i] = 0;
|
kernel_end[i] = 0;
|
||||||
|
|
||||||
shiftcount = 0;
|
shiftcount = 0;
|
||||||
isp = itemset;
|
isp = itemset;
|
||||||
while (isp < itemsetend)
|
while (isp < itemsetend)
|
||||||
{
|
{
|
||||||
i = *isp++;
|
i = *isp++;
|
||||||
symbol = ritem[i];
|
symbol = ritem[i];
|
||||||
if (symbol > 0)
|
if (symbol > 0)
|
||||||
{
|
{
|
||||||
ksp = kernel_end[symbol];
|
ksp = kernel_end[symbol];
|
||||||
|
if (!ksp)
|
||||||
if (!ksp)
|
|
||||||
{
|
{
|
||||||
shift_symbol[shiftcount++] = symbol;
|
shift_symbol[shiftcount++] = symbol;
|
||||||
ksp = kernel_base[symbol];
|
ksp = kernel_base[symbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
*ksp++ = i + 1;
|
*ksp++ = i + 1;
|
||||||
kernel_end[symbol] = ksp;
|
kernel_end[symbol] = ksp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nshifts = shiftcount;
|
nshifts = shiftcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,38 +282,38 @@ core *
|
||||||
new_state(symbol)
|
new_state(symbol)
|
||||||
int symbol;
|
int symbol;
|
||||||
{
|
{
|
||||||
register int n;
|
register int n;
|
||||||
register core *p;
|
register core *p;
|
||||||
register short *isp1;
|
register short *isp1;
|
||||||
register short *isp2;
|
register short *isp2;
|
||||||
register short *iend;
|
register short *iend;
|
||||||
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
fprintf(stderr, "Entering new_state, symbol = %d\n", symbol);
|
fprintf(stderr, "Entering new_state(%d)\n", symbol);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nstates >= MAXSHORT)
|
if (nstates >= MAXSHORT)
|
||||||
fatal("too many states");
|
fatal("too many states");
|
||||||
|
|
||||||
isp1 = kernel_base[symbol];
|
isp1 = kernel_base[symbol];
|
||||||
iend = kernel_end[symbol];
|
iend = kernel_end[symbol];
|
||||||
n = iend - isp1;
|
n = iend - isp1;
|
||||||
|
|
||||||
p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
|
p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
|
||||||
p->accessing_symbol = symbol;
|
p->accessing_symbol = symbol;
|
||||||
p->number = nstates;
|
p->number = nstates;
|
||||||
p->nitems = n;
|
p->nitems = n;
|
||||||
|
|
||||||
isp2 = p->items;
|
isp2 = p->items;
|
||||||
while (isp1 < iend)
|
while (isp1 < iend)
|
||||||
*isp2++ = *isp1++;
|
*isp2++ = *isp1++;
|
||||||
|
|
||||||
last_state->next = p;
|
last_state->next = p;
|
||||||
last_state = p;
|
last_state = p;
|
||||||
|
|
||||||
nstates++;
|
nstates++;
|
||||||
|
|
||||||
return (p);
|
return (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,33 +395,33 @@ show_shifts()
|
||||||
|
|
||||||
save_shifts()
|
save_shifts()
|
||||||
{
|
{
|
||||||
register shifts *p;
|
register shifts *p;
|
||||||
register short *sp1;
|
register short *sp1;
|
||||||
register short *sp2;
|
register short *sp2;
|
||||||
register short *send;
|
register short *send;
|
||||||
|
|
||||||
p = (shifts *) allocate((unsigned) (sizeof(shifts) +
|
p = (shifts *) allocate((unsigned) (sizeof(shifts) +
|
||||||
(nshifts - 1) * sizeof(short)));
|
(nshifts - 1) * sizeof(short)));
|
||||||
|
|
||||||
p->number = this_state->number;
|
p->number = this_state->number;
|
||||||
p->nshifts = nshifts;
|
p->nshifts = nshifts;
|
||||||
|
|
||||||
sp1 = shiftset;
|
sp1 = shiftset;
|
||||||
sp2 = p->shift;
|
sp2 = p->shift;
|
||||||
send = shiftset + nshifts;
|
send = shiftset + nshifts;
|
||||||
|
|
||||||
while (sp1 < send)
|
while (sp1 < send)
|
||||||
*sp2++ = *sp1++;
|
*sp2++ = *sp1++;
|
||||||
|
|
||||||
if (last_shift)
|
if (last_shift)
|
||||||
{
|
{
|
||||||
last_shift->next = p;
|
last_shift->next = p;
|
||||||
last_shift = p;
|
last_shift = p;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
first_shift = p;
|
first_shift = p;
|
||||||
last_shift = p;
|
last_shift = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,49 +429,48 @@ save_shifts()
|
||||||
|
|
||||||
save_reductions()
|
save_reductions()
|
||||||
{
|
{
|
||||||
register short *isp;
|
register short *isp;
|
||||||
register short *rp1;
|
register short *rp1;
|
||||||
register short *rp2;
|
register short *rp2;
|
||||||
register int item;
|
register int item;
|
||||||
register int count;
|
register int count;
|
||||||
register reductions *p;
|
register reductions *p;
|
||||||
|
register short *rend;
|
||||||
|
|
||||||
short *rend;
|
count = 0;
|
||||||
|
for (isp = itemset; isp < itemsetend; isp++)
|
||||||
count = 0;
|
|
||||||
for (isp = itemset; isp < itemsetend; isp++)
|
|
||||||
{
|
{
|
||||||
item = ritem[*isp];
|
item = ritem[*isp];
|
||||||
if (item < 0)
|
if (item < 0)
|
||||||
{
|
{
|
||||||
redset[count++] = -item;
|
redset[count++] = -item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count)
|
if (count)
|
||||||
{
|
{
|
||||||
p = (reductions *) allocate((unsigned) (sizeof(reductions) +
|
p = (reductions *) allocate((unsigned) (sizeof(reductions) +
|
||||||
(count - 1) * sizeof(short)));
|
(count - 1) * sizeof(short)));
|
||||||
|
|
||||||
p->number = this_state->number;
|
p->number = this_state->number;
|
||||||
p->nreds = count;
|
p->nreds = count;
|
||||||
|
|
||||||
rp1 = redset;
|
rp1 = redset;
|
||||||
rp2 = p->rules;
|
rp2 = p->rules;
|
||||||
rend = rp1 + count;
|
rend = rp1 + count;
|
||||||
|
|
||||||
while (rp1 < rend)
|
while (rp1 < rend)
|
||||||
*rp2++ = *rp1++;
|
*rp2++ = *rp1++;
|
||||||
|
|
||||||
if (last_reduction)
|
if (last_reduction)
|
||||||
{
|
{
|
||||||
last_reduction->next = p;
|
last_reduction->next = p;
|
||||||
last_reduction = p;
|
last_reduction = p;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
first_reduction = p;
|
first_reduction = p;
|
||||||
last_reduction = p;
|
last_reduction = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,59 +478,59 @@ save_reductions()
|
||||||
|
|
||||||
set_derives()
|
set_derives()
|
||||||
{
|
{
|
||||||
register int i, k;
|
register int i, k;
|
||||||
register int lhs;
|
register int lhs;
|
||||||
register short *rules;
|
register short *rules;
|
||||||
|
|
||||||
derives = NEW2(nsyms, short *);
|
derives = NEW2(nsyms, short *);
|
||||||
rules = NEW2(nvars + nrules, short);
|
rules = NEW2(nvars + nrules, short);
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
for (lhs = start_symbol; lhs < nsyms; lhs++)
|
for (lhs = start_symbol; lhs < nsyms; lhs++)
|
||||||
{
|
{
|
||||||
derives[lhs] = rules + k;
|
derives[lhs] = rules + k;
|
||||||
for (i = 0; i < nrules; i++)
|
for (i = 0; i < nrules; i++)
|
||||||
{
|
{
|
||||||
if (rlhs[i] == lhs)
|
if (rlhs[i] == lhs)
|
||||||
{
|
{
|
||||||
rules[k] = i;
|
rules[k] = i;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rules[k] = -1;
|
rules[k] = -1;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
print_derives();
|
print_derives();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
free_derives()
|
free_derives()
|
||||||
{
|
{
|
||||||
FREE(derives[start_symbol]);
|
FREE(derives[start_symbol]);
|
||||||
FREE(derives);
|
FREE(derives);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
print_derives()
|
print_derives()
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
register short *sp;
|
register short *sp;
|
||||||
|
|
||||||
printf("\nDERIVES\n\n");
|
printf("\nDERIVES\n\n");
|
||||||
|
|
||||||
for (i = start_symbol; i < nsyms; i++)
|
for (i = start_symbol; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
printf("%s derives ", symbol_name[i]);
|
printf("%s derives ", symbol_name[i]);
|
||||||
for (sp = derives[i]; *sp >= 0; sp++)
|
for (sp = derives[i]; *sp >= 0; sp++)
|
||||||
{
|
{
|
||||||
printf(" %d", *sp);
|
printf(" %d", *sp);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -592,7 +586,7 @@ set_nullable()
|
||||||
|
|
||||||
free_nullable()
|
free_nullable()
|
||||||
{
|
{
|
||||||
FREE(nullable);
|
FREE(nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
action **parser;
|
action **parser;
|
||||||
|
@ -202,7 +203,7 @@ remove_conflicts()
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
register int symbol;
|
register int symbol;
|
||||||
register action *p, *q;
|
register action *p, *pref;
|
||||||
|
|
||||||
SRtotal = 0;
|
SRtotal = 0;
|
||||||
RRtotal = 0;
|
RRtotal = 0;
|
||||||
|
@ -212,16 +213,58 @@ remove_conflicts()
|
||||||
{
|
{
|
||||||
SRcount = 0;
|
SRcount = 0;
|
||||||
RRcount = 0;
|
RRcount = 0;
|
||||||
for (p = parser[i]; p; p = q->next)
|
symbol = -1;
|
||||||
|
for (p = parser[i]; p; p = p->next)
|
||||||
{
|
{
|
||||||
symbol = p->symbol;
|
if (p->symbol != symbol)
|
||||||
q = p;
|
{
|
||||||
while (q->next && q->next->symbol == symbol)
|
pref = p;
|
||||||
q = q->next;
|
symbol = p->symbol;
|
||||||
if (i == final_state && symbol == 0)
|
}
|
||||||
end_conflicts(p, q);
|
else if (i == final_state && symbol == 0)
|
||||||
else if (p != q)
|
{
|
||||||
resolve_conflicts(p, q);
|
SRcount++;
|
||||||
|
p->suppressed = 1;
|
||||||
|
}
|
||||||
|
else if (pref->action_code == SHIFT)
|
||||||
|
{
|
||||||
|
if (pref->prec > 0 && p->prec > 0)
|
||||||
|
{
|
||||||
|
if (pref->prec < p->prec)
|
||||||
|
{
|
||||||
|
pref->suppressed = 2;
|
||||||
|
pref = p;
|
||||||
|
}
|
||||||
|
else if (pref->prec > p->prec)
|
||||||
|
{
|
||||||
|
p->suppressed = 2;
|
||||||
|
}
|
||||||
|
else if (pref->assoc == LEFT)
|
||||||
|
{
|
||||||
|
pref->suppressed = 2;
|
||||||
|
pref = p;
|
||||||
|
}
|
||||||
|
else if (pref->assoc == RIGHT)
|
||||||
|
{
|
||||||
|
p->suppressed = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pref->suppressed = 2;
|
||||||
|
p->suppressed = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SRcount++;
|
||||||
|
p->suppressed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RRcount++;
|
||||||
|
p->suppressed = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SRtotal += SRcount;
|
SRtotal += SRcount;
|
||||||
RRtotal += RRcount;
|
RRtotal += RRcount;
|
||||||
|
@ -231,64 +274,6 @@ remove_conflicts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
end_conflicts(p, q)
|
|
||||||
register action *p, *q;
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
SRcount++;
|
|
||||||
p->suppressed = 1;
|
|
||||||
if (p == q) break;
|
|
||||||
p = p->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
resolve_conflicts(first, last)
|
|
||||||
register action *first, *last;
|
|
||||||
{
|
|
||||||
register action *p;
|
|
||||||
register int count;
|
|
||||||
|
|
||||||
count = 1;
|
|
||||||
for (p = first; p != last; p = p->next)
|
|
||||||
++count;
|
|
||||||
assert(count > 1);
|
|
||||||
|
|
||||||
if (first->action_code == SHIFT && count == 2 &&
|
|
||||||
first->prec > 0 && last->prec > 0)
|
|
||||||
{
|
|
||||||
if (first->prec == last->prec)
|
|
||||||
{
|
|
||||||
if (first->assoc == LEFT)
|
|
||||||
first->suppressed = 2;
|
|
||||||
else if (first->assoc == RIGHT)
|
|
||||||
last->suppressed = 2;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
first->suppressed = 2;
|
|
||||||
last->suppressed = 2;
|
|
||||||
first->action_code = ERROR;
|
|
||||||
last->action_code = ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (first->prec < last->prec)
|
|
||||||
first->suppressed = 2;
|
|
||||||
else
|
|
||||||
last->suppressed = 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (first->action_code == SHIFT)
|
|
||||||
SRcount += (count - 1);
|
|
||||||
else
|
|
||||||
RRcount += (count - 1);
|
|
||||||
for (p = first; p != last; p = p->next, p->suppressed = 1)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
total_conflicts()
|
total_conflicts()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: ", myname);
|
fprintf(stderr, "%s: ", myname);
|
||||||
|
@ -369,3 +354,4 @@ free_parser()
|
||||||
|
|
||||||
FREE(parser);
|
FREE(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
char *banner[] =
|
char *banner[] =
|
||||||
{
|
{
|
||||||
"#ifndef lint",
|
"#ifndef lint",
|
||||||
"static char yysccsid[] = \"@(#)yaccpar 1.7 (Berkeley) 09/09/90\";",
|
"static char yysccsid[] = \"@(#)yaccpar 1.8 (Berkeley) 01/20/90\";",
|
||||||
"#endif",
|
"#endif",
|
||||||
"#define YYBYACC 1",
|
"#define YYBYACC 1",
|
||||||
0
|
0
|
||||||
|
@ -47,16 +47,16 @@ char *header[] =
|
||||||
"#ifdef YYMAXDEPTH",
|
"#ifdef YYMAXDEPTH",
|
||||||
"#define YYSTACKSIZE YYMAXDEPTH",
|
"#define YYSTACKSIZE YYMAXDEPTH",
|
||||||
"#else",
|
"#else",
|
||||||
"#define YYSTACKSIZE 600",
|
"#define YYSTACKSIZE 200", /* ACK mod: Changed from 600 to 200 */
|
||||||
"#define YYMAXDEPTH 600",
|
"#define YYMAXDEPTH 200", /* ACK mod: Changed from 600 to 200 */
|
||||||
"#endif",
|
"#endif",
|
||||||
"#endif",
|
"#endif",
|
||||||
|
"#if YYDEBUG",
|
||||||
"int yydebug;",
|
"int yydebug;",
|
||||||
|
"#endif",
|
||||||
"int yynerrs;",
|
"int yynerrs;",
|
||||||
"int yyerrflag;",
|
"int yyerrflag;",
|
||||||
"int yychar;",
|
"int yychar;",
|
||||||
"short *yyssp;",
|
|
||||||
"YYSTYPE *yyvsp;",
|
|
||||||
"YYSTYPE yyval;",
|
"YYSTYPE yyval;",
|
||||||
"YYSTYPE yylval;",
|
"YYSTYPE yylval;",
|
||||||
"short yyss[YYSTACKSIZE];",
|
"short yyss[YYSTACKSIZE];",
|
||||||
|
@ -75,6 +75,8 @@ char *body[] =
|
||||||
"yyparse()",
|
"yyparse()",
|
||||||
"{",
|
"{",
|
||||||
" register int yym, yyn, yystate;",
|
" register int yym, yyn, yystate;",
|
||||||
|
" register short *yyssp;", /* ACK mod: made this a local */
|
||||||
|
" register YYSTYPE *yyvsp;", /* ACK mod: made this a local */
|
||||||
"#if YYDEBUG",
|
"#if YYDEBUG",
|
||||||
" register char *yys;",
|
" register char *yys;",
|
||||||
" extern char *getenv();",
|
" extern char *getenv();",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,54 +92,44 @@ int state;
|
||||||
print_conflicts(state)
|
print_conflicts(state)
|
||||||
int state;
|
int state;
|
||||||
{
|
{
|
||||||
register int symbol;
|
register int symbol, act, number;
|
||||||
register action *p, *q, *r;
|
register action *p;
|
||||||
|
|
||||||
for (p = parser[state]; p; p = q->next)
|
symbol = -1;
|
||||||
|
for (p = parser[state]; p; p = p->next)
|
||||||
{
|
{
|
||||||
q = p;
|
if (p->suppressed == 2)
|
||||||
if (p->action_code == ERROR || p->suppressed == 2)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
symbol = p->symbol;
|
if (p->symbol != symbol)
|
||||||
while (q->next && q->next->symbol == symbol)
|
|
||||||
q = q->next;
|
|
||||||
if (state == final_state && symbol == 0)
|
|
||||||
{
|
{
|
||||||
r = p;
|
symbol = p->symbol;
|
||||||
for (;;)
|
number = p->number;
|
||||||
|
if (p->action_code == SHIFT)
|
||||||
|
act = SHIFT;
|
||||||
|
else
|
||||||
|
act = REDUCE;
|
||||||
|
}
|
||||||
|
else if (p->suppressed == 1)
|
||||||
|
{
|
||||||
|
if (state == final_state && symbol == 0)
|
||||||
{
|
{
|
||||||
fprintf(verbose_file, "%d: shift/reduce conflict \
|
fprintf(verbose_file, "%d: shift/reduce conflict \
|
||||||
(accept, reduce %d) on $end\n", state, r->number - 2);
|
(accept, reduce %d) on $end\n", state, p->number - 2);
|
||||||
if (r == q) break;
|
|
||||||
r = r->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (p != q)
|
|
||||||
{
|
|
||||||
r = p->next;
|
|
||||||
if (p->action_code == SHIFT)
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (r->action_code == REDUCE && p->suppressed != 2)
|
|
||||||
fprintf(verbose_file, "%d: shift/reduce conflict \
|
|
||||||
(shift %d, reduce %d) on %s\n", state, p->number, r->number - 2,
|
|
||||||
symbol_name[symbol]);
|
|
||||||
if (r == q) break;
|
|
||||||
r = r->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (;;)
|
if (act == SHIFT)
|
||||||
{
|
{
|
||||||
if (r->action_code == REDUCE && p->suppressed != 2)
|
fprintf(verbose_file, "%d: shift/reduce conflict \
|
||||||
fprintf(verbose_file, "%d: reduce/reduce conflict \
|
(shift %d, reduce %d) on %s\n", state, number, p->number - 2,
|
||||||
(reduce %d, reduce %d) on %s\n", state, p->number - 2, r->number - 2,
|
symbol_name[symbol]);
|
||||||
symbol_name[symbol]);
|
}
|
||||||
if (r == q) break;
|
else
|
||||||
r = r->next;
|
{
|
||||||
|
fprintf(verbose_file, "%d: reduce/reduce conflict \
|
||||||
|
(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
|
||||||
|
symbol_name[symbol]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,3 +326,4 @@ int stateno;
|
||||||
fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k);
|
fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue