@findex %code requires
@findex %code provides
@findex %code top
-(The prologue alternatives described here are experimental.
-More user feedback will help to determine whether they should become permanent
-features.)
The functionality of @var{Prologue} sections can often be subtle and
inflexible.
@subsection A Push Parser
@cindex push parser
@cindex push parser
-@findex %define api.push_pull
+@findex %define api.push-pull
(The current push parsing interface is experimental and may evolve.
More user feedback will help to stabilize it.)
Normally, Bison generates a pull parser.
The following Bison declaration says that you want the parser to be a push
-parser (@pxref{Decl Summary,,%define api.push_pull}):
+parser (@pxref{Decl Summary,,%define api.push-pull}):
@example
-%define api.push_pull "push"
+%define api.push-pull "push"
@end example
In almost all cases, you want to ensure that your push parser is also
@example
%define api.pure
-%define api.push_pull "push"
+%define api.push-pull "push"
@end example
There is a major notable functional difference between the pure push parser
Bison also supports both the push parser interface along with the pull parser
interface in the same generated parser. In order to get this functionality,
-you should replace the @code{%define api.push_pull "push"} declaration with the
-@code{%define api.push_pull "both"} declaration. Doing this will create all of
+you should replace the @code{%define api.push-pull "push"} declaration with the
+@code{%define api.push-pull "both"} declaration. Doing this will create all of
the symbols mentioned earlier along with the two extra symbols, @code{yyparse}
and @code{yypull_parse}. @code{yyparse} can be used exactly as it normally
would be used. However, the user should note that it is implemented in the
generated parser by calling @code{yypull_parse}.
This makes the @code{yyparse} function that is generated with the
-@code{%define api.push_pull "both"} declaration slower than the normal
+@code{%define api.push-pull "both"} declaration slower than the normal
@code{yyparse} function. If the user
calls the @code{yypull_parse} function it will parse the rest of the input
stream. It is possible to @code{yypush_parse} tokens to select a subgrammar
@end example
Adding the @code{%define api.pure} declaration does exactly the same thing to
-the generated parser with @code{%define api.push_pull "both"} as it did for
-@code{%define api.push_pull "push"}.
+the generated parser with @code{%define api.push-pull "both"} as it did for
+@code{%define api.push-pull "push"}.
@node Decl Summary
@subsection Bison Declaration Summary
For a detailed discussion, see @ref{Prologue Alternatives}.
For Java, the default location is inside the parser class.
-
-(Like all the Yacc prologue alternatives, this directive is experimental.
-More user feedback will help to determine whether it should become a permanent
-feature.)
@end deffn
@deffn {Directive} %code @var{qualifier} @{@var{code}@}
@end itemize
@end itemize
-(Like all the Yacc prologue alternatives, this directive is experimental.
-More user feedback will help to determine whether it should become a permanent
-feature.)
-
@cindex Prologue
For a detailed discussion of how to use @code{%code} in place of the
traditional Yacc prologue for C/C++, see @ref{Prologue Alternatives}.
@end itemize
@c api.pure
-@item api.push_pull
-@findex %define api.push_pull
+@item api.push-pull
+@findex %define api.push-pull
@itemize @bullet
@item Language(s): C (deterministic parsers only)
@item Default Value: @code{"pull"}
@end itemize
-@c api.push_pull
+@c api.push-pull
@item error-verbose
@findex %define error-verbose
@c error-verbose
-@item lr.default_rules
-@cindex default rules
-@findex %define lr.default_rules
+@item lr.default-reductions
+@cindex default reductions
+@findex %define lr.default-reductions
@cindex delayed syntax errors
@cindex syntax errors delayed
@item Language(s): all
@item Purpose: Specifies the kind of states that are permitted to
-contain default rules.
-That is, in such a state, Bison declares the rule with the largest
-lookahead set to be the default rule by which to reduce and then removes
-that lookahead set.
-The advantages of default rules are discussed below.
+contain default reductions.
+That is, in such a state, Bison declares the reduction with the largest
+lookahead set to be the default reduction and then removes that
+lookahead set.
+The advantages of default reductions are discussed below.
The disadvantage is that, when the generated parser encounters a
syntactically unacceptable token, the parser might then perform
-unnecessary reductions by default rules before it can detect the syntax
-error.
+unnecessary default reductions before it can detect the syntax error.
(This feature is experimental.
More user feedback will help to stabilize it.)
@item @code{"all"}.
For @acronym{LALR} and @acronym{IELR} parsers (@pxref{Decl
Summary,,lr.type}) by default, all states are permitted to contain
-default rules.
+default reductions.
The advantage is that parser table sizes can be significantly reduced.
The reason Bison does not by default attempt to address the disadvantage
of delayed syntax error detection is that this disadvantage is already
inherent in @acronym{LALR} and @acronym{IELR} parser tables.
-That is, unlike a canonical @acronym{LR} state, an @acronym{LALR} or
-@acronym{IELR} state can contain syntactically incorrect tokens in the
-lookahead sets of its rules.
+That is, unlike in a canonical @acronym{LR} state, the lookahead sets of
+reductions in an @acronym{LALR} or @acronym{IELR} state can contain
+tokens that are syntactically incorrect for some left contexts.
@item @code{"consistent"}.
@cindex consistent states
If that action is a reduction, then the parser does not need to request
a lookahead token from the scanner before performing that action.
However, the parser only recognizes the ability to ignore the lookahead
-token when such a reduction is encoded as a default rule.
-Thus, if default rules are permitted in and only in consistent states,
-then a canonical @acronym{LR} parser reports a syntax error as soon as
-it @emph{needs} the syntactically unacceptable token from the scanner.
+token when such a reduction is encoded as a default reduction.
+Thus, if default reductions are permitted in and only in consistent
+states, then a canonical @acronym{LR} parser reports a syntax error as
+soon as it @emph{needs} the syntactically unacceptable token from the
+scanner.
@item @code{"accepting"}.
@cindex accepting state
-By default, the only default rule permitted in a canonical @acronym{LR}
-parser is the accept rule in the accepting state, which the parser
-reaches only after reading all tokens from the input.
+By default, the only default reduction permitted in a canonical
+@acronym{LR} parser is the accept action in the accepting state, which
+the parser reaches only after reading all tokens from the input.
Thus, the default canonical @acronym{LR} parser reports a syntax error
as soon as it @emph{reaches} the syntactically unacceptable token
without performing any extra reductions.
@end itemize
@end itemize
-@item lr.keep_unreachable_states
-@findex %define lr.keep_unreachable_states
+@item lr.keep-unreachable-states
+@findex %define lr.keep-unreachable-states
@itemize @bullet
@item Language(s): all
However, Bison does not compute which goto actions are useless.
@end itemize
@end itemize
-@c lr.keep_unreachable_states
+@c lr.keep-unreachable-states
@item lr.type
@findex %define lr.type
historical reasons, @acronym{IELR} or canonical @acronym{LR} is almost
always preferable for deterministic parsers.
The trouble is that @acronym{LALR} parser tables can suffer from
-mysterious conflicts and may not accept the full set of sentences that
-@acronym{IELR} and canonical @acronym{LR} accept.
+mysterious conflicts and thus may not accept the full set of sentences
+that @acronym{IELR} and canonical @acronym{LR} accept.
@xref{Mystery Conflicts}, for details.
However, there are at least two scenarios where @acronym{LALR} may be
worthwhile:
do not resolve any conflicts statically (for example, with @code{%left}
or @code{%prec}), then the parser explores all potential parses of any
given input.
-Thus, the use of @acronym{LALR} parser tables is guaranteed not to alter
-the language accepted by the parser.
+In this case, the use of @acronym{LALR} parser tables is guaranteed not
+to alter the language accepted by the parser.
@acronym{LALR} parser tables are the smallest parser tables Bison can
currently generate, so they may be preferable.
@item @code{"canonical LR"}.
@cindex delayed syntax errors
@cindex syntax errors delayed
-The only advantage of canonical @acronym{LR} over @acronym{IELR} is that
-every canonical @acronym{LR} state encodes that state's exact set of
-syntactically acceptable tokens.
-The only difference in parsing behavior is then that the canonical
+The only advantage of canonical @acronym{LR} over @acronym{IELR} is
+that, for every left context of every canonical @acronym{LR} state, the
+set of tokens accepted by that state is the exact set of tokens that is
+syntactically acceptable in that left context.
+Thus, the only difference in parsing behavior is that the canonical
@acronym{LR} parser can report a syntax error as soon as possible
without performing any unnecessary reductions.
-@xref{Decl Summary,,lr.default_rules}, for further details.
+@xref{Decl Summary,,lr.default-reductions}, for further details.
Even when canonical @acronym{LR} behavior is ultimately desired,
@acronym{IELR}'s elimination of duplicate conflicts should still
facilitate the development of a grammar.
More user feedback will help to stabilize it.)
You call the function @code{yypush_parse} to parse a single token. This
-function is available if either the @code{%define api.push_pull "push"} or
-@code{%define api.push_pull "both"} declaration is used.
+function is available if either the @code{%define api.push-pull "push"} or
+@code{%define api.push-pull "both"} declaration is used.
@xref{Push Decl, ,A Push Parser}.
@deftypefun int yypush_parse (yypstate *yyps)
More user feedback will help to stabilize it.)
You call the function @code{yypull_parse} to parse the rest of the input
-stream. This function is available if the @code{%define api.push_pull "both"}
+stream. This function is available if the @code{%define api.push-pull "both"}
declaration is used.
@xref{Push Decl, ,A Push Parser}.
More user feedback will help to stabilize it.)
You call the function @code{yypstate_new} to create a new parser instance.
-This function is available if either the @code{%define api.push_pull "push"} or
-@code{%define api.push_pull "both"} declaration is used.
+This function is available if either the @code{%define api.push-pull "push"} or
+@code{%define api.push-pull "both"} declaration is used.
@xref{Push Decl, ,A Push Parser}.
@deftypefun yypstate *yypstate_new (void)
More user feedback will help to stabilize it.)
You call the function @code{yypstate_delete} to delete a parser instance.
-function is available if either the @code{%define api.push_pull "push"} or
-@code{%define api.push_pull "both"} declaration is used.
+function is available if either the @code{%define api.push-pull "push"} or
+@code{%define api.push-pull "both"} declaration is used.
@xref{Push Decl, ,A Push Parser}.
@deftypefun void yypstate_delete (yypstate *yyps)
@command{bison} reports:
@example
-tmp.y: warning: 1 nonterminal useless in grammar
-tmp.y: warning: 1 rule useless in grammar
+calc.y: warning: 1 nonterminal useless in grammar
+calc.y: warning: 1 rule useless in grammar
calc.y:11.1-7: warning: nonterminal useless in grammar: useless
calc.y:11.10-12: warning: rule useless in grammar: useless: STR
calc.y: conflicts: 7 shift/reduce
Java.
Push parsers are currently unsupported in Java and @code{%define
-api.push_pull} have no effect.
+api.push-pull} have no effect.
@acronym{GLR} parsers are currently unsupported in Java. Do not use the
@code{glr-parser} directive.
@item Consistent State
A state containing only one possible action.
-@xref{Decl Summary,,lr.default_rules}.
+@xref{Decl Summary,,lr.default-reductions}.
@item Context-free grammars
Grammars specified as rules that can be applied regardless of context.
permitted. @xref{Language and Grammar, ,Languages and Context-Free
Grammars}.
-@item Default Rule
-The rule by which a parser should reduce if the current parser state
+@item Default Reduction
+The reduction that a parser should perform if the current parser state
contains no other action for the lookahead token.
-In permitted parser states, Bison declares the rule with the largest
-lookahead set to be the default rule and removes that lookahead set.
-@xref{Decl Summary,,lr.default_rules}.
+In permitted parser states, Bison declares the reduction with the
+largest lookahead set to be the default reduction and removes that
+lookahead set.
+@xref{Decl Summary,,lr.default-reductions}.
@item Dynamic allocation
Allocation of memory that occurs during execution, rather than at