|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
header file guards conflictHi,
Just have used Bison for several months. I have two bison parsers in one project and for some reasons the header files of both parsers are included in one cpp code. Different namespace names are used, therefore, these two parsers do not conflict. However, there is an unexpected problem. The header guard in location.hh is BISON_LOCATION_HH, the same in both location.hh files (not only this file). As result, I need to do something like the following in my code: #include "parser1.hh" // undefine all the conflicted header guards #undef PARSER_HEADER_H #undef BISON_LOCATION_HH #undef BISON_POSITION_HH #include "parser2.hh" Is there a better way to do it? Thanks, Wei -- *Dr Wei Song ( ?? )* Advanced Processor Technologies Group Computer Science at the University of Manchester http://apt.cs.man.ac.uk/apt/people/wsong/ _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 16 mai 2012 à 16:51, Wei Song a écrit : > Hi, Hi! > Just have used Bison for several months. > > I have two bison parsers in one project and for some reasons the header files of both parsers are included in one cpp code. > Different namespace names are used, therefore, these two parsers do not conflict. > However, there is an unexpected problem. > The header guard in location.hh is BISON_LOCATION_HH, the same in both location.hh files (not only this file). > As result, I need to do something like the following in my code: > > #include "parser1.hh" > > // undefine all the conflicted header guards > #undef PARSER_HEADER_H > #undef BISON_LOCATION_HH > #undef BISON_POSITION_HH > > #include "parser2.hh" > > Is there a better way to do it? This is indeed a problem. I'm sure what the best way to address this is. In addition, in some cases, creating the files location.hh, stack.hh etc. is more troublesome than useful. Also, some people would like to be able to rename the location.hh file. Currently we use BISON_LOCATION_HH (it is open-coded). One first idea would be to use the output file name, so if for instance you passed "-o lang1/parser.cc", the header would be BISON_LANG1_LOCATION_HH. Would that suffice in your case? Maybe BISON_ is not needed actually. Maybe we should also include the given name-prefix? So this would typically be YY_LANG1_LOCATION_HH. Don't you have the exact same problem with your parser header file? Currently it is PARSER_HEADER_H… Using name-prefix + full output name (with directory) that would be YY_LANG1_PARSER_HH. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 11:34, Akim Demaille a écrit : > > Le 16 mai 2012 à 16:51, Wei Song a écrit : > >> Hi, > > Hi! > >> Just have used Bison for several months. >> >> I have two bison parsers in one project and for some reasons the header files of both parsers are included in one cpp code. >> Different namespace names are used, therefore, these two parsers do not conflict. >> However, there is an unexpected problem. >> The header guard in location.hh is BISON_LOCATION_HH, the same in both location.hh files (not only this file). >> As result, I need to do something like the following in my code: >> >> #include "parser1.hh" >> >> // undefine all the conflicted header guards >> #undef PARSER_HEADER_H >> #undef BISON_LOCATION_HH >> #undef BISON_POSITION_HH >> >> #include "parser2.hh" >> >> Is there a better way to do it? > > This is indeed a problem. I'm sure what the best way to > address this is. In addition, in some cases, creating the > files location.hh, stack.hh etc. is more troublesome than > useful. > > Also, some people would like to be able to rename the location.hh > file. > > Currently we use BISON_LOCATION_HH (it is open-coded). One > first idea would be to use the output file name, so if > for instance you passed "-o lang1/parser.cc", the header would > be BISON_LANG1_LOCATION_HH. Would that suffice in your case? > Maybe BISON_ is not needed actually. > > Maybe we should also include the given name-prefix? So > this would typically be YY_LANG1_LOCATION_HH. > > Don't you have the exact same problem with your parser > header file? Currently it is PARSER_HEADER_H… Using > name-prefix + full output name (with directory) that > would be YY_LANG1_PARSER_HH. I have started something in that spirit. There is one issue: the file name can be ugly (typically in a VPATH build there can be plenty of "../"), so the CPP guard is not nice looking either. For instance, in _my_ build of bison (with builddir=_build/debug7), I have examples/calc++/location.hh that looks like this: > /** > ** \file ../../../../examples/calc++/location.hh > ** Define the yy::location class. > */ > > #ifndef YY_____________EXAMPLES_CALC___LOCATION_HH > # define YY_____________EXAMPLES_CALC___LOCATION_HH > > # include <iostream> > # include <string> > # include "position.hh" > > > namespace yy { > > /* Line 168 of location.cc */ > #line 50 "../../../../examples/calc++/location.hh" > > /// Abstract a location. > class location But really, I think handling srcdir vs. builddir is a different issue that I don't wish to address now. I still cannot release 2.5.1 because I have issues with the generated ChangeLog that need to be addressed first. So I am tempted to include this into 2.5.1, even though it is quite a change. I'd be happy to have opinion on this. There are four related patches: 3dcbe90 lalr1.cc: extract stack.hh. To make merging easier in master. d5c5e39 lalr1.cc: improve Doxygen documentation. To include the prefix part in the \file directive. e7db5ac skeletons: remove support for unused directive. Something that should never have been included. 84e027a c++: compute the header guards. Really compute the CPP guards. These patches do not add CPP guards to the C headers, parser.h, generated by glr.c and yacc.c. Maybe we should? The patches will follow. In "next" ATM. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictThanks for the reply Akim.
On 2012/5/21 10:34, Akim Demaille wrote: > Currently we use BISON_LOCATION_HH (it is open-coded). One > first idea would be to use the output file name, so if > for instance you passed "-o lang1/parser.cc", the header would > be BISON_LANG1_LOCATION_HH. Would that suffice in your case? > Maybe BISON_ is not needed actually. > > Maybe we should also include the given name-prefix? So > this would typically be YY_LANG1_LOCATION_HH. Using the output file name will handle the problem but I am more prefer to including the given name-prefix in the header guard. My file structure is already divided in such a way that every language has its own sub-directory. The bison .y files are stored in the sub-directories rather in the root, therefore, there is no lang1 in the -o argument when running make. To my understanding, the name-prefix is more independent to the file structure. > > Don't you have the exact same problem with your parser > header file? Currently it is PARSER_HEADER_H… Using > name-prefix + full output name (with directory) that > would be YY_LANG1_PARSER_HH. Yes I do. I would like to see user-defined name-prefix in all header guards. Best regards, -Wei _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 14:42, Akim Demaille a écrit : > lalr1.cc: extract stack.hh. > To make merging easier in master. > lalr1.cc: improve Doxygen documentation. > To include the prefix part in the \file directive. > skeletons: remove support for unused directive. > Something that should never have been included. > c++: compute the header guards. > Really compute the CPP guards. This is the first patch. From 314996cd0828ebbacf849ee36ca023ec13c82bd0 Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 11:53:03 +0200 Subject: [PATCH 1/4] lalr1.cc: extract stack.hh. See commit 51bacae6b58fd5c6cce861f00440dc917384625e. * data/stack.hh: New, extracted from... * data/lalr1.cc: here. * data/Makefile.am: Adjust. --- data/Makefile.am | 2 +- data/lalr1.cc | 102 +-------------------------------------------- data/stack.hh | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 102 deletions(-) create mode 100644 data/stack.hh diff --git a/data/Makefile.am b/data/Makefile.am index 5c2955a..c223188 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -15,7 +15,7 @@ dist_pkgdata_DATA = README bison.m4 \ c-skel.m4 c.m4 yacc.c glr.c \ - c++-skel.m4 c++.m4 location.cc lalr1.cc glr.cc \ + c++-skel.m4 c++.m4 location.cc lalr1.cc glr.cc stack.hh \ java-skel.m4 java.m4 lalr1.java m4sugardir = $(pkgdatadir)/m4sugar diff --git a/data/lalr1.cc b/data/lalr1.cc index 76a8350..c63e66d 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -28,6 +28,7 @@ b4_percent_define_ifdef([[location_type]], [], [# Backward compatibility. m4_define([b4_location_constructors]) m4_include(b4_pkgdatadir/[location.cc])]) +m4_include(b4_pkgdatadir/[stack.hh]) # We do want M4 expansion after # for CPP macros. m4_changecom() @@ -1139,106 +1140,5 @@ b4_error_verbose_if([int yystate, int yytoken], const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[; ]b4_namespace_close[ - ]b4_epilogue -dnl -@output(b4_dir_prefix[]stack.hh@)@ -b4_copyright([Stack handling for Bison parsers in C++], - [2002-2012])[ - -#ifndef BISON_STACK_HH -# define BISON_STACK_HH - -#include <deque> - -]b4_namespace_open[ - template <class T, class S = std::deque<T> > - class stack - { - public: - - // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; - - stack () : seq_ () - { - } - - stack (unsigned int n) : seq_ (n) - { - } - - inline - T& - operator [] (unsigned int i) - { - return seq_[i]; - } - - inline - const T& - operator [] (unsigned int i) const - { - return seq_[i]; - } - - inline - void - push (const T& t) - { - seq_.push_front (t); - } - - inline - void - pop (unsigned int n = 1) - { - for (; n; --n) - seq_.pop_front (); - } - - inline - unsigned int - height () const - { - return seq_.size (); - } - - inline const_iterator begin () const { return seq_.rbegin (); } - inline const_iterator end () const { return seq_.rend (); } - - private: - - S seq_; - }; - - /// Present a slice of the top of a stack. - template <class T, class S = stack<T> > - class slice - { - public: - - slice (const S& stack, - unsigned int range) : stack_ (stack), - range_ (range) - { - } - - inline - const T& - operator [] (unsigned int i) const - { - return stack_[range_ - i]; - } - - private: - - const S& stack_; - unsigned int range_; - }; -]b4_namespace_close[ - -#endif // not BISON_STACK_HH[]dnl -] m4_divert_pop(0) diff --git a/data/stack.hh b/data/stack.hh new file mode 100644 index 0000000..e785e80 --- /dev/null +++ b/data/stack.hh @@ -0,0 +1,121 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +m4_pushdef([b4_copyright_years], + [2002-2012]) + +# We do want M4 expansion after # for CPP macros. +m4_changecom() +m4_divert_push(0)dnl +@output(b4_dir_prefix[]stack.hh@)@ +b4_copyright([Stack handling for Bison parsers in C++], + [2002-2012])[ + +#ifndef BISON_STACK_HH +# define BISON_STACK_HH + +# include <deque> + +]b4_namespace_open[ + template <class T, class S = std::deque<T> > + class stack + { + public: + // Hide our reversed order. + typedef typename S::reverse_iterator iterator; + typedef typename S::const_reverse_iterator const_iterator; + + stack () : seq_ () + { + } + + stack (unsigned int n) : seq_ (n) + { + } + + inline + T& + operator [] (unsigned int i) + { + return seq_[i]; + } + + inline + const T& + operator [] (unsigned int i) const + { + return seq_[i]; + } + + inline + void + push (const T& t) + { + seq_.push_front (t); + } + + inline + void + pop (unsigned int n = 1) + { + for (; n; --n) + seq_.pop_front (); + } + + inline + unsigned int + height () const + { + return seq_.size (); + } + + inline const_iterator begin () const { return seq_.rbegin (); } + inline const_iterator end () const { return seq_.rend (); } + + private: + S seq_; + }; + + /// Present a slice of the top of a stack. + template <class T, class S = stack<T> > + class slice + { + public: + slice (const S& stack, unsigned int range) + : stack_ (stack) + , range_ (range) + { + } + + inline + const T& + operator [] (unsigned int i) const + { + return stack_[range_ - i]; + } + + private: + const S& stack_; + unsigned int range_; + }; +]b4_namespace_close[ + +#endif // not BISON_STACK_HH[]dnl +] +m4_divert_pop(0) +m4_popdef([b4_copyright_years])dnl +m4_changecom([#]) -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: lalr1.cc: improve Doxygen documentation (was: header file guards conflict)Le 21 mai 2012 à 14:42, Akim Demaille a écrit : > lalr1.cc: extract stack.hh. > To make merging easier in master. > lalr1.cc: improve Doxygen documentation. > To include the prefix part in the \file directive. > skeletons: remove support for unused directive. > Something that should never have been included. > c++: compute the header guards. > Really compute the CPP guards. From 0e931dcd2eee03611ca980ed0d7805d045d3438c Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 11:40:42 +0200 Subject: [PATCH 2/4] lalr1.cc: improve Doxygen documentation. * data/location.cc: Qualify file names with directory name. --- data/lalr1.cc | 5 +++++ data/location.cc | 4 ++-- data/stack.hh | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/data/lalr1.cc b/data/lalr1.cc index c63e66d..0fe3aee 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -39,6 +39,11 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++], [2002-2012]) dnl FIXME: This is wrong, we want computed header guards. [ +/** + ** \file ]b4_spec_defines_file[ + ** Define the ]b4_namespace_ref[::parser class. + */ + /* C++ LALR(1) parser skeleton written by Akim Demaille. */ #ifndef PARSER_HEADER_H diff --git a/data/location.cc b/data/location.cc index cb0f1f9..0ee02c2 100644 --- a/data/location.cc +++ b/data/location.cc @@ -23,7 +23,7 @@ b4_copyright([Positions for Bison parsers in C++], [2002-2007, 2009-2012])[ /** - ** \file position.hh + ** \file ]b4_dir_prefix[position.hh ** Define the ]b4_namespace_ref[::position class. */ @@ -154,7 +154,7 @@ b4_copyright([Locations for Bison parsers in C++], [2002-2007, 2009-2012])[ /** - ** \file location.hh + ** \file ]b4_dir_prefix[location.hh ** Define the ]b4_namespace_ref[::location class. */ diff --git a/data/stack.hh b/data/stack.hh index e785e80..5293377 100644 --- a/data/stack.hh +++ b/data/stack.hh @@ -25,6 +25,11 @@ m4_divert_push(0)dnl b4_copyright([Stack handling for Bison parsers in C++], [2002-2012])[ +/** + ** \file ]b4_dir_prefix[stack.hh + ** Define the ]b4_namespace_ref[::stack class. + */ + #ifndef BISON_STACK_HH # define BISON_STACK_HH -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: skeletons: remove support for unused directive (was: header file guards conflict)Le 21 mai 2012 à 14:42, Akim Demaille a écrit : > lalr1.cc: extract stack.hh. > To make merging easier in master. > lalr1.cc: improve Doxygen documentation. > To include the prefix part in the \file directive. > skeletons: remove support for unused directive. > Something that should never have been included. > c++: compute the header guards. > Really compute the CPP guards. From 5dbb5cd2a06ed57661358af320e4226f0349d868 Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 13:12:34 +0200 Subject: [PATCH 3/4] skeletons: remove support for unused directive. * src/scan-skel.l (@dir_prefix@): Remove support, has never been used, not even in the commit that introduced it, 2b81e969ea04c1a6502928ba7e847ec8ff7dcb2f. --- src/scan-skel.l | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scan-skel.l b/src/scan-skel.l index 5fd9b20..2433905 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -77,7 +77,6 @@ static void fail_for_invalid_at (char const *at); "@oline@" fprintf (yyout, "%d", out_lineno + 1); "@ofile@" QPUTS (outname); -"@dir_prefix@" QPUTS (dir_prefix); @[a-z_]+"(" { yytext[yyleng-1] = '\0'; -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 14:42, Akim Demaille a écrit : > lalr1.cc: extract stack.hh. > To make merging easier in master. > lalr1.cc: improve Doxygen documentation. > To include the prefix part in the \file directive. > skeletons: remove support for unused directive. > Something that should never have been included. > c++: compute the header guards. > Really compute the CPP guards. This is the patch that really computes the header guards. From eb76fadde9c5a3b23dc6761ddd4d267a6e7c3965 Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 14:21:51 +0200 Subject: [PATCH 4/4] c++: compute the header guards. This is a frequent request. Recently pointed out by Wei Song, <http://lists.gnu.org/archive/html/help-bison/2012-05/msg00002.html>. * src/scan-skel.l (append_guard): New. (@guard): New directive. * data/lalr1.cc, data/location.cc, data/stack.hh: Use @guard for these files. * TODO (CPP Guard): Move to... * NEWS: here. Formatting changes. --- NEWS | 32 +++++++++++++++++++++++++++----- THANKS | 1 + TODO | 4 ---- data/lalr1.cc | 7 +++---- data/location.cc | 12 ++++++------ data/stack.hh | 6 +++--- src/scan-skel.l | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 72 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index f554b9f..a8846a8 100644 --- a/NEWS +++ b/NEWS @@ -27,18 +27,40 @@ Bison News The Java parser no longer throws ArrayIndexOutOfBoundsException if the first token leads to a syntax error. Some minor clean ups. -** C++11 compatibility: +** Changes for C++: - C and C++ parsers use nullptr instead of 0 when __cplusplus is +*** C++11 compatibility: + + C and C++ parsers use `nullptr' instead of `0' when __cplusplus is 201103L or higher. -** C++ locations: +*** Header guards + + The header files such as parser.hh, location.hh, etc. used a + constant name for preprocessor guards, for instance: + + #ifndef BISON_LOCATION_HH + # define BISON_LOCATION_HH + ... + #endif // !BISON_LOCATION_HH + + The inclusion guard is computed from `PREFIX/FILE-NAME', where lower + case characters are converted to upper case, and remaining + non-alphanumerical characters are converted to underscore. With + `bison -o sub/parser.cc', location.hh would now include: + + #ifndef YY_SUB_LOCATION_HH + # define YY_SUB_LOCATION_HH + ... + #endif // !YY_SUB_LOCATION_HH + +*** C++ locations: The position and location constructors (and their initialize methods) accept new arguments for line and column. Several issues in the documentation were fixed. -** liby is no longer asking for "rpl_fprintf" on some platforms. +** liby is no longer asking for `rpl_fprintf' on some platforms. ** Changes in the manual: @@ -77,7 +99,7 @@ Bison News *** The install-pdf target work properly: - Running "make install-pdf" (or -dvi, -html, -info, and -ps) no + Running `make install-pdf' (or -dvi, -html, -info, and -ps) no longer halts in the middle of its course. * Changes in version 2.5 (2011-05-14): diff --git a/THANKS b/THANKS index 6d0d89e..e3bf221 100644 --- a/THANKS +++ b/THANKS @@ -112,6 +112,7 @@ Tys Lefering gccbison@... Vin Shelton acs@... W.C.A. Wijngaards wouter@... Wayne Green wayne@... +Wei Song wsong83@... Wolfgang S. Kechel wolfgang.kechel@... Wolfram Wagner ww@... Wwp subscript@... diff --git a/TODO b/TODO index d86d8d8..21ef4b9 100644 --- a/TODO +++ b/TODO @@ -125,10 +125,6 @@ we do the same in yacc.c. The code bw glr.c and yacc.c is really alike, we can certainly factor some parts. -* Header guards - -From François: should we keep the directory part in the CPP guard? - * Yacc.c: CPP Macros diff --git a/data/lalr1.cc b/data/lalr1.cc index 0fe3aee..ebfd4e1 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -37,7 +37,6 @@ b4_defines_if( [@output(b4_spec_defines_file@)@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++], [2002-2012]) -dnl FIXME: This is wrong, we want computed header guards. [ /** ** \file ]b4_spec_defines_file[ @@ -46,8 +45,8 @@ dnl FIXME: This is wrong, we want computed header guards. /* C++ LALR(1) parser skeleton written by Akim Demaille. */ -#ifndef PARSER_HEADER_H -# define PARSER_HEADER_H +#ifndef @guard(]b4_spec_defines_file[@) +# define @guard(]b4_spec_defines_file[@) ]b4_percent_code_get([[requires]])[ @@ -286,7 +285,7 @@ b4_user_stype ]) b4_percent_code_get([[provides]])[]dnl -[#endif /* ! defined PARSER_HEADER_H */] +[#endif // !@guard(]b4_spec_defines_file[@)] ])dnl @output(b4_parser_file_name@)@ b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++], diff --git a/data/location.cc b/data/location.cc index 0ee02c2..06ce604 100644 --- a/data/location.cc +++ b/data/location.cc @@ -27,8 +27,8 @@ b4_copyright([Positions for Bison parsers in C++], ** Define the ]b4_namespace_ref[::position class. */ -#ifndef BISON_POSITION_HH -# define BISON_POSITION_HH +#ifndef @guard(]b4_dir_prefix[position.hh@) +# define @guard(]b4_dir_prefix[position.hh@) # include <iostream> # include <string> @@ -148,7 +148,7 @@ b4_copyright([Positions for Bison parsers in C++], } ]b4_namespace_close[ -#endif // not BISON_POSITION_HH] +#endif // !@guard(]b4_dir_prefix[position.hh@)] @output(b4_dir_prefix[]location.hh@)@ b4_copyright([Locations for Bison parsers in C++], [2002-2007, 2009-2012])[ @@ -158,8 +158,8 @@ b4_copyright([Locations for Bison parsers in C++], ** Define the ]b4_namespace_ref[::location class. */ -#ifndef BISON_LOCATION_HH -# define BISON_LOCATION_HH +#ifndef @guard(]b4_dir_prefix[location.hh@) +# define @guard(]b4_dir_prefix[location.hh@) # include <iostream> # include <string> @@ -295,6 +295,6 @@ b4_copyright([Locations for Bison parsers in C++], ]b4_namespace_close[ -#endif // not BISON_LOCATION_HH] +#endif // !@guard(]b4_dir_prefix[location.hh@)] m4_divert_pop(0) m4_changecom([#]) diff --git a/data/stack.hh b/data/stack.hh index 5293377..912e4ba 100644 --- a/data/stack.hh +++ b/data/stack.hh @@ -30,8 +30,8 @@ b4_copyright([Stack handling for Bison parsers in C++], ** Define the ]b4_namespace_ref[::stack class. */ -#ifndef BISON_STACK_HH -# define BISON_STACK_HH +#ifndef @guard(]b4_dir_prefix[stack.hh@) +# define @guard(]b4_dir_prefix[stack.hh@) # include <deque> @@ -119,7 +119,7 @@ b4_copyright([Stack handling for Bison parsers in C++], }; ]b4_namespace_close[ -#endif // not BISON_STACK_HH[]dnl +#endif // !@guard(]b4_dir_prefix[stack.hh@)[]dnl ] m4_divert_pop(0) m4_popdef([b4_copyright_years])dnl diff --git a/src/scan-skel.l b/src/scan-skel.l index 2433905..4b23d90 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -32,6 +32,7 @@ #include <dirname.h> #include <error.h> #include <quotearg.h> +#include <c-ctype.h> #include "complain.h" #include "getargs.h" @@ -173,6 +174,20 @@ skel_scanner_free (void) yylex_destroy (); } +/* Append SRC converted upper case alphanumeric or underscore to DST. + Return a pointer the next character in DST. */ +static +char * +append_guard (char *dst, char const *src) +{ + for ( ; *src; ++dst, ++src) + *dst = + c_islower (*src) ? c_toupper (*src) + : c_isalnum (*src) ? *src + : '_'; + return dst; +} + static void at_directive_perform (int at_directive_argc, char *at_directive_argv[], @@ -184,6 +199,23 @@ at_directive_perform (int at_directive_argc, fail_for_at_directive_too_many_args (at_directive_argv[0]); fputs (last_component (at_directive_argv[1]), yyout); } + else if (0 == strcmp (at_directive_argv[0], "@guard")) + { + if (at_directive_argc > 2) + fail_for_at_directive_too_many_args (at_directive_argv[0]); + else + { + char const *prefix = spec_name_prefix ? spec_name_prefix : "yy"; + char const *arg = at_directive_argv[1]; + char *guard = xmalloc (strlen (prefix) + 1 + strlen (arg) + 1); + char *cp = append_guard (guard, prefix); + *cp++ = '_'; + cp = append_guard (cp, arg); + *cp = 0; + fputs (guard, yyout); + free (guard); + } + } else if (0 == strcmp (at_directive_argv[0], "@warn") || 0 == strcmp (at_directive_argv[0], "@complain") || 0 == strcmp (at_directive_argv[0], "@fatal")) -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictHi Akim. I'm really not knowledgeable enough to comment on this
patch proper, but I have a nit about quotation usages ... On 05/21/2012 02:56 PM, Akim Demaille wrote: > > -** liby is no longer asking for "rpl_fprintf" on some platforms. > +** liby is no longer asking for `rpl_fprintf' on some platforms. > ... here and in a similar change below: the GCS now recommend to quote 'like this' or "like this", not `like this': <http://www.gnu.org/prep/standards/html_node/Quote-Characters.html> and several packages have already begun to comply -- among them is Automake: <http://lists.gnu.org/archive/html/bug-automake/2012-01/msg00056.html> HTH, Stefano _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictOn 21 May 2012, at 11:34, Akim Demaille wrote:
>> Is there a better way to do it? > > This is indeed a problem. I'm sure what the best way to > address this is. In addition, in some cases, creating the > files location.hh, stack.hh etc. is more troublesome than > useful. Perhaps add infixes 'loc', 'stk', etc., so that a parser with name <name> gets files <name>.loc.h <name>.stk.h etc. > Also, some people would like to be able to rename the location.hh > file. Then there would be additional rules for overriding. Hans _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 15:33, Stefano Lattarini a écrit : > Hi Akim. I'm really not knowledgeable enough to comment on this > patch proper, but I have a nit about quotation usages ... > > On 05/21/2012 02:56 PM, Akim Demaille wrote: >> >> -** liby is no longer asking for "rpl_fprintf" on some platforms. >> +** liby is no longer asking for `rpl_fprintf' on some platforms. >> > ... here and in a similar change below: the GCS now recommend to quote > 'like this' or "like this", not `like this': > > <http://www.gnu.org/prep/standards/html_node/Quote-Characters.html> > > and several packages have already begun to comply -- among them is Automake: > > <http://lists.gnu.org/archive/html/bug-automake/2012-01/msg00056.html> Hi Stefano, Yes, I am aware of this move, but actually, since currently the style is not converted in Bison, I wanted to first be consistent, as a kind of reminder. But you are right, it is actually simpler to convert right now. Note that bison, the program, is already converted, it's only NEWS. I looked at coreutils, and its NEWS uses inconsistently '' or "" (well, at least I did not understand the pattern for one or the other). Because ' is already used like this: "it's", "I'm" etc., I am tempted to promote "" over ''. This is ready to be prepended to this series of patches: From 6b1a80c331c9d01ae63587c27723d8864222f176 Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 15:52:17 +0200 Subject: [PATCH 1/5] news: convert to double quotes. * NEWS: Convert from `quoted' to "quoted". Reported by Stefano Lattarini. http://lists.gnu.org/archive/html/bison-patches/2012-05/msg00039.html --- NEWS | 276 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/NEWS b/NEWS index f554b9f..78d9494 100644 --- a/NEWS +++ b/NEWS @@ -5,8 +5,7 @@ Bison News ** Future changes: - The next major release will drop support for generating parsers in - K&R C. + The next major release will drop support for generating parsers in K&R C. ** yacc.c: YYBACKUP works as expected. @@ -14,29 +13,29 @@ Bison News *** Location support is eliminated when not requested: - GLR parsers used to include location-related code even when - locations were not requested, and therefore not even usable. + GLR parsers used to include location-related code even when locations were + not requested, and therefore not even usable. *** __attribute__ is preserved: - __attribute__ is no longer disabled when __STRICT_ANSI__ is defined - (i.e., when -std is passed to GCC). + __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e., + when -std is passed to GCC). ** lalr1.java: several fixes: - The Java parser no longer throws ArrayIndexOutOfBoundsException if - the first token leads to a syntax error. Some minor clean ups. + The Java parser no longer throws ArrayIndexOutOfBoundsException if the + first token leads to a syntax error. Some minor clean ups. ** C++11 compatibility: - C and C++ parsers use nullptr instead of 0 when __cplusplus is - 201103L or higher. + C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L + or higher. ** C++ locations: - The position and location constructors (and their initialize - methods) accept new arguments for line and column. Several issues - in the documentation were fixed. + The position and location constructors (and their initialize methods) + accept new arguments for line and column. Several issues in the + documentation were fixed. ** liby is no longer asking for "rpl_fprintf" on some platforms. @@ -44,41 +43,38 @@ Bison News *** %printer is documented - The %printer directive, supported since at least Bison 1.50, is - finally documented. The %mfcalc example is extended to demonstrate - its use of printer. + The %printer directive, supported since at least Bison 1.50, is finally + documented. The %mfcalc example is extended to demonstrate its use of + printer. - The C++ parsers now also support yyoutput (as an alias to - debug_stream ()) for consistency with the C skeletons. + The C++ parsers now also support yyoutput (as an alias to debug_stream ()) + for consistency with the C skeletons. *** Several improvements have been made: - The layout for grammar excerpts was changed to a more compact - scheme. Named references are motivated. The description of the - automaton description file (*.output) is updated to the current - format. Incorrect index entries were fixed. Some other errors were - fixed. + The layout for grammar excerpts was changed to a more compact scheme. + Named references are motivated. The description of the automaton + description file (*.output) is updated to the current format. Incorrect + index entries were fixed. Some other errors were fixed. ** Building bison: *** Conflicting prototypes with recent/modified Flex. - Fixed build problems with the current, unreleased, version of Flex, - and some modified versions of 2.5.35, which have modified function - prototypes. + Fixed build problems with the current, unreleased, version of Flex, and + some modified versions of 2.5.35, which have modified function prototypes. *** Warnings during the build procedure have been eliminated. *** Several portability problems in the test suite have been fixed: - This includes warnings with some compilers, unexpected behavior of - tools such as diff, warning messages from the test suite itself, - etc. + This includes warnings with some compilers, unexpected behavior of tools + such as diff, warning messages from the test suite itself, etc. *** The install-pdf target work properly: - Running "make install-pdf" (or -dvi, -html, -info, and -ps) no - longer halts in the middle of its course. + Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer + halts in the middle of its course. * Changes in version 2.5 (2011-05-14): @@ -137,8 +133,8 @@ Bison News %define lr.type canonical-lr The default-reduction optimization in the parser tables can also be - adjusted using `%define lr.default-reductions'. For details on both - of these features, see the new section `Tuning LR' in the Bison + adjusted using "%define lr.default-reductions". For details on both + of these features, see the new section "Tuning LR" in the Bison manual. These features are experimental. More user feedback will help to @@ -154,7 +150,7 @@ Bison News cause error recovery to begin in a different syntactic context than the one in which the invalid token was encountered. Second, when verbose error messages are enabled (with %error-verbose or the - obsolete `#define YYERROR_VERBOSE'), the expected token list in the + obsolete "#define YYERROR_VERBOSE"), the expected token list in the syntax error message can both contain invalid tokens and omit valid tokens. @@ -179,7 +175,7 @@ Bison News %define parse.lac full - See the new section `LAC' in the Bison manual for additional + See the new section "LAC" in the Bison manual for additional details including a few caveats. LAC is an experimental feature. More user feedback will help to @@ -204,7 +200,7 @@ Bison News except that the manner in which Bison processes multiple definitions for the same NAME differs. Most importantly, -F and --force-define quietly override %define, but -D and --define do not. For further - details, see the section `Bison Options' in the Bison manual. + details, see the section "Bison Options" in the Bison manual. *** Variables renamed: @@ -262,8 +258,8 @@ Bison News Similarly to the C parsers, the C++ parsers now define the YYRHSLOC macro and use it in the default YYLLOC_DEFAULT. You are encouraged - to use it. If, for instance, your location structure has `first' - and `last' members, instead of + to use it. If, for instance, your location structure has "first" + and "last" members, instead of # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ @@ -334,7 +330,7 @@ Bison News ** Verbose syntax error message fixes: - When %error-verbose or the obsolete `#define YYERROR_VERBOSE' is + When %error-verbose or the obsolete "#define YYERROR_VERBOSE" is specified, syntax error messages produced by the generated parser include the unexpected token as well as a list of expected tokens. The effect of %nonassoc on these verbose messages has been corrected @@ -345,7 +341,7 @@ Bison News in order to detect a syntax error. Because no unexpected token or expected tokens can then be reported, the verbose syntax error message described above is suppressed, and the parser instead - reports the simpler message, `syntax error'. Previously, this + reports the simpler message, "syntax error". Previously, this suppression was sometimes erroneously triggered by %nonassoc when a lookahead was actually required. Now verbose messages are suppressed only when all previous lookaheads have already been @@ -381,7 +377,7 @@ Bison News ** -W/--warnings fixes: -*** Bison now properly recognizes the `no-' versions of categories: +*** Bison now properly recognizes the "no-" versions of categories: For example, given the following command line, Bison now enables all warnings except warnings for incompatibilities with POSIX Yacc: @@ -392,7 +388,7 @@ Bison News Previously, conflict reports were independent of Bison's normal warning system. Now, Bison recognizes the warning categories - `conflicts-sr' and `conflicts-rr'. This change has important + "conflicts-sr" and "conflicts-rr". This change has important consequences for the -W and --warnings command-line options. For example: @@ -406,16 +402,16 @@ Bison News expected number of conflicts is not reported, so -W and --warning then have no effect on the conflict report. -*** The `none' category no longer disables a preceding `error': +*** The "none" category no longer disables a preceding "error": For example, for the following command line, Bison now reports errors instead of warnings for incompatibilities with POSIX Yacc: bison -Werror,none,yacc gram.y -*** The `none' category now disables all Bison warnings: +*** The "none" category now disables all Bison warnings: - Previously, the `none' category disabled only Bison warnings for + Previously, the "none" category disabled only Bison warnings for which there existed a specific -W/--warning category. However, given the following command line, Bison is now guaranteed to suppress all warnings: @@ -460,7 +456,7 @@ Bison News errors should no longer cause M4 to report a broken pipe on the affected platforms. -** `%prec IDENTIFIER' requires IDENTIFIER to be defined separately. +** "%prec IDENTIFIER" requires IDENTIFIER to be defined separately. POSIX specifies that an error be reported for any identifier that does not appear on the LHS of a grammar rule and that is not defined by @@ -515,7 +511,7 @@ Bison News that YYFAIL will automatically invoke yyerror to report the syntax error so that you don't have to. However, there are several other subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from - inherent flaws when %error-verbose or `#define YYERROR_VERBOSE' is + inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is used. For a more detailed discussion, see: http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html @@ -526,7 +522,7 @@ Bison News Bison features compatible with it. Thus, during parser generation, Bison 2.5 will produce a warning whenever it discovers YYFAIL in a rule action. In a later release, YYFAIL will be disabled for - %error-verbose and `#define YYERROR_VERBOSE'. Eventually, YYFAIL will + %error-verbose and "#define YYERROR_VERBOSE". Eventually, YYFAIL will be removed altogether. There exists at least one case where Bison 2.5's YYFAIL warning will @@ -534,7 +530,7 @@ Bison News Bison-defined macros for the sole purpose of suppressing C preprocessor warnings (from GCC cpp's -Wunused-macros, for example). To avoid Bison's future warning, such YYFAIL uses can be moved to the - epilogue (that is, after the second `%%') in the Bison input file. In + epilogue (that is, after the second "%%") in the Bison input file. In this release (2.4.2), Bison already generates its own code to suppress C preprocessor warnings for YYFAIL, so projects can remove their own phony uses of YYFAIL if compatibility with Bison releases prior to @@ -562,7 +558,7 @@ Bison News exp: exp "+" exp { $$ = $1 + $3; }; - Some grammars still depend on this `feature'. Bison 2.4.1 restores + Some grammars still depend on this "feature". Bison 2.4.1 restores the previous behavior in the case of C output (specifically, when neither %language or %skeleton or equivalent command-line options are used) to leave more time for grammars depending on the old @@ -593,7 +589,7 @@ Bison News %define NAME "VALUE" -** The directive `%pure-parser' is now deprecated in favor of: +** The directive "%pure-parser" is now deprecated in favor of: %define api.pure @@ -603,15 +599,15 @@ Bison News ** Push Parsing Bison can now generate an LALR(1) parser in C with a push interface. That - is, instead of invoking `yyparse', which pulls tokens from `yylex', you can - push one token at a time to the parser using `yypush_parse', which will + is, instead of invoking "yyparse", which pulls tokens from "yylex", you can + push one token at a time to the parser using "yypush_parse", which will return to the caller after processing each token. By default, the push interface is disabled. Either of the following directives will enable it: %define api.push_pull "push" // Just push; does not require yylex. %define api.push_pull "both" // Push and pull; requires yylex. - See the new section `A Push Parser' in the Bison manual for details. + See the new section "A Push Parser" in the Bison manual for details. The current push parsing interface is experimental and may evolve. More user feedback will help to stabilize it. @@ -623,10 +619,10 @@ Bison News ** Java Bison can now generate an LALR(1) parser in Java. The skeleton is - `data/lalr1.java'. Consider using the new %language directive instead of + "data/lalr1.java". Consider using the new %language directive instead of %skeleton to select it. - See the new section `Java Parsers' in the Bison manual for details. + See the new section "Java Parsers" in the Bison manual for details. The current Java interface is experimental and may evolve. More user feedback will help to stabilize it. @@ -641,7 +637,7 @@ Bison News ** XML Automaton Report Bison can now generate an XML report of the LALR(1) automaton using the new - `--xml' option. The current XML schema is experimental and may evolve. More + "--xml" option. The current XML schema is experimental and may evolve. More user feedback will help to stabilize it. ** The grammar file may now specify the name of the parser header file using @@ -673,31 +669,31 @@ Bison News %define lr.keep_unreachable_states - See the %define entry in the `Bison Declaration Summary' in the Bison manual + See the %define entry in the "Bison Declaration Summary" in the Bison manual for further discussion. -** Lookahead Set Correction in the `.output' Report +** Lookahead Set Correction in the ".output" Report - When instructed to generate a `.output' file including lookahead sets - (using `--report=lookahead', for example), Bison now prints each reduction's + When instructed to generate a ".output" file including lookahead sets + (using "--report=lookahead", for example), Bison now prints each reduction's lookahead set only next to the associated state's one item that (1) is associated with the same rule as the reduction and (2) has its dot at the end of its RHS. Previously, Bison also erroneously printed the lookahead set next to all of the state's other items associated with the same rule. This - bug affected only the `.output' file and not the generated parser source + bug affected only the ".output" file and not the generated parser source code. -** --report-file=FILE is a new option to override the default `.output' file +** --report-file=FILE is a new option to override the default ".output" file name. -** The `=' that used to be required in the following directives is now +** The "=" that used to be required in the following directives is now deprecated: %file-prefix "parser" %name-prefix "c_" %output "parser.c" -** An Alternative to `%{...%}' -- `%code QUALIFIER {CODE}' +** An Alternative to "%{...%}" -- "%code QUALIFIER {CODE}" Bison 2.3a provided a new set of directives as a more flexible alternative to the traditional Yacc prologue blocks. Those have now been consolidated into @@ -705,14 +701,14 @@ Bison News the purpose of the code and thus the location(s) where Bison should generate it: - 1. `%code {CODE}' replaces `%after-header {CODE}' - 2. `%code requires {CODE}' replaces `%start-header {CODE}' - 3. `%code provides {CODE}' replaces `%end-header {CODE}' - 4. `%code top {CODE}' replaces `%before-header {CODE}' + 1. "%code {CODE}" replaces "%after-header {CODE}" + 2. "%code requires {CODE}" replaces "%start-header {CODE}" + 3. "%code provides {CODE}" replaces "%end-header {CODE}" + 4. "%code top {CODE}" replaces "%before-header {CODE}" - See the %code entries in section `Bison Declaration Summary' in the Bison - manual for a summary of the new functionality. See the new section `Prologue - Alternatives' for a detailed discussion including the advantages of %code + See the %code entries in section "Bison Declaration Summary" in the Bison + manual for a summary of the new functionality. See the new section "Prologue + Alternatives" for a detailed discussion including the advantages of %code over the traditional Yacc prologues. The prologue alternatives are experimental. More user feedback will help to @@ -735,24 +731,24 @@ Bison News sometimes prove to be false alarms in existing grammars employing the Yacc constructs $0 or $-N (where N is some positive integer). - To enable these warnings, specify the option `--warnings=midrule-values' or - `-W', which is a synonym for `--warnings=all'. + To enable these warnings, specify the option "--warnings=midrule-values" or + "-W", which is a synonym for "--warnings=all". -** Default %destructor or %printer with `<*>' or `<>' +** Default %destructor or %printer with "<*>" or "<>" Bison now recognizes two separate kinds of default %destructor's and %printer's: - 1. Place `<*>' in a %destructor/%printer symbol list to define a default + 1. Place "<*>" in a %destructor/%printer symbol list to define a default %destructor/%printer for all grammar symbols for which you have formally declared semantic type tags. - 2. Place `<>' in a %destructor/%printer symbol list to define a default + 2. Place "<>" in a %destructor/%printer symbol list to define a default %destructor/%printer for all grammar symbols without declared semantic type tags. - Bison no longer supports the `%symbol-default' notation from Bison 2.3a. - `<*>' and `<>' combined achieve the same effect with one exception: Bison no + Bison no longer supports the "%symbol-default" notation from Bison 2.3a. + "<*>" and "<>" combined achieve the same effect with one exception: Bison no longer applies any %destructor to a mid-rule value if that mid-rule value is not actually ever referenced using either $$ or $n in a semantic action. @@ -760,11 +756,11 @@ Bison News feedback will help to determine whether they should become permanent features. - See the section `Freeing Discarded Symbols' in the Bison manual for further + See the section "Freeing Discarded Symbols" in the Bison manual for further details. ** %left, %right, and %nonassoc can now declare token numbers. This is required - by POSIX. However, see the end of section `Operator Precedence' in the Bison + by POSIX. However, see the end of section "Operator Precedence" in the Bison manual for a caveat concerning the treatment of literal strings. ** The nonfunctional --no-parser, -n, and %no-parser options have been @@ -798,17 +794,17 @@ Bison News %destructor { } <character> guarantees that, when the parser discards any user-defined symbol that has a - semantic type tag other than `<character>', it passes its semantic value to - `free'. However, when the parser discards a `STRING1' or a `string1', it - also prints its line number to `stdout'. It performs only the second - `%destructor' in this case, so it invokes `free' only once. + semantic type tag other than "<character>", it passes its semantic value to + "free". However, when the parser discards a "STRING1" or a "string1", it + also prints its line number to "stdout". It performs only the second + "%destructor" in this case, so it invokes "free" only once. [Although we failed to mention this here in the 2.3a release, the default %destructor's and %printer's were experimental, and they were rewritten in future versions.] -** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with `-y', - `--yacc', or `%yacc'), Bison no longer generates #define statements for +** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with "-y", + "--yacc", or "%yacc"), Bison no longer generates #define statements for associating token numbers with token names. Removing the #define statements helps to sanitize the global namespace during preprocessing, but POSIX Yacc requires them. Bison still generates an enum for token names in all cases. @@ -817,7 +813,7 @@ Bison News potentially incompatible with previous releases of Bison. As before, you declare prologue blocks in your grammar file with the - `%{ ... %}' syntax. To generate the pre-prologue, Bison concatenates all + "%{ ... %}" syntax. To generate the pre-prologue, Bison concatenates all prologue blocks that you've declared before the first %union. To generate the post-prologue, Bison concatenates all prologue blocks that you've declared after the first %union. @@ -846,7 +842,7 @@ Bison News * the code file before the contents of the header file. It does *not* * insert it into the header file. This is a good place to put * #include's that you want at the top of your code file. A common - * example is `#include "system.h"'. */ + * example is '#include "system.h"'. */ } %start-header { /* Bison inserts this block into both the header file and the code file. @@ -880,13 +876,13 @@ Bison News [Although we failed to mention this here in the 2.3a release, the prologue alternatives were experimental, and they were rewritten in future versions.] -** The option `--report=look-ahead' has been changed to `--report=lookahead'. +** The option "--report=look-ahead" has been changed to "--report=lookahead". The old spelling still works, but is not documented and may be removed in a future release. * Changes in version 2.3, 2006-06-05: -** GLR grammars should now use `YYRECOVERING ()' instead of `YYRECOVERING', +** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING", for compatibility with LALR(1) grammars. ** It is now documented that any definition of YYSTYPE or YYLTYPE should @@ -952,7 +948,7 @@ Bison News The %parse-params are available in the destructors (and the experimental printers) as per the documentation. -** Bison now warns if it finds a stray `$' or `@' in an action. +** Bison now warns if it finds a stray "$" or "@" in an action. ** %require "VERSION" This specifies that the grammar file depends on features implemented @@ -961,16 +957,16 @@ Bison News ** lalr1.cc: The token and value types are now class members. The tokens were defined as free form enums and cpp macros. YYSTYPE was defined as a free form union. They are now class members: - tokens are enumerations of the `yy::parser::token' struct, and the - semantic values have the `yy::parser::semantic_type' type. + tokens are enumerations of the "yy::parser::token" struct, and the + semantic values have the "yy::parser::semantic_type" type. If you do not want or can update to this scheme, the directive - `%define "global_tokens_and_yystype" "1"' triggers the global + '%define "global_tokens_and_yystype" "1"' triggers the global definition of tokens and YYSTYPE. This change is suitable both for previous releases of Bison, and this one. If you wish to update, then make sure older version of Bison will - fail using `%require "2.2"'. + fail using '%require "2.2"'. ** DJGPP support added. @@ -1038,10 +1034,10 @@ Bison News - A new directive "%expect-rr N" specifies the expected number of reduce/reduce conflicts in GLR parsers. - - %token numbers can now be hexadecimal integers, e.g., `%token FOO 0x12d'. + - %token numbers can now be hexadecimal integers, e.g., "%token FOO 0x12d". This is a GNU extension. - - The option `--report=lookahead' was changed to `--report=look-ahead'. + - The option "--report=lookahead" was changed to "--report=look-ahead". [However, this was changed back after 2.3.] - Experimental %destructor support has been added to lalr1.cc. @@ -1089,10 +1085,10 @@ Bison News This reverts to the behavior of Bison 1.33 and earlier, and improves compatibility with Yacc. - - `parse error' -> `syntax error' - Bison now uniformly uses the term `syntax error'; formerly, the code - and manual sometimes used the term `parse error' instead. POSIX - requires `syntax error' in diagnostics, and it was thought better to + - "parse error" -> "syntax error" + Bison now uniformly uses the term "syntax error"; formerly, the code + and manual sometimes used the term "parse error" instead. POSIX + requires "syntax error" in diagnostics, and it was thought better to be consistent. - The documentation now emphasizes that yylex and yyerror must be @@ -1105,7 +1101,7 @@ Bison News output as "foo\\bar.y". - Yacc command and library now available - The Bison distribution now installs a `yacc' command, as POSIX requires. + The Bison distribution now installs a "yacc" command, as POSIX requires. Also, Bison now installs a small library liby.a containing implementations of Yacc-compatible yyerror and main functions. This library is normally not useful, but POSIX requires it. @@ -1118,20 +1114,20 @@ Bison News ** Other compatibility issues - - %union directives can now have a tag before the `{', e.g., the - directive `%union foo {...}' now generates the C code - `typedef union foo { ... } YYSTYPE;'; this is for Yacc compatibility. - The default union tag is `YYSTYPE', for compatibility with Solaris 9 Yacc. - For consistency, YYLTYPE's struct tag is now `YYLTYPE' not `yyltype'. + - %union directives can now have a tag before the "{", e.g., the + directive "%union foo {...}" now generates the C code + "typedef union foo { ... } YYSTYPE;"; this is for Yacc compatibility. + The default union tag is "YYSTYPE", for compatibility with Solaris 9 Yacc. + For consistency, YYLTYPE's struct tag is now "YYLTYPE" not "yyltype". This is for compatibility with both Yacc and Bison 1.35. - - `;' is output before the terminating `}' of an action, for + - ";" is output before the terminating "}" of an action, for compatibility with Bison 1.35. - Bison now uses a Yacc-style format for conflict reports, e.g., - `conflicts: 2 shift/reduce, 1 reduce/reduce'. + "conflicts: 2 shift/reduce, 1 reduce/reduce". - - `yystype' and `yyltype' are now obsolescent macros instead of being + - "yystype" and "yyltype" are now obsolescent macros instead of being typedefs or tags; they are no longer documented and are planned to be withdrawn in a future release. @@ -1139,13 +1135,13 @@ Bison News - GLR and inline Users of Bison have to decide how they handle the portability of the - C keyword `inline'. + C keyword "inline". - - `parsing stack overflow...' -> `parser stack overflow' - GLR parsers now report `parser stack overflow' as per the Bison manual. + - "parsing stack overflow..." -> "parser stack overflow" + GLR parsers now report "parser stack overflow" as per the Bison manual. ** Bison now warns if it detects conflicting outputs to the same file, - e.g., it generates a warning for `bison -d -o foo.h foo.y' since + e.g., it generates a warning for "bison -d -o foo.h foo.y" since that command outputs both code and header to foo.h. ** #line in output files @@ -1202,8 +1198,8 @@ Bison News ** Output Directory When not in Yacc compatibility mode, when the output file was not - specified, running `bison foo/bar.y' created `foo/bar.c'. It - now creates `bar.c'. + specified, running "bison foo/bar.y" created "foo/bar.c". It + now creates "bar.c". ** Undefined token The undefined token was systematically mapped to 2 which prevented @@ -1220,11 +1216,11 @@ Bison News will be mapped onto another number. ** Verbose error messages - They no longer report `..., expecting error or...' for states where + They no longer report "..., expecting error or..." for states where error recovery is possible. ** End token - Defaults to `$end' instead of `$'. + Defaults to "$end" instead of "$". ** Error recovery now conforms to documentation and to POSIX When a Bison-generated parser encounters a syntax error, it now pops @@ -1261,7 +1257,7 @@ Bison News Rules that can never be reduced because of conflicts are now reported. -** Incorrect `Token not used' +** Incorrect "Token not used" On a grammar such as %token useless useful @@ -1269,7 +1265,7 @@ Bison News exp: '0' %prec useful; where a token was used to set the precedence of the last rule, - bison reported both `useful' and `useless' as useless tokens. + bison reported both "useful" and "useless" as useless tokens. ** Revert the C++ namespace changes introduced in 1.31 as they caused too many portability hassles. @@ -1283,7 +1279,7 @@ Bison News ** Token end-of-file The token end of file may be specified by the user, in which case, the user symbol is used in the reports, the graphs, and the verbose - error messages instead of `$end', which remains being the default. + error messages instead of "$end", which remains being the default. For instance %token MYEOF 0 or @@ -1297,7 +1293,10 @@ Bison News Croatian, thanks to Denis Lackovic. ** Incorrect token definitions - When given `%token 'a' "A"', Bison used to output `#define 'a' 65'. + When given + %token 'a' "A" + bison used to output + #define 'a' 65 ** Token definitions as enums Tokens are output both as the traditional #define's, and, provided @@ -1309,7 +1308,7 @@ Bison News produces additional information: - itemset complete the core item sets with their closure - - lookahead [changed to `look-ahead' in 1.875e through 2.3, but changed back] + - lookahead [changed to "look-ahead" in 1.875e through 2.3, but changed back] explicitly associate lookahead tokens to items - solved describe shift/reduce conflicts solving. @@ -1347,9 +1346,9 @@ Bison News ** File name clashes are detected $ bison foo.y -d -o foo.x - fatal error: header and parser would both be named `foo.x' + fatal error: header and parser would both be named "foo.x" -** A missing `;' at the end of a rule triggers a warning +** A missing ";" at the end of a rule triggers a warning In accordance with POSIX, and in agreement with other Yacc implementations, Bison will mandate this semicolon in the near future. This eases the implementation of a Bison parser of Bison @@ -1388,7 +1387,7 @@ Bison News GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that Bison dies on incorrect %expectations, we fear there will be too many bug reports for Gettext, so _for the time being_, %expect - does not trigger an error when the input file is named `plural.y'. + does not trigger an error when the input file is named "plural.y". ** Use of alloca in parsers If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use @@ -1465,15 +1464,15 @@ Bison News New. ** --output - New, aliasing `--output-file'. + New, aliasing "--output-file". * Changes in version 1.30, 2001-10-26: -** `--defines' and `--graph' have now an optional argument which is the - output file name. `-d' and `-g' do not change; they do not take any +** "--defines" and "--graph" have now an optional argument which is the + output file name. "-d" and "-g" do not change; they do not take any argument. -** `%source_extension' and `%header_extension' are removed, failed +** "%source_extension" and "%header_extension" are removed, failed experiment. ** Portability fixes. @@ -1483,9 +1482,9 @@ Bison News ** The output file does not define const, as this caused problems when used with common autoconfiguration schemes. If you still use ancient compilers that lack const, compile with the equivalent of the C compiler option - `-Dconst='. Autoconf's AC_C_CONST macro provides one way to do this. + "-Dconst=". Autoconf's AC_C_CONST macro provides one way to do this. -** Added `-g' and `--graph'. +** Added "-g" and "--graph". ** The Bison manual is now distributed under the terms of the GNU FDL. @@ -1497,18 +1496,18 @@ Bison News ** Added the old Bison reference card. -** Added `--locations' and `%locations'. +** Added "--locations" and "%locations". -** Added `-S' and `--skeleton'. +** Added "-S" and "--skeleton". -** `%raw', `-r', `--raw' is disabled. +** "%raw", "-r", "--raw" is disabled. ** Special characters are escaped when output. This solves the problems of the #line lines with path names including backslashes. ** New directives. - `%yacc', `%fixed_output_files', `%defines', `%no_parser', `%verbose', - `%debug', `%source_extension' and `%header_extension'. + "%yacc", "%fixed_output_files", "%defines", "%no_parser", "%verbose", + "%debug", "%source_extension" and "%header_extension". ** @$ Automatic location tracking. @@ -1625,4 +1624,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. Local Variables: mode: outline +fill-column: 76 End: -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 15:41, Hans Aberg a écrit : > On 21 May 2012, at 11:34, Akim Demaille wrote: > >>> Is there a better way to do it? >> >> This is indeed a problem. I'm sure what the best way to >> address this is. In addition, in some cases, creating the >> files location.hh, stack.hh etc. is more troublesome than >> useful. > > Perhaps add infixes 'loc', 'stk', etc., so that a parser with name <name> gets files > <name>.loc.h > <name>.stk.h > etc. Actually I want to have stack.hh disapear (it does not need to be exposed). It's a good idea though for the others, but since people want to be able to rename, it shall be more general. position.hh does not need to exist either, it can live within location.hh. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictOn 05/21/2012 04:00 PM, Akim Demaille wrote:
> > Le 21 mai 2012 à 15:33, Stefano Lattarini a écrit : > >> Hi Akim. I'm really not knowledgeable enough to comment on this >> patch proper, but I have a nit about quotation usages ... >> >> On 05/21/2012 02:56 PM, Akim Demaille wrote: >>> >>> -** liby is no longer asking for "rpl_fprintf" on some platforms. >>> +** liby is no longer asking for `rpl_fprintf' on some platforms. >>> >> ... here and in a similar change below: the GCS now recommend to quote >> 'like this' or "like this", not `like this': >> >> <http://www.gnu.org/prep/standards/html_node/Quote-Characters.html> >> >> and several packages have already begun to comply -- among them is Automake: >> >> <http://lists.gnu.org/archive/html/bug-automake/2012-01/msg00056.html> > > > Hi Stefano, > > Yes, I am aware of this move, but actually, since currently > the style is not converted in Bison, I wanted to first be > consistent, as a kind of reminder. > > But you are right, it is actually simpler to convert right now. > > Note that bison, the program, is already converted, > Ah, in fact I seemed to remember some related Great Testsuite Churning not much time ago :-) > it's only NEWS. > Are you sure it is worth to convert also older NEWS entry to the new quoting format? For example, in Automake, we haven't done so. Note however that I have no strong feelings on the issue, and I'm not even suggesting that you should not convert the older entries; just giving food for thought. I looked at coreutils, and its NEWS uses inconsistently > '' or "" (well, at least I did not understand the pattern for > one or the other). > > Because ' is already used like this: "it's", "I'm" etc., I > am tempted to promote "" over ''. > Personally, I'd use "" for sentences or quasi-sentences, and '' for stuff like options, constants, variables, commit IDs, etc. For example, ... > ** C++11 compatibility: > > - C and C++ parsers use nullptr instead of 0 when __cplusplus is > - 201103L or higher. > + C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L > + or higher. > ... here I'd use '' ... > @@ -137,8 +133,8 @@ Bison News > %define lr.type canonical-lr > > The default-reduction optimization in the parser tables can also be > - adjusted using `%define lr.default-reductions'. For details on both > - of these features, see the new section `Tuning LR' in the Bison > + adjusted using "%define lr.default-reductions". For details on both > + of these features, see the new section "Tuning LR" in the Bison > manual. > just a matter of personal taste. Regards, Stefano _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 16:30, Stefano Lattarini a écrit : >> it's only NEWS. >> > Are you sure it is worth to convert also older NEWS entry to the new > quoting format? Yes, I prefer. That's just more consistent. > Personally, I'd use "" for sentences or quasi-sentences, and '' for > stuff like options, constants, variables, commit IDs, etc. Yes, that's also what I do for Texinfo for instance, but here, I wanted something simple. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictOn 21 May 2012, at 16:02, Akim Demaille wrote:
> Le 21 mai 2012 à 15:41, Hans Aberg a écrit : > >> On 21 May 2012, at 11:34, Akim Demaille wrote: >> >>>> Is there a better way to do it? >>> >>> This is indeed a problem. I'm sure what the best way to >>> address this is. In addition, in some cases, creating the >>> files location.hh, stack.hh etc. is more troublesome than >>> useful. >> >> Perhaps add infixes 'loc', 'stk', etc., so that a parser with name <name> gets files >> <name>.loc.h >> <name>.stk.h >> etc. > > Actually I want to have stack.hh disapear (it does not > need to be exposed). It's a good idea though for the > others, but since people want to be able to rename, > it shall be more general. > > position.hh does not need to exist either, it can live > within location.hh. Is there any reason to not put all stuff that is public in the parser header? This would eliminate the need for any additional header files. Hans _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
RFC: header file guards conflictLe 21 mai 2012 à 14:56, Akim Demaille a écrit : > This is the patch that really computes the header guards. > >> From eb76fadde9c5a3b23dc6761ddd4d267a6e7c3965 Mon Sep 17 00:00:00 2001 > From: Akim Demaille <akim@...> > Date: Mon, 21 May 2012 14:21:51 +0200 > Subject: [PATCH 4/4] c++: compute the header guards. On second thought, I see no good reason to do this from C, m4 can do it. I first went for C since that's the way we handle @basename, but since we escape dangerous characters (equivalent to Autoconf's quadrigraphs), I fail to see the need. I could not have it fail, even with directory names such as [(". Also, instead of mapping every single non-alnum to _, I now collapse such series into a single _. So, for instance: /** ** \file ../../../../examples/calc++/calc++-parser.hh ** Define the yy::parser class. */ that had: +#ifndef YY_____________EXAMPLES_CALC___CALC___PARSER_HH +# define YY_____________EXAMPLES_CALC___CALC___PARSER_HH in the first version of the patch, now has: +#ifndef YY_EXAMPLES_CALC_CALC_PARSER_HH +# define YY_EXAMPLES_CALC_CALC_PARSER_HH From 22172d473180c53755290f13ebd2d53e12e74fe0 Mon Sep 17 00:00:00 2001 From: Akim Demaille <akim@...> Date: Mon, 21 May 2012 14:21:51 +0200 Subject: [PATCH] c++: compute the header guards. This is a frequent request. Recently pointed out by Wei Song, <http://lists.gnu.org/archive/html/help-bison/2012-05/msg00002.html>. * data/c.m4 (b4_tocpp, b4_cpp_guard, b4_cpp_guard_open) (b4_cpp_guard_close): New. * data/lalr1.cc, data/location.cc, data/stack.hh: Use them. * TODO (Header Guards): Move to... * NEWS: here. Formatting changes. --- NEWS | 27 +++++++++++++++++++++++++-- THANKS | 1 + TODO | 4 ---- data/c.m4 | 27 +++++++++++++++++++++++++++ data/lalr1.cc | 11 ++++------- data/location.cc | 10 ++++------ data/stack.hh | 6 ++---- 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 27c4974..4fadf4e 100644 --- a/NEWS +++ b/NEWS @@ -26,12 +26,35 @@ Bison News The Java parser no longer throws ArrayIndexOutOfBoundsException if the first token leads to a syntax error. Some minor clean ups. -** C++11 compatibility: +** Changes for C++: + +*** C++11 compatibility: C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L or higher. -** C++ locations: +*** Header guards + + The header files such as "parser.hh", "location.hh", etc. used a constant + name for preprocessor guards, for instance: + + #ifndef BISON_LOCATION_HH + # define BISON_LOCATION_HH + ... + #endif // !BISON_LOCATION_HH + + The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower + case characters are converted to upper case, and series of + non-alphanumerical characters are converted to an underscore. + + With "bison -o lang++/parser.cc", "location.hh" would now include: + + #ifndef YY_LANG_LOCATION_HH + # define YY_LANG_LOCATION_HH + ... + #endif // !YY_LANG_LOCATION_HH + +*** C++ locations: The position and location constructors (and their initialize methods) accept new arguments for line and column. Several issues in the diff --git a/THANKS b/THANKS index 6d0d89e..e3bf221 100644 --- a/THANKS +++ b/THANKS @@ -112,6 +112,7 @@ Tys Lefering gccbison@... Vin Shelton acs@... W.C.A. Wijngaards wouter@... Wayne Green wayne@... +Wei Song wsong83@... Wolfgang S. Kechel wolfgang.kechel@... Wolfram Wagner ww@... Wwp subscript@... diff --git a/TODO b/TODO index d86d8d8..21ef4b9 100644 --- a/TODO +++ b/TODO @@ -125,10 +125,6 @@ we do the same in yacc.c. The code bw glr.c and yacc.c is really alike, we can certainly factor some parts. -* Header guards - -From François: should we keep the directory part in the CPP guard? - * Yacc.c: CPP Macros diff --git a/data/c.m4 b/data/c.m4 index fee006a..b49d6dc 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -17,6 +17,33 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + +# b4_tocpp(STRING) +# ---------------- +# Convert STRING into a valid C macro name. +m4_define([b4_tocpp], +[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) + + +# b4_cpp_guard(FILE) +# ------------------ +# A valid C macro name to use as a CPP header guard for FILE. +m4_define([b4_cpp_guard], +[b4_tocpp(m4_defn([b4_prefix])/[$1])]) + + +# b4_cpp_guard_open(FILE) +# b4_cpp_guard_close(FILE) +# ------------------------ +# Open/close CPP inclusion guards for FILE. +m4_define([b4_cpp_guard_open], +[#ifndef b4_cpp_guard([$1]) +# define b4_cpp_guard([$1])]) + +m4_define([b4_cpp_guard_close], +[#endif b4_comment([!b4_cpp_guard([$1])])]) + + ## ---------------- ## ## Identification. ## ## ---------------- ## diff --git a/data/lalr1.cc b/data/lalr1.cc index 0fe3aee..4f0b268 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -37,7 +37,6 @@ b4_defines_if( [@output(b4_spec_defines_file@)@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++], [2002-2012]) -dnl FIXME: This is wrong, we want computed header guards. [ /** ** \file ]b4_spec_defines_file[ @@ -46,8 +45,7 @@ dnl FIXME: This is wrong, we want computed header guards. /* C++ LALR(1) parser skeleton written by Akim Demaille. */ -#ifndef PARSER_HEADER_H -# define PARSER_HEADER_H +]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_percent_code_get([[requires]])[ @@ -283,10 +281,9 @@ b4_user_stype /* Redirection for backward compatibility. */ # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type #endif -]) -b4_percent_code_get([[provides]])[]dnl - -[#endif /* ! defined PARSER_HEADER_H */] +])[ +]b4_percent_code_get([[provides]])[ +]b4_cpp_guard_close([b4_spec_defines_file]) ])dnl @output(b4_parser_file_name@)@ b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++], diff --git a/data/location.cc b/data/location.cc index 0ee02c2..f45f634 100644 --- a/data/location.cc +++ b/data/location.cc @@ -27,8 +27,7 @@ b4_copyright([Positions for Bison parsers in C++], ** Define the ]b4_namespace_ref[::position class. */ -#ifndef BISON_POSITION_HH -# define BISON_POSITION_HH +]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[ # include <iostream> # include <string> @@ -148,7 +147,7 @@ b4_copyright([Positions for Bison parsers in C++], } ]b4_namespace_close[ -#endif // not BISON_POSITION_HH] +]b4_cpp_guard_close([b4_dir_prefix[]position.hh]) @output(b4_dir_prefix[]location.hh@)@ b4_copyright([Locations for Bison parsers in C++], [2002-2007, 2009-2012])[ @@ -158,8 +157,7 @@ b4_copyright([Locations for Bison parsers in C++], ** Define the ]b4_namespace_ref[::location class. */ -#ifndef BISON_LOCATION_HH -# define BISON_LOCATION_HH +]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[ # include <iostream> # include <string> @@ -295,6 +293,6 @@ b4_copyright([Locations for Bison parsers in C++], ]b4_namespace_close[ -#endif // not BISON_LOCATION_HH] +]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) m4_divert_pop(0) m4_changecom([#]) diff --git a/data/stack.hh b/data/stack.hh index 5293377..ddedc79 100644 --- a/data/stack.hh +++ b/data/stack.hh @@ -30,8 +30,7 @@ b4_copyright([Stack handling for Bison parsers in C++], ** Define the ]b4_namespace_ref[::stack class. */ -#ifndef BISON_STACK_HH -# define BISON_STACK_HH +]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ # include <deque> @@ -119,8 +118,7 @@ b4_copyright([Stack handling for Bison parsers in C++], }; ]b4_namespace_close[ -#endif // not BISON_STACK_HH[]dnl -] +]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) m4_divert_pop(0) m4_popdef([b4_copyright_years])dnl m4_changecom([#]) -- 1.7.10.2 _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 17:55, Hans Aberg a écrit : > Is there any reason to not put all stuff that is public in the parser header? This would eliminate the need for any additional header files. That's the plan for those that need not be public. location.hh is different: you may use it for your ASTs if you wish. I, for one, do that. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictOn 21 May 2012, at 18:17, Akim Demaille wrote:
> Le 21 mai 2012 à 17:55, Hans Aberg a écrit : > >> Is there any reason to not put all stuff that is public in the parser header? This would eliminate the need for any additional header files. > > That's the plan for those that need not be public. > location.hh is different: you may use it for your > ASTs if you wish. I, for one, do that. Hm, I meant: put all stuff that the user might access in the parser header, and the other stuff in the parser source. The names belonging to different parsers won't collide if given different namespaces. Hans _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictLe 21 mai 2012 à 18:27, Hans Aberg a écrit : > On 21 May 2012, at 18:17, Akim Demaille wrote: > >> Le 21 mai 2012 à 17:55, Hans Aberg a écrit : >> >>> Is there any reason to not put all stuff that is public in the parser header? This would eliminate the need for any additional header files. >> >> That's the plan for those that need not be public. >> location.hh is different: you may use it for your >> ASTs if you wish. I, for one, do that. > > Hm, I meant: put all stuff that the user might access in the parser header, and the other stuff in the parser source. The names belonging to different parsers won't collide if given different namespaces. That's too much dependencies to inject. An AST does not need details about the parser, especially since these details may change when you touch the grammar. Even adding empty lines in the grammar can change the header. It would be disastrous to force a compilation of an AST hierarchy because of an eager #include where location.hh would suffice. Besides, when possible, it is certainly desirable to keep a single version of the code, to avoid bloating the binary. Weaker argument in the present case, I agree. _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
|
|
Re: header file guards conflictOn 21 May 2012, at 18:34, Akim Demaille wrote:
> Le 21 mai 2012 à 18:27, Hans Aberg a écrit : > >> On 21 May 2012, at 18:17, Akim Demaille wrote: >> >>> Le 21 mai 2012 à 17:55, Hans Aberg a écrit : >>> >>>> Is there any reason to not put all stuff that is public in the parser header? This would eliminate the need for any additional header files. >>> >>> That's the plan for those that need not be public. >>> location.hh is different: you may use it for your >>> ASTs if you wish. I, for one, do that. >> >> Hm, I meant: put all stuff that the user might access in the parser header, and the other stuff in the parser source. The names belonging to different parsers won't collide if given different namespaces. > > That's too much dependencies to inject. An AST does > not need details about the parser, especially since these > details may change when you touch the grammar. Even adding > empty lines in the grammar can change the header. It would > be disastrous to force a compilation of an AST hierarchy > because of an eager #include where location.hh would > suffice. > > Besides, when possible, it is certainly desirable to keep > a single version of the code, to avoid bloating the binary. > Weaker argument in the present case, I agree. So there should be more than one header. In order to separate them for different parsers residing the same directory, the simplest default seems to mark all filenames with the name of the parser. Hans _______________________________________________ help-bison@... https://lists.gnu.org/mailman/listinfo/help-bison |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |