[Top][All Lists]

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

Re: DR Grammars

From: Akim Demaille
Subject: Re: DR Grammars
Date: 19 Apr 2002 16:04:48 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

>>>>> "Tim" == Tim Josling <address@hidden> writes:

Tim> Here are some bugs and/or suggested improvements to the bison
Tim> manual.

Tim> S3.5.3. Add a note that in bison, unlike flex, the action only
Tim> applies to the last rule, eg

Tim> X: a|b { x_found = 1;}

Tim> x_found will only be set if the 'b' variation is foundbut not if
Tim> the 'a' variation is found.

Tim> Appendix A. Add mention of YYDEBUG and also of @n.

Tim> I'll send in patches to this effect, once the CVS source is fixed
Tim> (currently the info does not build),

Better some day than never...  I'm applying this:

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * doc/bison.texinfo (Actions): Make clear that `|' is not the same
        as Lex/Flex'.
        (Debugging): More details about enabling the debugging features.
        (Table of Symbols): Describe $$, $n, @$, and @n.
        Suggested by Tim Josling.

RCS file: /cvsroot/bison/bison/THANKS,v
retrieving revision 1.36
diff -u -u -r1.36 THANKS
--- THANKS 6 Mar 2002 16:08:18 -0000 1.36
+++ THANKS 19 Apr 2002 14:03:30 -0000
@@ -41,6 +41,7 @@
 Richard Stallman        address@hidden
 Robert Anisko           address@hidden
 Shura                   address@hidden
+Tim Josling             address@hidden
 Tom Lane                address@hidden
 Tom Tromey              address@hidden
 Wayne Green             address@hidden
Index: doc/bison.texinfo
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.55
diff -u -u -r1.55 bison.texinfo
--- doc/bison.texinfo 19 Apr 2002 13:35:08 -0000 1.55
+++ doc/bison.texinfo 19 Apr 2002 14:03:30 -0000
@@ -2505,6 +2505,18 @@
 useful semantic value associated with the @samp{+} token, it could be
 referred to as @code{$2}.
+Note that the vertical-bar character @samp{|} is really a rule
+separator, and actions are attached to a single rule.  This is a
+difference with tools like Flex, for which @samp{|} stands for either
+``or'', or ``the same action as that of the next rule''.  In the
+following example, the action is triggered only when @samp{b} is found:
+a-or-b: 'a'|'b'   @{ a_or_b_found = 1; @};
address@hidden group
address@hidden example
 @cindex default action
 If you don't specify an action for a rule, Bison supplies a default:
 @address@hidden = $1}.}  Thus, the value of the first symbol in the rule 
@@ -4948,7 +4960,6 @@
 @node Debugging
 @chapter Debugging Your Parser
address@hidden YYDEBUG
 @findex yydebug
 @cindex debugging
 @cindex tracing the parser
@@ -4956,15 +4967,32 @@
 If a Bison grammar compiles properly but doesn't do what you want when it
 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 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 prologue of the grammar file
-(@pxref{Prologue, , The Prologue}).  Alternatively, use the @samp{-t}
-option when you run Bison (@pxref{Invocation, ,Invoking Bison}) or the
address@hidden declaration (@pxref{Decl Summary, ,Bison Declaration
-Summary}).  We suggest that you always define @code{YYDEBUG} so that
-debugging is always possible.
+There are several means to enable compilation of trace facilities:
address@hidden @asis
address@hidden the macro @code{YYDEBUG}
address@hidden YYDEBUG
+Define the macro @code{YYDEBUG} to a nonzero value when you compile the
+parser.  This is compliant with POSIX Yacc.  You could use
address@hidden as a compiler option or you could put @samp{#define
+YYDEBUG 1} in the prologue of the grammar file (@pxref{Prologue, , The
address@hidden the option @option{-t}, @option{--debug}
+Use the @samp{-t} option when you run Bison (@pxref{Invocation,
+,Invoking Bison}).  This is POSIX compliant too.
address@hidden the directive @samp{%debug}
address@hidden %debug
+Add the @code{%debug} directive (@pxref{Decl Summary, ,Bison
+Declaration Summary}).  This is a Bison extension, which will prove
+useful when Bison will output parsers for languages that don't use a
+preprocessor.  Useless POSIX and Yacc portability matter to you, this is
+the preferred solution.
address@hidden table
+We suggest that you always enable the debug option so that debugging is
+always possible.
 The trace facility outputs messages with macro calls of the form
 @code{YYFPRINTF (stderr, @var{format}, @var{args})} where
@@ -5307,6 +5335,22 @@
 @cindex symbols in Bison, table of
 @table @code
address@hidden @@$
+In an action, the location of the left-hand side of the rule.
+  @xref{Locations, , Locations Overview}.
address@hidden @@@var{n}
+In an action, the location of the @var{n}-th symbol of the right-hand
+side of the rule.  @xref{Locations, , Locations Overview}.
address@hidden $$
+In an action, the semantic value of the left-hand side of the rule.
address@hidden address@hidden
+In an action, the semantic value of the @var{n}-th symbol of the
+right-hand side of the rule.  @xref{Actions}.
 @item error
 A token name reserved for error recovery.  This token may be used in
 grammar rules so as to allow the Bison parser to recognize an error in
@@ -5332,6 +5376,10 @@
 Macro to discard a value from the parser stack and fake a look-ahead
 token.  @xref{Action Features, ,Special Features for Use in Actions}.
address@hidden YYDEBUG
+Macro to define to equip the parser with tracing code. @xref{Debugging,
+,Debugging Your Parser}.
 @item YYERROR
 Macro to pretend that a syntax error has just been detected: call
 @code{yyerror} and then perform normal error recovery if possible
@@ -5504,6 +5552,8 @@
 Bison declaration to specify several possible data types for semantic
 values.  @xref{Union Decl, ,The Collection of Value Types}.
 @end table
address@hidden 1
 These are the punctuation and delimiters used in Bison input:

reply via email to

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