mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Write a test the yycheck overrun reported by Andrew Suffield.
* tests/regression.at (_AT_DATA_DANCER_Y, AT_CHECK_DANCER): New. Use them to exercise yycheck overrun. Based on Andrew Suffield's grammar.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Bison Regressions. -*- Autotest -*-
|
||||
# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -660,3 +660,136 @@ static const unsigned char yystos[] =
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## yycheck Bound Violation. ##
|
||||
## ------------------------- ##
|
||||
|
||||
|
||||
# _AT_DATA_DANCER_Y(BISON-OPTIONS)
|
||||
# --------------------------------
|
||||
# The following grammar, taken from Andrew Suffield's GPL'd implementation
|
||||
# of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
|
||||
# yycheck's bounds where issuing a verbose error message. Keep this test
|
||||
# so that possible bound checking compilers could check all the skeletons.
|
||||
m4_define([_AT_DATA_DANCER_Y],
|
||||
[AT_DATA_GRAMMAR([dancer.y],
|
||||
[%{
|
||||
AT_LALR1_CC_IF(
|
||||
[static int yylex (int *lval);],
|
||||
[#include <stdio.h>
|
||||
static void yyerror (const char *s);
|
||||
static int yylex ();])
|
||||
%}
|
||||
$1
|
||||
%token ARROW INVALID NUMBER STRING DATA
|
||||
%defines
|
||||
%verbose
|
||||
%error-verbose
|
||||
/* Grammar follows */
|
||||
%%
|
||||
line: header body
|
||||
;
|
||||
|
||||
header: '<' from ARROW to '>' type ':'
|
||||
| '<' ARROW to '>' type ':'
|
||||
| ARROW to type ':'
|
||||
| type ':'
|
||||
| '<' '>'
|
||||
;
|
||||
|
||||
from: DATA
|
||||
| STRING
|
||||
| INVALID
|
||||
;
|
||||
|
||||
to: DATA
|
||||
| STRING
|
||||
| INVALID
|
||||
;
|
||||
|
||||
type: DATA
|
||||
| STRING
|
||||
| INVALID
|
||||
;
|
||||
|
||||
body: /* empty */
|
||||
| body member
|
||||
;
|
||||
|
||||
member: STRING
|
||||
| DATA
|
||||
| '+' NUMBER
|
||||
| '-' NUMBER
|
||||
| NUMBER
|
||||
| INVALID
|
||||
;
|
||||
%%
|
||||
AT_LALR1_CC_IF(
|
||||
[/* Currently, print_ is required in C++. */
|
||||
void
|
||||
yy::Parser::print_ ()
|
||||
{
|
||||
}
|
||||
|
||||
/* A C++ error reporting function. */
|
||||
void
|
||||
yy::Parser::error_ ()
|
||||
{
|
||||
std::cerr << message << std::endl;
|
||||
}
|
||||
|
||||
int
|
||||
yyparse (void)
|
||||
{
|
||||
yy::Parser parser (!!YYDEBUG);
|
||||
return parser.parse ();
|
||||
}
|
||||
],
|
||||
[static void
|
||||
yyerror (const char *s)
|
||||
{
|
||||
fprintf (stderr, "%s\n", s);
|
||||
}])
|
||||
|
||||
static int
|
||||
yylex (AT_LALR1_CC_IF([int *lval]))
|
||||
[{
|
||||
static int toknum = 0;
|
||||
int tokens[] =
|
||||
{
|
||||
':', -1
|
||||
};
|
||||
return tokens[toknum++];
|
||||
}]
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
return yyparse ();
|
||||
}
|
||||
])
|
||||
])# _AT_DATA_DANCER_Y
|
||||
|
||||
|
||||
# AT_CHECK_DANCER(BISON-OPTIONS)
|
||||
# ------------------------------
|
||||
# Generate the grammar, compile it, run it.
|
||||
m4_define([AT_CHECK_DANCER],
|
||||
[AT_SETUP([Dancer $1])
|
||||
AT_BISON_OPTION_PUSHDEFS([$1])
|
||||
_AT_DATA_DANCER_Y([$1])
|
||||
AT_CHECK([bison -o dancer.c dancer.y])
|
||||
AT_LALR1_CC_IF([AT_COMPILE_CXX([dancer])],
|
||||
[AT_COMPILE([dancer])])
|
||||
AT_PARSER_CHECK([./dancer], 1, [],
|
||||
[syntax error, unexpected ':', expecting ARROW or INVALID or DATA or '<'
|
||||
])
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
AT_CHECK_DANCER()
|
||||
AT_CHECK_DANCER([%glr-parser])
|
||||
AT_CHECK_DANCER([%skeleton "lalr1.cc"])
|
||||
|
||||
Reference in New Issue
Block a user