# instead of being attached to the empty rule dedicated to this
# action.
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%define parse.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'); }
{ 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])
AT_SETUP([Exotic Dollars])
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%define parse.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)
%}
;
%%
-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)
{
[[
%{
# include <stdio.h>
- static int yylex (void);
- static void yyerror (char const *msg);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
typedef struct { int val; } stype;
# define YYSTYPE stype
%}
sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
%%
-
-static int
-yylex (void)
-{
- return 0;
-}
-
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE()[
int
main (void)
{
[[6
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
}])
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([typedef yy::location YYLTYPE;])[
+]AT_YYLEX_DECLARE[
+]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
[}
]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
/* Alias to ARGV[1]. */
const char *source = YY_NULL;
-static int
-yylex (]AT_LEX_FORMALS[)
+static
+]AT_YYLEX_PROTOTYPE[
{
static unsigned int counter = 0;
]])
])
-])
+AT_BISON_OPTION_POPDEFS
+])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
# 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]],
[[%define parse.error verbose
%debug
%{
# 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)
%}
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)
Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Entering state 6
Reading a token: Now at end of input.
-syntax error, unexpected $end, expecting 'e'
+1.5-4: syntax error, unexpected $end, expecting 'e'
Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Stack now 0 1 3 5
Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
Stack now 0
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
## ------------------------------------------------------ ##
AT_SETUP([Default tagged and per-type %printer and %destructor])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%define parse.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(SYM)
%}
;
%%
-
-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)
Stack now 0
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
[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]],
[[%define parse.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(SYM)
%}
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)
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input$1.c input$1.y])
AT_COMPILE([input$1])
# 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)
%}
;
%%
-
-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)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
# 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)
%}
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])
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)
;
%%
-
-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], 0,,
[[input.y:33.3-23: warning: unset value: $$
# 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([[@$ 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
return 0;
}
-static void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
int
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]])
# 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;
[]"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
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)
}
} ;
%%
-
-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]], [],
AT_SETUP([[YYBACKUP]])
+AT_BISON_OPTION_PUSHDEFS([%pure-parser])
+
AT_DATA_GRAMMAR([input.y],
[[
%error-verbose
# include <stdlib.h>
# include <assert.h>
- static void yyerror (const char *msg);
+ ]AT_YYERROR_DECLARE[
static int yylex (YYSTYPE *yylval);
}
%%
;
%%
+]AT_YYERROR_DEFINE[
static int
yylex (YYSTYPE *yylval)
{
return input[toknum++];
}
-static void
-yyerror (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
int
main (void)
{
return yyparse ();
}
]])
+AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])