* 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.
This commit is contained in:
Akim Demaille
2002-04-19 14:04:31 +00:00
parent e0c471a9e6
commit 3ded9a63e3
3 changed files with 69 additions and 10 deletions

View File

@@ -1,3 +1,11 @@
2002-04-19 Akim Demaille <akim@epita.fr>
* 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.
2002-04-19 Akim Demaille <akim@epita.fr> 2002-04-19 Akim Demaille <akim@epita.fr>
* doc/bison.texinfo: Remove the uses of the obsolete @refill. * doc/bison.texinfo: Remove the uses of the obsolete @refill.

1
THANKS
View File

@@ -41,6 +41,7 @@ Piotr Gackiewicz gacek@intertel.com.pl
Richard Stallman rms@gnu.org Richard Stallman rms@gnu.org
Robert Anisko anisko_r@epita.fr Robert Anisko anisko_r@epita.fr
Shura debil_urod@ngs.ru Shura debil_urod@ngs.ru
Tim Josling tej@melbpc.org.au
Tom Lane tgl@sss.pgh.pa.us Tom Lane tgl@sss.pgh.pa.us
Tom Tromey tromey@cygnus.com Tom Tromey tromey@cygnus.com
Wayne Green wayne@infosavvy.com Wayne Green wayne@infosavvy.com

View File

@@ -2505,6 +2505,18 @@ the addition-expression just recognized by the rule. If there were a
useful semantic value associated with the @samp{+} token, it could be useful semantic value associated with the @samp{+} token, it could be
referred to as @code{$2}. 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:
@example
@group
a-or-b: 'a'|'b' @{ a_or_b_found = 1; @};
@end group
@end example
@cindex default action @cindex default action
If you don't specify an action for a rule, Bison supplies a default: If you don't specify an action for a rule, Bison supplies a default:
@w{@code{$$ = $1}.} Thus, the value of the first symbol in the rule becomes @w{@code{$$ = $1}.} Thus, the value of the first symbol in the rule becomes
@@ -4948,7 +4960,6 @@ clear the flag.
@node Debugging @node Debugging
@chapter Debugging Your Parser @chapter Debugging Your Parser
@findex YYDEBUG
@findex yydebug @findex yydebug
@cindex debugging @cindex debugging
@cindex tracing the parser @cindex tracing the parser
@@ -4956,15 +4967,32 @@ clear the flag.
If a Bison grammar compiles properly but doesn't do what you want when it 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. runs, the @code{yydebug} parser-trace feature can help you figure out why.
To enable compilation of trace facilities, you must define the macro There are several means to enable compilation of trace facilities:
@code{YYDEBUG} to a nonzero value when you compile the parser. You
could use @samp{-DYYDEBUG=1} as a compiler option or you could put @table @asis
@samp{#define YYDEBUG 1} in the prologue of the grammar file @item the macro @code{YYDEBUG}
(@pxref{Prologue, , The Prologue}). Alternatively, use the @samp{-t} @findex YYDEBUG
option when you run Bison (@pxref{Invocation, ,Invoking Bison}) or the Define the macro @code{YYDEBUG} to a nonzero value when you compile the
@code{%debug} declaration (@pxref{Decl Summary, ,Bison Declaration parser. This is compliant with POSIX Yacc. You could use
Summary}). We suggest that you always define @code{YYDEBUG} so that @samp{-DYYDEBUG=1} as a compiler option or you could put @samp{#define
debugging is always possible. YYDEBUG 1} in the prologue of the grammar file (@pxref{Prologue, , The
Prologue}).
@item the option @option{-t}, @option{--debug}
Use the @samp{-t} option when you run Bison (@pxref{Invocation,
,Invoking Bison}). This is POSIX compliant too.
@item the directive @samp{%debug}
@findex %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.
@end 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 The trace facility outputs messages with macro calls of the form
@code{YYFPRINTF (stderr, @var{format}, @var{args})} where @code{YYFPRINTF (stderr, @var{format}, @var{args})} where
@@ -5307,6 +5335,22 @@ would instead be named @file{foo_tab.c}.
@cindex symbols in Bison, table of @cindex symbols in Bison, table of
@table @code @table @code
@item @@$
In an action, the location of the left-hand side of the rule.
@xref{Locations, , Locations Overview}.
@item @@@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}.
@item $$
In an action, the semantic value of the left-hand side of the rule.
@xref{Actions}.
@item $@var{n}
In an action, the semantic value of the @var{n}-th symbol of the
right-hand side of the rule. @xref{Actions}.
@item error @item error
A token name reserved for error recovery. This token may be used in 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 grammar rules so as to allow the Bison parser to recognize an error in
@@ -5332,6 +5376,10 @@ read, by making @code{yyparse} return 0 immediately.
Macro to discard a value from the parser stack and fake a look-ahead Macro to discard a value from the parser stack and fake a look-ahead
token. @xref{Action Features, ,Special Features for Use in Actions}. token. @xref{Action Features, ,Special Features for Use in Actions}.
@item YYDEBUG
Macro to define to equip the parser with tracing code. @xref{Debugging,
,Debugging Your Parser}.
@item YYERROR @item YYERROR
Macro to pretend that a syntax error has just been detected: call Macro to pretend that a syntax error has just been detected: call
@code{yyerror} and then perform normal error recovery if possible @code{yyerror} and then perform normal error recovery if possible
@@ -5505,6 +5553,8 @@ Bison declaration to specify several possible data types for semantic
values. @xref{Union Decl, ,The Collection of Value Types}. values. @xref{Union Decl, ,The Collection of Value Types}.
@end table @end table
@sp 1
These are the punctuation and delimiters used in Bison input: These are the punctuation and delimiters used in Bison input:
@table @samp @table @samp