diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-03-06 07:43:12 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-03-17 16:36:05 +0100 |
commit | 4e19ab9fcd28c9361ff08f46e5e353effb0a0520 (patch) | |
tree | 68189ef2969917076f5f991cf265e9c4e24666c0 /examples | |
parent | 6cb612e7e3bd5421377f39d3939f365f23139fc5 (diff) | |
download | bison-4e19ab9fcd28c9361ff08f46e5e353effb0a0520.tar.gz |
yacc.c: provide a means to include the header in the implementation
Currently when --defines is used, we generate a header, and paste an
exact copy of it into the generated parser implementation file. Let's
provide a means to #include it instead.
We don't do it by default because of the Autotools' ylwrap. This
program wraps invocations of yacc (that uses a fixed output name:
y.tab.c, y.tab.h, y.output) to support a more modern naming
scheme (dir/foo.y -> dir/foo.tab.c, dir/foo.tab.h, etc.). It does
that by renaming the generated files, and then by running sed to
propagate these renamings inside the files themselves.
Unfortunately Automake's Makefiles uses Bison as if it were Yacc (with
--yacc or with -o y.tab.c) and invoke bison via ylwrap. As a
consequence, as far as Bison is concerned, the output files are
y.tab.c and y.tab.h, so it emits '#include "y.tab.h"'. So far, so
good. But now ylwrap processes this '#include "y.tab.h"' into
'#include "dir/foo.tab.h"', which is not guaranteed to always work.
So, let's do the Right Thing when the output file is not y.tab.c, in
which case the user should %define api.header.include. Binding this
behavior to --yacc is tempting, but we recently told people to stop
using --yacc (as it also enables the Yacc warnings), but rather to use
-o y.tab.c.
Yacc.c is the only skeleton concerned: all the others do include their
header.
* data/skeletons/yacc.c (b4_header_include_if): New.
(api.header.include): Provide a default value when the output is not
y.tab.c.
* src/parse-gram.y (api.header.include): Define.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c/calc/calc.y | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/examples/c/calc/calc.y b/examples/c/calc/calc.y index f3771f2e..f3a6cb1d 100644 --- a/examples/c/calc/calc.y +++ b/examples/c/calc/calc.y @@ -7,6 +7,7 @@ void yyerror (char const *); } +%define api.header.include {"calc.h"} %define api.value.type union /* Generate YYSTYPE from these types: */ %token <double> NUM "number" %type <double> expr term fact |