From 505b2ec8fec9582f9526ca8cb28e846ea4362e80 Mon Sep 17 00:00:00 2001 From: etheisen Date: Sun, 4 Feb 1996 08:37:00 +0000 Subject: [PATCH] Yacc now understands %expect keyword. This should help prevent yacc from gagging on GNU bison grammer. --- usr.bin/yacc/defs.h | 4 +++- usr.bin/yacc/mkpar.c | 27 +++++++++++----------- usr.bin/yacc/reader.c | 52 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h index f3d9b1d34c5..4772d37c490 100644 --- a/usr.bin/yacc/defs.h +++ b/usr.bin/yacc/defs.h @@ -1,4 +1,4 @@ -/* $Id: defs.h,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $ */ +/* $Id: defs.h,v 1.2 1996/02/04 08:37:00 etheisen Exp $ */ #include #include @@ -66,6 +66,7 @@ #define START 7 #define UNION 8 #define IDENT 9 +#define EXPECT 10 /* symbol classes */ @@ -263,6 +264,7 @@ extern short *to_state; extern action **parser; extern int SRtotal; +extern int SRexpect; extern int RRtotal; extern short *SRconflicts; extern short *RRconflicts; diff --git a/usr.bin/yacc/mkpar.c b/usr.bin/yacc/mkpar.c index b1d5f57a5a9..b66784be599 100644 --- a/usr.bin/yacc/mkpar.c +++ b/usr.bin/yacc/mkpar.c @@ -1,11 +1,12 @@ #ifndef lint -static char rcsid[] = "$Id: mkpar.c,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $"; +static char rcsid[] = "$Id: mkpar.c,v 1.2 1996/02/04 08:37:01 etheisen Exp $"; #endif /* not lint */ #include "defs.h" action **parser; int SRtotal; +int SRexpect = 0; int RRtotal; short *SRconflicts; short *RRconflicts; @@ -279,21 +280,21 @@ remove_conflicts() total_conflicts() { - fprintf(stderr, "%s: ", myname); - if (SRtotal == 1) - fprintf(stderr, "1 shift/reduce conflict"); - else if (SRtotal > 1) - fprintf(stderr, "%d shift/reduce conflicts", SRtotal); - - if (SRtotal && RRtotal) - fprintf(stderr, ", "); + /* Warn if s/r != expect or if any r/r */ + if ((SRtotal != SRexpect) || RRtotal) + { + if (SRtotal == 1) + fprintf(stderr, "%s: 1 shift/reduce conflict\n", myname); + else if (SRtotal > 1) + fprintf(stderr, "%s: %d shift/reduce conflicts\n", myname, + SRtotal); + } if (RRtotal == 1) - fprintf(stderr, "1 reduce/reduce conflict"); + fprintf(stderr, "%s: 1 reduce/reduce conflict\n", myname); else if (RRtotal > 1) - fprintf(stderr, "%d reduce/reduce conflicts", RRtotal); - - fprintf(stderr, ".\n"); + fprintf(stderr, "%s: %d reduce/reduce conflicts\n", myname, + RRtotal); } diff --git a/usr.bin/yacc/reader.c b/usr.bin/yacc/reader.c index 89437531ee4..f4c0de4df35 100644 --- a/usr.bin/yacc/reader.c +++ b/usr.bin/yacc/reader.c @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "$Id: reader.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +static char rcsid[] = "$Id: reader.c,v 1.2 1996/02/04 08:37:02 etheisen Exp $"; #endif /* not lint */ #include "defs.h" @@ -250,6 +250,8 @@ keyword() return (UNION); if (strcmp(cache, "ident") == 0) return (IDENT); + if (strcmp(cache, "expect") == 0) + return (EXPECT); } else { @@ -890,6 +892,50 @@ int assoc; } +/* + * %expect requires special handling + * as it really isn't part of the yacc + * grammar only a flag for yacc proper. + */ +declare_expect(assoc) +int assoc; +{ + register int c; + + if (assoc != EXPECT) ++prec; + + /* + * Stay away from nextc - doesn't + * detect EOL and will read to EOF. + */ + c = *++cptr; + if (c == EOF) unexpected_EOF(); + + for(;;) + { + if (isdigit(c)) + { + SRexpect = get_number(); + break; + } + /* + * Looking for number before EOL. + * Spaces, tabs, and numbers are ok, + * words, punc., etc. are syntax errors. + */ + else if (c == '\n' || isalpha(c) || !isspace(c)) + { + syntax_error(lineno, line, cptr); + } + else + { + c = *++cptr; + if (c == EOF) unexpected_EOF(); + } + } +} + + declare_types() { register int c; @@ -973,6 +1019,10 @@ read_declarations() declare_tokens(k); break; + case EXPECT: + declare_expect(k); + break; + case TYPE: declare_types(); break; -- 2.20.1