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:
Akim Demaille
2020-07-05 07:21:07 +02:00
parent 7c0d36b760
commit 964fb2aa6f
4 changed files with 32 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
%require "3.6"
%require "3.7"
// Emitted on top of the implementation file.
%code top {
#include <ctype.h> // isdigit
#include <locale.h> // LC_ALL
@@ -24,6 +25,7 @@
#endif
}
// Emitted in the header file, before the definition of YYSTYPE.
%code requires {
// Function type.
typedef double (func_t) (double);
@@ -46,6 +48,7 @@
symrec *getsym (char const *name);
}
// Emitted in the header file, after the definition of YYSTYPE.
%code provides {
# ifndef __attribute__
# ifndef __GNUC__
@@ -57,6 +60,7 @@
__attribute__ ((__format__ (__printf__, 2, 3)));
}
// Emitted in the implementation file.
%code {
#if defined ENABLE_NLS && ENABLE_NLS
# define _(Msgid) gettext (Msgid)
@@ -68,6 +72,9 @@
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.
%define api.pure full

View File

@@ -19,6 +19,9 @@
#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.
%define api.pure full

View File

@@ -46,14 +46,29 @@
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
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
// with TOK_ (e.g., TOK_EOF).
%define api.token.prefix {TOK_}
// Generate YYSTYPE from the types assigned to symbols.
%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
// Generate the parser description file (parse.output).
%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}
%token

View File

@@ -58,6 +58,10 @@
#include "scan-code.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 location current_lhs_loc;
static named_ref *current_lhs_named_ref;
@@ -1082,9 +1086,6 @@ handle_require (location const *loc, char const *version_quoted)
}
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 =
0 < strverscmp (api_version, PACKAGE_VERSION)
? api_version : PACKAGE_VERSION;