mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
examples: include the generated header
* examples/c/bistromathic/parse.y, examples/c/lexcalc/parse.y, * examples/c/reccalc/parse.y: here. Add some comments. * src/parse-gram.y (api_version): Pull out of handle_require. Bump to 3.7.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
%require "3.6"
|
%require "3.7"
|
||||||
|
|
||||||
|
// Emitted on top of the implementation file.
|
||||||
%code top {
|
%code top {
|
||||||
#include <ctype.h> // isdigit
|
#include <ctype.h> // isdigit
|
||||||
#include <locale.h> // LC_ALL
|
#include <locale.h> // LC_ALL
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emitted in the header file, before the definition of YYSTYPE.
|
||||||
%code requires {
|
%code requires {
|
||||||
// Function type.
|
// Function type.
|
||||||
typedef double (func_t) (double);
|
typedef double (func_t) (double);
|
||||||
@@ -46,6 +48,7 @@
|
|||||||
symrec *getsym (char const *name);
|
symrec *getsym (char const *name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emitted in the header file, after the definition of YYSTYPE.
|
||||||
%code provides {
|
%code provides {
|
||||||
# ifndef __attribute__
|
# ifndef __attribute__
|
||||||
# ifndef __GNUC__
|
# ifndef __GNUC__
|
||||||
@@ -57,6 +60,7 @@
|
|||||||
__attribute__ ((__format__ (__printf__, 2, 3)));
|
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emitted in the implementation file.
|
||||||
%code {
|
%code {
|
||||||
#if defined ENABLE_NLS && ENABLE_NLS
|
#if defined ENABLE_NLS && ENABLE_NLS
|
||||||
# define _(Msgid) gettext (Msgid)
|
# define _(Msgid) gettext (Msgid)
|
||||||
@@ -68,6 +72,9 @@
|
|||||||
int done = 0;
|
int done = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include the header in the implementation rather than duplicating it.
|
||||||
|
%define api.header.include {"parse.h"}
|
||||||
|
|
||||||
// Don't share global variables between the scanner and the parser.
|
// Don't share global variables between the scanner and the parser.
|
||||||
%define api.pure full
|
%define api.pure full
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
#include <stdlib.h> // getenv.
|
#include <stdlib.h> // getenv.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include the header in the implementation rather than duplicating it.
|
||||||
|
%define api.header.include {"parse.h"}
|
||||||
|
|
||||||
// Don't share global variables between the scanner and the parser.
|
// Don't share global variables between the scanner and the parser.
|
||||||
%define api.pure full
|
%define api.pure full
|
||||||
|
|
||||||
|
|||||||
@@ -46,14 +46,29 @@
|
|||||||
result parse (void);
|
result parse (void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include the header in the implementation rather than duplicating it.
|
||||||
|
%define api.header.include {"parse.h"}
|
||||||
|
|
||||||
|
// Don't share global variables between the scanner and the parser.
|
||||||
%define api.pure full
|
%define api.pure full
|
||||||
|
|
||||||
|
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
|
||||||
|
// with TOK_ (e.g., TOK_EOF).
|
||||||
%define api.token.prefix {TOK_}
|
%define api.token.prefix {TOK_}
|
||||||
|
|
||||||
|
// Generate YYSTYPE from the types assigned to symbols.
|
||||||
%define api.value.type union
|
%define api.value.type union
|
||||||
%define parse.error verbose
|
|
||||||
|
// Error messages with "unexpected XXX, expected XXX...".
|
||||||
|
%define parse.error detailed
|
||||||
|
|
||||||
|
// Enable run-time traces (yydebug).
|
||||||
%define parse.trace
|
%define parse.trace
|
||||||
|
|
||||||
|
// Generate the parser description file (parse.output).
|
||||||
%verbose
|
%verbose
|
||||||
|
|
||||||
// Scanner and error count are exchanged between main, yyparse and yylex.
|
// Scanner and error count are exchanged between main, yyparse and yylex.
|
||||||
%param {yyscan_t scanner}{result *res}
|
%param {yyscan_t scanner}{result *res}
|
||||||
|
|
||||||
%token
|
%token
|
||||||
|
|||||||
@@ -58,6 +58,10 @@
|
|||||||
#include "scan-code.h"
|
#include "scan-code.h"
|
||||||
#include "scan-gram.h"
|
#include "scan-gram.h"
|
||||||
|
|
||||||
|
/* Pretend to be at least that version, to check features published
|
||||||
|
in that version while developping it. */
|
||||||
|
static const char* api_version = "3.7";
|
||||||
|
|
||||||
static int current_prec = 0;
|
static int current_prec = 0;
|
||||||
static location current_lhs_loc;
|
static location current_lhs_loc;
|
||||||
static named_ref *current_lhs_named_ref;
|
static named_ref *current_lhs_named_ref;
|
||||||
@@ -1082,9 +1086,6 @@ handle_require (location const *loc, char const *version_quoted)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Pretend to be at least that version, to check features published
|
|
||||||
in that version while developping it. */
|
|
||||||
const char* api_version = "3.6";
|
|
||||||
const char* package_version =
|
const char* package_version =
|
||||||
0 < strverscmp (api_version, PACKAGE_VERSION)
|
0 < strverscmp (api_version, PACKAGE_VERSION)
|
||||||
? api_version : PACKAGE_VERSION;
|
? api_version : PACKAGE_VERSION;
|
||||||
|
|||||||
Reference in New Issue
Block a user