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)
@echo "done"
clean:; @rm -f $(OBJS)
clobber:; @rm -f $(OBJS) $(PROGRAM)
clean:; @rm -f $(OBJS) $(PROGRAM)
index:; @ctags -wx $(HDRS) $(SRCS)

View file

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

View file

@ -1,3 +1,4 @@
#include "defs.h"
extern short *itemset;
@ -71,18 +72,15 @@ allocate_itemsets()
}
allocate_storage()
{
allocate_itemsets();
shiftset = NEW2(nsyms, short);
redset = NEW2(nrules + 1, short);
state_set = NEW2(nitems, core *);
}
append_states()
{
register int i;
@ -90,9 +88,8 @@ append_states()
register int symbol;
#ifdef TRACE
fprintf(stderr, "Entering append_states\n");
fprintf(stderr, "Entering append_states()\n");
#endif
for (i = 1; i < nshifts; i++)
{
symbol = shift_symbol[i];
@ -163,11 +160,10 @@ int symbol;
register short *iend;
register core *sp;
register int found;
int n;
register int n;
#ifdef TRACE
fprintf(stderr, "Entering get_state, symbol = %d\n", symbol);
fprintf(stderr, "Entering get_state(%d)\n", symbol);
#endif
isp1 = kernel_base[symbol];
@ -266,7 +262,6 @@ new_itemsets()
if (symbol > 0)
{
ksp = kernel_end[symbol];
if (!ksp)
{
shift_symbol[shiftcount++] = symbol;
@ -294,7 +289,7 @@ int symbol;
register short *iend;
#ifdef TRACE
fprintf(stderr, "Entering new_state, symbol = %d\n", symbol);
fprintf(stderr, "Entering new_state(%d)\n", symbol);
#endif
if (nstates >= MAXSHORT)
@ -440,8 +435,7 @@ save_reductions()
register int item;
register int count;
register reductions *p;
short *rend;
register short *rend;
count = 0;
for (isp = itemset; isp < itemsetend; isp++)

View file

@ -1,3 +1,4 @@
#include "defs.h"
action **parser;
@ -202,7 +203,7 @@ remove_conflicts()
{
register int i;
register int symbol;
register action *p, *q;
register action *p, *pref;
SRtotal = 0;
RRtotal = 0;
@ -212,16 +213,58 @@ remove_conflicts()
{
SRcount = 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;
q = p;
while (q->next && q->next->symbol == symbol)
q = q->next;
if (i == final_state && symbol == 0)
end_conflicts(p, q);
else if (p != q)
resolve_conflicts(p, q);
}
else if (i == final_state && symbol == 0)
{
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;
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()
{
fprintf(stderr, "%s: ", myname);
@ -369,3 +354,4 @@ free_parser()
FREE(parser);
}

View file

@ -9,7 +9,7 @@
char *banner[] =
{
"#ifndef lint",
"static char yysccsid[] = \"@(#)yaccpar 1.7 (Berkeley) 09/09/90\";",
"static char yysccsid[] = \"@(#)yaccpar 1.8 (Berkeley) 01/20/90\";",
"#endif",
"#define YYBYACC 1",
0
@ -47,16 +47,16 @@ char *header[] =
"#ifdef YYMAXDEPTH",
"#define YYSTACKSIZE YYMAXDEPTH",
"#else",
"#define YYSTACKSIZE 600",
"#define YYMAXDEPTH 600",
"#define YYSTACKSIZE 200", /* ACK mod: Changed from 600 to 200 */
"#define YYMAXDEPTH 200", /* ACK mod: Changed from 600 to 200 */
"#endif",
"#endif",
"#if YYDEBUG",
"int yydebug;",
"#endif",
"int yynerrs;",
"int yyerrflag;",
"int yychar;",
"short *yyssp;",
"YYSTYPE *yyvsp;",
"YYSTYPE yyval;",
"YYSTYPE yylval;",
"short yyss[YYSTACKSIZE];",
@ -75,6 +75,8 @@ char *body[] =
"yyparse()",
"{",
" 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",
" register char *yys;",
" extern char *getenv();",

View file

@ -1,3 +1,4 @@
#include "defs.h"
@ -91,54 +92,44 @@ int state;
print_conflicts(state)
int state;
{
register int symbol;
register action *p, *q, *r;
register int symbol, act, number;
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->action_code == ERROR || p->suppressed == 2)
if (p->suppressed == 2)
continue;
if (p->symbol != symbol)
{
symbol = p->symbol;
while (q->next && q->next->symbol == symbol)
q = q->next;
number = p->number;
if (p->action_code == SHIFT)
act = SHIFT;
else
act = REDUCE;
}
else if (p->suppressed == 1)
{
if (state == final_state && symbol == 0)
{
r = p;
for (;;)
{
fprintf(verbose_file, "%d: shift/reduce conflict \
(accept, reduce %d) on $end\n", state, r->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;
}
(accept, reduce %d) on $end\n", state, p->number - 2);
}
else
{
for (;;)
if (act == SHIFT)
{
if (r->action_code == REDUCE && p->suppressed != 2)
fprintf(verbose_file, "%d: reduce/reduce conflict \
(reduce %d, reduce %d) on %s\n", state, p->number - 2, r->number - 2,
fprintf(verbose_file, "%d: shift/reduce conflict \
(shift %d, reduce %d) on %s\n", state, number, p->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]);
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);
}
}