[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generated headers

From: Frank Heckenbach
Subject: Re: Generated headers
Date: Sat, 17 Mar 2018 22:24:42 +0100

To answer my own question, I wrote:

> when using "%defines" or "--defines", bison generates the normal C++
> file, the header (whose name can be set with "--defines") and 3 more
> files, position.hh, location.hh and stack.hh whose names apparently
> cannot be changed.
> I think that's not nice for at least two reasons:
> - When using several C++ bison parsers in the same source directory
>   (I'm not doing this now, but I might in the future), they would
>   overwrite each other. Even if the contents might be the same, this
>   seems strange.

As Hans Åberg pointed out, there will be an actual conflict if using
multiple parsers with different namespaces.

> - To write a proper Makefile, one should remove those files in one
>   of the *clean rules. Should one hard code those 3 names? Might
>   bison add another one in the future?
>   Or, more dangerous, might it get rid of (some of) them? Then, much
>   later, someone else might unknowingly use one of those names for a
>   real source file and have it deleted accidentally. (Same if the
>   source stops using bison sometime in the future.)
> So, isn't there some way to rename those files, either based on the
> bison source file name, or by a command-line option or directive, or
> at least, if still hard coded, in a way that clearly marks them as
> bison outputs, e.g. bison-generated-foo.hh?

Indeed, there was no way.

I made some changes (see attached patch) to make it possible to add
a prefix to those headers with a directive like this:

%define extra_header_prefix {myparser-}


--- stack.hh
+++ stack.hh
@@ -130,15 +130,15 @@
 b4_copyright([Stack handling for Bison parsers in C++])[
- ** \file ]b4_dir_prefix[stack.hh
+ ** \file 
  ** Define the ]b4_namespace_ref[::stack class.
 # include <vector>
@@ -146,7 +146,7 @@
--- location.cc
+++ location.cc
@@ -294,15 +294,15 @@
 b4_copyright([Positions for Bison parsers in C++])[
- ** \file ]b4_dir_prefix[position.hh
+ ** \file 
  ** Define the ]b4_namespace_ref[::position class.
 # include <algorithm> // std::max
 # include <iostream>
@@ -313,26 +313,26 @@
 b4_copyright([Locations for Bison parsers in C++])[
- ** \file ]b4_dir_prefix[location.hh
+ ** \file 
  ** Define the ]b4_namespace_ref[::location class.
-# include "position.hh"
+# include "]b4_percent_define_get([[extra_header_prefix]])[position.hh"
--- lalr1.cc
+++ lalr1.cc
@@ -154,8 +154,8 @@
 # include <stdexcept>
 # include <string>
 # include <vector>]b4_defines_if([[
-# include "stack.hh"
-]b4_bison_locations_if([[# include "location.hh"]])])[
+# include "]b4_percent_define_get([[extra_header_prefix]])[stack.hh"
+]b4_bison_locations_if([[# include 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]