Add support for Bison's "%expect <int>" 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
This commit is contained in:
parent
3521a62093
commit
2277698a5c
@ -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 <sys/cdefs.h> /* 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;
|
||||
|
@ -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 <stdlib.h>
|
||||
#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");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user