[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] tests: factor the declaration/definition of yyerror and yyle
From: |
Akim Demaille |
Subject: |
[PATCH 1/4] tests: factor the declaration/definition of yyerror and yylex. |
Date: |
Sun, 17 Jun 2012 19:54:38 +0200 |
* tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DECLARE_EXTERN)
(AT_YYERROR_DEFINE, AT_YYLEX_DECLARE, AT_YYLEX_DECLARE_EXTERN)
(AT_YYLEX_DEFINE): New.
Must be used inside AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
* tests/actions.at, tests/conflicts.at, tests/glr-regression.at,
* tests/headers.at, tests/input.at, tests/named-refs.at,
* tests/regression.at, tests/skeletons.at, tests/synclines.at,
* tests/torture.at: Use them.
---
tests/actions.at | 265 ++++++++++++-----------------------------
tests/conflicts.at | 59 ++-------
tests/glr-regression.at | 303 +++++++++++++++++------------------------------
tests/headers.at | 8 +-
tests/input.at | 12 +-
tests/local.at | 82 +++++++++++--
tests/named-refs.at | 24 ++--
tests/regression.at | 160 +++++++++----------------
tests/skeletons.at | 11 +-
tests/synclines.at | 26 ++--
tests/torture.at | 27 ++---
11 files changed, 378 insertions(+), 599 deletions(-)
diff --git a/tests/actions.at b/tests/actions.at
index 22c3aa2..cfac299 100644
--- a/tests/actions.at
+++ b/tests/actions.at
@@ -28,14 +28,13 @@ AT_SETUP([Mid-rule actions])
# instead of being attached to the empty rule dedicated to this
# action.
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
%{
-# include <stdio.h>
-# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%%
exp: { putchar ('0'); }
@@ -51,28 +50,15 @@ exp: { putchar ('0'); }
{ putchar ('\n'); }
;
%%
-static int
-yylex (void)
-{
- static char const input[] = "123456789";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE(123456789)[
int
main (void)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-d -v -o input.c input.y])
AT_COMPILE([input])
@@ -92,14 +78,13 @@ AT_CLEANUP
AT_SETUP([Exotic Dollars])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
%{
-# include <stdio.h>
-# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(Var)
%}
@@ -130,21 +115,8 @@ sum_of_the_five_previous_values:
;
%%
-static int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return EOF;
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([])[
int
main (void)
{
@@ -164,9 +136,9 @@ AT_PARSER_CHECK([./input], 0,
AT_DATA_GRAMMAR([[input.y]],
[[
%{
-# include <stdio.h>
- static int yylex (void);
- static void yyerror (char const *msg);
+#include <stdio.h>
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
typedef struct { int val; } stype;
# define YYSTYPE stype
%}
@@ -185,12 +157,7 @@ yylex (void)
return 0;
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -204,6 +171,7 @@ AT_PARSER_CHECK([[./input]], [[0]],
[[6
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -245,7 +213,7 @@ AT_LALR1_CC_IF([%define global_tokens_and_yystype])
m4_ifval([$6], [[%code provides {]], [[%code {]])
AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
[static int yylex (]AT_LEX_FORMALS[);
-]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
+]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
[}
]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
@@ -593,7 +561,8 @@ Parsing FAILED (status 2).
]])
])
-])
+AT_BISON_OPTION_POPDEFS
+])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
@@ -632,7 +601,7 @@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
# called for $end, and that $$ and @$ work correctly.
AT_SETUP([Default tagless %printer and %destructor])
-
+AT_BISON_OPTION_PUSHDEFS([%locations])
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
@@ -645,8 +614,8 @@ AT_DATA_GRAMMAR([[input.y]],
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
# define USE(SYM)
%}
@@ -677,25 +646,8 @@ AT_DATA_GRAMMAR([[input.y]],
start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "abcd";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- yylval = input[toknum++];
- yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = toknum;
- return yylval;
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([abcd], [[yylval = res]])[
int
main (void)
@@ -741,6 +693,7 @@ Cleanup: discarding lookahead token $end (1.5-1.5: )
Stack now 0
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -750,7 +703,7 @@ AT_CLEANUP
## ------------------------------------------------------ ##
AT_SETUP([Default tagged and per-type %printer and %destructor])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
@@ -758,8 +711,8 @@ AT_DATA_GRAMMAR([[input.y]],
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -805,22 +758,8 @@ start:
;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "abcdef";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([abcdef])[
int
main (void)
@@ -878,6 +817,7 @@ Cleanup: discarding lookahead token $end ()
Stack now 0
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -895,6 +835,7 @@
m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN],
[m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
[m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
+AT_BISON_OPTION_PUSHDEFS([%locations])
AT_DATA_GRAMMAR([[input]]$1[[.y]],
[[%error-verbose
%debug
@@ -907,8 +848,8 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]],
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -950,12 +891,7 @@ yylex (void)
yylloc.first_column = yylloc.last_column = 1;
return 0;
}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
+]AT_YYERROR_DEFINE[
int
main (void)
@@ -964,6 +900,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input$1.c input$1.y])
AT_COMPILE([input$1])
@@ -1010,15 +947,15 @@ AT_SETUP([Default %printer and %destructor are not for
error or $undefined])
# semantic value, which would be initialized from the lookahead, which
# would be destroyed separately.
# - For $undefined, who knows what the semantic value would be.
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -1039,24 +976,8 @@ start:
;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "abd";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- yylval = input[toknum++];
- return yylval;
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([abd], [yylval = res])[
int
main (void)
{
@@ -1064,6 +985,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
@@ -1125,14 +1047,15 @@ AT_SETUP([Default %printer and %destructor are not for
$accept])
# true for $undefined and the error token, so there are three warnings for
# %printer and three for %destructor.)
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug /* So that %printer is actually compiled. */
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -1153,28 +1076,15 @@ AT_DATA_GRAMMAR([[input.y]],
start: { USE($$); } ;
%%
-
-static int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return 0;
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([])[
int
main (void)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
@@ -1189,14 +1099,15 @@ AT_CLEANUP
AT_SETUP([Default %printer and %destructor for mid-rule values])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug /* So that %printer is actually compiled. */
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (const char *msg);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
# define USE(SYM)
# define YYLTYPE int
# define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
@@ -1220,22 +1131,8 @@ start:
;
%%
-
-static int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return 0;
-}
-
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([])[
int
main (void)
{
@@ -1243,6 +1140,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y], 0,,
[[input.y:33.3-23: warning: unset value: $$
@@ -1296,15 +1194,15 @@ AT_CLEANUP
# Bison once forgot to check for @$ in actions other than semantic actions.
# AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
-# -------------------------------------------------------
+# -------------------------------------------
m4_define([AT_CHECK_ACTION_LOCATIONS],
[AT_SETUP(address@hidden in ]$1[ implies %locations]])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
- static int yylex (void);
- static void yyerror (char const *msg);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
}
%debug
@@ -1325,12 +1223,7 @@ yylex (void)
return 0;
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -1340,7 +1233,7 @@ main (void)
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
-
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP])
AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
@@ -1357,7 +1250,7 @@ AT_SETUP([[Fix user actions without a trailing
semicolon]])
# This feature is undocumented, but we accidentally broke it in 2.3a,
# and there was a complaint at:
# <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[%%
start: test2 test1 test0 testc;
@@ -1407,6 +1300,7 @@ no_semi
[]"broken\" $ @ $$ @$ [];\
string;"}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], [0], [],
[[input.y:8.48: warning: a ';' might be needed at the end of action code
@@ -1462,13 +1356,14 @@ AT_CLEANUP
AT_SETUP([[Destroying lookahead assigned by semantic action]])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%code {
#include <assert.h>
#include <stdio.h>
- static void yyerror (char const *);
- static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
#define USE(Var)
}
@@ -1496,27 +1391,15 @@ accept: /*empty*/ {
} ;
%%
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-static int
-yylex (void)
-{
- static char const *input = "a";
- return *input++;
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([a])[
int
main (void)
{
return yyparse ();
}
]])
-
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[./input]], [[0]], [],
@@ -1532,6 +1415,8 @@ AT_CLEANUP
AT_SETUP([[YYBACKUP]])
+AT_BISON_OPTION_PUSHDEFS([%pure-parser])
+
AT_DATA_GRAMMAR([input.y],
[[
%error-verbose
@@ -1542,7 +1427,7 @@ AT_DATA_GRAMMAR([input.y],
# include <stdlib.h>
# include <assert.h>
- static void yyerror (const char *msg);
+ ]AT_YYERROR_DECLARE[
static int yylex (YYSTYPE *yylval);
}
%%
@@ -1557,6 +1442,7 @@ exp:
;
%%
+]AT_YYERROR_DEFINE[
static int
yylex (YYSTYPE *yylval)
{
@@ -1567,12 +1453,6 @@ yylex (YYSTYPE *yylval)
return input[toknum++];
}
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
int
main (void)
{
@@ -1580,6 +1460,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
diff --git a/tests/conflicts.at b/tests/conflicts.at
index 76cb6aa..54df051 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -50,6 +50,7 @@ AT_CLEANUP
AT_SETUP([%nonassoc and eof])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%{
@@ -58,12 +59,7 @@ AT_DATA_GRAMMAR([input.y],
#include <string.h>
#define YYERROR_VERBOSE 1
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
/* The current argument. */
static const char *input;
@@ -93,6 +89,7 @@ main (int argc, const char *argv[])
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
[AT_BISON_CHECK([$1[ -o input.c input.y]])
@@ -171,7 +168,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
#include <string>]], [[
#include <assert.h>
#include <stdio.h>
- void yyerror (char const *msg);]])[
+ ]AT_YYERROR_DECLARE])[
]AT_YYLEX_PROTOTYPE[;
#define USE(Var)
}
@@ -212,31 +209,11 @@ public Object getLVal ()
*lvalp = 1;
return *input++;
}]])[
-
-/*----------.
-| yyerror. |
-`----------*/]AT_SKEL_JAVA_IF([[
-
-public void yyerror (String msg)
-{
- System.err.println (msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_SKEL_JAVA_IF([[
};
-%%]], [AT_SKEL_CC_IF([[
-
-void
-yy::parser::error (const yy::location &, std::string const &msg)
-{
- std::cerr << msg << std::endl;
-}]], [[
-
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}]])])[
+%%]])[
/*-------.
| main. |
@@ -471,12 +448,12 @@ AT_CLEANUP
# with minimal LR parser tables.
AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
}
%error-verbose
@@ -513,19 +490,8 @@ look:
reduce-nonassoc: %prec 'a';
%%
-
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-int
-yylex (void)
-{
- char const *input = "aaa";
- return *input++;
-}
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([aaa])[
int
main (void)
@@ -533,6 +499,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
# Show canonical LR's failure.
AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
diff --git a/tests/glr-regression.at b/tests/glr-regression.at
index 0cbffd1..9c53463 100644
--- a/tests/glr-regression.at
+++ b/tests/glr-regression.at
@@ -24,6 +24,7 @@ AT_BANNER([[GLR Regression Tests]])
AT_SETUP([Badly Collapsed GLR States])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr1.y],
[[/* Regression Test: Improper state compression */
/* Reported by Scott McPeak */
@@ -34,8 +35,8 @@ AT_DATA_GRAMMAR([glr-regr1.y],
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
-int yylex (void);
-void yyerror (char const *msg);
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
%}
@@ -71,12 +72,7 @@ main (void)
return yyparse ();
}
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
yylex (void)
@@ -94,6 +90,7 @@ yylex (void)
}
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr1.c glr-regr1.y]], 0, [],
[glr-regr1.y: conflicts: 1 shift/reduce
@@ -119,6 +116,7 @@ AT_CLEANUP
AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr2a.y],
[[/* Regression Test: Improper handling of embedded actions and $-N */
/* Reported by S. Eken */
@@ -130,8 +128,8 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
- int yylex (void);
- void yyerror (char const *);
+ ]AT_YYLEX_DECLARE[
+ ]AT_YYERROR_DECLARE[
%}
%glr-parser
@@ -171,7 +169,7 @@ var_printer: 'v'
{ printf ("Variable: '%s'\n", $-1); }
%%
-
+]AT_YYERROR_DEFINE[
FILE *input;
int
@@ -181,7 +179,8 @@ yylex (void)
char *s;
if (feof (stdin))
abort ();
- switch (fscanf (input, " %1[a-z,]", buf)) {
+ switch (fscanf (input, " %1[a-z,]", buf))
+ {
case 1:
return buf[0];
case EOF:
@@ -199,11 +198,6 @@ yylex (void)
return 'V';
}
-void
-yyerror (char const *s)
-{ printf ("%s\n", s);
-}
-
int
main (int argc, char **argv)
{
@@ -212,6 +206,7 @@ main (int argc, char **argv)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr2a.c glr-regr2a.y]], 0, [],
[glr-regr2a.y: conflicts: 2 shift/reduce
@@ -238,6 +233,7 @@ AT_CLEANUP
AT_SETUP([Improper merging of GLR delayed action sets])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr3.y],
[[/* Regression Test: Improper merging of GLR delayed action sets. */
/* Reported by M. Rosien */
@@ -248,8 +244,8 @@ AT_DATA_GRAMMAR([glr-regr3.y],
#include <stdarg.h>
static int MergeRule (int x0, int x1);
-static void yyerror (char const * s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
#define RULE(x) (1 << (x))
@@ -290,13 +286,12 @@ NT6 : P1 NT1 O1 T3 P2 { $$ = RULE(11) | $2; }
%merge<MergeRule>
%%
-static int MergeRule (int x0, int x1) {
+static int
+MergeRule (int x0, int x1)
+{
return x0 | x1;
}
-
-static void yyerror(char const * s) {
- fprintf(stderr,"error: %s\n",s);
-}
+]AT_YYERROR_DEFINE[
FILE *input = YY_NULL;
@@ -320,12 +315,15 @@ int yylex (void)
return BAD_CHAR;
}
-int main(int argc, char* argv[]) {
+int
+main(int argc, char* argv[])
+{
input = stdin;
if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr3.c glr-regr3.y]], 0, [],
[glr-regr3.y: conflicts: 1 shift/reduce, 1 reduce/reduce
@@ -347,6 +345,7 @@ AT_CLEANUP
AT_SETUP([Duplicate representation of merged trees])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr4.y],
[[
%union { char *ptr; }
@@ -359,8 +358,8 @@ AT_DATA_GRAMMAR([glr-regr4.y],
#include <string.h>
static char *merge (YYSTYPE, YYSTYPE);
static char *make_value (char const *, char const *);
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static char *ptrs[100];
static char **ptrs_next = ptrs;
%}
@@ -384,16 +383,8 @@ A2: 'a' { $$ = make_value ("A2", "'a'"); } ;
B: 'a' { $$ = make_value ("B", "'a'"); } ;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "a";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([a])[
int
main (void)
@@ -423,13 +414,8 @@ merge (YYSTYPE s1, YYSTYPE s2)
sprintf (value, format, s1.ptr, s2.ptr);
return value;
}
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr4.c glr-regr4.y]], 0, [],
[glr-regr4.y: conflicts: 1 reduce/reduce
@@ -450,13 +436,14 @@ AT_CLEANUP
AT_SETUP([User destructor for unresolved GLR semantic value])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr5.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */
%}
@@ -480,29 +467,15 @@ start:
;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "a";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYLEX_DEFINE(a)[
+]AT_YYERROR_DEFINE[
int
main (void)
{
return yyparse () != 1;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr5.c glr-regr5.y]], 0, [],
[glr-regr5.y: conflicts: 1 reduce/reduce
@@ -523,13 +496,14 @@ AT_CLEANUP
AT_SETUP([User destructor after an error during a split parse])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr6.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
%}
%glr-parser
@@ -556,18 +530,14 @@ yylex (void)
return input[toknum++];
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
main (void)
{
return yyparse () != 1;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr6.c glr-regr6.y]], 0, [],
[glr-regr6.y: conflicts: 1 reduce/reduce
@@ -590,13 +560,14 @@ AT_CLEANUP
AT_SETUP([Duplicated user destructor for lookahead])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr7.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
#define YYSTACKEXPANDABLE 0
typedef struct count_node {
int count;
@@ -641,12 +612,7 @@ yylex (void)
return 'a';
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -660,6 +626,7 @@ main (void)
return status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr7.c glr-regr7.y]], 0, [],
[glr-regr7.y: conflicts: 2 reduce/reduce
@@ -682,14 +649,15 @@ AT_CLEANUP
AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr8.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
- static void yyerror (char const *msg);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
+ ]AT_YYERROR_DECLARE[
%}
%token T_CONSTANT
@@ -723,12 +691,7 @@ OptSignalWord : /* empty */
%%
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int lexIndex;
int yylex (void)
@@ -758,6 +721,7 @@ main (void)
return 0;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr8.c glr-regr8.y]], 0, [],
[glr-regr8.y: conflicts: 1 reduce/reduce
@@ -780,13 +744,14 @@ AT_CLEANUP
AT_SETUP([No users destructors if stack 0 deleted])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr9.y],
[[
%{
# include <stdio.h>
# include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
# define YYSTACKEXPANDABLE 0
static int tokens = 0;
static int destructors = 0;
@@ -822,12 +787,7 @@ yylex (void)
return 'a';
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -841,6 +801,7 @@ main (void)
return !exit_status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr9.c glr-regr9.y]], 0, [],
[glr-regr9.y: conflicts: 1 reduce/reduce
@@ -860,13 +821,14 @@ AT_CLEANUP
AT_SETUP([Corrupted semantic options if user action cuts parse])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr10.y],
[[
%{
# include <stdlib.h>
# include <stdio.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
#define GARBAGE_SIZE 50
static char garbage[GARBAGE_SIZE];
%}
@@ -884,12 +846,7 @@ start:
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -908,6 +865,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr10.c glr-regr10.y]], 0, [],
[glr-regr10.y: conflicts: 1 reduce/reduce
@@ -925,12 +883,13 @@ AT_CLEANUP
AT_SETUP([Undesirable destructors if user action cuts parse])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr11.y],
[[
%{
# include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static int destructors = 0;
# define USE(val)
%}
@@ -949,21 +908,8 @@ start:
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-static int
-yylex (void)
-{
- static char const input[] = "a";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([a])[
int
main (void)
@@ -977,6 +923,7 @@ main (void)
return exit_status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr11.c glr-regr11.y]], 0, [],
[glr-regr11.y: conflicts: 1 reduce/reduce
@@ -994,6 +941,7 @@ AT_CLEANUP
AT_SETUP([Leaked semantic values if user action cuts parse])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr12.y],
[[
%glr-parser
@@ -1007,8 +955,8 @@ AT_DATA_GRAMMAR([glr-regr12.y],
%{
# include <stdlib.h>
static int merge (YYSTYPE, YYSTYPE);
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static int parent_rhs_before_value = 0;
static int merged_value = 0;
static int parent_rhs_after_value = 0;
@@ -1068,12 +1016,7 @@ merge (YYSTYPE s1, YYSTYPE s2)
return dummy;
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1108,6 +1051,7 @@ main (void)
return exit_status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr12.c glr-regr12.y]], 0, [],
[glr-regr12.y: conflicts: 1 shift/reduce, 1 reduce/reduce
@@ -1127,6 +1071,7 @@ AT_CLEANUP
AT_SETUP([Incorrect lookahead during deterministic GLR])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr13.y],
[[
/* Tests:
@@ -1138,8 +1083,8 @@ AT_DATA_GRAMMAR([glr-regr13.y],
%{
#include <stdio.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
#define USE(value)
%}
@@ -1190,12 +1135,7 @@ change_lookahead:
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1237,6 +1177,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr13.c glr-regr13.y]], 0, [], [])
AT_COMPILE([glr-regr13])
@@ -1263,6 +1204,7 @@ AT_CLEANUP
AT_SETUP([Incorrect lookahead during nondeterministic GLR])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr14.y],
[[
/* Tests:
@@ -1289,8 +1231,8 @@ AT_DATA_GRAMMAR([glr-regr14.y],
%{
#include <stdlib.h>
#include <stdio.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
static char merge (union YYSTYPE, union YYSTYPE);
#define USE(value)
@@ -1399,12 +1341,7 @@ no_look:
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1453,6 +1390,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr14.c glr-regr14.y]], 0, [],
[glr-regr14.y: conflicts: 3 reduce/reduce
@@ -1483,6 +1421,7 @@ AT_CLEANUP
AT_SETUP([Leaked semantic values when reporting ambiguity])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr15.y],
[[
%glr-parser
@@ -1490,8 +1429,8 @@ AT_DATA_GRAMMAR([glr-regr15.y],
%{
# include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static int parent_rhs_before_value = 0;
# define USE(val)
%}
@@ -1530,12 +1469,7 @@ ambiguity2: ;
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1557,6 +1491,7 @@ main (void)
return exit_status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr15.c glr-regr15.y]], 0, [],
[glr-regr15.y: conflicts: 2 reduce/reduce
@@ -1575,6 +1510,8 @@ AT_CLEANUP
## ------------------------------------------------------------------------- ##
AT_SETUP([Leaked lookahead after nondeterministic parse syntax error])
+
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr16.y],
[[
%glr-parser
@@ -1582,8 +1519,8 @@ AT_DATA_GRAMMAR([glr-regr16.y],
%{
# include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
static int lookahead_value = 0;
# define USE(val)
%}
@@ -1596,12 +1533,7 @@ alt2: ;
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1626,6 +1558,7 @@ main (void)
return exit_status;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr16.c glr-regr16.y]], 0, [],
[glr-regr16.y: conflicts: 1 reduce/reduce
@@ -1644,6 +1577,8 @@ AT_CLEANUP
## ------------------------------------------------------------------------- ##
AT_SETUP([Uninitialized location when reporting ambiguity])
+
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr17.y],
[[
%glr-parser
@@ -1713,6 +1648,7 @@ main (void)
return yyparse () != 1;
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [],
[glr-regr17.y: conflicts: 3 reduce/reduce
@@ -1731,12 +1667,14 @@ AT_CLEANUP
## -------------------------------------------------------------##
AT_SETUP([Missed %merge type warnings when LHS type is declared later])
+
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr18.y],
[[%glr-parser
%{
#include <stdlib.h>
- static void yyerror (char const *);
+ ]AT_YYERROR_DECLARE[
static int yylex ();
%}
@@ -1758,27 +1696,15 @@ sym3: %merge<merge> { $$ = 0; } ;
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-static int
-yylex ()
-{
- static int called;
- if (called++)
- abort ();
- return 0;
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE()[
int
main (void)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr18.c glr-regr18.y]], 1, [],
[glr-regr18.y:26.18-24: result type clash on merge function 'merge': <type2>
!= <type1>
@@ -1796,13 +1722,14 @@ AT_CLEANUP
AT_SETUP([Ambiguity reports])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
- static void yyerror (char const *);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
%}
%debug
@@ -1816,23 +1743,8 @@ start:
b: 'b';
d: /* nada. */;
%%
-
-static int
-yylex (void)
-{
- static char const input[] = "abc";
- static size_t toknum;
- if (! (toknum < sizeof input))
- abort ();
- return input[toknum++];
-}
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYLEX_DEFINE([abc])[
+]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -1840,6 +1752,7 @@ main (void)
return !!yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], 0, [],
[input.y: conflicts: 1 reduce/reduce
diff --git a/tests/headers.at b/tests/headers.at
index 9710e0c..0729f44 100644
--- a/tests/headers.at
+++ b/tests/headers.at
@@ -41,7 +41,6 @@ AT_BISON_CHECK([--defines input.y])
AT_CLEANUP
-
## --------------------- ##
## Invalid CPP headers. ##
## --------------------- ##
@@ -51,7 +50,7 @@ AT_CLEANUP
# FIXME: Much of this can be covered by calc.at.
m4_define([AT_TEST_CPP_GUARD_H],
[AT_SETUP([Invalid CPP guards: $2 --defines=$1.h])
-
+AT_BISON_OPTION_PUSHDEFS([$2])
# Possibly create inner directories.
dirname=`AS_DIRNAME([$1])`
AS_MKDIR_P([$dirname])
@@ -60,8 +59,8 @@ AT_DATA_GRAMMAR([$1.y],
[$2
%{
#include <$1.h>
-void yyerror (const char *);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%%
dummy:;
@@ -73,6 +72,7 @@ AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y])
AT_COMPILE([$1.o], [-I. -c $1.c])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
diff --git a/tests/input.at b/tests/input.at
index 93ae3de..8849855 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -468,8 +468,8 @@ char quote[] = "@:>@@:>@,";
%}
%{
-static void yyerror (const char *s);
-static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%type <ival> '@<:@'
@@ -621,14 +621,15 @@ AT_CLEANUP
AT_SETUP([Symbols])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%token WITH-DASH
%token WITHOUT_DASH "WITHOUT-DASH"
%token WITH.PERIOD
%token WITHOUT_PERIOD "WITHOUT.PERIOD"
%code {
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
}
%%
start: with-dash without_dash with.period without_period;
@@ -637,7 +638,10 @@ without_dash: "WITHOUT-DASH";
with.period: WITH.PERIOD;
without_period: "WITHOUT.PERIOD";
%%
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE[
]])
+AT_BISON_OPTION_POPDEFS
# POSIX Yacc accept periods, but not dashes.
AT_BISON_CHECK([--yacc input.y], [1], [],
diff --git a/tests/local.at b/tests/local.at
index 6efe66f..e6e7354 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -267,6 +267,73 @@ m4_define([AT_DATA_GRAMMAR],
$2])
])
+# AT_YYLEX_DECLARE_EXTERN
+# AT_YYLEX_DECLARE
+# AT_YYLEX_DEFINE(INPUT-STRING, [ACTION])
+# ---------------------------------------
+m4_define([AT_YYLEX_DECLARE_EXTERN],
+[int yylex (void);dnl
+])
+
+m4_define([AT_YYLEX_DECLARE],
+[static AT_YYLEX_DECLARE_EXTERN[]dnl
+])
+
+m4_define([AT_YYLEX_DEFINE],
+[[#include <stdlib.h> /* abort */
+static int
+yylex (void)
+{
+ static char const input[] = "$1";
+ static size_t toknum = 0;
+ int res;
+ if (! (toknum < sizeof input))
+ abort ();
+ res = input[toknum++];
+ ]$2;[]AT_LOCATION_IF([[
+ yylloc.first_line = yylloc.last_line = 1;
+ yylloc.first_column = yylloc.last_column = toknum;]])[
+ return res;
+}]dnl
+])
+
+# AT_YYERROR_DECLARE_EXTERN
+# AT_YYERROR_DECLARE
+# AT_YYERROR_DEFINE
+# -------------------------
+# Beware that must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS
+# pair.
+m4_define([AT_YYERROR_DECLARE_EXTERN],
+[void yyerror (const char *msg);dnl
+])
+
+m4_define([AT_YYERROR_DECLARE],
+[static AT_YYERROR_DECLARE_EXTERN[]dnl
+])
+
+m4_define([AT_YYERROR_DEFINE],
+[AT_SKEL_JAVA_IF([[
+public void yyerror (String msg)
+{
+ System.err.println (msg);
+}]], [AT_SKEL_CC_IF([[
+void
+yy::parser::error (const yy::location &, std::string const &msg)
+{
+ std::cerr << msg << std::endl;
+}]], [[
+#include <stdio.h>
+static void
+yyerror (char const *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}]])])dnl
+])
+
+## --------------- ##
+## Running Bison. ##
+## --------------- ##
+
# AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# -------------------------------------------------
# Check Bison by invoking `bison BISON_ARGS'. BISON_ARGS should not contain
@@ -588,12 +655,12 @@ m4_define([AT_TEST_TABLES_AND_PARSE],
[m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
AT_SETUP([$1])
-
+AT_BISON_OPTION_PUSHDEFS([$4])
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
- static void yyerror (char const *msg);
- static int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
}
]$4[
@@ -603,13 +670,7 @@ AT_DATA_GRAMMAR([[input.y]],
]$5[
%%
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -665,6 +726,7 @@ AT_PARSER_CHECK([[./input]],
m4_ifval([$11], [m4_dquote($11)]),
m4_ifval([$12], [m4_dquote($12)]))
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
m4_popdef([AT_COND_CASE])])
diff --git a/tests/named-refs.at b/tests/named-refs.at
index d2942cf..c9b91a0 100644
--- a/tests/named-refs.at
+++ b/tests/named-refs.at
@@ -19,7 +19,7 @@
AT_BANNER([[Named references tests.]])
AT_SETUP([Tutorial calculator])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
@@ -33,8 +33,8 @@ FILE *input;
static semantic_value global_result = 0;
static int global_count = 0;
static int power (int base, int exponent);
-static void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%union
@@ -83,12 +83,7 @@ exp:
| '-' error { $$ = 0; YYERROR; }
;
%%
-
-static void yyerror (const char *s)
-{
- fprintf (stderr, "%s\n", s);
-}
-
+]AT_YYERROR_DEFINE[
static int get_char (void)
{
int res = getc (input);
@@ -119,7 +114,8 @@ static int read_signed_integer (void)
return sign * n;
}
-int yylex (void)
+static int
+yylex (void)
{
int c;
/* Skip white space. */
@@ -190,6 +186,7 @@ AT_DATA([input.txt],
AT_BISON_CHECK([-o test.c test.y])
AT_COMPILE([[test]])
AT_PARSER_CHECK([./test input.txt], 0, [], [stderr])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -198,13 +195,13 @@ AT_CLEANUP
AT_SETUP([Undefined and ambiguous references])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
static int power (int base, int exponent);
-static void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%union
@@ -268,6 +265,7 @@ test.y:55.3-53: symbol not found in production: r12
test.y:56.29-33: invalid reference: '$expo'
test.y:56.3-46: symbol not found in production: expo
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
#######################################################################
diff --git a/tests/regression.at b/tests/regression.at
index f5603ea..e93b901 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -26,8 +26,8 @@ AT_SETUP([Trivial grammars])
AT_DATA_GRAMMAR([input.y],
[[%{
-void yyerror (char const *);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
#define YYSTYPE int *
%}
@@ -54,8 +54,8 @@ AT_SETUP([YYSTYPE typedef])
AT_DATA_GRAMMAR([input.y],
[[%{
-void yyerror (char const *);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
typedef union { char const *val; } YYSTYPE;
%}
@@ -85,8 +85,8 @@ AT_SETUP([Early token definitions with --yacc])
AT_DATA_GRAMMAR([input.y],
[[%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%union
@@ -124,8 +124,8 @@ AT_SETUP([Early token definitions without --yacc])
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
void print_my_token (void);
%}
@@ -433,8 +433,8 @@ AT_DATA_GRAMMAR([input.y],
[%{
#include <stdlib.h>
#include <stdio.h>
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
[%error-verbose
%token MYEOF 0 "end of file"
@@ -498,19 +498,21 @@ AT_CLEANUP
AT_SETUP([Characters Escapes])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
[%%
exp:
'\'' "\'"
| '\"' "\""
-| '"' "'"
+| '"' "'" /* Pacify font-lock-mode: ". */
;
]])
-# Pacify font-lock-mode: "
+
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
@@ -837,7 +839,7 @@ static int yylex (AT_LALR1_CC_IF([int *], [void]));
AT_LALR1_CC_IF([],
[#include <stdlib.h>
#include <stdio.h>
-static void yyerror (const char *);])
+]AT_YYERROR_DECLARE[])
%}
$1
%token ARROW INVALID NUMBER STRING DATA
@@ -965,7 +967,7 @@ static int yylex (AT_LALR1_CC_IF([int *], [void]));
AT_LALR1_CC_IF([],
[#include <stdio.h>
#include <stdlib.h>
-static void yyerror (const char *);])
+]AT_YYERROR_DECLARE[])
%}
$1
%defines
@@ -1056,12 +1058,12 @@ AT_SETUP([Braced code in declaration in rules section])
# Bison once mistook braced code in a declaration in the rules section to be a
# rule action.
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
-static void yyerror (char const *msg);
-static int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%error-verbose
@@ -1080,12 +1082,7 @@ start:
%%
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -1099,6 +1096,7 @@ main (void)
return !yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-t -o input.c input.y])
AT_COMPILE([input])
@@ -1196,12 +1194,12 @@ AT_SETUP([[Token number in precedence declaration]])
# POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
# we lost this in Bison 1.50.
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
%}
%error-verbose
@@ -1221,12 +1219,7 @@ sr_conflict:
%%
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
yylex (void)
{
@@ -1241,6 +1234,7 @@ main (void)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
[[input.y:23.5-19: warning: rule useless in parser due to conflicts: start:
start
@@ -1283,11 +1277,12 @@ AT_CLEANUP
AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
#define YYSTACK_USE_ALLOCA 1
}
@@ -1323,28 +1318,18 @@ syntax_error:
%%
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-int
-yylex (void)
-{
- /* Induce two syntax error messages (which requires full error
- recovery by shifting 3 tokens) in order to detect any loss of the
- reallocated buffer. */
- static char const *input = "abc";
- return *input++;
-}
-
+]AT_YYERROR_DEFINE[
+/* Induce two syntax error messages (which requires full error
+ recovery by shifting 3 tokens) in order to detect any loss of the
+ reallocated buffer. */
+]AT_YYLEX_DEFINE([abc])[
int
main (void)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
@@ -1370,12 +1355,12 @@ AT_CLEANUP
# yyparse would invoke yyerror using the old contents of yymsg.
AT_SETUP([[%error-verbose overflow]])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
/* This prevents this test case from having to induce error messages
large enough to overflow size_t. */
@@ -1441,21 +1426,10 @@ syntax_error2:
%%
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-int
-yylex (void)
-{
- /* Induce two syntax error messages (which requires full error
- recovery by shifting 3 tokens). */
- static char const *input = "abc";
- return *input++;
-}
-
+]AT_YYERROR_DEFINE[
+/* Induce two syntax error messages (which requires full error
+ recovery by shifting 3 tokens). */
+]AT_YYLEX_DEFINE([abc])[
int
main (void)
{
@@ -1481,7 +1455,7 @@ AT_PARSER_CHECK([[./input]], [[2]], [],
syntax error
memory exhausted
]])
-
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -1499,7 +1473,7 @@ AT_BISON_OPTION_PUSHDEFS([$1])
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
- void yyerror (char const *);
+ ]AT_YYERROR_DECLARE[
int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[);
}
@@ -1520,13 +1494,7 @@ B: 'b' ;
C: /*empty*/ { printf ("consistent default reduction\n"); } ;
%%
-
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[)
{
@@ -1592,13 +1560,13 @@ AT_CLEANUP
AT_SETUP([[LAC: Memory exhaustion]])
-m4_pushdef([AT_LAC_CHECK], [
-
+m4_pushdef([AT_LAC_CHECK],
+[AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
- void yyerror (char const *);
- int yylex (void);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
#define YYMAXDEPTH 8
}
@@ -1610,20 +1578,8 @@ S: A A A A A A A A A ;
A: /*empty*/ | 'a' ;
%%
-
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-int
-yylex (void)
-{
- static char const *input = "]$1[";
- return *input++;
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([$1])[
int
main (void)
{
@@ -1637,12 +1593,12 @@ AT_BISON_CHECK([[-Dparse.lac=full
-Dparse.lac.es-capacity-initial=1 \
[[input.y: conflicts: 8 shift/reduce
]])
AT_COMPILE([[input]])
-
+AT_BISON_OPTION_POPDEFS
])
# Check for memory exhaustion during parsing.
-AT_LAC_CHECK([[]])
-AT_PARSER_CHECK([[./input]], [[2]], [[]],
+AT_LAC_CHECK([])
+AT_PARSER_CHECK([[./input]], [[2]], [],
[[Starting parse
Entering state 0
Reading a token: Now at end of input.
@@ -1655,8 +1611,8 @@ Stack now 0
# Induce an immediate syntax error with an undefined token, and check
# for memory exhaustion while building syntax error message.
-AT_LAC_CHECK([[z]], [[0]])
-AT_PARSER_CHECK([[./input]], [[2]], [[]],
+AT_LAC_CHECK([z], [[0]])
+AT_PARSER_CHECK([[./input]], [[2]], [],
[[Starting parse
Entering state 0
Reading a token: Next token is token $undefined ()
diff --git a/tests/skeletons.at b/tests/skeletons.at
index 1a9933f..76cf066 100644
--- a/tests/skeletons.at
+++ b/tests/skeletons.at
@@ -83,10 +83,11 @@ AT_CLEANUP
AT_SETUP([[Installed skeleton file names]])
+AT_BISON_OPTION_PUSHDEFS
m4_pushdef([AT_GRAM],
[[%{
#include <stdio.h>
- void yyerror (char const *msg);
+ ]AT_YYERROR_DECLARE[
int yylex (void);
%}
@@ -99,12 +100,7 @@ start: ;
%%
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
yylex (void)
{
@@ -139,6 +135,7 @@ AT_PARSER_CHECK([[./input-gram]], [[1]], [],
m4_popdef([AT_GRAM])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
diff --git a/tests/synclines.at b/tests/synclines.at
index c12ab9b..8d742d5 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -68,7 +68,7 @@ AT_CHECK([[sed -e '/^distcc\[[0-9]*\] /d'
\
# to issue ERROR-MSG.
m4_define([AT_TEST_SYNCLINE],
[AT_SETUP([$1])
-
+AT_BISON_OPTION_PUSHDEFS
# It seems impossible to find a generic scheme to check the location
# of an error. Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
@@ -98,6 +98,7 @@ AT_DATA([[input.y]], [$2])
AT_BISON_CHECK([-o input.c input.y])
AT_SYNCLINES_COMPILE([input.c])
AT_CHECK([cat stdout], 0, [$3])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
@@ -110,11 +111,12 @@ AT_CLEANUP
AT_TEST_SYNCLINE([Prologue synch line],
[[%{
#error "2"
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
+%%
]],
[input.y:2: #error "2"
])
@@ -130,11 +132,12 @@ AT_TEST_SYNCLINE([%union synch line],
char dummy;
}
%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
+%%
]],
[input.y:2: #error "2"
])
@@ -146,8 +149,8 @@ exp: '0';
AT_TEST_SYNCLINE([Postprologue synch line],
[[%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%union
{
@@ -158,6 +161,7 @@ int yylex (void);
%}
%%
exp: '0';
+%%
]],
[input.y:10: #error "10"
])
@@ -169,8 +173,8 @@ exp: '0';
AT_TEST_SYNCLINE([Action synch line],
[[%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp:
@@ -188,8 +192,8 @@ exp:
AT_TEST_SYNCLINE([Epilogue synch line],
[[%{
-void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
diff --git a/tests/torture.at b/tests/torture.at
index 2b2d422..3fff08e 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -56,8 +56,8 @@ print <<EOF;
#include <stdio.h>
#include <stdlib.h>
-static int yylex (void);
-static void yyerror (const char *msg);
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
%}
%union
{
@@ -171,8 +171,8 @@ print <<EOF;
#include <stdio.h>
#include <stdlib.h>
-static int yylex (void);
-static void yyerror (const char *msg);
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
%}
%token
@@ -278,8 +278,8 @@ print <<EOF;
# include <stdlib.h>
# include <assert.h>
-static int yylex (void);
-static void yyerror (const char *msg);
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
%}
%union
{
@@ -390,7 +390,8 @@ AT_CLEANUP
# ------------------------------------------------
# A parser specialized in torturing the stack size.
m4_define([AT_DATA_STACK_TORTURE],
-[# A grammar of parens growing the stack thanks to right recursion.
+[AT_BISON_OPTION_PUSHDEFS([$2])
+# A grammar of parens growing the stack thanks to right recursion.
# exp:
AT_DATA([input.y],
[[%{
@@ -399,8 +400,8 @@ AT_DATA([input.y],
#include <stdio.h>
#include <stdlib.h>
]$1[
- static int yylex (void);
- static void yyerror (const char *msg);
+ ]AT_YYLEX_DECLARE[
+ ]AT_YYERROR_DECLARE[
%}
]$2[
%error-verbose
@@ -409,12 +410,7 @@ AT_DATA([input.y],
%%
exp: WAIT_FOR_EOF exp | ;
%%
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -462,6 +458,7 @@ main (int argc, const char **argv)
}
}
]])
+AT_BISON_OPTION_POPDEFS([$2])
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
])
--
1.7.10.4