mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-11 17:04:19 +01:00
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
32610e173d
commit
030b221f78
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=49208
@ -34,7 +34,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)defs.h 5.6 (Berkeley) 5/24/93
|
* @(#)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 */
|
#include <sys/cdefs.h> /* for __P macro */
|
||||||
@ -104,6 +104,7 @@
|
|||||||
#define START 7
|
#define START 7
|
||||||
#define UNION 8
|
#define UNION 8
|
||||||
#define IDENT 9
|
#define IDENT 9
|
||||||
|
#define EXPECT 10
|
||||||
|
|
||||||
|
|
||||||
/* symbol classes */
|
/* symbol classes */
|
||||||
@ -300,6 +301,7 @@ extern short *from_state;
|
|||||||
extern short *to_state;
|
extern short *to_state;
|
||||||
|
|
||||||
extern action **parser;
|
extern action **parser;
|
||||||
|
extern int SRexpect;
|
||||||
extern int SRtotal;
|
extern int SRtotal;
|
||||||
extern int RRtotal;
|
extern int RRtotal;
|
||||||
extern short *SRconflicts;
|
extern short *SRconflicts;
|
||||||
|
@ -39,13 +39,14 @@
|
|||||||
static char const sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91";
|
static char const sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
action **parser;
|
action **parser;
|
||||||
|
int SRexpect;
|
||||||
int SRtotal;
|
int SRtotal;
|
||||||
int RRtotal;
|
int RRtotal;
|
||||||
short *SRconflicts;
|
short *SRconflicts;
|
||||||
@ -332,11 +333,15 @@ remove_conflicts()
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
total_conflicts()
|
total_conflicts()
|
||||||
|
{
|
||||||
|
/* Warn if s/r != expect or if any r/r */
|
||||||
|
if ((SRtotal != SRexpect) || RRtotal)
|
||||||
{
|
{
|
||||||
if (SRtotal == 1)
|
if (SRtotal == 1)
|
||||||
warnx("1 shift/reduce conflict");
|
warnx("1 shift/reduce conflict");
|
||||||
else if (SRtotal > 1)
|
else if (SRtotal > 1)
|
||||||
warnx("%d shift/reduce conflicts", SRtotal);
|
warnx("%d shift/reduce conflicts", SRtotal);
|
||||||
|
}
|
||||||
|
|
||||||
if (RRtotal == 1)
|
if (RRtotal == 1)
|
||||||
warnx("1 reduce/reduce conflict");
|
warnx("1 reduce/reduce conflict");
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id: reader.c,v 1.6 1997/02/22 19:58:01 peter Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
@ -329,6 +329,8 @@ keyword()
|
|||||||
return (UNION);
|
return (UNION);
|
||||||
if (strcmp(cache, "ident") == 0)
|
if (strcmp(cache, "ident") == 0)
|
||||||
return (IDENT);
|
return (IDENT);
|
||||||
|
if (strcmp(cache, "expect") == 0)
|
||||||
|
return (EXPECT);
|
||||||
}
|
}
|
||||||
else
|
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
|
static void
|
||||||
declare_types()
|
declare_types()
|
||||||
{
|
{
|
||||||
@ -1060,6 +1107,10 @@ read_declarations()
|
|||||||
declare_tokens(k);
|
declare_tokens(k);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EXPECT:
|
||||||
|
declare_expect(k);
|
||||||
|
break;
|
||||||
|
|
||||||
case TYPE:
|
case TYPE:
|
||||||
declare_types();
|
declare_types();
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user