@c the smallbook format.
@c @smallbook
-@c Set following if you have the new `shorttitlepage' command
-@c @clear shorttitlepage-enabled
-@c @set shorttitlepage-enabled
-
@c Set following if you want to document %default-prec and %no-default-prec.
@c This feature is experimental and may change in future Bison versions.
@c @set defaultprec
-@c ISPELL CHECK: done, 14 Jan 1993 --bob
-
-@c Check COPYRIGHT dates. should be updated in the titlepage, ifinfo
-@c titlepage; should NOT be changed in the GPL. --mew
-
-@c FIXME: I don't understand this `iftex'. Obsolete? --akim.
-@iftex
+@ifnotinfo
@syncodeindex fn cp
@syncodeindex vr cp
@syncodeindex tp cp
-@end iftex
+@end ifnotinfo
@ifinfo
@synindex fn cp
@synindex vr cp
* bison: (bison). @acronym{GNU} parser generator (Yacc replacement).
@end direntry
-@ifset shorttitlepage-enabled
-@shorttitlepage Bison
-@end ifset
@titlepage
@title Bison
@subtitle The Yacc-compatible Parser Generator
The Bison Parser Algorithm
-* Look-Ahead:: Parser looks one token ahead when deciding what to do.
+* Lookahead:: Parser looks one token ahead when deciding what to do.
* Shift/Reduce:: Conflicts: when either shifting or reduction is valid.
* Precedence:: Operator precedence works by resolving conflicts.
* Contextual Precedence:: When an operator's precedence depends on context.
* How Can I Reset the Parser:: @code{yyparse} Keeps some State
* Strings are Destroyed:: @code{yylval} Loses Track of Strings
* Implementing Gotos/Loops:: Control Flow in the Calculator
+* Multiple start-symbols:: Factoring closely related grammars
+* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
+* I can't build Bison:: Troubleshooting
+* Where can I find help?:: Troubleshouting
+* Bug Reports:: Troublereporting
+* Other Languages:: Parsers in Java and others
+* Beta Testing:: Experimenting development versions
+* Mailing Lists:: Meeting other Bison users
Copying This Manual
@unnumbered Introduction
@cindex introduction
-@dfn{Bison} is a general-purpose parser generator that converts a
-grammar description for an @acronym{LALR}(1) context-free grammar into a C
-program to parse that grammar. Once you are proficient with Bison,
-you may use it to develop a wide range of language parsers, from those
+@dfn{Bison} is a general-purpose parser generator that converts an
+annotated context-free grammar into an @acronym{LALR}(1) or
+@acronym{GLR} parser for that grammar. Once you are proficient with
+Bison, you can use it to develop a wide range of language parsers, from those
used in simple desk calculators to complex programming languages.
Bison is upward compatible with Yacc: all properly-written Yacc grammars
ought to work with Bison with no change. Anyone familiar with Yacc
should be able to use Bison with little trouble. You need to be fluent in
-C programming in order to use Bison or to understand this manual.
+C or C++ programming in order to use Bison or to understand this manual.
We begin with tutorial chapters that explain the basic concepts of using
Bison and show three explained examples, each building on the last. If you
@node Conditions
@unnumbered Conditions for Using Bison
-As of Bison version 1.24, we have changed the distribution terms for
-@code{yyparse} to permit using Bison's output in nonfree programs when
-Bison is generating C code for @acronym{LALR}(1) parsers. Formerly, these
+The distribution terms for Bison-generated parsers permit using the
+parsers in nonfree programs. Before Bison version 2.2, these extra
+permissions applied only when Bison was generating @acronym{LALR}(1)
+parsers in C@. And before Bison version 1.24, Bison-generated
parsers could be used only in programs that were free software.
The other @acronym{GNU} programming tools, such as the @acronym{GNU} C
The output of the Bison utility---the Bison parser file---contains a
verbatim copy of a sizable piece of Bison, which is the code for the
-@code{yyparse} function. (The actions from your grammar are inserted
-into this function at one point, but the rest of the function is not
-changed.) When we applied the @acronym{GPL} terms to the code for
-@code{yyparse},
+parser's implementation. (The actions from your grammar are inserted
+into this implementation at one point, but most of the rest of the
+implementation is not changed.) When we applied the @acronym{GPL}
+terms to the skeleton code for the parser's implementation,
the effect was to restrict the use of Bison output to free software.
We didn't change the terms because of sympathy for people who want to
practical conditions for using Bison match the practical conditions for
using the other @acronym{GNU} tools.
-This exception applies only when Bison is generating C code for an
-@acronym{LALR}(1) parser; otherwise, the @acronym{GPL} terms operate
-as usual. You can
-tell whether the exception applies to your @samp{.c} output file by
-inspecting it to see whether it says ``As a special exception, when
-this file is copied by Bison into a Bison output file, you may use
-that output file without restriction.''
+This exception applies when Bison is generating code for a parser.
+You can tell whether the exception applies to a Bison output file by
+inspecting the file for text beginning with ``As a special
+exception@dots{}''. The text spells out the exact terms of the
+exception.
@include gpl.texi
are called @acronym{LALR}(1) grammars.
In brief, in these grammars, it must be possible to
tell how to parse any portion of an input string with just a single
-token of look-ahead. Strictly speaking, that is a description of an
+token of lookahead. Strictly speaking, that is a description of an
@acronym{LR}(1) grammar, and @acronym{LALR}(1) involves additional
restrictions that are
hard to explain simply; but it is rare in actual practice to find an
Parsers for @acronym{LALR}(1) grammars are @dfn{deterministic}, meaning
roughly that the next grammar rule to apply at any point in the input is
uniquely determined by the preceding input and a fixed, finite portion
-(called a @dfn{look-ahead}) of the remaining input. A context-free
+(called a @dfn{lookahead}) of the remaining input. A context-free
grammar can be @dfn{ambiguous}, meaning that there are multiple ways to
apply the grammar rules to get the same inputs. Even unambiguous
grammars can be @dfn{nondeterministic}, meaning that no fixed
-look-ahead always suffices to determine the next grammar rule to apply.
+lookahead always suffices to determine the next grammar rule to apply.
With the proper declarations, Bison is also able to parse these more
general context-free grammars, using a technique known as @acronym{GLR}
parsing (for Generalized @acronym{LR}). Bison's @acronym{GLR} parsers
square (int x) /* @r{identifier, open-paren, keyword `int',}
@r{identifier, close-paren} */
@{ /* @r{open-brace} */
- return x * x; /* @r{keyword `return', identifier, asterisk,
- identifier, semicolon} */
+ return x * x; /* @r{keyword `return', identifier, asterisk,}
+ @r{identifier, semicolon} */
@} /* @r{close-brace} */
@end example
@end ifinfo
In the simplest cases, you can use the @acronym{GLR} algorithm
to parse grammars that are unambiguous, but fail to be @acronym{LALR}(1).
-Such grammars typically require more than one symbol of look-ahead,
+Such grammars typically require more than one symbol of lookahead,
or (in rare cases) fall into the category of grammars in which the
@acronym{LALR}(1) algorithm throws away too much information (they are in
@acronym{LR}(1), but not @acronym{LALR}(1), @ref{Mystery Conflicts}).
valid, and more-complicated cases can come up in practical programs.)
These two declarations look identical until the @samp{..} token.
-With normal @acronym{LALR}(1) one-token look-ahead it is not
+With normal @acronym{LALR}(1) one-token lookahead it is not
possible to decide between the two forms when the identifier
@samp{a} is parsed. It is, however, desirable
for a parser to decide this, since in the latter case
The effect of all this is that the parser seems to ``guess'' the
correct branch to take, or in other words, it seems to use more
-look-ahead than the underlying @acronym{LALR}(1) algorithm actually allows
+lookahead than the underlying @acronym{LALR}(1) algorithm actually allows
for. In this example, @acronym{LALR}(2) would suffice, but also some cases
that are not @acronym{LALR}(@math{k}) for any @math{k} can be handled this way.
@vindex yylloc
@cindex @acronym{GLR} parsers and @code{yylloc}
In any semantic action, you can examine @code{yychar} to determine the type of
-the look-ahead token present at the time of the associated reduction.
+the lookahead token present at the time of the associated reduction.
After checking that @code{yychar} is not set to @code{YYEMPTY} or @code{YYEOF},
you can then examine @code{yylval} and @code{yylloc} to determine the
-look-ahead token's semantic value and location, if any.
+lookahead token's semantic value and location, if any.
In a nondeferred semantic action, you can also modify any of these variables to
influence syntax analysis.
-@xref{Look-Ahead, ,Look-Ahead Tokens}.
+@xref{Lookahead, ,Lookahead Tokens}.
@findex yyclearin
@cindex @acronym{GLR} parsers and @code{yyclearin}
@findex YYERROR
@cindex @acronym{GLR} parsers and @code{YYERROR}
Another Bison feature requiring special consideration is @code{YYERROR}
-(@pxref{Action Features}), which you can invoke in any semantic action to
+(@pxref{Action Features}), which you can invoke in a semantic action to
initiate error recovery.
During deterministic @acronym{GLR} operation, the effect of @code{YYERROR} is
the same as its effect in an @acronym{LALR}(1) parser.
In a deferred semantic action, its effect is undefined.
@c The effect is probably a syntax error at the split point.
+Also, see @ref{Location Default Action, ,Default Action for Locations}, which
+describes a special usage of @code{YYLLOC_DEFAULT} in @acronym{GLR} parsers.
+
@node Compiler Requirements
@subsection Considerations when Compiling @acronym{GLR} Parsers
@cindex @code{inline}
desk-top calculator.
These examples are simple, but Bison grammars for real programming
-languages are written the same way.
-@ifinfo
-You can copy these examples out of the Info file and into a source file
-to try them.
-@end ifinfo
+languages are written the same way. You can copy these examples into a
+source file to try them.
@menu
* RPN Calc:: Reverse polish notation calculator;
The groupings of the rpcalc ``language'' defined here are the expression
(given the name @code{exp}), the line of input (@code{line}), and the
complete input transcript (@code{input}). Each of these nonterminal
-symbols has several alternate rules, joined by the @samp{|} punctuator
+symbols has several alternate rules, joined by the vertical bar @samp{|}
which is read as ``or''. The following sections explain what these rules
mean.
don't need any C declarations, you may omit the @samp{%@{} and
@samp{%@}} delimiters that bracket this section.
+The @var{Prologue} section is terminated by the the first occurrence
+of @samp{%@}} that is outside a comment, a string literal, or a
+character constant.
+
You may have more than one @var{Prologue} section, intermixed with the
@var{Bison declarations}. This allows you to have C and Bison
declarations that refer to each other. For example, the @code{%union}
@end example
@noindent
+@cindex braced code
+This is an example of @dfn{braced code}, that is, C code surrounded by
+braces, much like a compound statement in C@. Braced code can contain
+any sequence of C tokens, so long as its braces are balanced. Bison
+does not check the braced code for correctness directly; it merely
+copies the code to the output file, where the C compiler can check it.
+
+Within braced code, the balanced-brace count is not affected by braces
+within comments, string literals, or character constants, but it is
+affected by the C digraphs @samp{<%} and @samp{%>} that represent
+braces. At the top level braced code must be terminated by @samp{@}}
+and not by a digraph. Bison does not look for trigraphs, so if braced
+code uses trigraphs you should ensure that they do not affect the
+nesting of braces or the boundaries of comments, string literals, or
+character constants.
+
Usually there is only one action and it follows the components.
@xref{Actions}.
Multiple rules for the same @var{result} can be written separately or can
be joined with the vertical-bar character @samp{|} as follows:
-@ifinfo
-@example
-@var{result}: @var{rule1-components}@dots{}
- | @var{rule2-components}@dots{}
- @dots{}
- ;
-@end example
-@end ifinfo
-@iftex
@example
@group
@var{result}: @var{rule1-components}@dots{}
;
@end group
@end example
-@end iftex
@noindent
They are still considered distinct rules even when joined in this way.
@end example
@noindent
+@code{YYSTYPE}'s replacement list should be a type name
+that does not contain parentheses or square brackets.
This macro definition must go in the prologue of the grammar file
(@pxref{Grammar Outline, ,Outline of a Bison Grammar}).
is to compute a semantic value for the grouping built by the rule from the
semantic values associated with tokens or smaller groupings.
-An action consists of C statements surrounded by braces, much like a
-compound statement in C@. An action can contain any sequence of C
-statements. Bison does not look for trigraphs, though, so if your C
-code uses trigraphs you should ensure that they do not affect the
-nesting of braces or the boundaries of comments, strings, or character
-literals.
-
-An action can be placed at any position in the rule;
+An action consists of braced code containing C statements, and can be
+placed at any position in the rule;
it is executed at that position. Most rules have just one action at the
end of the rule, following all the components. Actions in the middle of
a rule are tricky and used only for special purposes (@pxref{Mid-Rule
definition of @code{foo}.
@vindex yylval
-It is also possible to access the semantic value of the look-ahead token, if
+It is also possible to access the semantic value of the lookahead token, if
any, from a semantic action.
This semantic value is stored in @code{yylval}.
@xref{Action Features, ,Special Features for Use in Actions}.
removes the temporary @code{let}-variable from the list so that it won't
appear to exist while the rest of the program is parsed.
+@findex %destructor
+@cindex discarded symbols, mid-rule actions
+@cindex error recovery, mid-rule actions
+In the above example, if the parser initiates error recovery (@pxref{Error
+Recovery}) while parsing the tokens in the embedded statement @code{stmt},
+it might discard the previous semantic context @code{$<context>5} without
+restoring it.
+Thus, @code{$<context>5} needs a destructor (@pxref{Destructor Decl, , Freeing
+Discarded Symbols}).
+However, Bison currently provides no means to declare a destructor for a
+mid-rule action's semantic value.
+
+One solution is to bury the mid-rule action inside a nonterminal symbol and to
+declare a destructor for that symbol:
+
+@example
+@group
+%type <context> let
+%destructor @{ pop_context ($$); @} let
+
+%%
+
+stmt: let stmt
+ @{ $$ = $2;
+ pop_context ($1); @}
+ ;
+
+let: LET '(' var ')'
+ @{ $$ = push_context ();
+ declare_variable ($3); @}
+ ;
+
+@end group
+@end example
+
+@noindent
+Note that the action is now at the end of its rule.
+Any mid-rule action can be converted to an end-of-rule action in this way, and
+this is what Bison actually does to implement mid-rule actions.
+
Taking action before a rule is completely recognized often leads to
conflicts since the parser must commit to a parse in order to execute the
action. For example, the following two rules, without mid-rule actions,
when it has read no farther than the open-brace. In other words, it
must commit to using one rule or the other, without sufficient
information to do it correctly. (The open-brace token is what is called
-the @dfn{look-ahead} token at this time, since the parser is still
-deciding what to do about it. @xref{Look-Ahead, ,Look-Ahead Tokens}.)
+the @dfn{lookahead} token at this time, since the parser is still
+deciding what to do about it. @xref{Lookahead, ,Lookahead Tokens}.)
You might think that you could correct the problem by putting identical
actions into the two rules, like this:
@noindent
Now Bison can execute the action in the rule for @code{subroutine} without
-deciding which rule for @code{compound} it will eventually use. Note that
-the action is now at the end of its rule. Any mid-rule action can be
-converted to an end-of-rule action in this way, and this is what Bison
-actually does to implement mid-rule actions.
+deciding which rule for @code{compound} it will eventually use.
@node Locations
@section Tracking Locations
Defining a data type for locations is much simpler than for semantic values,
since all tokens and groupings always use the same type.
-The type of locations is specified by defining a macro called @code{YYLTYPE}.
+You can specify the type of locations by defining a macro called
+@code{YYLTYPE}, just as you can specify the semantic value type by
+defining @code{YYSTYPE} (@pxref{Value Type}).
When @code{YYLTYPE} is not defined, Bison uses a default structure type with
four members:
@end example
@vindex yylloc
-It is also possible to access the location of the look-ahead token, if any,
+It is also possible to access the location of the lookahead token, if any,
from a semantic action.
This location is stored in @code{yylloc}.
@xref{Action Features, ,Special Features for Use in Actions}.
@node Location Default Action
@subsection Default Action for Locations
@vindex YYLLOC_DEFAULT
+@cindex @acronym{GLR} parsers and @code{YYLLOC_DEFAULT}
Actually, actions are not the best place to compute locations. Since
locations are much more general than semantic values, there is room in
rule. The @code{YYLLOC_DEFAULT} macro is invoked each time a rule is
matched, before the associated action is run. It is also invoked
while processing a syntax error, to compute the error's location.
+Before reporting an unresolvable syntactic ambiguity, a @acronym{GLR}
+parser invokes @code{YYLLOC_DEFAULT} recursively to compute the location
+of that ambiguity.
Most of the time, this macro is general enough to suppress location
dedicated code from semantic actions.
the location of the grouping (the result of the computation). When a
rule is matched, the second parameter identifies locations of
all right hand side elements of the rule being matched, and the third
-parameter is the size of the rule's right hand side. When processing
-a syntax error, the second parameter identifies locations of
-the symbols that were discarded during error processing, and the third
+parameter is the size of the rule's right hand side.
+When a @acronym{GLR} parser reports an ambiguity, which of multiple candidate
+right hand sides it passes to @code{YYLLOC_DEFAULT} is undefined.
+When processing a syntax error, the second parameter identifies locations
+of the symbols that were discarded during error processing, and the third
parameter is the number of discarded symbols.
By default, @code{YYLLOC_DEFAULT} is defined this way:
@cindex value types, declaring
@findex %union
-The @code{%union} declaration specifies the entire collection of possible
-data types for semantic values. The keyword @code{%union} is followed by a
-pair of braces containing the same thing that goes inside a @code{union} in
-C.
+The @code{%union} declaration specifies the entire collection of
+possible data types for semantic values. The keyword @code{%union} is
+followed by braced code containing the same thing that goes inside a
+@code{union} in C@.
For example:
@end group
@end example
+@noindent
specifies the union tag @code{value}, so the corresponding C type is
@code{union value}. If you do not specify a tag, it defaults to
@code{YYSTYPE}.
+As another extension to @acronym{POSIX}, you may specify multiple
+@code{%union} declarations; their contents are concatenated. However,
+only the first @code{%union} declaration can specify a tag.
+
Note that, unlike making a @code{union} declaration in C, you need not write
a semicolon after the closing brace.
@deffn {Directive} %initial-action @{ @var{code} @}
@findex %initial-action
-Declare that the @var{code} must be invoked before parsing each time
+Declare that the braced @var{code} must be invoked before parsing each time
@code{yyparse} is called. The @var{code} may use @code{$$} and
-@code{@@$} --- initial value and location of the look-ahead --- and the
+@code{@@$} --- initial value and location of the lookahead --- and the
@code{%parse-param}.
@end deffn
@deffn {Directive} %destructor @{ @var{code} @} @var{symbols}
@findex %destructor
-Invoke @var{code} whenever the parser discards one of the @var{symbols}.
+Invoke the braced @var{code} whenever the parser discards one of the
+@var{symbols}.
Within @var{code}, @code{$$} designates the semantic value associated
with the discarded symbol. The additional parser parameters are also
available (@pxref{Parser Function, , The Parser Function
@item
incoming terminals during the second phase of error recovery,
@item
-the current look-ahead and the entire stack (except the current
+the current lookahead and the entire stack (except the current
right-hand side symbols) when the parser returns immediately, and
@item
the start symbol, when the parser succeeds.
@deffn {Directive} %name-prefix="@var{prefix}"
Rename the external symbols used in the parser so that they start with
@var{prefix} instead of @samp{yy}. The precise list of symbols renamed
+in C parsers
is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs},
-@code{yylval}, @code{yylloc}, @code{yychar}, @code{yydebug}, and
-possible @code{yylloc}. For example, if you use
+@code{yylval}, @code{yychar}, @code{yydebug}, and
+(if locations are used) @code{yylloc}. For example, if you use
@samp{%name-prefix="c_"}, the names become @code{c_parse}, @code{c_lex},
-and so on. @xref{Multiple Parsers, ,Multiple Parsers in the Same
-Program}.
+and so on. In C++ parsers, it is only the surrounding namespace which is
+named @var{prefix} instead of @samp{yy}.
+@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
@end deffn
@ifset defaultprec
@deffn {Directive} %verbose
Write an extra output file containing verbose descriptions of the
-parser states and what is done for each type of look-ahead token in
+parser states and what is done for each type of lookahead token in
that state. @xref{Understanding, , Understanding Your Parser}, for more
information.
@end deffn
@deffn {Directive} %parse-param @{@var{argument-declaration}@}
@findex %parse-param
-Declare that an argument declared by @code{argument-declaration} is an
-additional @code{yyparse} argument.
+Declare that an argument declared by the braced-code
+@var{argument-declaration} is an additional @code{yyparse} argument.
The @var{argument-declaration} is used when declaring
functions or prototypes. The last identifier in
@var{argument-declaration} must be the argument name.
@deffn {Directive} lex-param @{@var{argument-declaration}@}
@findex %lex-param
-Declare that @code{argument-declaration} is an additional @code{yylex}
-argument declaration.
+Declare that the braced-code @var{argument-declaration} is an
+additional @code{yylex} argument declaration.
@end deffn
For instance:
@deffn {Macro} YYBACKUP (@var{token}, @var{value});
@findex YYBACKUP
Unshift a token. This macro is allowed only for rules that reduce
-a single value, and only when there is no look-ahead token.
+a single value, and only when there is no lookahead token.
It is also disallowed in @acronym{GLR} parsers.
-It installs a look-ahead token with token type @var{token} and
+It installs a lookahead token with token type @var{token} and
semantic value @var{value}; then it discards the value that was
going to be reduced by this rule.
If the macro is used when it is not valid, such as when there is
-a look-ahead token already, then it reports a syntax error with
+a lookahead token already, then it reports a syntax error with
a message @samp{cannot back up} and performs ordinary error
recovery.
@deffn {Macro} YYEMPTY
@vindex YYEMPTY
-Value stored in @code{yychar} when there is no look-ahead token.
+Value stored in @code{yychar} when there is no lookahead token.
@end deffn
@deffn {Macro} YYEOF
@vindex YYEOF
-Value stored in @code{yychar} when the look-ahead is the end of the input
+Value stored in @code{yychar} when the lookahead is the end of the input
stream.
@end deffn
@end deffn
@deffn {Macro} YYRECOVERING
-This macro stands for an expression that has the value 1 when the parser
-is recovering from a syntax error, and 0 the rest of the time.
+@findex YYRECOVERING
+The expression @code{YYRECOVERING ()} yields 1 when the parser
+is recovering from a syntax error, and 0 otherwise.
@xref{Error Recovery}.
@end deffn
@deffn {Variable} yychar
-Variable containing either the look-ahead token, or @code{YYEOF} when the
-look-ahead is the end of the input stream, or @code{YYEMPTY} when no look-ahead
+Variable containing either the lookahead token, or @code{YYEOF} when the
+lookahead is the end of the input stream, or @code{YYEMPTY} when no lookahead
has been performed so the next token is not yet known.
Do not modify @code{yychar} in a deferred semantic action (@pxref{GLR Semantic
Actions}).
-@xref{Look-Ahead, ,Look-Ahead Tokens}.
+@xref{Lookahead, ,Lookahead Tokens}.
@end deffn
@deffn {Macro} yyclearin;
-Discard the current look-ahead token. This is useful primarily in
+Discard the current lookahead token. This is useful primarily in
error rules.
Do not invoke @code{yyclearin} in a deferred semantic action (@pxref{GLR
Semantic Actions}).
@end deffn
@deffn {Variable} yylloc
-Variable containing the look-ahead token location when @code{yychar} is not set
+Variable containing the lookahead token location when @code{yychar} is not set
to @code{YYEMPTY} or @code{YYEOF}.
Do not modify @code{yylloc} in a deferred semantic action (@pxref{GLR Semantic
Actions}).
@end deffn
@deffn {Variable} yylval
-Variable containing the look-ahead token semantic value when @code{yychar} is
+Variable containing the lookahead token semantic value when @code{yychar} is
not set to @code{YYEMPTY} or @code{YYEOF}.
Do not modify @code{yylval} in a deferred semantic action (@pxref{GLR Semantic
Actions}).
This kind of parser is known in the literature as a bottom-up parser.
@menu
-* Look-Ahead:: Parser looks one token ahead when deciding what to do.
+* Lookahead:: Parser looks one token ahead when deciding what to do.
* Shift/Reduce:: Conflicts: when either shifting or reduction is valid.
* Precedence:: Operator precedence works by resolving conflicts.
* Contextual Precedence:: When an operator's precedence depends on context.
* Memory Management:: What happens when memory is exhausted. How to avoid it.
@end menu
-@node Look-Ahead
-@section Look-Ahead Tokens
-@cindex look-ahead token
+@node Lookahead
+@section Lookahead Tokens
+@cindex lookahead token
The Bison parser does @emph{not} always reduce immediately as soon as the
last @var{n} tokens and groupings match a rule. This is because such a
token in order to decide what to do.
When a token is read, it is not immediately shifted; first it becomes the
-@dfn{look-ahead token}, which is not on the stack. Now the parser can
+@dfn{lookahead token}, which is not on the stack. Now the parser can
perform one or more reductions of tokens and groupings on the stack, while
-the look-ahead token remains off to the side. When no more reductions
-should take place, the look-ahead token is shifted onto the stack. This
+the lookahead token remains off to the side. When no more reductions
+should take place, the lookahead token is shifted onto the stack. This
does not mean that all possible reductions have been done; depending on the
-token type of the look-ahead token, some rules may choose to delay their
+token type of the lookahead token, some rules may choose to delay their
application.
-Here is a simple case where look-ahead is needed. These three rules define
+Here is a simple case where lookahead is needed. These three rules define
expressions which contain binary addition operators and postfix unary
factorial operators (@samp{!}), and allow parentheses for grouping.
@vindex yychar
@vindex yylval
@vindex yylloc
-The look-ahead token is stored in the variable @code{yychar}.
+The lookahead token is stored in the variable @code{yychar}.
Its semantic value and location, if any, are stored in the variables
@code{yylval} and @code{yylloc}.
@xref{Action Features, ,Special Features for Use in Actions}.
Here we assume that @code{IF}, @code{THEN} and @code{ELSE} are
terminal symbols for specific keyword tokens.
-When the @code{ELSE} token is read and becomes the look-ahead token, the
+When the @code{ELSE} token is read and becomes the lookahead token, the
contents of the stack (assuming the input is valid) are just right for
reduction by the first rule. But it is also legitimate to shift the
@code{ELSE}, because that would lead to eventual reduction by the second
The latter alternative, @dfn{right association}, is desirable for
assignment operators. The choice of left or right association is a
matter of whether the parser chooses to shift or reduce when the stack
-contains @w{@samp{1 - 2}} and the look-ahead token is @samp{-}: shifting
+contains @w{@samp{1 - 2}} and the lookahead token is @samp{-}: shifting
makes right-associativity.
@node Using Precedence
Precedence, ,Context-Dependent Precedence}.)
Finally, the resolution of conflicts works by comparing the precedence
-of the rule being considered with that of the look-ahead token. If the
+of the rule being considered with that of the lookahead token. If the
token's precedence is higher, the choice is to shift. If the rule's
precedence is higher, the choice is to reduce. If they have equal
precedence, the choice is made based on the associativity of that
resolved.
Not all rules and not all tokens have precedence. If either the rule or
-the look-ahead token has no precedence, then the default is to shift.
+the lookahead token has no precedence, then the default is to shift.
@node Contextual Precedence
@section Context-Dependent Precedence
near the top of the stack. The current state collects all the information
about previous input which is relevant to deciding what to do next.
-Each time a look-ahead token is read, the current parser state together
-with the type of look-ahead token are looked up in a table. This table
-entry can say, ``Shift the look-ahead token.'' In this case, it also
+Each time a lookahead token is read, the current parser state together
+with the type of lookahead token are looked up in a table. This table
+entry can say, ``Shift the lookahead token.'' In this case, it also
specifies the new parser state, which is pushed onto the top of the
parser stack. Or it can say, ``Reduce using rule number @var{n}.''
This means that a certain number of tokens or groupings are taken off
that number of states are popped from the stack, and one new state is
pushed.
-There is one other alternative: the table can say that the look-ahead token
+There is one other alternative: the table can say that the lookahead token
is erroneous in the current state. This causes error processing to begin
(@pxref{Error Recovery}).
@end example
It would seem that this grammar can be parsed with only a single token
-of look-ahead: when a @code{param_spec} is being read, an @code{ID} is
+of lookahead: when a @code{param_spec} is being read, an @code{ID} is
a @code{name} if a comma or colon follows, or a @code{type} if another
@code{ID} follows. In other words, this grammar is @acronym{LR}(1).
same. They appear similar because the same set of rules would be
active---the rule for reducing to a @code{name} and that for reducing to
a @code{type}. Bison is unable to determine at that stage of processing
-that the rules would require different look-ahead tokens in the two
+that the rules would require different lookahead tokens in the two
contexts, so it makes a single parser state for them both. Combining
the two contexts causes a conflict later. In parser terminology, this
occurrence means that the grammar is not @acronym{LALR}(1).
Bison produces @emph{deterministic} parsers that choose uniquely
when to reduce and which reduction to apply
-based on a summary of the preceding input and on one extra token of look-ahead.
+based on a summary of the preceding input and on one extra token of lookahead.
As a result, normal Bison handles a proper subset of the family of
context-free languages.
Ambiguous grammars, since they have strings with more than one possible
sequence of reductions cannot have deterministic parsers in this sense.
The same is true of languages that require more than one symbol of
-look-ahead, since the parser lacks the information necessary to make a
+lookahead, since the parser lacks the information necessary to make a
decision at the point it must be made in a shift-reduce parser.
Finally, as previously mentioned (@pxref{Mystery Conflicts}),
there are languages where Bison's particular choice of how to
@code{error} token is acceptable. (This means that the subexpressions
already parsed are discarded, back to the last complete @code{stmnts}.)
At this point the @code{error} token can be shifted. Then, if the old
-look-ahead token is not acceptable to be shifted next, the parser reads
+lookahead token is not acceptable to be shifted next, the parser reads
tokens and discards them until it finds a token which is acceptable. In
this example, Bison reads and discards input until the next newline so
that the fourth rule can apply. Note that discarded symbols are
@samp{yyerrok;} is a valid C statement.
@findex yyclearin
-The previous look-ahead token is reanalyzed immediately after an error. If
+The previous lookahead token is reanalyzed immediately after an error. If
this is unacceptable, then the macro @code{yyclearin} may be used to clear
this token. Write the statement @samp{yyclearin;} in the error rule's
action.
For example, suppose that on a syntax error, an error handling routine is
called that advances the input stream to some point where parsing should
once again commence. The next symbol returned by the lexical scanner is
-probably correct. The previous look-ahead token ought to be discarded
+probably correct. The previous lookahead token ought to be discarded
with @samp{yyclearin;}.
@vindex YYRECOVERING
-The macro @code{YYRECOVERING} stands for an expression that has the
-value 1 when the parser is recovering from a syntax error, and 0 the
-rest of the time. A value of 1 indicates that error messages are
-currently suppressed for new syntax errors.
+The expression @code{YYRECOVERING ()} yields 1 when the parser
+is recovering from a syntax error, and 0 otherwise.
+Syntax error diagnostics are suppressed while recovering from a syntax
+error.
@node Context Dependency
@chapter Handling Context Dependencies
symbol (here, @code{exp}). When the parser returns to this state right
after having reduced a rule that produced an @code{exp}, the control
flow jumps to state 2. If there is no such transition on a nonterminal
-symbol, and the look-ahead is a @code{NUM}, then this token is shifted on
+symbol, and the lookahead is a @code{NUM}, then this token is shifted on
the parse stack, and the control flow jumps to state 1. Any other
-look-ahead triggers a syntax error.''
+lookahead triggers a syntax error.''
@cindex core, item set
@cindex item set core
@cindex kernel, item set
@cindex item set core
Even though the only active rule in state 0 seems to be rule 0, the
-report lists @code{NUM} as a look-ahead token because @code{NUM} can be
+report lists @code{NUM} as a lookahead token because @code{NUM} can be
at the beginning of any rule deriving an @code{exp}. By default Bison
reports the so-called @dfn{core} or @dfn{kernel} of the item set, but if
you want to see more detail you can invoke @command{bison} with
@end example
@noindent
-the rule 5, @samp{exp: NUM;}, is completed. Whatever the look-ahead token
+the rule 5, @samp{exp: NUM;}, is completed. Whatever the lookahead token
(@samp{$default}), the parser will reduce it. If it was coming from
state 0, then, after this reduction it will return to state 0, and will
jump to state 2 (@samp{exp: go to state 2}).
@noindent
In state 2, the automaton can only shift a symbol. For instance,
-because of the item @samp{exp -> exp . '+' exp}, if the look-ahead if
+because of the item @samp{exp -> exp . '+' exp}, if the lookahead if
@samp{+}, it will be shifted on the parse stack, and the automaton
control will jump to state 4, corresponding to the item @samp{exp -> exp
'+' . exp}. Since there is no default action, any other token than
$default reduce using rule 1 (exp)
@end example
-Indeed, there are two actions associated to the look-ahead @samp{/}:
+Indeed, there are two actions associated to the lookahead @samp{/}:
either shifting (and going to state 7), or reducing rule 1. The
conflict means that either the grammar is ambiguous, or the parser lacks
information to make the right decision. Indeed the grammar is
shifting the next token and going to the corresponding state, or
reducing a single rule. In the other cases, i.e., when shifting
@emph{and} reducing is possible or when @emph{several} reductions are
-possible, the look-ahead is required to select the action. State 8 is
-one such state: if the look-ahead is @samp{*} or @samp{/} then the action
+possible, the lookahead is required to select the action. State 8 is
+one such state: if the lookahead is @samp{*} or @samp{/} then the action
is shifting, otherwise the action is reducing rule 1. In other words,
the first two items, corresponding to rule 1, are not eligible when the
-look-ahead token is @samp{*}, since we specified that @samp{*} has higher
+lookahead token is @samp{*}, since we specified that @samp{*} has higher
precedence than @samp{+}. More generally, some items are eligible only
-with some set of possible look-ahead tokens. When run with
-@option{--report=look-ahead}, Bison specifies these look-ahead tokens:
+with some set of possible lookahead tokens. When run with
+@option{--report=lookahead}, Bison specifies these lookahead tokens:
@example
state 8
@item -b @var{file-prefix}
@itemx --file-prefix=@var{prefix}
-Pretend that @code{%verbose} was specified, i.e, specify prefix to use
+Pretend that @code{%file-prefix} was specified, i.e, specify prefix to use
for all Bison output file names. @xref{Decl Summary}.
@item -r @var{things}
Description of the grammar, conflicts (resolved and unresolved), and
@acronym{LALR} automaton.
-@item look-ahead
+@item lookahead
Implies @code{state} and augments the description of the automaton with
-each rule's look-ahead set.
+each rule's lookahead set.
@item itemset
Implies @code{state} and augments the description of the automaton with
the full set of items for each state, instead of its core only.
@end table
-For instance, on the following grammar
-
@item -v
@itemx --verbose
Pretend that @code{%verbose} was specified, i.e, write an extra output
@node Option Cross Key
@section Option Cross Key
+@c FIXME: How about putting the directives too?
Here is a list of options, alphabetized by long option, to help you find
the corresponding short option.
-@tex
-\def\leaderfill{\leaders\hbox to 1em{\hss.\hss}\hfill}
-
-{\tt
-\line{ --debug \leaderfill -t}
-\line{ --defines \leaderfill -d}
-\line{ --file-prefix \leaderfill -b}
-\line{ --graph \leaderfill -g}
-\line{ --help \leaderfill -h}
-\line{ --name-prefix \leaderfill -p}
-\line{ --no-lines \leaderfill -l}
-\line{ --no-parser \leaderfill -n}
-\line{ --output \leaderfill -o}
-\line{ --print-localedir}
-\line{ --token-table \leaderfill -k}
-\line{ --verbose \leaderfill -v}
-\line{ --version \leaderfill -V}
-\line{ --yacc \leaderfill -y}
-}
-@end tex
-
-@ifinfo
-@example
---debug -t
---defines=@var{defines-file} -d
---file-prefix=@var{prefix} -b @var{file-prefix}
---graph=@var{graph-file} -d
---help -h
---name-prefix=@var{prefix} -p @var{name-prefix}
---no-lines -l
---no-parser -n
---output=@var{outfile} -o @var{outfile}
---print-localedir
---token-table -k
---verbose -v
---version -V
---yacc -y
-@end example
-@end ifinfo
+@multitable {@option{--defines=@var{defines-file}}} {@option{-b @var{file-prefix}XXX}}
+@headitem Long Option @tab Short Option
+@item @option{--debug} @tab @option{-t}
+@item @option{--defines=@var{defines-file}} @tab @option{-d}
+@item @option{--file-prefix=@var{prefix}} @tab @option{-b @var{file-prefix}}
+@item @option{--graph=@var{graph-file}} @tab @option{-d}
+@item @option{--help} @tab @option{-h}
+@item @option{--name-prefix=@var{prefix}} @tab @option{-p @var{name-prefix}}
+@item @option{--no-lines} @tab @option{-l}
+@item @option{--no-parser} @tab @option{-n}
+@item @option{--output=@var{outfile}} @tab @option{-o @var{outfile}}
+@item @option{--print-localedir} @tab
+@item @option{--token-table} @tab @option{-k}
+@item @option{--verbose} @tab @option{-v}
+@item @option{--version} @tab @option{-V}
+@item @option{--yacc} @tab @option{-y}
+@end multitable
@node Yacc Library
@section Yacc Library
@c - Always pure
@c - initial action
-The C++ parser @acronym{LALR}(1) skeleton is named @file{lalr1.cc}. To select
-it, you may either pass the option @option{--skeleton=lalr1.cc} to
-Bison, or include the directive @samp{%skeleton "lalr1.cc"} in the
+The C++ parser @acronym{LALR}(1) skeleton is named @file{lalr1.cc}. To
+select it, you may either pass the option @option{--skeleton=lalr1.cc}
+to Bison, or include the directive @samp{%skeleton "lalr1.cc"} in the
grammar preamble. When run, @command{bison} will create several
-files:
+entities in the @samp{yy} namespace. Use the @samp{%name-prefix}
+directive to change the namespace name, see @ref{Decl Summary}. The
+various classes are generated in the following files:
+
@table @file
@item position.hh
@itemx location.hh
@item @var{file}.hh
@itemx @var{file}.cc
-The declaration and implementation of the C++ parser class.
-@var{file} is the name of the output file. It follows the same
-rules as with regular C parsers.
+(Assuming the extension of the input file was @samp{.yy}.) The
+declaration and implementation of the C++ parser class. The basename
+and extension of these two files follow the same rules as with regular C
+parsers (@pxref{Invocation}).
-Note that @file{@var{file}.hh} is @emph{mandatory}, the C++ cannot
-work without the parser class declaration. Therefore, you must either
-pass @option{-d}/@option{--defines} to @command{bison}, or use the
+The header is @emph{mandatory}; you must either pass
+@option{-d}/@option{--defines} to @command{bison}, or use the
@samp{%defines} directive.
@end table
@comment file: calc++-driver.hh
@example
// Announce to Flex the prototype we want for lexing function, ...
-# define YY_DECL \
- int yylex (yy::calcxx_parser::semantic_type* yylval, \
- yy::calcxx_parser::location_type* yylloc, \
- calcxx_driver& driver)
+# define YY_DECL \
+ yy::calcxx_parser::token_type \
+ yylex (yy::calcxx_parser::semantic_type* yylval, \
+ yy::calcxx_parser::location_type* yylloc, \
+ calcxx_driver& driver)
// ... and declare it for the parser's sake.
YY_DECL;
@end example
To enable memory deallocation during error recovery, use
@code{%destructor}.
+@c FIXME: Document %printer, and mention that it takes a braced-code operand.
@comment file: calc++-parser.yy
@example
%printer @{ debug_stream () << *$$; @} "identifier"
# include <string>
# include "calc++-driver.hh"
# include "calc++-parser.hh"
+
+/* Work around an incompatibility in flex (at least versions
+ 2.5.31 through 2.5.33): it generates code that does
+ not conform to C89. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+# undef yywrap
+# define yywrap() 1
+
+/* By default yylex returns int, we use token_type.
+ Unfortunately yyterminate by default returns 0, which is
+ not of token_type. */
+#define yyterminate() return token::END
%@}
@end example
%@{
typedef yy::calcxx_parser::token token;
%@}
-
-[-+*/] return yytext[0];
+ /* Convert ints to the actual type of tokens. */
+[-+*/] return yy::calcxx_parser::token_type (yytext[0]);
":=" return token::ASSIGN;
@{int@} @{
errno = 0;
are addressed.
@menu
-* Memory Exhausted:: Breaking the Stack Limits
-* How Can I Reset the Parser:: @code{yyparse} Keeps some State
-* Strings are Destroyed:: @code{yylval} Loses Track of Strings
-* Implementing Gotos/Loops:: Control Flow in the Calculator
+* Memory Exhausted:: Breaking the Stack Limits
+* How Can I Reset the Parser:: @code{yyparse} Keeps some State
+* Strings are Destroyed:: @code{yylval} Loses Track of Strings
+* Implementing Gotos/Loops:: Control Flow in the Calculator
+* Multiple start-symbols:: Factoring closely related grammars
+* Secure? Conform?:: Is Bison @acronym{POSIX} safe?
+* I can't build Bison:: Troubleshooting
+* Where can I find help?:: Troubleshouting
+* Bug Reports:: Troublereporting
+* Other Languages:: Parsers in Java and others
+* Beta Testing:: Experimenting development versions
+* Mailing Lists:: Meeting other Bison users
@end menu
@node Memory Exhausted
This error is probably the single most frequent ``bug report'' sent to
Bison lists, but is only concerned with a misunderstanding of the role
-of scanner. Consider the following Lex code:
+of the scanner. Consider the following Lex code:
@verbatim
%{
invited to consult the dedicated literature.
+@node Multiple start-symbols
+@section Multiple start-symbols
+
+@display
+I have several closely related grammars, and I would like to share their
+implementations. In fact, I could use a single grammar but with
+multiple entry points.
+@end display
+
+Bison does not support multiple start-symbols, but there is a very
+simple means to simulate them. If @code{foo} and @code{bar} are the two
+pseudo start-symbols, then introduce two new tokens, say
+@code{START_FOO} and @code{START_BAR}, and use them as switches from the
+real start-symbol:
+
+@example
+%token START_FOO START_BAR;
+%start start;
+start: START_FOO foo
+ | START_BAR bar;
+@end example
+
+These tokens prevents the introduction of new conflicts. As far as the
+parser goes, that is all that is needed.
+
+Now the difficult part is ensuring that the scanner will send these
+tokens first. If your scanner is hand-written, that should be
+straightforward. If your scanner is generated by Lex, them there is
+simple means to do it: recall that anything between @samp{%@{ ... %@}}
+after the first @code{%%} is copied verbatim in the top of the generated
+@code{yylex} function. Make sure a variable @code{start_token} is
+available in the scanner (e.g., a global variable or using
+@code{%lex-param} etc.), and use the following:
+
+@example
+ /* @r{Prologue.} */
+%%
+%@{
+ if (start_token)
+ @{
+ int t = start_token;
+ start_token = 0;
+ return t;
+ @}
+%@}
+ /* @r{The rules.} */
+@end example
+
+
+@node Secure? Conform?
+@section Secure? Conform?
+
+@display
+Is Bison secure? Does it conform to POSIX?
+@end display
+
+If you're looking for a guarantee or certification, we don't provide it.
+However, Bison is intended to be a reliable program that conforms to the
+@acronym{POSIX} specification for Yacc. If you run into problems,
+please send us a bug report.
+
+@node I can't build Bison
+@section I can't build Bison
+
+@display
+I can't build Bison because @command{make} complains that
+@code{msgfmt} is not found.
+What should I do?
+@end display
+
+Like most GNU packages with internationalization support, that feature
+is turned on by default. If you have problems building in the @file{po}
+subdirectory, it indicates that your system's internationalization
+support is lacking. You can re-configure Bison with
+@option{--disable-nls} to turn off this support, or you can install GNU
+gettext from @url{ftp://ftp.gnu.org/gnu/gettext/} and re-configure
+Bison. See the file @file{ABOUT-NLS} for more information.
+
+
+@node Where can I find help?
+@section Where can I find help?
+
+@display
+I'm having trouble using Bison. Where can I find help?
+@end display
+
+First, read this fine manual. Beyond that, you can send mail to
+@email{help-bison@@gnu.org}. This mailing list is intended to be
+populated with people who are willing to answer questions about using
+and installing Bison. Please keep in mind that (most of) the people on
+the list have aspects of their lives which are not related to Bison (!),
+so you may not receive an answer to your question right away. This can
+be frustrating, but please try not to honk them off; remember that any
+help they provide is purely voluntary and out of the kindness of their
+hearts.
+
+@node Bug Reports
+@section Bug Reports
+
+@display
+I found a bug. What should I include in the bug report?
+@end display
+
+Before you send a bug report, make sure you are using the latest
+version. Check @url{ftp://ftp.gnu.org/pub/gnu/bison/} or one of its
+mirrors. Be sure to include the version number in your bug report. If
+the bug is present in the latest version but not in a previous version,
+try to determine the most recent version which did not contain the bug.
+
+If the bug is parser-related, you should include the smallest grammar
+you can which demonstrates the bug. The grammar file should also be
+complete (i.e., I should be able to run it through Bison without having
+to edit or add anything). The smaller and simpler the grammar, the
+easier it will be to fix the bug.
+
+Include information about your compilation environment, including your
+operating system's name and version and your compiler's name and
+version. If you have trouble compiling, you should also include a
+transcript of the build session, starting with the invocation of
+`configure'. Depending on the nature of the bug, you may be asked to
+send additional files as well (such as `config.h' or `config.cache').
+
+Patches are most welcome, but not required. That is, do not hesitate to
+send a bug report just because you can not provide a fix.
+
+Send bug reports to @email{bug-bison@@gnu.org}.
+
+@node Other Languages
+@section Other Languages
+
+@display
+Will Bison ever have C++ support? How about Java or @var{insert your
+favorite language here}?
+@end display
+
+C++ support is there now, and is documented. We'd love to add other
+languages; contributions are welcome.
+
+@node Beta Testing
+@section Beta Testing
+
+@display
+What is involved in being a beta tester?
+@end display
+
+It's not terribly involved. Basically, you would download a test
+release, compile it, and use it to build and run a parser or two. After
+that, you would submit either a bug report or a message saying that
+everything is okay. It is important to report successes as well as
+failures because test releases eventually become mainstream releases,
+but only if they are adequately tested. If no one tests, development is
+essentially halted.
+
+Beta testers are particularly needed for operating systems to which the
+developers do not have easy access. They currently have easy access to
+recent GNU/Linux and Solaris versions. Reports about other operating
+systems are especially welcome.
+
+@node Mailing Lists
+@section Mailing Lists
+
+@display
+How do I join the help-bison and bug-bison mailing lists?
+@end display
+
+See @url{http://lists.gnu.org/}.
@c ================================================= Table of Symbols
grammar rules so as to allow the Bison parser to recognize an error in
the grammar without halting the process. In effect, a sentence
containing an error may be recognized as valid. On a syntax error, the
-token @code{error} becomes the current look-ahead token. Actions
-corresponding to @code{error} are then executed, and the look-ahead
+token @code{error} becomes the current lookahead token. Actions
+corresponding to @code{error} are then executed, and the lookahead
token is reset to the token that originally caused the violation.
@xref{Error Recovery}.
@end deffn
@end deffn
@deffn {Macro} YYBACKUP
-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 lookahead
token. @xref{Action Features, ,Special Features for Use in Actions}.
@end deffn
@deffn {Variable} yychar
External integer variable that contains the integer value of the
-look-ahead token. (In a pure parser, it is a local variable within
+lookahead token. (In a pure parser, it is a local variable within
@code{yyparse}.) Error-recovery rule actions may examine this variable.
@xref{Action Features, ,Special Features for Use in Actions}.
@end deffn
@deffn {Variable} yyclearin
Macro used in error-recovery rule actions. It clears the previous
-look-ahead token. @xref{Error Recovery}.
+lookahead token. @xref{Error Recovery}.
@end deffn
@deffn {Macro} YYDEBUG
You can ignore this variable if you don't use the @samp{@@} feature in the
grammar actions.
@xref{Token Locations, ,Textual Locations of Tokens}.
-In semantic actions, it stores the location of the look-ahead token.
+In semantic actions, it stores the location of the lookahead token.
@xref{Actions and Locations, ,Actions and Locations}.
@end deffn
variable within @code{yyparse}, and its address is passed to
@code{yylex}.)
@xref{Token Values, ,Semantic Values of Tokens}.
-In semantic actions, it stores the semantic value of the look-ahead token.
+In semantic actions, it stores the semantic value of the lookahead token.
@xref{Actions, ,Actions}.
@end deffn
@end deffn
@deffn {Macro} YYRECOVERING
-Macro whose value indicates whether the parser is recovering from a
-syntax error. @xref{Action Features, ,Special Features for Use in Actions}.
+The expression @code{YYRECOVERING ()} yields 1 when the parser
+is recovering from a syntax error, and 0 otherwise.
+@xref{Action Features, ,Special Features for Use in Actions}.
@end deffn
@deffn {Macro} YYSTACK_USE_ALLOCA
@item Literal string token
A token which consists of two or more fixed characters. @xref{Symbols}.
-@item Look-ahead token
-A token already read but not yet shifted. @xref{Look-Ahead, ,Look-Ahead
+@item Lookahead token
+A token already read but not yet shifted. @xref{Lookahead, ,Lookahead
Tokens}.
@item @acronym{LALR}(1)
@item @acronym{LR}(1)
The class of context-free grammars in which at most one token of
-look-ahead is needed to disambiguate the parsing of any piece of input.
+lookahead is needed to disambiguate the parsing of any piece of input.
@item Nonterminal symbol
A grammar symbol standing for a grammatical construct that can