bug-bison
[Top][All Lists]
Advanced

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

Re: Bison 1.30f


From: Hans Aberg
Subject: Re: Bison 1.30f
Date: Tue, 11 Dec 2001 12:58:50 +0100

At 13:04 -0800 2001/12/10, Paul Eggert wrote:
>If so, it seems to me that the following patch would be worthwhile
>even before we modify Bison to output beautiful C++ code.  Hans, can
>you please check whether it works for you with C++?  (It passes
>Bison's 'make check' test for C.)

I get the following output, which is not in the skeleton file:
  #ifndef YYSTYPE
  #define YYSTYPE int
  #endif
  #include <stdio.h>
The Bison source file files.h says:
  /* If semantic parser, output a .h file that defines YYSTYPE... */
  extern struct obstack attrs_obstack;
so I figure this text is output by the Bison program. I figure that you
could try to move this to the bison.simple file, so that it outputs
  #ifndef YYSTYPE
  #define YYSTYPE int
  #endif
  #ifdef __cplusplus
  # include <cstddef>
  #else
  # include <stdio.h>
  #endif

Also, I wonder what happens with the sequence (in bison.simple)
  # if YYSTACK_USE_ALLOCA
  #  define YYSTACK_ALLOC alloca
  #  define YYSIZE_T size_t
If you later have
  #  ifdef __cplusplus
  ...
  #   define YYSIZE_T std::size_t
you will get an erroneous macro redefinition. Pehrpas, under C++, one
should have
  #   define YYSIZE_T std::size_t
  using std::size_t;
If you have #include <cstdlib>, then it be sufficient to add
  using std::size_t;
But the problem is which one should come first: The alloca test, or the
#include <cstdlib>, and to make sure YYSIZE_T is not redefined.

Also, if I put in my .y file:
  #define YYSTACK_USE_ALLOCA 1
I get the "Error   : undefined identifier 'alloca'". The reason is that the
bison.simple alloca test does not #include <alloca.h>. This may be fixed by
changing to:
# if YYSTACK_USE_ALLOCA
#  include <alloca.h>
#  define YYSTACK_ALLOC alloca
...
at the beginning of the alloca test i bison.simple.

As for the comment (a little further down):
#      include <alloca.h> /* INFRINGES ON USER NAME SPACE */
it should probably be
#      include <alloca.h> /* MAY INFRINGE ON USER NAME SPACE */

When YYSTACK_USE_ALLOCA is not defined, it currently merely chooses malloc,
etc; this is OK with me. But I figure it means that the portion of the
alloca test:
#  ifndef YYSTACK_USE_ALLOCA
#   if defined (alloca) || defined (_ALLOCA_H)
#    define YYSTACK_ALLOC alloca
#    define YYSIZE_T size_t
will never be used.

You have forgotten to pick out some comments, such as:
  # ifdef __cplusplus
  #  include <cstddef> /* INFRINGES ON USER NAME SPACE */
  #  define YYSIZE_T std::size_t
as it now does not infringe on namespaces. (As a matter of style, one might
write
  # ifdef __cplusplus
  #  include <cstddef> // DOES NOT INFRINGE ON USER NAME SPACE
  #  define YYSIZE_T std::size_t
if one wants to make it even further clear that it is under C++.)

(I recall that my compiler has a flaw that makes it difficult to check the
C++ namespace correctness fully: Instead of adding a "using" directive for
every name, it adds a "using namespace std" in the C compatibility headers.
So if I get only one such header, it destroys it. Later versions of the
compiler has fixed this one.)

Modulo the above said, it compiled in the various YYSTACK_USE_ALLOCA
combinations, though.

  Hans Aberg





reply via email to

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