[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposed Bison patch for YYDEBUG for POSIX compliance
From: |
Paul Eggert |
Subject: |
proposed Bison patch for YYDEBUG for POSIX compliance |
Date: |
Fri, 14 Dec 2001 18:24:34 -0800 (PST) |
Here's a proposed patch to fix one or two POSIX-compliance bugs in Bison.
* POSIX says that YYDEBUG must be defined to be 0 if the user never specifies
debugging, but the Bison-generated parser leaves YYDEBUG undefined.
* This is a very minor point, but POSIX doesn't seem to require that
the user must YYDEBUG to a parenthesized expression, e.g. `#define
YYDEBUG 0 ? 0 : 1' seems to be allowed. We might as well survive
such programs while we're at it.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.173.2.229
diff -p -u -r1.173.2.229 ChangeLog
--- ChangeLog 13 Dec 2001 11:14:19 -0000 1.173.2.229
+++ ChangeLog 15 Dec 2001 02:20:56 -0000
@@ -1,3 +1,12 @@
+2001-12-14 Paul Eggert <address@hidden>
+
+ * src/output.c (output): Define YYDEBUG to 0 if it is not defined
+ and if we are not debugging.
+ * NEWS, doc/bison.texinfo, doc/bison.1, doc/bison.rnh: Document this.
+
+ * src/output.c (output_gram, output_rule_data): Do not assume that
+ the user defines YYDEBUG to a properly parenthesized expression.
+
2001-12-13 Akim Demaille <address@hidden>
Version 1.30g.
Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.21.2.36
diff -p -u -r1.21.2.36 NEWS
--- NEWS 13 Dec 2001 12:07:47 -0000 1.21.2.36
+++ NEWS 15 Dec 2001 02:20:56 -0000
@@ -3,6 +3,9 @@ Bison News
Changes in version 1.30h:
+* When the generated parser lacks debugging code, YYDEBUG is now 0 instead
+ undefined, as POSIX requires.
+
Changes in version 1.30g:
* Bug fixes
cvs server: Diffing config
cvs server: Diffing doc
Index: doc/bison.1
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.1,v
retrieving revision 1.7.2.3
diff -p -u -r1.7.2.3 bison.1
--- doc/bison.1 19 Sep 2001 13:09:32 -0000 1.7.2.3
+++ doc/bison.1 15 Dec 2001 02:20:56 -0000
@@ -262,9 +262,9 @@ and so on.
.ns
.TP
.B \-\-debug
-Output a definition of the macro
+In the parser file, define the macro
.B YYDEBUG
-into the parser file,
+to 1 if it is not already defined,
so that the debugging facilities are compiled.
.TP
.B \-v
Index: doc/bison.rnh
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.rnh,v
retrieving revision 1.2
diff -p -u -r1.2 bison.rnh
--- doc/bison.rnh 16 Oct 1995 14:11:03 -0000 1.2
+++ doc/bison.rnh 15 Dec 2001 02:20:56 -0000
@@ -56,7 +56,8 @@ foo_tab.c.
.indent -1
2 /DEBUG
.skip
-Output a definition of the macro YYDEBUG into the parser file,
+In the parser file,
+define the macro YYDEBUG to 1 if it is not already defined,
so that the debugging facilities are compiled.
.skip
.indent -1
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.37.2.12
diff -p -u -r1.37.2.12 bison.texinfo
--- doc/bison.texinfo 13 Dec 2001 02:45:14 -0000 1.37.2.12
+++ doc/bison.texinfo 15 Dec 2001 02:20:58 -0000
@@ -708,8 +708,8 @@ headers. On some address@hidden hosts, @c
@code{<stddef.h>}, and @code{<stdlib.h>} are included as needed to
declare memory allocators and related types. In the same situation,
C++ parsers may include @code{<cstddef>} and @code{<cstdlib>} instead.
-Other system headers may be included if you define @code{YYDEBUG}
-(@pxref{Debugging, ,Debugging Your Parser}).
+Other system headers may be included if you define @code{YYDEBUG} to a
+nonzero value (@pxref{Debugging, ,Debugging Your Parser}).
@node Stages
@section Stages in Using Bison
@@ -3235,9 +3235,9 @@ directives:
@table @code
@item %debug
-Output a definition of the macro @code{YYDEBUG} into the parser file, so
-that the debugging facilities are compiled. @xref{Debugging, ,Debugging
-Your Parser}.
+In the parser file, define the macro @code{YYDEBUG} to 1 if it is not
+already defined, so that the debugging facilities are compiled.
address@hidden, ,Debugging Your Parser}.
@item %defines
Write an extra output file containing macro definitions for the token
@@ -4925,21 +4925,23 @@ If a Bison grammar compiles properly but
runs, the @code{yydebug} parser-trace feature can help you figure out why.
To enable compilation of trace facilities, you must define the macro
address@hidden when you compile the parser. You could use
address@hidden as a compiler option or you could put @samp{#define
-YYDEBUG 1} in the C declarations section of the grammar file
-(@pxref{C Declarations, ,The C Declarations Section}). Alternatively, use the
@samp{-t} option when
-you run Bison (@pxref{Invocation, ,Invoking Bison}). We always define
@code{YYDEBUG} so that
-debugging is always possible.
address@hidden to a nonzero value when you compile the parser. You
+could use @samp{-DYYDEBUG=1} as a compiler option or you could put
address@hidden YYDEBUG 1} in the C declarations section of the grammar
+file (@pxref{C Declarations, ,The C Declarations Section}).
+Alternatively, use the @samp{-t} option when you run Bison
+(@pxref{Invocation, ,Invoking Bison}) or the @code{%debug} declaration
+(@pxref{Decl Summary, ,Bison Declaration Summary}). We suggest that
+you always define @code{YYDEBUG} so that debugging is always possible.
The trace facility outputs messages with macro calls of the form
@code{YYFPRINTF (YYSTDERR, @var{format}, @var{args})} where
@var{format} and @var{args} are the usual @code{printf} format and
-arguments. If you define @code{YYDEBUG} but do not define
address@hidden, @code{<stdio.h>} is automatically included and the
-macros are defined to @code{fprintf} and @code{stderr}. In the same
-situation, C++ parsers include @code{<cstdio.h>} instead, and use
address@hidden::fprintf} and @code{std::stderr}.
+arguments. If you define @code{YYDEBUG} to a nonzero value but do not
+define @code{YYFPRINTF}, @code{<stdio.h>} is automatically included
+and the macros are defined to @code{fprintf} and @code{stderr}. In
+the same situation, C++ parsers include @code{<cstdio.h>} instead, and
+use @code{std::fprintf} and @code{std::stderr}.
Once you have compiled the program with trace facilities, the way to
request a trace is to store a nonzero value in the variable @code{yydebug}.
@@ -5100,9 +5102,9 @@ you are developing Bison.
@item -t
@itemx --debug
-Output a definition of the macro @code{YYDEBUG} into the parser file, so
-that the debugging facilities are compiled. @xref{Debugging, ,Debugging
-Your Parser}.
+In the parser file, define the macro @code{YYDEBUG} to 1 if it is not
+already defined, so that the debugging facilities are compiled.
address@hidden, ,Debugging Your Parser}.
@item --locations
Pretend that @code{%locations} was specified. @xref{Decl Summary}.
cvs server: Diffing etc
cvs server: Diffing intl
cvs server: Diffing lib
cvs server: Diffing m4
cvs server: Diffing po
cvs server: Diffing src
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.39.2.18
diff -p -u -r1.39.2.18 output.c
--- src/output.c 13 Dec 2001 02:21:12 -0000 1.39.2.18
+++ src/output.c 15 Dec 2001 02:20:58 -0000
@@ -316,7 +316,7 @@ output_gram (void)
yyprhs and yyrhs are needed only for yydebug. */
/* With the no_parser option, all tables are generated */
if (!semantic_parser && !no_parser_flag)
- obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n");
+ obstack_sgrow (&table_obstack, "\n#if YYDEBUG\n");
{
int i;
@@ -372,7 +372,7 @@ output_rule_data (void)
short *short_tab = NULL;
obstack_sgrow (&table_obstack, "\n\
-#if YYDEBUG != 0\n");
+#if YYDEBUG\n");
{
short *values = XCALLOC (short, nrules + 1);
@@ -400,7 +400,7 @@ output_rule_data (void)
/* Output the table of symbol names. */
if (!token_table_flag && !no_parser_flag)
obstack_sgrow (&table_obstack,
- "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n");
+ "\n#if (YYDEBUG) || defined YYERROR_VERBOSE\n\n");
obstack_sgrow (&table_obstack, "\
/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n");
obstack_sgrow (&table_obstack,
@@ -1268,12 +1268,11 @@ output (void)
obstack_grow (&table_obstack, obstack_finish (&attrs_obstack), size);
}
reader_output_yylsp (&table_obstack);
- if (debug_flag)
- obstack_sgrow (&table_obstack, "\
+ obstack_fgrow1 (&table_obstack, "\
#ifndef YYDEBUG\n\
-# define YYDEBUG 1\n\
+# define YYDEBUG %d\n\
#endif\n\
-\n");
+\n", debug_flag);
if (semantic_parser)
obstack_fgrow1 (&table_obstack, "#include %s\n",
cvs server: Diffing tests
- proposed Bison patch for YYDEBUG for POSIX compliance,
Paul Eggert <=