Upgraded to Berkeley's version 1.8

This commit is contained in:
ceriel 1991-01-22 10:58:49 +00:00
parent 530ce78c37
commit 8eff53f8ea
6 changed files with 305 additions and 334 deletions

View file

@ -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)

View file

@ -78,7 +78,6 @@
#define SHIFT 1 #define SHIFT 1
#define REDUCE 2 #define REDUCE 2
#define ERROR 3
/* character macros */ /* character macros */

View file

@ -1,3 +1,4 @@
#include "defs.h" #include "defs.h"
extern short *itemset; extern short *itemset;
@ -71,18 +72,15 @@ allocate_itemsets()
} }
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;
@ -90,9 +88,8 @@ append_states()
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];
@ -163,11 +160,10 @@ int symbol;
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];
@ -266,7 +262,6 @@ new_itemsets()
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;
@ -294,7 +289,7 @@ int symbol;
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)
@ -440,8 +435,7 @@ save_reductions()
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; count = 0;
for (isp = itemset; isp < itemsetend; isp++) for (isp = itemset; isp < itemsetend; isp++)

View file

@ -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)
{ {
if (p->symbol != symbol)
{
pref = p;
symbol = p->symbol; symbol = p->symbol;
q = p; }
while (q->next && q->next->symbol == symbol) else if (i == final_state && symbol == 0)
q = q->next; {
if (i == final_state && symbol == 0) SRcount++;
end_conflicts(p, q); p->suppressed = 1;
else if (p != q) }
resolve_conflicts(p, q); 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);
} }

View file

@ -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();",

View file

@ -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;
if (p->symbol != symbol)
{
symbol = p->symbol; symbol = p->symbol;
while (q->next && q->next->symbol == symbol) number = p->number;
q = q->next; if (p->action_code == SHIFT)
act = SHIFT;
else
act = REDUCE;
}
else if (p->suppressed == 1)
{
if (state == final_state && symbol == 0) if (state == final_state && symbol == 0)
{
r = p;
for (;;)
{ {
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]);
}
else
{
fprintf(verbose_file, "%d: reduce/reduce conflict \
(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
symbol_name[symbol]); symbol_name[symbol]);
if (r == q) break;
r = r->next;
} }
} }
} }
@ -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);
} }
} }