=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/yacc/reader.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/yacc/reader.c 1996/03/27 19:33:19 1.3 +++ src/usr.bin/yacc/reader.c 1996/03/31 04:56:01 1.4 @@ -1,7 +1,7 @@ -/* $OpenBSD: reader.c,v 1.3 1996/03/27 19:33:19 niklas Exp $ */ +/* $OpenBSD: reader.c,v 1.4 1996/03/31 04:56:01 etheisen Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: reader.c,v 1.3 1996/03/27 19:33:19 niklas Exp $"; +static char rcsid[] = "$Id: reader.c,v 1.4 1996/03/31 04:56:01 etheisen Exp $"; #endif /* not lint */ #include "defs.h" @@ -894,6 +894,50 @@ } +/* + * %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; @@ -939,24 +983,7 @@ goal = bp; } -handle_expect() -{ - register int c; - register int num; - c = nextc(); - if (c == EOF) unexpected_EOF(); - if (!isdigit(c)) - syntax_error(lineno, line, cptr); - num = get_number(); - if (num == 1) - fprintf (stderr, "%s: Expect 1 shift/reduce conflict.\n", myname); - else - fprintf (stderr, "%s: Expect %d shift/reduce conflicts.\n", myname, - num); -} - - read_declarations() { register int c, k; @@ -994,16 +1021,16 @@ declare_tokens(k); break; + case EXPECT: + declare_expect(k); + break; + case TYPE: declare_types(); break; case START: declare_start(); - break; - - case EXPECT: - handle_expect(); break; } }