For consistency, use lookahead' instead of look-ahead' or

`look_ahead'.  Discussed starting at
<http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00049.html>
and then at
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00017.html>.
* NEWS: For the next release, note the change to `--report'.
* TODO, doc/bison.1: Update English.
* doc/bison.texinfo: Update English.
(Understanding Your Parser, Bison Options): Document as
`--report=lookahead' rather than `--report=look-ahead'.
* src/conflicts.c: Update English in comments.
(lookahead_set): Rename from look_ahead_set.
(flush_reduce): Rename argument look_ahead_tokens to lookahead_tokens.
(resolve_sr_conflict): Rename local look_ahead_tokens to
lookahead_tokens, and update other uses.
(flush_shift, set_conflicts, conflicts_solve, count_sr_conflicts,
count_rr_conflicts, conflicts_free): Update uses.
* src/getargs.c (report_args): Move "lookahead" before alternate
spellings.
(report_types): Update uses.
(usage): For `--report' usage description, state `lookahead' spelling
rather than `look-ahead'.
* src/getargs.h (report.report_lookahead_tokens): Rename from
report_look_ahead_tokens.
* src/lalr.c: Update English in comments.
(compute_lookahead_tokens): Rename from compute_look_ahead_tokens.
(state_lookahead_tokens_count): Rename from
state_look_ahead_tokens_count.
Rename local n_look_ahead_tokens to n_lookahead_tokens.
(lookahead_tokens_print): Rename from look_ahead_tokens_print.
Rename local n_look_ahead_tokens to n_lookahead_tokens.
Update other uses.
Update English in output.
(add_lookback_edge, initialize_LA, lalr, lalr_free): Update uses.
* src/print.c: Update English in comments.
(lookahead_set): Rename from look_ahead_set.
(print_reduction): Rename argument lookahead_token from
look_ahead_token.
(print_core, state_default_rule, print_reductions, print_results):
Update uses.
* src/print_graph.c: Update English in comments.
(print_core): Update uses.
* src/state.c: Update English in comments.
(reductions_new): Update uses.
(state_rule_lookahead_tokens_print): Rename from
state_rule_look_ahead_tokens_print, and update other uses.
* src/state.h: Update English in comments.
(reductions.lookahead_tokens): Rename from look_ahead_tokens.
(state_rule_lookahead_tokens_print): Rename from
state_rule_look_ahead_tokens_print.
* src/tables.c: Update English in comments.
(conflict_row, action_row): Update uses.
* tests/glr-regression.at
(Incorrect lookahead during deterministic GLR,
Incorrect lookahead during nondeterministic GLR): Rename
print_look_ahead to print_lookahead.
* tests/torture.at: Update English in comments.
(AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR): Rename from
AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR.
(Many lookahead tokens): Update uses.
* data/glr.c: Update English in comments.
* lalr1.cc: Likewise.
* yacc.c: Likewise.
* src/conflicts.h: Likewise.
* src/lalr.h: Likewise.
* src/main.c: Likewise.
* src/output.c: Likewise.
* src/parse-gram.c: Likewise.
* src/tables.h: Likewise.
* tests/calc.at: Likewise.
This commit is contained in:
Joel E. Denny
2006-06-10 03:02:23 +00:00
parent 3c40d0b52d
commit 742e4900c8
26 changed files with 361 additions and 283 deletions

View File

@@ -1,3 +1,76 @@
2006-06-09 Joel E. Denny <jdenny@ces.clemson.edu>
For consistency, use `lookahead' instead of `look-ahead' or
`look_ahead'. Discussed starting at
<http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00049.html>
and then at
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00017.html>.
* NEWS: For the next release, note the change to `--report'.
* TODO, doc/bison.1: Update English.
* doc/bison.texinfo: Update English.
(Understanding Your Parser, Bison Options): Document as
`--report=lookahead' rather than `--report=look-ahead'.
* src/conflicts.c: Update English in comments.
(lookahead_set): Rename from look_ahead_set.
(flush_reduce): Rename argument look_ahead_tokens to lookahead_tokens.
(resolve_sr_conflict): Rename local look_ahead_tokens to
lookahead_tokens, and update other uses.
(flush_shift, set_conflicts, conflicts_solve, count_sr_conflicts,
count_rr_conflicts, conflicts_free): Update uses.
* src/getargs.c (report_args): Move "lookahead" before alternate
spellings.
(report_types): Update uses.
(usage): For `--report' usage description, state `lookahead' spelling
rather than `look-ahead'.
* src/getargs.h (report.report_lookahead_tokens): Rename from
report_look_ahead_tokens.
* src/lalr.c: Update English in comments.
(compute_lookahead_tokens): Rename from compute_look_ahead_tokens.
(state_lookahead_tokens_count): Rename from
state_look_ahead_tokens_count.
Rename local n_look_ahead_tokens to n_lookahead_tokens.
(lookahead_tokens_print): Rename from look_ahead_tokens_print.
Rename local n_look_ahead_tokens to n_lookahead_tokens.
Update other uses.
Update English in output.
(add_lookback_edge, initialize_LA, lalr, lalr_free): Update uses.
* src/print.c: Update English in comments.
(lookahead_set): Rename from look_ahead_set.
(print_reduction): Rename argument lookahead_token from
look_ahead_token.
(print_core, state_default_rule, print_reductions, print_results):
Update uses.
* src/print_graph.c: Update English in comments.
(print_core): Update uses.
* src/state.c: Update English in comments.
(reductions_new): Update uses.
(state_rule_lookahead_tokens_print): Rename from
state_rule_look_ahead_tokens_print, and update other uses.
* src/state.h: Update English in comments.
(reductions.lookahead_tokens): Rename from look_ahead_tokens.
(state_rule_lookahead_tokens_print): Rename from
state_rule_look_ahead_tokens_print.
* src/tables.c: Update English in comments.
(conflict_row, action_row): Update uses.
* tests/glr-regression.at
(Incorrect lookahead during deterministic GLR,
Incorrect lookahead during nondeterministic GLR): Rename
print_look_ahead to print_lookahead.
* tests/torture.at: Update English in comments.
(AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR): Rename from
AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR.
(Many lookahead tokens): Update uses.
* data/glr.c: Update English in comments.
* lalr1.cc: Likewise.
* yacc.c: Likewise.
* src/conflicts.h: Likewise.
* src/lalr.h: Likewise.
* src/main.c: Likewise.
* src/output.c: Likewise.
* src/parse-gram.c: Likewise.
* src/tables.h: Likewise.
* tests/calc.at: Likewise.
2006-06-08 Joel E. Denny <jdenny@ces.clemson.edu> 2006-06-08 Joel E. Denny <jdenny@ces.clemson.edu>
* src/flex-scanner.h (yytext): Remove stray `*/' in #define. * src/flex-scanner.h (yytext): Remove stray `*/' in #define.

5
NEWS
View File

@@ -1,6 +1,11 @@
Bison News Bison News
---------- ----------
Changes in version 2.3+:
* The option `--report=look-ahead' has been changed to `--report=lookahead'.
The old spelling still works but is not documented and will be removed.
Changes in version 2.3, 2006-06-05: Changes in version 2.3, 2006-06-05:
* GLR grammars should now use `YYRECOVERING ()' instead of `YYRECOVERING', * GLR grammars should now use `YYRECOVERING ()' instead of `YYRECOVERING',

2
TODO
View File

@@ -36,7 +36,7 @@ Catch up with yacc.c.
** GLR ** GLR
How would Paul like to display the conflicted actions? In particular, How would Paul like to display the conflicted actions? In particular,
what when two reductions are possible on a given look-ahead token, but one is what when two reductions are possible on a given lookahead token, but one is
part of $default. Should we make the two reductions explicit, or just part of $default. Should we make the two reductions explicit, or just
keep $default? See the following point. keep $default? See the following point.

View File

@@ -67,7 +67,7 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
# b4_lyyerror_args # b4_lyyerror_args
# ---------------- # ----------------
# Same as above, but on the look-ahead, hence &yylloc instead of yylocp. # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
m4_define([b4_lyyerror_args], m4_define([b4_lyyerror_args],
[b4_pure_if([b4_locations_if([&yylloc, ])])dnl [b4_pure_if([b4_locations_if([&yylloc, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
@@ -82,7 +82,7 @@ m4_define([b4_pure_args],
# b4_lpure_args # b4_lpure_args
# ------------- # -------------
# Same as above, but on the look-ahead, hence &yylloc instead of yylocp. # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
m4_define([b4_lpure_args], m4_define([b4_lpure_args],
[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) [b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
@@ -2178,7 +2178,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
yylval, and yylloc are the syntactic category, semantic value, and location yylval, and yylloc are the syntactic category, semantic value, and location
of the look-ahead. */ of the lookahead. */
/*ARGSUSED*/ static void /*ARGSUSED*/ static void
yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
{ {

View File

@@ -156,7 +156,7 @@ b4_syncline([@oline@], [@ofile@])
/// Generate an error message. /// Generate an error message.
/// \param state the state where the error occurred. /// \param state the state where the error occurred.
/// \param tok the look-ahead token. /// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate]dnl virtual std::string yysyntax_error_ (int yystate]dnl
b4_error_verbose_if([, int tok])[); b4_error_verbose_if([, int tok])[);
@@ -515,7 +515,7 @@ namespace ]b4_namespace[
int int
]b4_parser_class_name[::parse () ]b4_parser_class_name[::parse ()
{ {
/// Look-ahead and look-ahead in internal form. /// Lookahead and lookahead in internal form.
int yychar = yyempty_; int yychar = yyempty_;
int yytoken = 0; int yytoken = 0;
@@ -528,9 +528,9 @@ namespace ]b4_namespace[
int yynerrs_ = 0; int yynerrs_ = 0;
int yyerrstatus_ = 0; int yyerrstatus_ = 0;
/// Semantic value of the look-ahead. /// Semantic value of the lookahead.
semantic_type yylval; semantic_type yylval;
/// Location of the look-ahead. /// Location of the lookahead.
location_type yylloc; location_type yylloc;
/// The locations where the error started and ended. /// The locations where the error started and ended.
location yyerror_range[2]; location yyerror_range[2];
@@ -573,12 +573,12 @@ b4_syncline([@oline@], [@ofile@])])dnl
/* Backup. */ /* Backup. */
yybackup: yybackup:
/* Try to take a decision without look-ahead. */ /* Try to take a decision without lookahead. */
yyn = yypact_[yystate]; yyn = yypact_[yystate];
if (yyn == yypact_ninf_) if (yyn == yypact_ninf_)
goto yydefault; goto yydefault;
/* Read a look-ahead token. */ /* Read a lookahead token. */
if (yychar == yyempty_) if (yychar == yyempty_)
{ {
YYCDEBUG << "Reading a token: "; YYCDEBUG << "Reading a token: ";
@@ -621,7 +621,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
if (yyn == yyfinal_) if (yyn == yyfinal_)
goto yyacceptlab; goto yyacceptlab;
/* Shift the look-ahead token. */ /* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
/* Discard the token being shifted unless it is eof. */ /* Discard the token being shifted unless it is eof. */
@@ -710,7 +710,7 @@ b4_error_verbose_if([, yytoken])[));
yyerror_range[0] = yylloc; yyerror_range[0] = yylloc;
if (yyerrstatus_ == 3) if (yyerrstatus_ == 3)
{ {
/* If just tried and failed to reuse look-ahead token after an /* If just tried and failed to reuse lookahead token after an
error, discard it. */ error, discard it. */
if (yychar <= yyeof_) if (yychar <= yyeof_)
@@ -726,7 +726,7 @@ b4_error_verbose_if([, yytoken])[));
} }
} }
/* Else will try to reuse look-ahead token after shifting the error /* Else will try to reuse lookahead token after shifting the error
token. */ token. */
goto yyerrlab1; goto yyerrlab1;
@@ -788,7 +788,7 @@ b4_error_verbose_if([, yytoken])[));
yyerror_range[1] = yylloc; yyerror_range[1] = yylloc;
// Using YYLLOC is tempting, but would change the location of // Using YYLLOC is tempting, but would change the location of
// the look-ahead. YYLOC is available though. // the lookahead. YYLOC is available though.
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
yysemantic_stack_.push (yylval); yysemantic_stack_.push (yylval);
yylocation_stack_.push (yyloc); yylocation_stack_.push (yyloc);

View File

@@ -964,15 +964,15 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
# Declare the variables that are global, or local to YYPARSE if # Declare the variables that are global, or local to YYPARSE if
# pure-parser. # pure-parser.
m4_define([b4_declare_parser_variables], m4_define([b4_declare_parser_variables],
[/* The look-ahead symbol. */ [/* The lookahead symbol. */
int yychar; int yychar;
/* The semantic value of the look-ahead symbol. */ /* The semantic value of the lookahead symbol. */
YYSTYPE yylval; YYSTYPE yylval;
/* Number of syntax errors so far. */ /* Number of syntax errors so far. */
int yynerrs;b4_locations_if([ int yynerrs;b4_locations_if([
/* Location data for the look-ahead symbol. */ /* Location data for the lookahead symbol. */
YYLTYPE yylloc;]) YYLTYPE yylloc;])
]) ])
m4_divert_pop([KILL])dnl# ====================== End of M4 code. m4_divert_pop([KILL])dnl# ====================== End of M4 code.
@@ -997,7 +997,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
int yyresult; int yyresult;
/* Number of tokens to shift before error messages enabled. */ /* Number of tokens to shift before error messages enabled. */
int yyerrstatus; int yyerrstatus;
/* Look-ahead token as an internal (translated) token number. */ /* Lookahead token as an internal (translated) token number. */
int yytoken = 0; int yytoken = 0;
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */ /* Buffer for error messages, and its allocated size. */
@@ -1168,16 +1168,16 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc;
yybackup: yybackup:
/* Do appropriate processing given the current state. Read a /* Do appropriate processing given the current state. Read a
look-ahead token if we need one and don't already have one. */ lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to look-ahead token. */ /* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate]; yyn = yypact[yystate];
if (yyn == YYPACT_NINF) if (yyn == YYPACT_NINF)
goto yydefault; goto yydefault;
/* Not known => get a look-ahead token if don't already have one. */ /* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY) if (yychar == YYEMPTY)
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
@@ -1217,7 +1217,7 @@ yybackup:
if (yyerrstatus) if (yyerrstatus)
yyerrstatus--; yyerrstatus--;
/* Shift the look-ahead token. */ /* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
/* Discard the shifted token unless it is eof. */ /* Discard the shifted token unless it is eof. */
@@ -1341,7 +1341,7 @@ yyerrlab:
if (yyerrstatus == 3) if (yyerrstatus == 3)
{ {
/* If just tried and failed to reuse look-ahead token after an /* If just tried and failed to reuse lookahead token after an
error, discard it. */ error, discard it. */
if (yychar <= YYEOF) if (yychar <= YYEOF)
@@ -1358,7 +1358,7 @@ yyerrlab:
} }
} }
/* Else will try to reuse look-ahead token after shifting the error /* Else will try to reuse lookahead token after shifting the error
token. */ token. */
goto yyerrlab1; goto yyerrlab1;
@@ -1423,7 +1423,7 @@ yyerrlab1:
]b4_locations_if([[ ]b4_locations_if([[
yyerror_range[1] = yylloc; yyerror_range[1] = yylloc;
/* Using YYLLOC is tempting, but would change the location of /* Using YYLLOC is tempting, but would change the location of
the look-ahead. YYLOC is available though. */ the lookahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
*++yylsp = yyloc;]])[ *++yylsp = yyloc;]])[

View File

@@ -284,7 +284,7 @@ so that the debugging facilities are compiled.
.TP .TP
.B \-\-verbose .B \-\-verbose
Write an extra output file containing verbose descriptions of the 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. that state.
.sp .sp
This file also describes all the conflicts, both those resolved by This file also describes all the conflicts, both those resolved by

View File

@@ -248,7 +248,7 @@ The Lexical Analyzer Function @code{yylex}
The Bison Parser Algorithm 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. * Shift/Reduce:: Conflicts: when either shifting or reduction is valid.
* Precedence:: Operator precedence works by resolving conflicts. * Precedence:: Operator precedence works by resolving conflicts.
* Contextual Precedence:: When an operator's precedence depends on context. * Contextual Precedence:: When an operator's precedence depends on context.
@@ -445,7 +445,7 @@ can handle almost all context-free grammars, Bison is optimized for what
are called @acronym{LALR}(1) grammars. are called @acronym{LALR}(1) grammars.
In brief, in these grammars, it must be possible to In brief, in these grammars, it must be possible to
tell how to parse any portion of an input string with just a single 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 @acronym{LR}(1) grammar, and @acronym{LALR}(1) involves additional
restrictions that are restrictions that are
hard to explain simply; but it is rare in actual practice to find an hard to explain simply; but it is rare in actual practice to find an
@@ -461,11 +461,11 @@ more information on this.
Parsers for @acronym{LALR}(1) grammars are @dfn{deterministic}, meaning 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 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 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 grammar can be @dfn{ambiguous}, meaning that there are multiple ways to
apply the grammar rules to get the same inputs. Even unambiguous apply the grammar rules to get the same inputs. Even unambiguous
grammars can be @dfn{nondeterministic}, meaning that no fixed 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 With the proper declarations, Bison is also able to parse these more
general context-free grammars, using a technique known as @acronym{GLR} general context-free grammars, using a technique known as @acronym{GLR}
parsing (for Generalized @acronym{LR}). Bison's @acronym{GLR} parsers parsing (for Generalized @acronym{LR}). Bison's @acronym{GLR} parsers
@@ -746,7 +746,7 @@ merged result.
In the simplest cases, you can use the @acronym{GLR} algorithm In the simplest cases, you can use the @acronym{GLR} algorithm
to parse grammars that are unambiguous, but fail to be @acronym{LALR}(1). 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 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{LALR}(1) algorithm throws away too much information (they are in
@acronym{LR}(1), but not @acronym{LALR}(1), @ref{Mystery Conflicts}). @acronym{LR}(1), but not @acronym{LALR}(1), @ref{Mystery Conflicts}).
@@ -786,7 +786,7 @@ type enum = (a);
valid, and more-complicated cases can come up in practical programs.) valid, and more-complicated cases can come up in practical programs.)
These two declarations look identical until the @samp{..} token. 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 possible to decide between the two forms when the identifier
@samp{a} is parsed. It is, however, desirable @samp{a} is parsed. It is, however, desirable
for a parser to decide this, since in the latter case for a parser to decide this, since in the latter case
@@ -825,7 +825,7 @@ reports a syntax error as usual.
The effect of all this is that the parser seems to ``guess'' the 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 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 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. that are not @acronym{LALR}(@math{k}) for any @math{k} can be handled this way.
@@ -1106,13 +1106,13 @@ action in a @acronym{GLR} parser.
@vindex yylloc @vindex yylloc
@cindex @acronym{GLR} parsers and @code{yylloc} @cindex @acronym{GLR} parsers and @code{yylloc}
In any semantic action, you can examine @code{yychar} to determine the type of 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}, 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 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 In a nondeferred semantic action, you can also modify any of these variables to
influence syntax analysis. influence syntax analysis.
@xref{Look-Ahead, ,Look-Ahead Tokens}. @xref{Lookahead, ,Lookahead Tokens}.
@findex yyclearin @findex yyclearin
@cindex @acronym{GLR} parsers and @code{yyclearin} @cindex @acronym{GLR} parsers and @code{yyclearin}
@@ -3189,7 +3189,7 @@ always refers to the @code{expr} which precedes @code{bar} in the
definition of @code{foo}. definition of @code{foo}.
@vindex yylval @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. any, from a semantic action.
This semantic value is stored in @code{yylval}. This semantic value is stored in @code{yylval}.
@xref{Action Features, ,Special Features for Use in Actions}. @xref{Action Features, ,Special Features for Use in Actions}.
@@ -3377,8 +3377,8 @@ Now the parser is forced to decide whether to run the mid-rule action
when it has read no farther than the open-brace. In other words, it 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 must commit to using one rule or the other, without sufficient
information to do it correctly. (The open-brace token is what is called 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 the @dfn{lookahead} token at this time, since the parser is still
deciding what to do about it. @xref{Look-Ahead, ,Look-Ahead Tokens}.) deciding what to do about it. @xref{Lookahead, ,Lookahead Tokens}.)
You might think that you could correct the problem by putting identical You might think that you could correct the problem by putting identical
actions into the two rules, like this: actions into the two rules, like this:
@@ -3551,7 +3551,7 @@ exp: @dots{}
@end example @end example
@vindex yylloc @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. from a semantic action.
This location is stored in @code{yylloc}. This location is stored in @code{yylloc}.
@xref{Action Features, ,Special Features for Use in Actions}. @xref{Action Features, ,Special Features for Use in Actions}.
@@ -3899,7 +3899,7 @@ code.
@findex %initial-action @findex %initial-action
Declare that the braced @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{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}. @code{%parse-param}.
@end deffn @end deffn
@@ -3971,7 +3971,7 @@ stacked symbols popped during the first phase of error recovery,
@item @item
incoming terminals during the second phase of error recovery, incoming terminals during the second phase of error recovery,
@item @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 right-hand side symbols) when the parser returns immediately, and
@item @item
the start symbol, when the parser succeeds. the start symbol, when the parser succeeds.
@@ -4309,7 +4309,7 @@ The number of parser states (@pxref{Parser States}).
@deffn {Directive} %verbose @deffn {Directive} %verbose
Write an extra output file containing verbose descriptions of the 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 that state. @xref{Understanding, , Understanding Your Parser}, for more
information. information.
@end deffn @end deffn
@@ -4857,14 +4857,14 @@ Return immediately from @code{yyparse}, indicating success.
@deffn {Macro} YYBACKUP (@var{token}, @var{value}); @deffn {Macro} YYBACKUP (@var{token}, @var{value});
@findex YYBACKUP @findex YYBACKUP
Unshift a token. This macro is allowed only for rules that reduce 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 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 semantic value @var{value}; then it discards the value that was
going to be reduced by this rule. going to be reduced by this rule.
If the macro is used when it is not valid, such as when there is 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 a message @samp{cannot back up} and performs ordinary error
recovery. recovery.
@@ -4873,12 +4873,12 @@ In either case, the rest of the action is not executed.
@deffn {Macro} YYEMPTY @deffn {Macro} YYEMPTY
@vindex 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 @end deffn
@deffn {Macro} YYEOF @deffn {Macro} YYEOF
@vindex 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. stream.
@end deffn @end deffn
@@ -4899,16 +4899,16 @@ is recovering from a syntax error, and 0 otherwise.
@end deffn @end deffn
@deffn {Variable} yychar @deffn {Variable} yychar
Variable containing either the look-ahead token, or @code{YYEOF} when the Variable containing either the lookahead token, or @code{YYEOF} when the
look-ahead is the end of the input stream, or @code{YYEMPTY} when no look-ahead 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. has been performed so the next token is not yet known.
Do not modify @code{yychar} in a deferred semantic action (@pxref{GLR Semantic Do not modify @code{yychar} in a deferred semantic action (@pxref{GLR Semantic
Actions}). Actions}).
@xref{Look-Ahead, ,Look-Ahead Tokens}. @xref{Lookahead, ,Lookahead Tokens}.
@end deffn @end deffn
@deffn {Macro} yyclearin; @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. error rules.
Do not invoke @code{yyclearin} in a deferred semantic action (@pxref{GLR Do not invoke @code{yyclearin} in a deferred semantic action (@pxref{GLR
Semantic Actions}). Semantic Actions}).
@@ -4922,7 +4922,7 @@ errors. This is useful primarily in error rules.
@end deffn @end deffn
@deffn {Variable} yylloc @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}. to @code{YYEMPTY} or @code{YYEOF}.
Do not modify @code{yylloc} in a deferred semantic action (@pxref{GLR Semantic Do not modify @code{yylloc} in a deferred semantic action (@pxref{GLR Semantic
Actions}). Actions}).
@@ -4930,7 +4930,7 @@ Actions}).
@end deffn @end deffn
@deffn {Variable} yylval @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}. not set to @code{YYEMPTY} or @code{YYEOF}.
Do not modify @code{yylval} in a deferred semantic action (@pxref{GLR Semantic Do not modify @code{yylval} in a deferred semantic action (@pxref{GLR Semantic
Actions}). Actions}).
@@ -5111,7 +5111,7 @@ to a single grouping whose symbol is the grammar's start-symbol
This kind of parser is known in the literature as a bottom-up parser. This kind of parser is known in the literature as a bottom-up parser.
@menu @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. * Shift/Reduce:: Conflicts: when either shifting or reduction is valid.
* Precedence:: Operator precedence works by resolving conflicts. * Precedence:: Operator precedence works by resolving conflicts.
* Contextual Precedence:: When an operator's precedence depends on context. * Contextual Precedence:: When an operator's precedence depends on context.
@@ -5122,9 +5122,9 @@ This kind of parser is known in the literature as a bottom-up parser.
* Memory Management:: What happens when memory is exhausted. How to avoid it. * Memory Management:: What happens when memory is exhausted. How to avoid it.
@end menu @end menu
@node Look-Ahead @node Lookahead
@section Look-Ahead Tokens @section Lookahead Tokens
@cindex look-ahead token @cindex lookahead token
The Bison parser does @emph{not} always reduce immediately as soon as the 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 last @var{n} tokens and groupings match a rule. This is because such a
@@ -5133,15 +5133,15 @@ reduction is possible, the parser sometimes ``looks ahead'' at the next
token in order to decide what to do. token in order to decide what to do.
When a token is read, it is not immediately shifted; first it becomes the 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 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 the lookahead token remains off to the side. When no more reductions
should take place, the look-ahead token is shifted onto the stack. This 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 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. 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 expressions which contain binary addition operators and postfix unary
factorial operators (@samp{!}), and allow parentheses for grouping. factorial operators (@samp{!}), and allow parentheses for grouping.
@@ -5176,7 +5176,7 @@ doing so would produce on the stack the sequence of symbols @code{expr
@vindex yychar @vindex yychar
@vindex yylval @vindex yylval
@vindex yylloc @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 Its semantic value and location, if any, are stored in the variables
@code{yylval} and @code{yylloc}. @code{yylval} and @code{yylloc}.
@xref{Action Features, ,Special Features for Use in Actions}. @xref{Action Features, ,Special Features for Use in Actions}.
@@ -5204,7 +5204,7 @@ if_stmt:
Here we assume that @code{IF}, @code{THEN} and @code{ELSE} are Here we assume that @code{IF}, @code{THEN} and @code{ELSE} are
terminal symbols for specific keyword tokens. 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 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 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 @code{ELSE}, because that would lead to eventual reduction by the second
@@ -5338,7 +5338,7 @@ operators we prefer the former, which is called @dfn{left association}.
The latter alternative, @dfn{right association}, is desirable for The latter alternative, @dfn{right association}, is desirable for
assignment operators. The choice of left or right association is a assignment operators. The choice of left or right association is a
matter of whether the parser chooses to shift or reduce when the stack 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. makes right-associativity.
@node Using Precedence @node Using Precedence
@@ -5399,7 +5399,7 @@ specify explicitly the precedence of a rule. @xref{Contextual
Precedence, ,Context-Dependent Precedence}.) Precedence, ,Context-Dependent Precedence}.)
Finally, the resolution of conflicts works by comparing the 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 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 is higher, the choice is to reduce. If they have equal
precedence, the choice is made based on the associativity of that precedence, the choice is made based on the associativity of that
@@ -5408,7 +5408,7 @@ precedence level. The verbose output file made by @samp{-v}
resolved. resolved.
Not all rules and not all tokens have precedence. If either the rule or 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 @node Contextual Precedence
@section Context-Dependent Precedence @section Context-Dependent Precedence
@@ -5502,9 +5502,9 @@ represent the entire sequence of terminal and nonterminal symbols at or
near the top of the stack. The current state collects all the information 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. 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 Each time a lookahead token is read, the current parser state together
with the type of look-ahead token are looked up in a table. This table with the type of lookahead token are looked up in a table. This table
entry can say, ``Shift the look-ahead token.'' In this case, it also 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 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}.'' 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 This means that a certain number of tokens or groupings are taken off
@@ -5512,7 +5512,7 @@ the top of the stack, and replaced by one grouping. In other words,
that number of states are popped from the stack, and one new state is that number of states are popped from the stack, and one new state is
pushed. 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 is erroneous in the current state. This causes error processing to begin
(@pxref{Error Recovery}). (@pxref{Error Recovery}).
@@ -5670,7 +5670,7 @@ name_list:
@end example @end example
It would seem that this grammar can be parsed with only a single token 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 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). @code{ID} follows. In other words, this grammar is @acronym{LR}(1).
@@ -5684,7 +5684,7 @@ a @code{return_spec}, are similar enough that Bison assumes they are the
same. They appear similar because the same set of rules would be 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 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 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 contexts, so it makes a single parser state for them both. Combining
the two contexts causes a conflict later. In parser terminology, this the two contexts causes a conflict later. In parser terminology, this
occurrence means that the grammar is not @acronym{LALR}(1). occurrence means that the grammar is not @acronym{LALR}(1).
@@ -5757,13 +5757,13 @@ pp.@: 615--649 @uref{http://doi.acm.org/10.1145/69622.357187}.
Bison produces @emph{deterministic} parsers that choose uniquely Bison produces @emph{deterministic} parsers that choose uniquely
when to reduce and which reduction to apply 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 As a result, normal Bison handles a proper subset of the family of
context-free languages. context-free languages.
Ambiguous grammars, since they have strings with more than one possible Ambiguous grammars, since they have strings with more than one possible
sequence of reductions cannot have deterministic parsers in this sense. sequence of reductions cannot have deterministic parsers in this sense.
The same is true of languages that require more than one symbol of 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. decision at the point it must be made in a shift-reduce parser.
Finally, as previously mentioned (@pxref{Mystery Conflicts}), Finally, as previously mentioned (@pxref{Mystery Conflicts}),
there are languages where Bison's particular choice of how to there are languages where Bison's particular choice of how to
@@ -5940,7 +5940,7 @@ and objects from the stack until it gets back to a state in which the
@code{error} token is acceptable. (This means that the subexpressions @code{error} token is acceptable. (This means that the subexpressions
already parsed are discarded, back to the last complete @code{stmnts}.) 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 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 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 this example, Bison reads and discards input until the next newline so
that the fourth rule can apply. Note that discarded symbols are that the fourth rule can apply. Note that discarded symbols are
@@ -5991,7 +5991,7 @@ error messages will be suppressed. This macro requires no arguments;
@samp{yyerrok;} is a valid C statement. @samp{yyerrok;} is a valid C statement.
@findex yyclearin @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 is unacceptable, then the macro @code{yyclearin} may be used to clear
this token. Write the statement @samp{yyclearin;} in the error rule's this token. Write the statement @samp{yyclearin;} in the error rule's
action. action.
@@ -6000,7 +6000,7 @@ action.
For example, suppose that on a syntax error, an error handling routine is 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 called that advances the input stream to some point where parsing should
once again commence. The next symbol returned by the lexical scanner is 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;}. with @samp{yyclearin;}.
@vindex YYRECOVERING @vindex YYRECOVERING
@@ -6388,16 +6388,16 @@ beginning of the parsing, in the initial rule, right before the start
symbol (here, @code{exp}). When the parser returns to this state right symbol (here, @code{exp}). When the parser returns to this state right
after having reduced a rule that produced an @code{exp}, the control 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 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 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 core, item set
@cindex item set core @cindex item set core
@cindex kernel, item set @cindex kernel, item set
@cindex item set core @cindex item set core
Even though the only active rule in state 0 seems to be rule 0, the 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 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 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 you want to see more detail you can invoke @command{bison} with
@@ -6431,7 +6431,7 @@ state 1
@end example @end example
@noindent @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 (@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 state 0, then, after this reduction it will return to state 0, and will
jump to state 2 (@samp{exp: go to state 2}). jump to state 2 (@samp{exp: go to state 2}).
@@ -6454,7 +6454,7 @@ state 2
@noindent @noindent
In state 2, the automaton can only shift a symbol. For instance, 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 @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 control will jump to state 4, corresponding to the item @samp{exp -> exp
'+' . exp}. Since there is no default action, any other token than '+' . exp}. Since there is no default action, any other token than
@@ -6531,7 +6531,7 @@ state 8
$default reduce using rule 1 (exp) $default reduce using rule 1 (exp)
@end example @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 either shifting (and going to state 7), or reducing rule 1. The
conflict means that either the grammar is ambiguous, or the parser lacks conflict means that either the grammar is ambiguous, or the parser lacks
information to make the right decision. Indeed the grammar is information to make the right decision. Indeed the grammar is
@@ -6549,14 +6549,14 @@ Note that all the previous states had a single possible action: either
shifting the next token and going to the corresponding state, or shifting the next token and going to the corresponding state, or
reducing a single rule. In the other cases, i.e., when shifting reducing a single rule. In the other cases, i.e., when shifting
@emph{and} reducing is possible or when @emph{several} reductions are @emph{and} reducing is possible or when @emph{several} reductions are
possible, the look-ahead is required to select the action. State 8 is possible, the lookahead is required to select the action. State 8 is
one such state: if the look-ahead is @samp{*} or @samp{/} then the action 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, 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 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 precedence than @samp{+}. More generally, some items are eligible only
with some set of possible look-ahead tokens. When run with with some set of possible lookahead tokens. When run with
@option{--report=look-ahead}, Bison specifies these look-ahead tokens: @option{--report=lookahead}, Bison specifies these lookahead tokens:
@example @example
state 8 state 8
@@ -6914,9 +6914,9 @@ separated list of @var{things} among:
Description of the grammar, conflicts (resolved and unresolved), and Description of the grammar, conflicts (resolved and unresolved), and
@acronym{LALR} automaton. @acronym{LALR} automaton.
@item look-ahead @item lookahead
Implies @code{state} and augments the description of the automaton with Implies @code{state} and augments the description of the automaton with
each rule's look-ahead set. each rule's lookahead set.
@item itemset @item itemset
Implies @code{state} and augments the description of the automaton with Implies @code{state} and augments the description of the automaton with
@@ -8207,8 +8207,8 @@ 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
the grammar without halting the process. In effect, a sentence the grammar without halting the process. In effect, a sentence
containing an error may be recognized as valid. On a syntax error, the containing an error may be recognized as valid. On a syntax error, the
token @code{error} becomes the current look-ahead token. Actions token @code{error} becomes the current lookahead token. Actions
corresponding to @code{error} are then executed, and the look-ahead corresponding to @code{error} are then executed, and the lookahead
token is reset to the token that originally caused the violation. token is reset to the token that originally caused the violation.
@xref{Error Recovery}. @xref{Error Recovery}.
@end deffn @end deffn
@@ -8348,20 +8348,20 @@ read, by making @code{yyparse} return 0 immediately.
@end deffn @end deffn
@deffn {Macro} YYBACKUP @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}. token. @xref{Action Features, ,Special Features for Use in Actions}.
@end deffn @end deffn
@deffn {Variable} yychar @deffn {Variable} yychar
External integer variable that contains the integer value of the 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. @code{yyparse}.) Error-recovery rule actions may examine this variable.
@xref{Action Features, ,Special Features for Use in Actions}. @xref{Action Features, ,Special Features for Use in Actions}.
@end deffn @end deffn
@deffn {Variable} yyclearin @deffn {Variable} yyclearin
Macro used in error-recovery rule actions. It clears the previous Macro used in error-recovery rule actions. It clears the previous
look-ahead token. @xref{Error Recovery}. lookahead token. @xref{Error Recovery}.
@end deffn @end deffn
@deffn {Macro} YYDEBUG @deffn {Macro} YYDEBUG
@@ -8427,7 +8427,7 @@ variable within @code{yyparse}, and its address is passed to
You can ignore this variable if you don't use the @samp{@@} feature in the You can ignore this variable if you don't use the @samp{@@} feature in the
grammar actions. grammar actions.
@xref{Token Locations, ,Textual Locations of Tokens}. @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}. @xref{Actions and Locations, ,Actions and Locations}.
@end deffn @end deffn
@@ -8442,7 +8442,7 @@ value associated with a token. (In a pure parser, it is a local
variable within @code{yyparse}, and its address is passed to variable within @code{yyparse}, and its address is passed to
@code{yylex}.) @code{yylex}.)
@xref{Token Values, ,Semantic Values of Tokens}. @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}. @xref{Actions, ,Actions}.
@end deffn @end deffn
@@ -8582,8 +8582,8 @@ tokens are parsed. @xref{Lexical Tie-ins}.
@item Literal string token @item Literal string token
A token which consists of two or more fixed characters. @xref{Symbols}. A token which consists of two or more fixed characters. @xref{Symbols}.
@item Look-ahead token @item Lookahead token
A token already read but not yet shifted. @xref{Look-Ahead, ,Look-Ahead A token already read but not yet shifted. @xref{Lookahead, ,Lookahead
Tokens}. Tokens}.
@item @acronym{LALR}(1) @item @acronym{LALR}(1)
@@ -8593,7 +8593,7 @@ Conflicts, ,Mysterious Reduce/Reduce Conflicts}.
@item @acronym{LR}(1) @item @acronym{LR}(1)
The class of context-free grammars in which at most one token of 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 @item Nonterminal symbol
A grammar symbol standing for a grammatical construct that can A grammar symbol standing for a grammatical construct that can

View File

@@ -1,4 +1,4 @@
/* Find and resolve or report look-ahead conflicts for bison, /* Find and resolve or report lookahead conflicts for bison,
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc. Free Software Foundation, Inc.
@@ -43,7 +43,7 @@ static char *conflicts;
static struct obstack solved_conflicts_obstack; static struct obstack solved_conflicts_obstack;
static bitset shift_set; static bitset shift_set;
static bitset look_ahead_set; static bitset lookahead_set;
@@ -147,7 +147,7 @@ flush_shift (state *s, int token)
transitions *trans = s->transitions; transitions *trans = s->transitions;
int i; int i;
bitset_reset (look_ahead_set, token); bitset_reset (lookahead_set, token);
for (i = 0; i < trans->num; i++) for (i = 0; i < trans->num; i++)
if (!TRANSITION_IS_DISABLED (trans, i) if (!TRANSITION_IS_DISABLED (trans, i)
&& TRANSITION_SYMBOL (trans, i) == token) && TRANSITION_SYMBOL (trans, i) == token)
@@ -157,14 +157,14 @@ flush_shift (state *s, int token)
/*--------------------------------------------------------------------. /*--------------------------------------------------------------------.
| Turn off the reduce recorded for the specified token for the | | Turn off the reduce recorded for the specified token for the |
| specified look-ahead. Used when we resolve a shift-reduce conflict | | specified lookahead. Used when we resolve a shift-reduce conflict |
| in favor of the shift. | | in favor of the shift. |
`--------------------------------------------------------------------*/ `--------------------------------------------------------------------*/
static void static void
flush_reduce (bitset look_ahead_tokens, int token) flush_reduce (bitset lookahead_tokens, int token)
{ {
bitset_reset (look_ahead_tokens, token); bitset_reset (lookahead_tokens, token);
} }
@@ -174,7 +174,7 @@ flush_reduce (bitset look_ahead_tokens, int token)
| rule has a precedence. A conflict is resolved by modifying the | | rule has a precedence. A conflict is resolved by modifying the |
| shift or reduce tables so that there is no longer a conflict. | | shift or reduce tables so that there is no longer a conflict. |
| | | |
| RULENO is the number of the look-ahead bitset to consider. | | RULENO is the number of the lookahead bitset to consider. |
| | | |
| ERRORS can be used to store discovered explicit errors. | | ERRORS can be used to store discovered explicit errors. |
`------------------------------------------------------------------*/ `------------------------------------------------------------------*/
@@ -187,12 +187,12 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
/* Find the rule to reduce by to get precedence of reduction. */ /* Find the rule to reduce by to get precedence of reduction. */
rule *redrule = reds->rules[ruleno]; rule *redrule = reds->rules[ruleno];
int redprec = redrule->prec->prec; int redprec = redrule->prec->prec;
bitset look_ahead_tokens = reds->look_ahead_tokens[ruleno]; bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
int nerrs = 0; int nerrs = 0;
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
if (bitset_test (look_ahead_tokens, i) if (bitset_test (lookahead_tokens, i)
&& bitset_test (look_ahead_set, i) && bitset_test (lookahead_set, i)
&& symbols[i]->prec) && symbols[i]->prec)
{ {
/* Shift-reduce conflict occurs for token number i /* Shift-reduce conflict occurs for token number i
@@ -206,7 +206,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
else if (symbols[i]->prec > redprec) else if (symbols[i]->prec > redprec)
{ {
log_resolution (redrule, i, shift_resolution); log_resolution (redrule, i, shift_resolution);
flush_reduce (look_ahead_tokens, i); flush_reduce (lookahead_tokens, i);
} }
else else
/* Matching precedence levels. /* Matching precedence levels.
@@ -221,7 +221,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
case right_assoc: case right_assoc:
log_resolution (redrule, i, right_resolution); log_resolution (redrule, i, right_resolution);
flush_reduce (look_ahead_tokens, i); flush_reduce (lookahead_tokens, i);
break; break;
case left_assoc: case left_assoc:
@@ -232,7 +232,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
case non_assoc: case non_assoc:
log_resolution (redrule, i, nonassoc_resolution); log_resolution (redrule, i, nonassoc_resolution);
flush_shift (s, i); flush_shift (s, i);
flush_reduce (look_ahead_tokens, i); flush_reduce (lookahead_tokens, i);
/* Record an explicit error for this token. */ /* Record an explicit error for this token. */
errors[nerrs++] = symbols[i]; errors[nerrs++] = symbols[i];
break; break;
@@ -258,7 +258,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
| Solve the S/R conflicts of state S using the | | Solve the S/R conflicts of state S using the |
| precedence/associativity, and flag it inconsistent if it still has | | precedence/associativity, and flag it inconsistent if it still has |
| conflicts. ERRORS can be used as storage to compute the list of | | conflicts. ERRORS can be used as storage to compute the list of |
| look-ahead tokens on which S raises a syntax error (%nonassoc). | | lookahead tokens on which S raises a syntax error (%nonassoc). |
`-------------------------------------------------------------------*/ `-------------------------------------------------------------------*/
static void static void
@@ -271,27 +271,27 @@ set_conflicts (state *s, symbol **errors)
if (s->consistent) if (s->consistent)
return; return;
bitset_zero (look_ahead_set); bitset_zero (lookahead_set);
FOR_EACH_SHIFT (trans, i) FOR_EACH_SHIFT (trans, i)
bitset_set (look_ahead_set, TRANSITION_SYMBOL (trans, i)); bitset_set (lookahead_set, TRANSITION_SYMBOL (trans, i));
/* Loop over all rules which require look-ahead in this state. First /* Loop over all rules which require lookahead in this state. First
check for shift-reduce conflict, and try to resolve using check for shift-reduce conflict, and try to resolve using
precedence. */ precedence. */
for (i = 0; i < reds->num; ++i) for (i = 0; i < reds->num; ++i)
if (reds->rules[i]->prec && reds->rules[i]->prec->prec if (reds->rules[i]->prec && reds->rules[i]->prec->prec
&& !bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set)) && !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
resolve_sr_conflict (s, i, errors); resolve_sr_conflict (s, i, errors);
/* Loop over all rules which require look-ahead in this state. Check /* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. */ for conflicts not resolved above. */
for (i = 0; i < reds->num; ++i) for (i = 0; i < reds->num; ++i)
{ {
if (!bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set)) if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
conflicts[s->number] = 1; conflicts[s->number] = 1;
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]); bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
} }
} }
@@ -305,12 +305,12 @@ void
conflicts_solve (void) conflicts_solve (void)
{ {
state_number i; state_number i;
/* List of look-ahead tokens on which we explicitly raise a syntax error. */ /* List of lookahead tokens on which we explicitly raise a syntax error. */
symbol **errors = xnmalloc (ntokens + 1, sizeof *errors); symbol **errors = xnmalloc (ntokens + 1, sizeof *errors);
conflicts = xcalloc (nstates, sizeof *conflicts); conflicts = xcalloc (nstates, sizeof *conflicts);
shift_set = bitset_create (ntokens, BITSET_FIXED); shift_set = bitset_create (ntokens, BITSET_FIXED);
look_ahead_set = bitset_create (ntokens, BITSET_FIXED); lookahead_set = bitset_create (ntokens, BITSET_FIXED);
obstack_init (&solved_conflicts_obstack); obstack_init (&solved_conflicts_obstack);
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
@@ -342,18 +342,18 @@ count_sr_conflicts (state *s)
if (!trans) if (!trans)
return 0; return 0;
bitset_zero (look_ahead_set); bitset_zero (lookahead_set);
bitset_zero (shift_set); bitset_zero (shift_set);
FOR_EACH_SHIFT (trans, i) FOR_EACH_SHIFT (trans, i)
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i)); bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
for (i = 0; i < reds->num; ++i) for (i = 0; i < reds->num; ++i)
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]); bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
bitset_and (look_ahead_set, look_ahead_set, shift_set); bitset_and (lookahead_set, lookahead_set, shift_set);
src_count = bitset_count (look_ahead_set); src_count = bitset_count (lookahead_set);
return src_count; return src_count;
} }
@@ -378,7 +378,7 @@ count_rr_conflicts (state *s, bool one_per_token)
int count = 0; int count = 0;
int j; int j;
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
if (bitset_test (reds->look_ahead_tokens[j], i)) if (bitset_test (reds->lookahead_tokens[j], i))
count++; count++;
if (count >= 2) if (count >= 2)
@@ -433,7 +433,7 @@ conflicts_output (FILE *out)
/*--------------------------------------------------------. /*--------------------------------------------------------.
| Total the number of S/R and R/R conflicts. Unlike the | | Total the number of S/R and R/R conflicts. Unlike the |
| code in conflicts_output, however, count EACH pair of | | code in conflicts_output, however, count EACH pair of |
| reductions for the same state and look-ahead as one | | reductions for the same state and lookahead as one |
| conflict. | | conflict. |
`--------------------------------------------------------*/ `--------------------------------------------------------*/
@@ -530,6 +530,6 @@ conflicts_free (void)
{ {
free (conflicts); free (conflicts);
bitset_free (shift_set); bitset_free (shift_set);
bitset_free (look_ahead_set); bitset_free (lookahead_set);
obstack_free (&solved_conflicts_obstack, NULL); obstack_free (&solved_conflicts_obstack, NULL);
} }

View File

@@ -1,4 +1,4 @@
/* Find and resolve or report look-ahead conflicts for bison, /* Find and resolve or report lookahead conflicts for bison,
Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc. Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.

View File

@@ -145,7 +145,7 @@ static const char * const report_args[] =
"none", "none",
"state", "states", "state", "states",
"itemset", "itemsets", "itemset", "itemsets",
"look-ahead", "lookahead", "lookaheads", "lookahead", "lookaheads", "look-ahead",
"solved", "solved",
"all", "all",
0 0
@@ -156,9 +156,9 @@ static const int report_types[] =
report_none, report_none,
report_states, report_states, report_states, report_states,
report_states | report_itemsets, report_states | report_itemsets, report_states | report_itemsets, report_states | report_itemsets,
report_states | report_look_ahead_tokens, report_states | report_lookahead_tokens,
report_states | report_look_ahead_tokens, report_states | report_lookahead_tokens,
report_states | report_look_ahead_tokens, report_states | report_lookahead_tokens,
report_states | report_solved_conflicts, report_states | report_solved_conflicts,
report_all report_all
}; };
@@ -247,7 +247,7 @@ Output:\n\
THINGS is a list of comma separated words that can include:\n\ THINGS is a list of comma separated words that can include:\n\
`state' describe the states\n\ `state' describe the states\n\
`itemset' complete the core item sets with their closure\n\ `itemset' complete the core item sets with their closure\n\
`look-ahead' explicitly associate look-ahead tokens to items\n\ `lookahead' explicitly associate lookahead tokens to items\n\
`solved' describe shift/reduce conflicts solving\n\ `solved' describe shift/reduce conflicts solving\n\
`all' include all the above information\n\ `all' include all the above information\n\
`none' disable the report\n\ `none' disable the report\n\

View File

@@ -84,7 +84,7 @@ enum report
report_none = 0, report_none = 0,
report_states = 1 << 0, report_states = 1 << 0,
report_itemsets = 1 << 1, report_itemsets = 1 << 1,
report_look_ahead_tokens= 1 << 2, report_lookahead_tokens = 1 << 2,
report_solved_conflicts = 1 << 3, report_solved_conflicts = 1 << 3,
report_all = ~0 report_all = ~0
}; };

View File

@@ -1,4 +1,4 @@
/* Compute look-ahead criteria for Bison. /* Compute lookahead criteria for Bison.
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004, 2005, Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004, 2005,
2006 Free Software Foundation, Inc. 2006 Free Software Foundation, Inc.
@@ -22,7 +22,7 @@
/* Compute how to make the finite state machine deterministic; find /* Compute how to make the finite state machine deterministic; find
which rules need look-ahead in each state, and which look-ahead which rules need lookahead in each state, and which lookahead
tokens they accept. */ tokens they accept. */
#include <config.h> #include <config.h>
@@ -219,9 +219,9 @@ add_lookback_edge (state *s, rule *r, goto_number gotono)
{ {
int ri = state_reduction_find (s, r); int ri = state_reduction_find (s, r);
goto_list *sp = xmalloc (sizeof *sp); goto_list *sp = xmalloc (sizeof *sp);
sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri]; sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri];
sp->value = gotono; sp->value = gotono;
lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp; lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp;
} }
@@ -314,7 +314,7 @@ compute_FOLLOWS (void)
static void static void
compute_look_ahead_tokens (void) compute_lookahead_tokens (void)
{ {
size_t i; size_t i;
goto_list *sp; goto_list *sp;
@@ -332,27 +332,27 @@ compute_look_ahead_tokens (void)
} }
/*-----------------------------------------------------. /*----------------------------------------------------.
| Count the number of look-ahead tokens required for S | | Count the number of lookahead tokens required for S |
| (N_LOOK_AHEAD_TOKENS member). | | (N_LOOKAHEAD_TOKENS member). |
`-----------------------------------------------------*/ `----------------------------------------------------*/
static int static int
state_look_ahead_tokens_count (state *s) state_lookahead_tokens_count (state *s)
{ {
int k; int k;
int n_look_ahead_tokens = 0; int n_lookahead_tokens = 0;
reductions *rp = s->reductions; reductions *rp = s->reductions;
transitions *sp = s->transitions; transitions *sp = s->transitions;
/* We need a look-ahead either to distinguish different /* We need a lookahead either to distinguish different
reductions (i.e., there are two or more), or to distinguish a reductions (i.e., there are two or more), or to distinguish a
reduction from a shift. Otherwise, it is straightforward, reduction from a shift. Otherwise, it is straightforward,
and the state is `consistent'. */ and the state is `consistent'. */
if (rp->num > 1 if (rp->num > 1
|| (rp->num == 1 && sp->num && || (rp->num == 1 && sp->num &&
!TRANSITION_IS_DISABLED (sp, 0) && TRANSITION_IS_SHIFT (sp, 0))) !TRANSITION_IS_DISABLED (sp, 0) && TRANSITION_IS_SHIFT (sp, 0)))
n_look_ahead_tokens += rp->num; n_lookahead_tokens += rp->num;
else else
s->consistent = 1; s->consistent = 1;
@@ -363,13 +363,13 @@ state_look_ahead_tokens_count (state *s)
break; break;
} }
return n_look_ahead_tokens; return n_lookahead_tokens;
} }
/*-----------------------------------------------------. /*----------------------------------------------------.
| Compute LA, NLA, and the look_ahead_tokens members. | | Compute LA, NLA, and the lookahead_tokens members. |
`-----------------------------------------------------*/ `----------------------------------------------------*/
static void static void
initialize_LA (void) initialize_LA (void)
@@ -377,10 +377,10 @@ initialize_LA (void)
state_number i; state_number i;
bitsetv pLA; bitsetv pLA;
/* Compute the total number of reductions requiring a look-ahead. */ /* Compute the total number of reductions requiring a lookahead. */
nLA = 0; nLA = 0;
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
nLA += state_look_ahead_tokens_count (states[i]); nLA += state_lookahead_tokens_count (states[i]);
/* Avoid having to special case 0. */ /* Avoid having to special case 0. */
if (!nLA) if (!nLA)
nLA = 1; nLA = 1;
@@ -388,54 +388,54 @@ initialize_LA (void)
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
lookback = xcalloc (nLA, sizeof *lookback); lookback = xcalloc (nLA, sizeof *lookback);
/* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions /* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
require look-ahead tokens. */ require lookahead tokens. */
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
{ {
int count = state_look_ahead_tokens_count (states[i]); int count = state_lookahead_tokens_count (states[i]);
if (count) if (count)
{ {
states[i]->reductions->look_ahead_tokens = pLA; states[i]->reductions->lookahead_tokens = pLA;
pLA += count; pLA += count;
} }
} }
} }
/*----------------------------------------------. /*---------------------------------------------.
| Output the look-ahead tokens for each state. | | Output the lookahead tokens for each state. |
`----------------------------------------------*/ `---------------------------------------------*/
static void static void
look_ahead_tokens_print (FILE *out) lookahead_tokens_print (FILE *out)
{ {
state_number i; state_number i;
int j, k; int j, k;
fprintf (out, "Look-ahead tokens: BEGIN\n"); fprintf (out, "Lookahead tokens: BEGIN\n");
for (i = 0; i < nstates; ++i) for (i = 0; i < nstates; ++i)
{ {
reductions *reds = states[i]->reductions; reductions *reds = states[i]->reductions;
bitset_iterator iter; bitset_iterator iter;
int n_look_ahead_tokens = 0; int n_lookahead_tokens = 0;
if (reds->look_ahead_tokens) if (reds->lookahead_tokens)
for (k = 0; k < reds->num; ++k) for (k = 0; k < reds->num; ++k)
if (reds->look_ahead_tokens[k]) if (reds->lookahead_tokens[k])
++n_look_ahead_tokens; ++n_lookahead_tokens;
fprintf (out, "State %d: %d look-ahead tokens\n", fprintf (out, "State %d: %d lookahead tokens\n",
i, n_look_ahead_tokens); i, n_lookahead_tokens);
if (reds->look_ahead_tokens) if (reds->lookahead_tokens)
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
BITSET_FOR_EACH (iter, reds->look_ahead_tokens[j], k, 0) BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0)
{ {
fprintf (out, " on %d (%s) -> rule %d\n", fprintf (out, " on %d (%s) -> rule %d\n",
k, symbols[k]->tag, k, symbols[k]->tag,
reds->rules[j]->number); reds->rules[j]->number);
}; };
} }
fprintf (out, "Look-ahead tokens: END\n"); fprintf (out, "Lookahead tokens: END\n");
} }
void void
@@ -446,10 +446,10 @@ lalr (void)
initialize_F (); initialize_F ();
build_relations (); build_relations ();
compute_FOLLOWS (); compute_FOLLOWS ();
compute_look_ahead_tokens (); compute_lookahead_tokens ();
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
look_ahead_tokens_print (stderr); lookahead_tokens_print (stderr);
} }
@@ -458,6 +458,6 @@ lalr_free (void)
{ {
state_number s; state_number s;
for (s = 0; s < nstates; ++s) for (s = 0; s < nstates; ++s)
states[s]->reductions->look_ahead_tokens = NULL; states[s]->reductions->lookahead_tokens = NULL;
bitsetv_free (LA); bitsetv_free (LA);
} }

View File

@@ -1,4 +1,4 @@
/* Compute look-ahead criteria for bison, /* Compute lookahead criteria for bison,
Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004 Free Software Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004 Free Software
Foundation, Inc. Foundation, Inc.
@@ -33,12 +33,12 @@
# include "state.h" # include "state.h"
/* Compute how to make the finite state machine deterministic; find /* Compute how to make the finite state machine deterministic; find
which rules need look-ahead in each state, and which look-ahead which rules need lookahead in each state, and which lookahead
tokens they accept. */ tokens they accept. */
void lalr (void); void lalr (void);
/* Release the information related to look-ahead tokens. Can be performed /* Release the information related to lookahead tokens. Can be performed
once the action tables are computed. */ once the action tables are computed. */
void lalr_free (void); void lalr_free (void);

View File

@@ -110,7 +110,7 @@ main (int argc, char *argv[])
timevar_pop (TV_LALR); timevar_pop (TV_LALR);
/* Find and record any conflicts: places where one token of /* Find and record any conflicts: places where one token of
look-ahead is not enough to disambiguate the parsing. In file lookahead is not enough to disambiguate the parsing. In file
conflicts. Also resolve s/r conflicts based on precedence conflicts. Also resolve s/r conflicts based on precedence
declarations. */ declarations. */
timevar_push (TV_CONFLICTS); timevar_push (TV_CONFLICTS);
@@ -150,7 +150,7 @@ main (int argc, char *argv[])
if (complaint_issued) if (complaint_issued)
goto finish; goto finish;
/* Look-ahead tokens are no longer needed. */ /* Lookahead tokens are no longer needed. */
timevar_push (TV_FREE); timevar_push (TV_FREE);
lalr_free (); lalr_free ();
timevar_pop (TV_FREE); timevar_pop (TV_FREE);

View File

@@ -448,7 +448,7 @@ static void
prepare_actions (void) prepare_actions (void)
{ {
/* Figure out the actions for the specified state, indexed by /* Figure out the actions for the specified state, indexed by
look-ahead token type. */ lookahead token type. */
muscle_insert_rule_number_table ("defact", yydefact, muscle_insert_rule_number_table ("defact", yydefact,
yydefact[0], 1, nstates); yydefact[0], 1, nstates);

View File

@@ -1456,15 +1456,15 @@ yyparse ()
#endif #endif
#endif #endif
{ {
/* The look-ahead symbol. */ /* The lookahead symbol. */
int yychar; int yychar;
/* The semantic value of the look-ahead symbol. */ /* The semantic value of the lookahead symbol. */
YYSTYPE yylval; YYSTYPE yylval;
/* Number of syntax errors so far. */ /* Number of syntax errors so far. */
int yynerrs; int yynerrs;
/* Location data for the look-ahead symbol. */ /* Location data for the lookahead symbol. */
YYLTYPE yylloc; YYLTYPE yylloc;
int yystate; int yystate;
@@ -1472,7 +1472,7 @@ YYLTYPE yylloc;
int yyresult; int yyresult;
/* Number of tokens to shift before error messages enabled. */ /* Number of tokens to shift before error messages enabled. */
int yyerrstatus; int yyerrstatus;
/* Look-ahead token as an internal (translated) token number. */ /* Lookahead token as an internal (translated) token number. */
int yytoken = 0; int yytoken = 0;
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */ /* Buffer for error messages, and its allocated size. */
@@ -1640,16 +1640,16 @@ YYLTYPE yylloc;
yybackup: yybackup:
/* Do appropriate processing given the current state. Read a /* Do appropriate processing given the current state. Read a
look-ahead token if we need one and don't already have one. */ lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to look-ahead token. */ /* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate]; yyn = yypact[yystate];
if (yyn == YYPACT_NINF) if (yyn == YYPACT_NINF)
goto yydefault; goto yydefault;
/* Not known => get a look-ahead token if don't already have one. */ /* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY) if (yychar == YYEMPTY)
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
@@ -1689,7 +1689,7 @@ yybackup:
if (yyerrstatus) if (yyerrstatus)
yyerrstatus--; yyerrstatus--;
/* Shift the look-ahead token. */ /* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
/* Discard the shifted token unless it is eof. */ /* Discard the shifted token unless it is eof. */
@@ -2216,7 +2216,7 @@ yyerrlab:
if (yyerrstatus == 3) if (yyerrstatus == 3)
{ {
/* If just tried and failed to reuse look-ahead token after an /* If just tried and failed to reuse lookahead token after an
error, discard it. */ error, discard it. */
if (yychar <= YYEOF) if (yychar <= YYEOF)
@@ -2233,7 +2233,7 @@ yyerrlab:
} }
} }
/* Else will try to reuse look-ahead token after shifting the error /* Else will try to reuse lookahead token after shifting the error
token. */ token. */
goto yyerrlab1; goto yyerrlab1;
@@ -2298,7 +2298,7 @@ yyerrlab1:
yyerror_range[1] = yylloc; yyerror_range[1] = yylloc;
/* Using YYLLOC is tempting, but would change the location of /* Using YYLLOC is tempting, but would change the location of
the look-ahead. YYLOC is available though. */ the lookahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
*++yylsp = yyloc; *++yylsp = yyloc;

View File

@@ -40,7 +40,7 @@
#include "symtab.h" #include "symtab.h"
static bitset shift_set; static bitset shift_set;
static bitset look_ahead_set; static bitset lookahead_set;
#if 0 #if 0
static void static void
@@ -111,9 +111,9 @@ print_core (FILE *out, state *s)
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", symbols[*sp]->tag); fprintf (out, " %s", symbols[*sp]->tag);
/* Display the look-ahead tokens? */ /* Display the lookahead tokens? */
if (report_flag & report_look_ahead_tokens) if (report_flag & report_lookahead_tokens)
state_rule_look_ahead_tokens_print (s, &rules[r], out); state_rule_lookahead_tokens_print (s, &rules[r], out);
fputc ('\n', out); fputc ('\n', out);
} }
@@ -132,7 +132,7 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
size_t width = 0; size_t width = 0;
int i; int i;
/* Compute the width of the look-ahead token column. */ /* Compute the width of the lookahead token column. */
for (i = 0; i < trans->num; i++) for (i = 0; i < trans->num; i++)
if (!TRANSITION_IS_DISABLED (trans, i) if (!TRANSITION_IS_DISABLED (trans, i)
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p) && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
@@ -148,7 +148,7 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
fputc ('\n', out); fputc ('\n', out);
width += 2; width += 2;
/* Report look-ahead tokens and shifts. */ /* Report lookahead tokens and shifts. */
for (i = 0; i < trans->num; i++) for (i = 0; i < trans->num; i++)
if (!TRANSITION_IS_DISABLED (trans, i) if (!TRANSITION_IS_DISABLED (trans, i)
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p) && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
@@ -180,7 +180,7 @@ print_errs (FILE *out, state *s)
size_t width = 0; size_t width = 0;
int i; int i;
/* Compute the width of the look-ahead token column. */ /* Compute the width of the lookahead token column. */
for (i = 0; i < errp->num; ++i) for (i = 0; i < errp->num; ++i)
if (errp->symbols[i]) if (errp->symbols[i])
max_length (&width, errp->symbols[i]->tag); max_length (&width, errp->symbols[i]->tag);
@@ -192,7 +192,7 @@ print_errs (FILE *out, state *s)
fputc ('\n', out); fputc ('\n', out);
width += 2; width += 2;
/* Report look-ahead tokens and errors. */ /* Report lookahead tokens and errors. */
for (i = 0; i < errp->num; ++i) for (i = 0; i < errp->num; ++i)
if (errp->symbols[i]) if (errp->symbols[i])
{ {
@@ -218,11 +218,11 @@ state_default_rule (state *s)
int cmax = 0; int cmax = 0;
int i; int i;
/* No need for a look-ahead. */ /* No need for a lookahead. */
if (s->consistent) if (s->consistent)
return reds->rules[0]; return reds->rules[0];
/* 1. Each reduction is possibly masked by the look-ahead tokens on which /* 1. Each reduction is possibly masked by the lookahead tokens on which
we shift (S/R conflicts)... */ we shift (S/R conflicts)... */
bitset_zero (shift_set); bitset_zero (shift_set);
{ {
@@ -237,7 +237,7 @@ state_default_rule (state *s)
} }
} }
/* 2. Each reduction is possibly masked by the look-ahead tokens on which /* 2. Each reduction is possibly masked by the lookahead tokens on which
we raise an error (due to %nonassoc). */ we raise an error (due to %nonassoc). */
{ {
errs *errp = s->errs; errs *errp = s->errs;
@@ -250,10 +250,10 @@ state_default_rule (state *s)
{ {
int count = 0; int count = 0;
/* How many non-masked look-ahead tokens are there for this /* How many non-masked lookahead tokens are there for this
reduction? */ reduction? */
bitset_andn (look_ahead_set, reds->look_ahead_tokens[i], shift_set); bitset_andn (lookahead_set, reds->lookahead_tokens[i], shift_set);
count = bitset_count (look_ahead_set); count = bitset_count (lookahead_set);
if (count > cmax) if (count > cmax)
{ {
@@ -264,27 +264,27 @@ state_default_rule (state *s)
/* 3. And finally, each reduction is possibly masked by previous /* 3. And finally, each reduction is possibly masked by previous
reductions (in R/R conflicts, we keep the first reductions). reductions (in R/R conflicts, we keep the first reductions).
*/ */
bitset_or (shift_set, shift_set, reds->look_ahead_tokens[i]); bitset_or (shift_set, shift_set, reds->lookahead_tokens[i]);
} }
return default_rule; return default_rule;
} }
/*--------------------------------------------------------------------------. /*-------------------------------------------------------------------------.
| Report a reduction of RULE on LOOK_AHEAD_TOKEN (which can be `default'). | | Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be `default'). |
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and | | If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
| R/R conflicts). | | R/R conflicts). |
`--------------------------------------------------------------------------*/ `-------------------------------------------------------------------------*/
static void static void
print_reduction (FILE *out, size_t width, print_reduction (FILE *out, size_t width,
const char *look_ahead_token, const char *lookahead_token,
rule *r, bool enabled) rule *r, bool enabled)
{ {
int j; int j;
fprintf (out, " %s", look_ahead_token); fprintf (out, " %s", lookahead_token);
for (j = width - strlen (look_ahead_token); j > 0; --j) for (j = width - strlen (lookahead_token); j > 0; --j)
fputc (' ', out); fputc (' ', out);
if (!enabled) if (!enabled)
fputc ('[', out); fputc ('[', out);
@@ -320,17 +320,17 @@ print_reductions (FILE *out, state *s)
FOR_EACH_SHIFT (trans, i) FOR_EACH_SHIFT (trans, i)
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i)); bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
/* Compute the width of the look-ahead token column. */ /* Compute the width of the lookahead token column. */
if (default_rule) if (default_rule)
width = strlen (_("$default")); width = strlen (_("$default"));
if (reds->look_ahead_tokens) if (reds->lookahead_tokens)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
{ {
bool count = bitset_test (shift_set, i); bool count = bitset_test (shift_set, i);
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
if (bitset_test (reds->look_ahead_tokens[j], i)) if (bitset_test (reds->lookahead_tokens[j], i))
{ {
if (! count) if (! count)
{ {
@@ -352,15 +352,15 @@ print_reductions (FILE *out, state *s)
fputc ('\n', out); fputc ('\n', out);
width += 2; width += 2;
/* Report look-ahead tokens (or $default) and reductions. */ /* Report lookahead tokens (or $default) and reductions. */
if (reds->look_ahead_tokens) if (reds->lookahead_tokens)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
{ {
bool defaulted = false; bool defaulted = false;
bool count = bitset_test (shift_set, i); bool count = bitset_test (shift_set, i);
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
if (bitset_test (reds->look_ahead_tokens[j], i)) if (bitset_test (reds->lookahead_tokens[j], i))
{ {
if (! count) if (! count)
{ {
@@ -563,11 +563,11 @@ print_results (void)
new_closure (nritems); new_closure (nritems);
/* Storage for print_reductions. */ /* Storage for print_reductions. */
shift_set = bitset_create (ntokens, BITSET_FIXED); shift_set = bitset_create (ntokens, BITSET_FIXED);
look_ahead_set = bitset_create (ntokens, BITSET_FIXED); lookahead_set = bitset_create (ntokens, BITSET_FIXED);
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
print_state (out, states[i]); print_state (out, states[i]);
bitset_free (shift_set); bitset_free (shift_set);
bitset_free (look_ahead_set); bitset_free (lookahead_set);
if (report_flag & report_itemsets) if (report_flag & report_itemsets)
free_closure (); free_closure ();

View File

@@ -88,21 +88,21 @@ print_core (struct obstack *oout, state *s)
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
obstack_fgrow1 (oout, " %s", symbols[*sp]->tag); obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
/* Experimental feature: display the look-ahead tokens. */ /* Experimental feature: display the lookahead tokens. */
if (report_flag & report_look_ahead_tokens) if (report_flag & report_lookahead_tokens)
{ {
/* Find the reduction we are handling. */ /* Find the reduction we are handling. */
reductions *reds = s->reductions; reductions *reds = s->reductions;
int redno = state_reduction_find (s, &rules[r]); int redno = state_reduction_find (s, &rules[r]);
/* Print them if there are. */ /* Print them if there are. */
if (reds->look_ahead_tokens && redno != -1) if (reds->lookahead_tokens && redno != -1)
{ {
bitset_iterator biter; bitset_iterator biter;
int k; int k;
char const *sep = ""; char const *sep = "";
obstack_sgrow (oout, "["); obstack_sgrow (oout, "[");
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[redno], k, 0) BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
{ {
obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag); obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag);
sep = ", "; sep = ", ";

View File

@@ -105,7 +105,7 @@ reductions_new (int num, rule **reds)
size_t rules_size = num * sizeof *reds; size_t rules_size = num * sizeof *reds;
reductions *res = xmalloc (offsetof (reductions, rules) + rules_size); reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
res->num = num; res->num = num;
res->look_ahead_tokens = NULL; res->lookahead_tokens = NULL;
memcpy (res->rules, reds, rules_size); memcpy (res->rules, reds, rules_size);
return res; return res;
} }
@@ -218,26 +218,26 @@ state_errs_set (state *s, int num, symbol **tokens)
/*---------------------------------------------------. /*--------------------------------------------------.
| Print on OUT all the look-ahead tokens such that S | | Print on OUT all the lookahead tokens such that S |
| wants to reduce R. | | wants to reduce R. |
`---------------------------------------------------*/ `--------------------------------------------------*/
void void
state_rule_look_ahead_tokens_print (state *s, rule *r, FILE *out) state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out)
{ {
/* Find the reduction we are handling. */ /* Find the reduction we are handling. */
reductions *reds = s->reductions; reductions *reds = s->reductions;
int red = state_reduction_find (s, r); int red = state_reduction_find (s, r);
/* Print them if there are. */ /* Print them if there are. */
if (reds->look_ahead_tokens && red != -1) if (reds->lookahead_tokens && red != -1)
{ {
bitset_iterator biter; bitset_iterator biter;
int k; int k;
char const *sep = ""; char const *sep = "";
fprintf (out, " ["); fprintf (out, " [");
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[red], k, 0) BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
{ {
fprintf (out, "%s%s", sep, symbols[k]->tag); fprintf (out, "%s%s", sep, symbols[k]->tag);
sep = ", "; sep = ", ";

View File

@@ -46,11 +46,11 @@
Each core contains a vector of NITEMS items which are the indices Each core contains a vector of NITEMS items which are the indices
in the RITEMS vector of the items that are selected in this state. in the RITEMS vector of the items that are selected in this state.
The two types of actions are shifts/gotos (push the look-ahead token The two types of actions are shifts/gotos (push the lookahead token
and read another/goto to the state designated by a nterm) and and read another/goto to the state designated by a nterm) and
reductions (combine the last n things on the stack via a rule, reductions (combine the last n things on the stack via a rule,
replace them with the symbol that the rule derives, and leave the replace them with the symbol that the rule derives, and leave the
look-ahead token alone). When the states are generated, these lookahead token alone). When the states are generated, these
actions are represented in two other lists. actions are represented in two other lists.
Each transition structure describes the possible transitions out Each transition structure describes the possible transitions out
@@ -185,7 +185,7 @@ errs *errs_new (int num, symbol **tokens);
typedef struct typedef struct
{ {
int num; int num;
bitset *look_ahead_tokens; bitset *lookahead_tokens;
rule *rules[1]; rule *rules[1];
} reductions; } reductions;
@@ -203,7 +203,7 @@ struct state
reductions *reductions; reductions *reductions;
errs *errs; errs *errs;
/* Nonzero if no look-ahead is needed to decide what to do in state S. */ /* Nonzero if no lookahead is needed to decide what to do in state S. */
char consistent; char consistent;
/* If some conflicts were solved thanks to precedence/associativity, /* If some conflicts were solved thanks to precedence/associativity,
@@ -234,9 +234,9 @@ int state_reduction_find (state *s, rule *r);
/* Set the errs of STATE. */ /* Set the errs of STATE. */
void state_errs_set (state *s, int num, symbol **errors); void state_errs_set (state *s, int num, symbol **errors);
/* Print on OUT all the look-ahead tokens such that this STATE wants to /* Print on OUT all the lookahead tokens such that this STATE wants to
reduce R. */ reduce R. */
void state_rule_look_ahead_tokens_print (state *s, rule *r, FILE *out); void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out);
/* Create/destroy the states hash table. */ /* Create/destroy the states hash table. */
void state_hash_new (void); void state_hash_new (void);

View File

@@ -198,7 +198,7 @@ conflict_row (state *s)
/* Find all reductions for token J, and record all that do not /* Find all reductions for token J, and record all that do not
match ACTROW[J]. */ match ACTROW[J]. */
for (i = 0; i < reds->num; i += 1) for (i = 0; i < reds->num; i += 1)
if (bitset_test (reds->look_ahead_tokens[i], j) if (bitset_test (reds->lookahead_tokens[i], j)
&& (actrow[j] && (actrow[j]
!= rule_number_as_item_number (reds->rules[i]->number))) != rule_number_as_item_number (reds->rules[i]->number)))
{ {
@@ -219,7 +219,7 @@ conflict_row (state *s)
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Decide what to do for each type of token if seen as the | | Decide what to do for each type of token if seen as the |
| look-ahead in specified state. The value returned is used as the | | lookahead in specified state. The value returned is used as the |
| default action (yydefact) for the state. In addition, ACTROW is | | default action (yydefact) for the state. In addition, ACTROW is |
| filled with what to do for each kind of token, index by symbol | | filled with what to do for each kind of token, index by symbol |
| number, with zero meaning do the default action. The value | | number, with zero meaning do the default action. The value |
@@ -227,7 +227,7 @@ conflict_row (state *s)
| situation is an error. The parser recognizes this value | | situation is an error. The parser recognizes this value |
| specially. | | specially. |
| | | |
| This is where conflicts are resolved. The loop over look-ahead | | This is where conflicts are resolved. The loop over lookahead |
| rules considered lower-numbered rules last, and the last rule | | rules considered lower-numbered rules last, and the last rule |
| considered that likes a token gets to handle it. | | considered that likes a token gets to handle it. |
| | | |
@@ -252,17 +252,17 @@ action_row (state *s)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
actrow[i] = conflrow[i] = 0; actrow[i] = conflrow[i] = 0;
if (reds->look_ahead_tokens) if (reds->lookahead_tokens)
{ {
int j; int j;
bitset_iterator biter; bitset_iterator biter;
/* loop over all the rules available here which require /* loop over all the rules available here which require
look-ahead (in reverse order to give precedence to the first lookahead (in reverse order to give precedence to the first
rule) */ rule) */
for (i = reds->num - 1; i >= 0; --i) for (i = reds->num - 1; i >= 0; --i)
/* and find each token which the rule finds acceptable /* and find each token which the rule finds acceptable
to come next */ to come next */
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[i], j, 0) BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0)
{ {
/* and record this rule as the rule to use if that /* and record this rule as the rule to use if that
token follows. */ token follows. */
@@ -410,7 +410,7 @@ save_row (state_number s)
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Figure out the actions for the specified state, indexed by | | Figure out the actions for the specified state, indexed by |
| look-ahead token type. | | lookahead token type. |
| | | |
| The YYDEFACT table is output now. The detailed info is saved for | | The YYDEFACT table is output now. The detailed info is saved for |
| putting into YYTABLE later. | | putting into YYTABLE later. |

View File

@@ -56,7 +56,7 @@
something else to do. something else to do.
YYPACT[S] = index in YYTABLE of the portion describing state S. YYPACT[S] = index in YYTABLE of the portion describing state S.
The look-ahead token's type is used to index that portion to find The lookahead token's type is used to index that portion to find
out what to do. out what to do.
If the value in YYTABLE is positive, we shift the token and go to If the value in YYTABLE is positive, we shift the token and go to

View File

@@ -503,8 +503,8 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
# #
# - test the action associated to `error' # - test the action associated to `error'
# #
# - check the look-ahead that triggers an error is not discarded # - check the lookahead that triggers an error is not discarded
# when we enter error recovery. Below, the look-ahead causing the # when we enter error recovery. Below, the lookahead causing the
# first error is ")", which is needed to recover from the error and # first error is ")", which is needed to recover from the error and
# produce the "0" that triggers the "0 != 1" error. # produce the "0" that triggers the "0 != 1" error.
# #
@@ -518,7 +518,7 @@ _AT_CHECK_CALC_ERROR([$1], [0],
calc: error: 4444 != 1]) calc: error: 4444 != 1])
# The same, but this time exercising explicitly triggered syntax errors. # The same, but this time exercising explicitly triggered syntax errors.
# POSIX says the look-ahead causing the error should not be discarded. # POSIX says the lookahead causing the error should not be discarded.
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102], _AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
[1.9: syntax error, unexpected number [1.9: syntax error, unexpected number
calc: error: 2222 != 1]) calc: error: 2222 != 1])

View File

@@ -1090,7 +1090,7 @@ AT_DATA_GRAMMAR([glr-regr13.y],
#include <stdio.h> #include <stdio.h>
static void yyerror (char const *); static void yyerror (char const *);
static int yylex (void); static int yylex (void);
static void print_look_ahead (char const *); static void print_lookahead (char const *);
#define USE(value) #define USE(value)
%} %}
@@ -1104,32 +1104,32 @@ AT_DATA_GRAMMAR([glr-regr13.y],
start: start:
defstate_init defstate_shift 'b' change_lookahead 'a' { defstate_init defstate_shift 'b' change_lookahead 'a' {
USE ($3); USE ($3);
print_look_ahead ("start <- defstate_init defstate_shift 'b'"); print_lookahead ("start <- defstate_init defstate_shift 'b'");
} }
; ;
defstate_init: defstate_init:
{ {
print_look_ahead ("defstate_init <- empty string"); print_lookahead ("defstate_init <- empty string");
} }
; ;
defstate_shift: defstate_shift:
nondefstate defstate_look 'a' { nondefstate defstate_look 'a' {
USE ($3); USE ($3);
print_look_ahead ("defstate_shift <- nondefstate defstate_look 'a'"); print_lookahead ("defstate_shift <- nondefstate defstate_look 'a'");
} }
; ;
defstate_look: defstate_look:
{ {
print_look_ahead ("defstate_look <- empty string"); print_lookahead ("defstate_look <- empty string");
} }
; ;
nondefstate: nondefstate:
{ {
print_look_ahead ("nondefstate <- empty string"); print_lookahead ("nondefstate <- empty string");
} }
| 'b' { | 'b' {
USE ($1); USE ($1);
print_look_ahead ("nondefstate <- 'b'"); print_lookahead ("nondefstate <- 'b'");
} }
; ;
change_lookahead: change_lookahead:
@@ -1158,7 +1158,7 @@ yylex (void)
} }
static void static void
print_look_ahead (char const *reduction) print_lookahead (char const *reduction)
{ {
printf ("%s:\n yychar=", reduction); printf ("%s:\n yychar=", reduction);
if (yychar == YYEMPTY) if (yychar == YYEMPTY)
@@ -1238,7 +1238,7 @@ AT_DATA_GRAMMAR([glr-regr14.y],
#include <stdio.h> #include <stdio.h>
static void yyerror (char const *); static void yyerror (char const *);
static int yylex (void); static int yylex (void);
static void print_look_ahead (char const *); static void print_lookahead (char const *);
static char merge (union YYSTYPE, union YYSTYPE); static char merge (union YYSTYPE, union YYSTYPE);
#define USE(value) #define USE(value)
%} %}
@@ -1252,7 +1252,7 @@ AT_DATA_GRAMMAR([glr-regr14.y],
start: start:
merge 'c' stack_explosion { merge 'c' stack_explosion {
USE ($2); USE ($3); USE ($2); USE ($3);
print_look_ahead ("start <- merge 'c' stack_explosion"); print_lookahead ("start <- merge 'c' stack_explosion");
} }
; ;
@@ -1260,44 +1260,44 @@ start:
merge: merge:
nonconflict1 'a' 'b' nonconflict2 %dprec 1 { nonconflict1 'a' 'b' nonconflict2 %dprec 1 {
USE ($2); USE ($3); USE ($2); USE ($3);
print_look_ahead ("merge <- nonconflict1 'a' 'b' nonconflict2"); print_lookahead ("merge <- nonconflict1 'a' 'b' nonconflict2");
} }
| conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 { | conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 {
USE ($3); USE ($5); USE ($3); USE ($5);
print_look_ahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'" print_lookahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'"
" defstate_shift"); " defstate_shift");
} }
; ;
nonconflict1: nonconflict1:
{ {
print_look_ahead ("nonconflict1 <- empty string"); print_lookahead ("nonconflict1 <- empty string");
} }
; ;
nonconflict2: nonconflict2:
{ {
print_look_ahead ("nonconflict2 <- empty string"); print_lookahead ("nonconflict2 <- empty string");
} }
| 'a' { | 'a' {
USE ($1); USE ($1);
print_look_ahead ("nonconflict2 <- 'a'"); print_lookahead ("nonconflict2 <- 'a'");
} }
; ;
conflict: conflict:
{ {
print_look_ahead ("conflict <- empty string"); print_lookahead ("conflict <- empty string");
} }
; ;
defstate_look: defstate_look:
{ {
print_look_ahead ("defstate_look <- empty string"); print_lookahead ("defstate_look <- empty string");
} }
; ;
/* yychar != YYEMPTY but lookahead need is yyfalse. */ /* yychar != YYEMPTY but lookahead need is yyfalse. */
defstate_shift: defstate_shift:
{ {
print_look_ahead ("defstate_shift <- empty string"); print_lookahead ("defstate_shift <- empty string");
} }
; ;
@@ -1364,7 +1364,7 @@ yylex (void)
} }
static void static void
print_look_ahead (char const *reduction) print_lookahead (char const *reduction)
{ {
printf ("%s:\n yychar=", reduction); printf ("%s:\n yychar=", reduction);
if (yychar == YYEMPTY) if (yychar == YYEMPTY)

View File

@@ -257,11 +257,11 @@ AT_CLEANUP
# AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR(FILE-NAME, SIZE) # AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR(FILE-NAME, SIZE)
# -------------------------------------------------- # --------------------------------------------------
# Create FILE-NAME, containing a self checking parser for a grammar # Create FILE-NAME, containing a self checking parser for a grammar
# requiring SIZE look-ahead tokens. # requiring SIZE lookahead tokens.
m4_define([AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR], m4_define([AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR],
[AT_DATA([[gengram.pl]], [AT_DATA([[gengram.pl]],
[[#! /usr/bin/perl -w [[#! /usr/bin/perl -w
@@ -362,12 +362,12 @@ mv stdout $1
## ------------------------ ## ## ------------------------ ##
## Many look-ahead tokens. ## ## Many lookahead tokens. ##
## ------------------------ ## ## ------------------------ ##
AT_SETUP([Many look-ahead tokens]) AT_SETUP([Many lookahead tokens])
AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR([input.y], [1000]) AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR([input.y], [1000])
# GNU m4 requires about 70 MiB for this test on a 32-bit host. # GNU m4 requires about 70 MiB for this test on a 32-bit host.
# Ask for 200 MiB, which should be plenty even on a 64-bit host. # Ask for 200 MiB, which should be plenty even on a 64-bit host.