From d7c5d95faa4a761ee09f697104220c6d7429f997 Mon Sep 17 00:00:00 2001 From: obrien Date: Thu, 29 Jul 1999 08:42:21 +0000 Subject: [PATCH] Add support for Bison's "%expect " directive. I originally coded this myself, and now I realize {Net,Open}BSD had already coded this. I have tossed my version to reduce diffs between the projects. Obtained from: OpenBSD 2.5 --- usr.bin/yacc/defs.h | 4 +++- usr.bin/yacc/mkpar.c | 15 ++++++++---- usr.bin/yacc/reader.c | 53 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h index 229eacccd8c..612d4ee4e04 100644 --- a/usr.bin/yacc/defs.h +++ b/usr.bin/yacc/defs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)defs.h 5.6 (Berkeley) 5/24/93 - * $Id: defs.h,v 1.5 1997/02/22 19:57:58 peter Exp $ + * $Id: defs.h,v 1.6 1997/08/28 06:33:52 charnier Exp $ */ #include /* for __P macro */ @@ -104,6 +104,7 @@ #define START 7 #define UNION 8 #define IDENT 9 +#define EXPECT 10 /* symbol classes */ @@ -300,6 +301,7 @@ extern short *from_state; extern short *to_state; extern action **parser; +extern int SRexpect; extern int SRtotal; extern int RRtotal; extern short *SRconflicts; diff --git a/usr.bin/yacc/mkpar.c b/usr.bin/yacc/mkpar.c index b6ef27dfa3b..ad44c4c2b78 100644 --- a/usr.bin/yacc/mkpar.c +++ b/usr.bin/yacc/mkpar.c @@ -39,13 +39,14 @@ static char const sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91"; #endif static const char rcsid[] = - "$Id: mkpar.c,v 1.7 1997/08/28 06:33:53 charnier Exp $"; + "$Id: mkpar.c,v 1.8 1999/07/04 17:26:16 billf Exp $"; #endif /* not lint */ #include #include "defs.h" action **parser; +int SRexpect; int SRtotal; int RRtotal; short *SRconflicts; @@ -333,10 +334,14 @@ remove_conflicts() static void total_conflicts() { - if (SRtotal == 1) - warnx("1 shift/reduce conflict"); - else if (SRtotal > 1) - warnx("%d shift/reduce conflicts", SRtotal); + /* Warn if s/r != expect or if any r/r */ + if ((SRtotal != SRexpect) || RRtotal) + { + if (SRtotal == 1) + warnx("1 shift/reduce conflict"); + else if (SRtotal > 1) + warnx("%d shift/reduce conflicts", SRtotal); + } if (RRtotal == 1) warnx("1 reduce/reduce conflict"); diff --git a/usr.bin/yacc/reader.c b/usr.bin/yacc/reader.c index 45665703f35..e0eed8d6531 100644 --- a/usr.bin/yacc/reader.c +++ b/usr.bin/yacc/reader.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: reader.c,v 1.6 1997/02/22 19:58:01 peter Exp $ */ #ifndef lint @@ -329,6 +329,8 @@ keyword() return (UNION); if (strcmp(cache, "ident") == 0) return (IDENT); + if (strcmp(cache, "expect") == 0) + return (EXPECT); } else { @@ -974,6 +976,51 @@ int assoc; } +/* + * %expect requires special handling + * as it really isn't part of the yacc + * grammar only a flag for yacc proper. + */ +static void +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(); + } + } +} + + static void declare_types() { @@ -1060,6 +1107,10 @@ read_declarations() declare_tokens(k); break; + case EXPECT: + declare_expect(k); + break; + case TYPE: declare_types(); break; -- 2.45.0