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-} Regards, Frank --- stack.hh +++ stack.hh @@ -130,15 +130,15 @@ ]]) b4_defines_if( -[b4_output_begin([b4_dir_prefix[]stack.hh]) +[b4_output_begin([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])stack.hh]) b4_copyright([Stack handling for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[stack.hh + ** \file ]b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])[stack.hh ** Define the ]b4_namespace_ref[::stack class. */ -]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ +]b4_cpp_guard_open([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])stack.hh])[ # include <vector> @@ -146,7 +146,7 @@ ]b4_stack_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) +]b4_cpp_guard_close([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])stack.hh]) b4_output_end() ]) --- location.cc +++ location.cc @@ -294,15 +294,15 @@ b4_defines_if([ -b4_output_begin([b4_dir_prefix[]position.hh]) +b4_output_begin([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])position.hh]) b4_copyright([Positions for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[position.hh + ** \file ]b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])[position.hh ** Define the ]b4_namespace_ref[::position class. */ -]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[ +]b4_cpp_guard_open([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])position.hh])[ # include <algorithm> // std::max # include <iostream> @@ -313,26 +313,26 @@ ]b4_namespace_open[ ]b4_position_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]position.hh]) +]b4_cpp_guard_close([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])position.hh]) b4_output_end() -b4_output_begin([b4_dir_prefix[]location.hh]) +b4_output_begin([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])location.hh]) b4_copyright([Locations for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[location.hh + ** \file ]b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])[location.hh ** Define the ]b4_namespace_ref[::location class. */ -]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[ +]b4_cpp_guard_open([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])location.hh])[ -# include "position.hh" +# include "]b4_percent_define_get([[extra_header_prefix]])[position.hh" ]b4_namespace_open[ ]b4_location_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) +]b4_cpp_guard_close([b4_dir_prefix[]b4_percent_define_get([[extra_header_prefix]])location.hh]) b4_output_end() ]) --- 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 "]b4_percent_define_get([[extra_header_prefix]])[location.hh"]])])[ ]b4_variant_if([b4_variant_includes])[ ]b4_attribute_define[