[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
examples: include the generated header
From: |
Akim Demaille |
Subject: |
examples: include the generated header |
Date: |
Sun, 5 Jul 2020 08:19:19 +0200 |
Because they use ylwrap, these examples actually duplicate parse.h into parse.c.
commit 964fb2aa6f610db61c2af717f036dcada52b8766
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Sun Jul 5 07:21:07 2020 +0200
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.
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 6d86c77f..bb93af0f 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -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
diff --git a/examples/c/lexcalc/parse.y b/examples/c/lexcalc/parse.y
index 41546cb3..6db00c9b 100644
--- a/examples/c/lexcalc/parse.y
+++ b/examples/c/lexcalc/parse.y
@@ -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
diff --git a/examples/c/reccalc/parse.y b/examples/c/reccalc/parse.y
index bcea1b83..c11f9b66 100644
--- a/examples/c/reccalc/parse.y
+++ b/examples/c/reccalc/parse.y
@@ -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
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 01b2f1bb..4581fc73 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- examples: include the generated header,
Akim Demaille <=