mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Use "look-ahead" instead of "lookahead", consistently.
This commit is contained in:
25
ChangeLog
25
ChangeLog
@@ -1,3 +1,28 @@
|
|||||||
|
2004-06-21 Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
|
||||||
|
* NEWS, TODO, doc/bison.texinfo:
|
||||||
|
Use "look-ahead" instead of "lookahead", to be consistent.
|
||||||
|
* REFERENCES: Fix incorrect reference to DeRemer and Pennello,
|
||||||
|
while we're fixing "look-ahead".
|
||||||
|
* src/conflicts.c (shift_set): Renamed from shiftset.
|
||||||
|
(look_ahead_set): Renamed from lookaheadset.
|
||||||
|
* src/print.c: Likewise.
|
||||||
|
* src/getargs.c (report_args): Add "look-ahead" as the new canonical
|
||||||
|
name for "lookahead".
|
||||||
|
(report_types, usage): Likewise.
|
||||||
|
* src/getargs.h (report_look_ahead_tokens): Renamed from
|
||||||
|
report_lookaheads.
|
||||||
|
* src/lalr.c (compute_look_ahead_tokens): Renamed from
|
||||||
|
compute_lookaheads.
|
||||||
|
(state_look_ahead_tokens_count): Renamed from state_lookaheads_count.
|
||||||
|
(look_ahead_tokens_print): Renamed from lookaheads_print.
|
||||||
|
* src/state.c (state_rule_look_ahead_tokens_print): Renamed from
|
||||||
|
state_rule_lookaheads_print.
|
||||||
|
* src/state.h: Likewise.
|
||||||
|
(reductions.look_ahead_tokens): Renamed from lookaheads.
|
||||||
|
* tests/torture.at (AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR): Renamed from
|
||||||
|
AT_DATA_LOOKAHEADS_GRAMMAR.
|
||||||
|
|
||||||
2004-06-03 Paul Eggert <eggert@cs.ucla.edu>
|
2004-06-03 Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
|
||||||
* README: Update location of patched M4 distribution.
|
* README: Update location of patched M4 distribution.
|
||||||
|
|||||||
9
NEWS
9
NEWS
@@ -1,6 +1,11 @@
|
|||||||
Bison News
|
Bison News
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
Changes in version 1.875e:
|
||||||
|
|
||||||
|
* The option `--report=lookahead' was changed to `--report=look-ahead'.
|
||||||
|
The old spelling still works, but is not documented and will be removed.
|
||||||
|
|
||||||
Changes in version 1.875d, 2004-05-21:
|
Changes in version 1.875d, 2004-05-21:
|
||||||
|
|
||||||
* Unescaped newlines are no longer allowed in character constants or
|
* Unescaped newlines are no longer allowed in character constants or
|
||||||
@@ -288,8 +293,8 @@ Changes in version 1.50, 2002-10-04:
|
|||||||
produces additional information:
|
produces additional information:
|
||||||
- itemset
|
- itemset
|
||||||
complete the core item sets with their closure
|
complete the core item sets with their closure
|
||||||
- lookahead
|
- lookahead [changed to `look-ahead' in 1.875e and later]
|
||||||
explicitly associate lookaheads to items
|
explicitly associate look-ahead tokens to items
|
||||||
- solved
|
- solved
|
||||||
describe shift/reduce conflicts solving.
|
describe shift/reduce conflicts solving.
|
||||||
Bison used to systematically output this information on top of
|
Bison used to systematically output this information on top of
|
||||||
|
|||||||
@@ -19,12 +19,15 @@ kludges that Johnson had to perpetrate to make Yacc fit in a PDP-11.
|
|||||||
Also, Bison uses a faster but less space-efficient encoding for the
|
Also, Bison uses a faster but less space-efficient encoding for the
|
||||||
parse tables (see Corbett's PhD thesis from Berkeley, "Static
|
parse tables (see Corbett's PhD thesis from Berkeley, "Static
|
||||||
Semantics in Compiler Error Recovery", June 1985, Report No. UCB/CSD
|
Semantics in Compiler Error Recovery", June 1985, Report No. UCB/CSD
|
||||||
85/251), and more modern technique for generating the lookahead sets.
|
85/251), and more modern technique for generating the look-ahead sets.
|
||||||
(See "Efficient Construction of LALR(1) Lookahead Sets" by F. DeRemer
|
(See Frank DeRemer and Thomas Pennello, "Efficient Computation of
|
||||||
and A. Pennello, in ACM TOPLS Vol 4 No 4, October 1982. Their
|
LALR(1) Look-Ahead Sets", ACM Transactions on Programming Languages
|
||||||
|
and Systems (TOPLAS) 4, 4 (October 1982), 615-649. Their
|
||||||
technique is the standard one now.)
|
technique is the standard one now.)
|
||||||
|
|
||||||
paul rubin
|
paul rubin
|
||||||
free software foundation
|
free software foundation
|
||||||
|
|
||||||
|
|
||||||
|
[DeRemer-Pennello reference corrected by Paul Eggert <eggert@cs.ucla.edu>,
|
||||||
|
2004-06-21.]
|
||||||
|
|||||||
4
TODO
4
TODO
@@ -29,7 +29,7 @@ Currently, the GLR parser cannot compile with a C++ compiler.
|
|||||||
|
|
||||||
** 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 lookahead, but one is
|
what when two reductions are possible on a given look-ahead 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.
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ the parser with a means to create the (visual) parse tree.
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Bison.
|
This file is part of GNU Bison.
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
|
|||||||
|
|
||||||
# b4_lyyerror_args
|
# b4_lyyerror_args
|
||||||
# ----------------
|
# ----------------
|
||||||
# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
|
# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
|
||||||
m4_define([b4_lyyerror_args],
|
m4_define([b4_lyyerror_args],
|
||||||
[b4_pure_if([b4_location_if([yyllocp, ])])dnl
|
[b4_pure_if([b4_location_if([yyllocp, ])])dnl
|
||||||
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
|
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
|
||||||
@@ -82,14 +82,14 @@ m4_define([b4_pure_formals],
|
|||||||
|
|
||||||
# b4_lpure_args
|
# b4_lpure_args
|
||||||
# -------------
|
# -------------
|
||||||
# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
|
# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
|
||||||
m4_define([b4_lpure_args],
|
m4_define([b4_lpure_args],
|
||||||
[b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args])
|
[b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args])
|
||||||
|
|
||||||
|
|
||||||
# b4_lpure_formals
|
# b4_lpure_formals
|
||||||
# ----------------
|
# ----------------
|
||||||
# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
|
# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
|
||||||
m4_define([b4_lpure_formals],
|
m4_define([b4_lpure_formals],
|
||||||
[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
|
[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
|
||||||
|
|
||||||
@@ -1686,7 +1686,7 @@ yyreportSyntaxError (yyGLRStack* yystack,
|
|||||||
|
|
||||||
/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
|
/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
|
||||||
YYLVALP, and YYLLOCP point to the syntactic category, semantic
|
YYLVALP, and YYLLOCP point to the syntactic category, semantic
|
||||||
value, and location of the lookahead. */
|
value, and location of the look-ahead. */
|
||||||
static void
|
static void
|
||||||
yyrecoverSyntaxError (yyGLRStack* yystack,
|
yyrecoverSyntaxError (yyGLRStack* yystack,
|
||||||
YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
|
YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
|
||||||
|
|||||||
@@ -307,14 +307,14 @@ namespace yy
|
|||||||
int debug_;
|
int debug_;
|
||||||
std::ostream &cdebug_;
|
std::ostream &cdebug_;
|
||||||
|
|
||||||
/* Lookahead and lookahead in internal form. */
|
/* Look-ahead and look-ahead in internal form. */
|
||||||
int looka_;
|
int looka_;
|
||||||
int ilooka_;
|
int ilooka_;
|
||||||
|
|
||||||
/* Message. */
|
/* Message. */
|
||||||
std::string message;
|
std::string message;
|
||||||
|
|
||||||
/* Semantic value and location of lookahead token. */
|
/* Semantic value and location of look-ahead token. */
|
||||||
SemanticType value;
|
SemanticType value;
|
||||||
LocationType location;
|
LocationType location;
|
||||||
/* Beginning of the last erroneous token popped off. */
|
/* Beginning of the last erroneous token popped off. */
|
||||||
@@ -394,12 +394,12 @@ yy::]b4_parser_class_name[::parse ()
|
|||||||
/* Backup. */
|
/* Backup. */
|
||||||
yybackup:
|
yybackup:
|
||||||
|
|
||||||
/* Try to take a decision without lookahead. */
|
/* Try to take a decision without look-ahead. */
|
||||||
n_ = pact_[state_];
|
n_ = pact_[state_];
|
||||||
if (n_ == pact_ninf_)
|
if (n_ == pact_ninf_)
|
||||||
goto yydefault;
|
goto yydefault;
|
||||||
|
|
||||||
/* Read a lookahead token. */
|
/* Read a look-ahead token. */
|
||||||
if (looka_ == empty_)
|
if (looka_ == empty_)
|
||||||
{
|
{
|
||||||
YYCDEBUG << "Reading a token: ";
|
YYCDEBUG << "Reading a token: ";
|
||||||
@@ -452,7 +452,7 @@ yy::]b4_parser_class_name[::parse ()
|
|||||||
if (n_ == final_)
|
if (n_ == final_)
|
||||||
goto yyacceptlab;
|
goto yyacceptlab;
|
||||||
|
|
||||||
/* Shift the lookahead token. */
|
/* Shift the look-ahead token. */
|
||||||
#if YYDEBUG
|
#if YYDEBUG
|
||||||
YYCDEBUG << "Shifting token " << looka_
|
YYCDEBUG << "Shifting token " << looka_
|
||||||
<< " (" << name_[ilooka_] << "), ";
|
<< " (" << name_[ilooka_] << "), ";
|
||||||
@@ -546,7 +546,7 @@ b4_syncline([@oline@], [@ofile@])[
|
|||||||
error_start_ = location.begin;
|
error_start_ = location.begin;
|
||||||
if (errstatus_ == 3)
|
if (errstatus_ == 3)
|
||||||
{
|
{
|
||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse look-ahead token after an
|
||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
/* Return failure if at end of input. */
|
/* Return failure if at end of input. */
|
||||||
@@ -580,7 +580,7 @@ b4_syncline([@oline@], [@ofile@])[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse look-ahead token after shifting the error
|
||||||
token. */
|
token. */
|
||||||
goto yyerrlab1;
|
goto yyerrlab1;
|
||||||
|
|
||||||
|
|||||||
22
data/yacc.c
22
data/yacc.c
@@ -713,15 +713,15 @@ m4_divert_push([KILL])# ======================== M4 code.
|
|||||||
# 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 lookahead symbol. */
|
[/* The look-ahead symbol. */
|
||||||
int yychar;
|
int yychar;
|
||||||
|
|
||||||
/* The semantic value of the lookahead symbol. */
|
/* The semantic value of the look-ahead symbol. */
|
||||||
YYSTYPE yylval;
|
YYSTYPE yylval;
|
||||||
|
|
||||||
/* Number of syntax errors so far. */
|
/* Number of syntax errors so far. */
|
||||||
int yynerrs;b4_location_if([
|
int yynerrs;b4_location_if([
|
||||||
/* Location data for the lookahead symbol. */
|
/* Location data for the look-ahead symbol. */
|
||||||
YYLTYPE yylloc;])
|
YYLTYPE yylloc;])
|
||||||
])
|
])
|
||||||
m4_divert_pop([KILL])dnl# ====================== End of M4 code.
|
m4_divert_pop([KILL])dnl# ====================== End of M4 code.
|
||||||
@@ -751,7 +751,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;
|
||||||
/* Lookahead token as an internal (translated) token number. */
|
/* Look-ahead token as an internal (translated) token number. */
|
||||||
int yytoken = 0;
|
int yytoken = 0;
|
||||||
|
|
||||||
/* Three stacks and their tools:
|
/* Three stacks and their tools:
|
||||||
@@ -906,18 +906,18 @@ b4_syncline([@oline@], [@ofile@])])dnl
|
|||||||
yybackup:
|
yybackup:
|
||||||
|
|
||||||
/* Do appropriate processing given the current state. */
|
/* Do appropriate processing given the current state. */
|
||||||
/* Read a lookahead token if we need one and don't already have one. */
|
/* Read a look-ahead token if we need one and don't already have one. */
|
||||||
/* yyresume: */
|
/* yyresume: */
|
||||||
|
|
||||||
/* First try to decide what to do without reference to lookahead token. */
|
/* First try to decide what to do without reference to look-ahead token. */
|
||||||
|
|
||||||
yyn = yypact[yystate];
|
yyn = yypact[yystate];
|
||||||
if (yyn == YYPACT_NINF)
|
if (yyn == YYPACT_NINF)
|
||||||
goto yydefault;
|
goto yydefault;
|
||||||
|
|
||||||
/* Not known => get a lookahead token if don't already have one. */
|
/* Not known => get a look-ahead token if don't already have one. */
|
||||||
|
|
||||||
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
|
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
|
||||||
if (yychar == YYEMPTY)
|
if (yychar == YYEMPTY)
|
||||||
{
|
{
|
||||||
YYDPRINTF ((stderr, "Reading a token: "));
|
YYDPRINTF ((stderr, "Reading a token: "));
|
||||||
@@ -952,7 +952,7 @@ yybackup:
|
|||||||
if (yyn == YYFINAL)
|
if (yyn == YYFINAL)
|
||||||
YYACCEPT;
|
YYACCEPT;
|
||||||
|
|
||||||
/* Shift the lookahead token. */
|
/* Shift the look-ahead token. */
|
||||||
YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
|
YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
|
||||||
|
|
||||||
/* Discard the token being shifted unless it is eof. */
|
/* Discard the token being shifted unless it is eof. */
|
||||||
@@ -1108,7 +1108,7 @@ yyerrlab:
|
|||||||
|
|
||||||
if (yyerrstatus == 3)
|
if (yyerrstatus == 3)
|
||||||
{
|
{
|
||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse look-ahead token after an
|
||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
if (yychar <= YYEOF)
|
if (yychar <= YYEOF)
|
||||||
@@ -1134,7 +1134,7 @@ yyerrlab:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse look-ahead token after shifting the error
|
||||||
token. */
|
token. */
|
||||||
goto yyerrlab1;
|
goto yyerrlab1;
|
||||||
|
|
||||||
|
|||||||
@@ -5187,13 +5187,13 @@ return_spec:
|
|||||||
|
|
||||||
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 lookahead.
|
based on a summary of the preceding input and on one extra token of look-ahead.
|
||||||
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
|
||||||
lookahead, since the parser lacks the information necessary to make a
|
look-ahead, 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
|
||||||
@@ -5805,16 +5805,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 lookahead is a @code{NUM}, then this token is shifted on
|
symbol, and the look-ahead 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
|
||||||
lookahead triggers a syntax error.''
|
look-ahead 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 lookahead symbol because @code{NUM} can be
|
report lists @code{NUM} as a look-ahead 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
|
||||||
@@ -5848,7 +5848,7 @@ state 1
|
|||||||
@end example
|
@end example
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
the rule 5, @samp{exp: NUM;}, is completed. Whatever the lookahead
|
the rule 5, @samp{exp: NUM;}, is completed. Whatever the look-ahead 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}).
|
||||||
@@ -5871,7 +5871,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 lookahead if
|
because of the item @samp{exp -> exp . '+' exp}, if the look-ahead 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
|
||||||
@@ -5948,7 +5948,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 lookahead @samp{/}:
|
Indeed, there are two actions associated to the look-ahead @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
|
||||||
@@ -5966,14 +5966,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 lookahead is required to select the action. State 8 is
|
possible, the look-ahead is required to select the action. State 8 is
|
||||||
one such state: if the lookahead is @samp{*} or @samp{/} then the action
|
one such state: if the look-ahead 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
|
||||||
lookahead is @samp{*}, since we specified that @samp{*} has higher
|
look-ahead token is @samp{*}, since we specified that @samp{*} has higher
|
||||||
precedence that @samp{+}. More generally, some items are eligible only
|
precedence than @samp{+}. More generally, some items are eligible only
|
||||||
with some set of possible lookaheads. When run with
|
with some set of possible look-ahead tokens. When run with
|
||||||
@option{--report=lookahead}, Bison specifies these lookaheads:
|
@option{--report=look-ahead}, Bison specifies these look-ahead tokens:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
state 8
|
state 8
|
||||||
@@ -6319,9 +6319,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 lookahead
|
@item look-ahead
|
||||||
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 lookahead set.
|
each rule's look-ahead 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
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ int expected_rr_conflicts = -1;
|
|||||||
static char *conflicts = NULL;
|
static char *conflicts = NULL;
|
||||||
struct obstack solved_conflicts_obstack;
|
struct obstack solved_conflicts_obstack;
|
||||||
|
|
||||||
static bitset shiftset;
|
static bitset shift_set;
|
||||||
static bitset lookaheadset;
|
static bitset look_ahead_set;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ flush_shift (state *s, int token)
|
|||||||
transitions *trans = s->transitions;
|
transitions *trans = s->transitions;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
bitset_reset (lookaheadset, token);
|
bitset_reset (look_ahead_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)
|
||||||
@@ -154,16 +154,16 @@ 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 lookahead. Used when we resolve a shift-reduce conflict |
|
| specified look-ahead. 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 lookaheads, int token)
|
flush_reduce (bitset look_ahead_tokens, int token)
|
||||||
{
|
{
|
||||||
bitset_reset (lookaheads, token);
|
bitset_reset (look_ahead_tokens, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ flush_reduce (bitset lookaheads, 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. |
|
||||||
| |
|
| |
|
||||||
| LOOKAHEAD is the number of the lookahead bitset to consider. |
|
| RULENO is the number of the look-ahead bitset to consider. |
|
||||||
| |
|
| |
|
||||||
| ERRORS can be used to store discovered explicit errors. |
|
| ERRORS can be used to store discovered explicit errors. |
|
||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
@@ -186,12 +186,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 lookaheads = reds->lookaheads[ruleno];
|
bitset look_ahead_tokens = reds->look_ahead_tokens[ruleno];
|
||||||
int nerrs = 0;
|
int nerrs = 0;
|
||||||
|
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
if (bitset_test (lookaheads, i)
|
if (bitset_test (look_ahead_tokens, i)
|
||||||
&& bitset_test (lookaheadset, i)
|
&& bitset_test (look_ahead_set, i)
|
||||||
&& symbols[i]->prec)
|
&& symbols[i]->prec)
|
||||||
{
|
{
|
||||||
/* Shift-reduce conflict occurs for token number i
|
/* Shift-reduce conflict occurs for token number i
|
||||||
@@ -205,7 +205,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 (lookaheads, i);
|
flush_reduce (look_ahead_tokens, i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* Matching precedence levels.
|
/* Matching precedence levels.
|
||||||
@@ -217,7 +217,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 (lookaheads, i);
|
flush_reduce (look_ahead_tokens, i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case left_assoc:
|
case left_assoc:
|
||||||
@@ -228,7 +228,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 (lookaheads, i);
|
flush_reduce (look_ahead_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;
|
||||||
@@ -257,7 +257,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 |
|
||||||
| lookaheads on which S raises a syntax error (%nonassoc). |
|
| look-ahead tokens on which S raises a syntax error (%nonassoc). |
|
||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -270,27 +270,27 @@ set_conflicts (state *s, symbol **errors)
|
|||||||
if (s->consistent)
|
if (s->consistent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bitset_zero (lookaheadset);
|
bitset_zero (look_ahead_set);
|
||||||
|
|
||||||
FOR_EACH_SHIFT (trans, i)
|
FOR_EACH_SHIFT (trans, i)
|
||||||
bitset_set (lookaheadset, TRANSITION_SYMBOL (trans, i));
|
bitset_set (look_ahead_set, TRANSITION_SYMBOL (trans, i));
|
||||||
|
|
||||||
/* Loop over all rules which require lookahead in this state. First
|
/* Loop over all rules which require look-ahead 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->lookaheads[i], lookaheadset))
|
&& !bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set))
|
||||||
resolve_sr_conflict (s, i, errors);
|
resolve_sr_conflict (s, i, errors);
|
||||||
|
|
||||||
/* Loop over all rules which require lookahead in this state. Check
|
/* Loop over all rules which require look-ahead 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->lookaheads[i], lookaheadset))
|
if (!bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set))
|
||||||
conflicts[s->number] = 1;
|
conflicts[s->number] = 1;
|
||||||
|
|
||||||
bitset_or (lookaheadset, lookaheadset, reds->lookaheads[i]);
|
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,12 +304,12 @@ void
|
|||||||
conflicts_solve (void)
|
conflicts_solve (void)
|
||||||
{
|
{
|
||||||
state_number i;
|
state_number i;
|
||||||
/* List of lookaheads on which we explicitly raise a syntax error. */
|
/* List of look-ahead tokens on which we explicitly raise a syntax error. */
|
||||||
symbol **errors = MALLOC (errors, ntokens + 1);
|
symbol **errors = MALLOC (errors, ntokens + 1);
|
||||||
|
|
||||||
CALLOC (conflicts, nstates);
|
CALLOC (conflicts, nstates);
|
||||||
shiftset = bitset_create (ntokens, BITSET_FIXED);
|
shift_set = bitset_create (ntokens, BITSET_FIXED);
|
||||||
lookaheadset = bitset_create (ntokens, BITSET_FIXED);
|
look_ahead_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++)
|
||||||
@@ -341,18 +341,18 @@ count_sr_conflicts (state *s)
|
|||||||
if (!trans)
|
if (!trans)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bitset_zero (lookaheadset);
|
bitset_zero (look_ahead_set);
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shift_set);
|
||||||
|
|
||||||
FOR_EACH_SHIFT (trans, i)
|
FOR_EACH_SHIFT (trans, i)
|
||||||
bitset_set (shiftset, 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 (lookaheadset, lookaheadset, reds->lookaheads[i]);
|
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]);
|
||||||
|
|
||||||
bitset_and (lookaheadset, lookaheadset, shiftset);
|
bitset_and (look_ahead_set, look_ahead_set, shift_set);
|
||||||
|
|
||||||
src_count = bitset_count (lookaheadset);
|
src_count = bitset_count (look_ahead_set);
|
||||||
|
|
||||||
return src_count;
|
return src_count;
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,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->lookaheads[j], i))
|
if (bitset_test (reds->look_ahead_tokens[j], i))
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (count >= 2)
|
if (count >= 2)
|
||||||
@@ -432,7 +432,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 lookahead as one |
|
| reductions for the same state and look-ahead as one |
|
||||||
| conflict. |
|
| conflict. |
|
||||||
`--------------------------------------------------------*/
|
`--------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -523,7 +523,7 @@ void
|
|||||||
conflicts_free (void)
|
conflicts_free (void)
|
||||||
{
|
{
|
||||||
XFREE (conflicts);
|
XFREE (conflicts);
|
||||||
bitset_free (shiftset);
|
bitset_free (shift_set);
|
||||||
bitset_free (lookaheadset);
|
bitset_free (look_ahead_set);
|
||||||
obstack_free (&solved_conflicts_obstack, NULL);
|
obstack_free (&solved_conflicts_obstack, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ static const char * const report_args[] =
|
|||||||
"none",
|
"none",
|
||||||
"state", "states",
|
"state", "states",
|
||||||
"itemset", "itemsets",
|
"itemset", "itemsets",
|
||||||
"lookahead", "lookaheads",
|
"look-ahead", "lookahead", "lookaheads",
|
||||||
"solved",
|
"solved",
|
||||||
"all",
|
"all",
|
||||||
0
|
0
|
||||||
@@ -149,7 +149,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_lookaheads, report_states | report_lookaheads,
|
report_states | report_look_ahead_tokens,
|
||||||
|
report_states | report_look_ahead_tokens,
|
||||||
|
report_states | report_look_ahead_tokens,
|
||||||
report_states | report_solved_conflicts,
|
report_states | report_solved_conflicts,
|
||||||
report_all
|
report_all
|
||||||
};
|
};
|
||||||
@@ -237,7 +239,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\
|
||||||
`lookahead' explicitly associate lookaheads to items\n\
|
`look-ahead' explicitly associate look-ahead 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\
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Parse command line arguments for bison.
|
/* Parse command line arguments for bison.
|
||||||
Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003
|
Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -76,7 +76,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_lookaheads = 1 << 2,
|
report_look_ahead_tokens= 1 << 2,
|
||||||
report_solved_conflicts = 1 << 3,
|
report_solved_conflicts = 1 << 3,
|
||||||
report_all = ~0
|
report_all = ~0
|
||||||
};
|
};
|
||||||
|
|||||||
80
src/lalr.c
80
src/lalr.c
@@ -1,6 +1,6 @@
|
|||||||
/* Compute look-ahead criteria for Bison.
|
/* Compute look-ahead criteria for Bison.
|
||||||
|
|
||||||
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003
|
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -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 lookahead in each state, and which lookahead
|
which rules need look-ahead in each state, and which look-ahead
|
||||||
tokens they accept. */
|
tokens they accept. */
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
@@ -215,9 +215,9 @@ add_lookback_edge (state *s, rule *r, int gotono)
|
|||||||
{
|
{
|
||||||
int ri = state_reduction_find (s, r);
|
int ri = state_reduction_find (s, r);
|
||||||
goto_list *sp = MALLOC (sp, 1);
|
goto_list *sp = MALLOC (sp, 1);
|
||||||
sp->next = lookback[(s->reductions->lookaheads - LA) + ri];
|
sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri];
|
||||||
sp->value = gotono;
|
sp->value = gotono;
|
||||||
lookback[(s->reductions->lookaheads - LA) + ri] = sp;
|
lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ compute_FOLLOWS (void)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
compute_lookaheads (void)
|
compute_look_ahead_tokens (void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
goto_list *sp;
|
goto_list *sp;
|
||||||
@@ -324,27 +324,27 @@ compute_lookaheads (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------.
|
/*-----------------------------------------------------.
|
||||||
| Count the number of lookaheads required for S (NLOOKAHEADS |
|
| Count the number of look-ahead tokens required for S |
|
||||||
| member). |
|
| (N_LOOK_AHEAD_TOKENS member). |
|
||||||
`-----------------------------------------------------------*/
|
`-----------------------------------------------------*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
state_lookaheads_count (state *s)
|
state_look_ahead_tokens_count (state *s)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
int nlookaheads = 0;
|
int n_look_ahead_tokens = 0;
|
||||||
reductions *rp = s->reductions;
|
reductions *rp = s->reductions;
|
||||||
transitions *sp = s->transitions;
|
transitions *sp = s->transitions;
|
||||||
|
|
||||||
/* We need a lookahead either to distinguish different
|
/* We need a look-ahead 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)))
|
||||||
nlookaheads += rp->num;
|
n_look_ahead_tokens += rp->num;
|
||||||
else
|
else
|
||||||
s->consistent = 1;
|
s->consistent = 1;
|
||||||
|
|
||||||
@@ -355,13 +355,13 @@ state_lookaheads_count (state *s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nlookaheads;
|
return n_look_ahead_tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------.
|
/*-----------------------------------------------------.
|
||||||
| Compute LA, NLA, and the lookaheads members. |
|
| Compute LA, NLA, and the look_ahead_tokens members. |
|
||||||
`----------------------------------------------*/
|
`-----------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initialize_LA (void)
|
initialize_LA (void)
|
||||||
@@ -369,10 +369,10 @@ initialize_LA (void)
|
|||||||
state_number i;
|
state_number i;
|
||||||
bitsetv pLA;
|
bitsetv pLA;
|
||||||
|
|
||||||
/* Compute the total number of reductions requiring a lookahead. */
|
/* Compute the total number of reductions requiring a look-ahead. */
|
||||||
nLA = 0;
|
nLA = 0;
|
||||||
for (i = 0; i < nstates; i++)
|
for (i = 0; i < nstates; i++)
|
||||||
nLA += state_lookaheads_count (states[i]);
|
nLA += state_look_ahead_tokens_count (states[i]);
|
||||||
/* Avoid having to special case 0. */
|
/* Avoid having to special case 0. */
|
||||||
if (!nLA)
|
if (!nLA)
|
||||||
nLA = 1;
|
nLA = 1;
|
||||||
@@ -380,54 +380,54 @@ initialize_LA (void)
|
|||||||
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
||||||
CALLOC (lookback, nLA);
|
CALLOC (lookback, nLA);
|
||||||
|
|
||||||
/* Initialize the members LOOKAHEADS for each state which reductions
|
/* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions
|
||||||
require lookaheads. */
|
require look-ahead tokens. */
|
||||||
for (i = 0; i < nstates; i++)
|
for (i = 0; i < nstates; i++)
|
||||||
{
|
{
|
||||||
int count = state_lookaheads_count (states[i]);
|
int count = state_look_ahead_tokens_count (states[i]);
|
||||||
if (count)
|
if (count)
|
||||||
{
|
{
|
||||||
states[i]->reductions->lookaheads = pLA;
|
states[i]->reductions->look_ahead_tokens = pLA;
|
||||||
pLA += count;
|
pLA += count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------.
|
/*----------------------------------------------.
|
||||||
| Output the lookaheads for each state. |
|
| Output the look-ahead tokens for each state. |
|
||||||
`---------------------------------------*/
|
`----------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lookaheads_print (FILE *out)
|
look_ahead_tokens_print (FILE *out)
|
||||||
{
|
{
|
||||||
state_number i;
|
state_number i;
|
||||||
int j, k;
|
int j, k;
|
||||||
fprintf (out, "Lookaheads: BEGIN\n");
|
fprintf (out, "Look-ahead 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 nlookaheads = 0;
|
int n_look_ahead_tokens = 0;
|
||||||
|
|
||||||
if (reds->lookaheads)
|
if (reds->look_ahead_tokens)
|
||||||
for (k = 0; k < reds->num; ++k)
|
for (k = 0; k < reds->num; ++k)
|
||||||
if (reds->lookaheads[k])
|
if (reds->look_ahead_tokens[k])
|
||||||
++nlookaheads;
|
++n_look_ahead_tokens;
|
||||||
|
|
||||||
fprintf (out, "State %d: %d lookaheads\n",
|
fprintf (out, "State %d: %d look-ahead tokens\n",
|
||||||
i, nlookaheads);
|
i, n_look_ahead_tokens);
|
||||||
|
|
||||||
if (reds->lookaheads)
|
if (reds->look_ahead_tokens)
|
||||||
for (j = 0; j < reds->num; ++j)
|
for (j = 0; j < reds->num; ++j)
|
||||||
BITSET_FOR_EACH (iter, reds->lookaheads[j], k, 0)
|
BITSET_FOR_EACH (iter, reds->look_ahead_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, "Lookaheads: END\n");
|
fprintf (out, "Look-ahead tokens: END\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -438,10 +438,10 @@ lalr (void)
|
|||||||
initialize_F ();
|
initialize_F ();
|
||||||
build_relations ();
|
build_relations ();
|
||||||
compute_FOLLOWS ();
|
compute_FOLLOWS ();
|
||||||
compute_lookaheads ();
|
compute_look_ahead_tokens ();
|
||||||
|
|
||||||
if (trace_flag & trace_sets)
|
if (trace_flag & trace_sets)
|
||||||
lookaheads_print (stderr);
|
look_ahead_tokens_print (stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -450,6 +450,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->lookaheads = NULL;
|
states[s]->reductions->look_ahead_tokens = NULL;
|
||||||
bitsetv_free (LA);
|
bitsetv_free (LA);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 lookahead in each state, and which lookahead
|
which rules need look-ahead in each state, and which look-ahead
|
||||||
tokens they accept. */
|
tokens they accept. */
|
||||||
|
|
||||||
void lalr (void);
|
void lalr (void);
|
||||||
|
|
||||||
/* Release the information related to lookaheads. Can be performed
|
/* Release the information related to look-ahead tokens. Can be performed
|
||||||
once the action tables are computed. */
|
once the action tables are computed. */
|
||||||
|
|
||||||
void lalr_free (void);
|
void lalr_free (void);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* Top level entry point of Bison.
|
/* Top level entry point of Bison.
|
||||||
|
|
||||||
Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002
|
Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002, 2004
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -107,7 +107,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
|
||||||
lookahead is not enough to disambiguate the parsing. In file
|
look-ahead 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);
|
||||||
@@ -147,7 +147,7 @@ main (int argc, char *argv[])
|
|||||||
if (complaint_issued)
|
if (complaint_issued)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
/* Lookaheads are no longer needed. */
|
/* Look-ahead 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);
|
||||||
|
|||||||
@@ -454,7 +454,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
|
||||||
lookahead token type. */
|
look-ahead token type. */
|
||||||
|
|
||||||
muscle_insert_rule_number_table ("defact", yydefact,
|
muscle_insert_rule_number_table ("defact", yydefact,
|
||||||
yydefact[0], 1, nstates);
|
yydefact[0], 1, nstates);
|
||||||
|
|||||||
86
src/print.c
86
src/print.c
@@ -1,6 +1,6 @@
|
|||||||
/* Print information on generated parser, for bison,
|
/* Print information on generated parser, for bison,
|
||||||
|
|
||||||
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003
|
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
@@ -39,8 +39,8 @@
|
|||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
|
|
||||||
static bitset shiftset;
|
static bitset shift_set;
|
||||||
static bitset lookaheadset;
|
static bitset look_ahead_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 lookaheads? */
|
/* Display the look-ahead tokens? */
|
||||||
if (report_flag & report_lookaheads)
|
if (report_flag & report_look_ahead_tokens)
|
||||||
state_rule_lookaheads_print (s, &rules[r], out);
|
state_rule_look_ahead_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 lookaheads column. */
|
/* Compute the width of the look-ahead 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 lookaheads and shifts. */
|
/* Report look-ahead 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 lookaheads column. */
|
/* Compute the width of the look-ahead 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 lookaheads and errors. */
|
/* Report look-ahead 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,13 +218,13 @@ state_default_rule (state *s)
|
|||||||
int cmax = 0;
|
int cmax = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* No need for a lookahead. */
|
/* No need for a look-ahead. */
|
||||||
if (s->consistent)
|
if (s->consistent)
|
||||||
return reds->rules[0];
|
return reds->rules[0];
|
||||||
|
|
||||||
/* 1. Each reduction is possibly masked by the lookaheads on which
|
/* 1. Each reduction is possibly masked by the look-ahead tokens on which
|
||||||
we shift (S/R conflicts)... */
|
we shift (S/R conflicts)... */
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shift_set);
|
||||||
{
|
{
|
||||||
transitions *trans = s->transitions;
|
transitions *trans = s->transitions;
|
||||||
FOR_EACH_SHIFT (trans, i)
|
FOR_EACH_SHIFT (trans, i)
|
||||||
@@ -233,27 +233,27 @@ state_default_rule (state *s)
|
|||||||
default rule. */
|
default rule. */
|
||||||
if (TRANSITION_IS_ERROR (trans, i))
|
if (TRANSITION_IS_ERROR (trans, i))
|
||||||
return NULL;
|
return NULL;
|
||||||
bitset_set (shiftset, TRANSITION_SYMBOL (trans, i));
|
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2. Each reduction is possibly masked by the lookaheads on which
|
/* 2. Each reduction is possibly masked by the look-ahead 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;
|
||||||
for (i = 0; i < errp->num; i++)
|
for (i = 0; i < errp->num; i++)
|
||||||
if (errp->symbols[i])
|
if (errp->symbols[i])
|
||||||
bitset_set (shiftset, errp->symbols[i]->number);
|
bitset_set (shift_set, errp->symbols[i]->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < reds->num; ++i)
|
for (i = 0; i < reds->num; ++i)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
/* How many non-masked lookaheads are there for this reduction?
|
/* How many non-masked look-ahead tokens are there for this
|
||||||
*/
|
reduction? */
|
||||||
bitset_andn (lookaheadset, reds->lookaheads[i], shiftset);
|
bitset_andn (look_ahead_set, reds->look_ahead_tokens[i], shift_set);
|
||||||
count = bitset_count (lookaheadset);
|
count = bitset_count (look_ahead_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 (shiftset, shiftset, reds->lookaheads[i]);
|
bitset_or (shift_set, shift_set, reds->look_ahead_tokens[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return default_rule;
|
return default_rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------.
|
/*--------------------------------------------------------------------------.
|
||||||
| Report a reduction of RULE on LOOKAHEADS (which can be `default'). |
|
| Report a reduction of RULE on LOOK_AHEAD_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 *lookahead,
|
const char *look_ahead_token,
|
||||||
rule *r, bool enabled)
|
rule *r, bool enabled)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
fprintf (out, " %s", lookahead);
|
fprintf (out, " %s", look_ahead_token);
|
||||||
for (j = width - strlen (lookahead); j > 0; --j)
|
for (j = width - strlen (look_ahead_token); j > 0; --j)
|
||||||
fputc (' ', out);
|
fputc (' ', out);
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
fputc ('[', out);
|
fputc ('[', out);
|
||||||
@@ -316,21 +316,21 @@ print_reductions (FILE *out, state *s)
|
|||||||
|
|
||||||
default_rule = state_default_rule (s);
|
default_rule = state_default_rule (s);
|
||||||
|
|
||||||
bitset_zero (shiftset);
|
bitset_zero (shift_set);
|
||||||
FOR_EACH_SHIFT (trans, i)
|
FOR_EACH_SHIFT (trans, i)
|
||||||
bitset_set (shiftset, TRANSITION_SYMBOL (trans, i));
|
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
|
||||||
|
|
||||||
/* Compute the width of the lookaheads column. */
|
/* Compute the width of the look-ahead token column. */
|
||||||
if (default_rule)
|
if (default_rule)
|
||||||
width = strlen (_("$default"));
|
width = strlen (_("$default"));
|
||||||
|
|
||||||
if (reds->lookaheads)
|
if (reds->look_ahead_tokens)
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
{
|
{
|
||||||
bool count = bitset_test (shiftset, 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->lookaheads[j], i))
|
if (bitset_test (reds->look_ahead_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 lookaheads (or $default) and reductions. */
|
/* Report look-ahead tokens (or $default) and reductions. */
|
||||||
if (reds->lookaheads)
|
if (reds->look_ahead_tokens)
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
{
|
{
|
||||||
bool defaulted = false;
|
bool defaulted = false;
|
||||||
bool count = bitset_test (shiftset, 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->lookaheads[j], i))
|
if (bitset_test (reds->look_ahead_tokens[j], i))
|
||||||
{
|
{
|
||||||
if (! count)
|
if (! count)
|
||||||
{
|
{
|
||||||
@@ -562,12 +562,12 @@ print_results (void)
|
|||||||
if (report_flag & report_itemsets)
|
if (report_flag & report_itemsets)
|
||||||
new_closure (nritems);
|
new_closure (nritems);
|
||||||
/* Storage for print_reductions. */
|
/* Storage for print_reductions. */
|
||||||
shiftset = bitset_create (ntokens, BITSET_FIXED);
|
shift_set = bitset_create (ntokens, BITSET_FIXED);
|
||||||
lookaheadset = bitset_create (ntokens, BITSET_FIXED);
|
look_ahead_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 (shiftset);
|
bitset_free (shift_set);
|
||||||
bitset_free (lookaheadset);
|
bitset_free (look_ahead_set);
|
||||||
if (report_flag & report_itemsets)
|
if (report_flag & report_itemsets)
|
||||||
free_closure ();
|
free_closure ();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* Output a VCG description on generated parser, for Bison,
|
/* Output a VCG description on generated parser, for Bison,
|
||||||
|
|
||||||
Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2002, 2003, 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.
|
||||||
|
|
||||||
@@ -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 lookaheads. */
|
/* Experimental feature: display the look-ahead tokens. */
|
||||||
if (report_flag & report_lookaheads)
|
if (report_flag & report_look_ahead_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->lookaheads && redno != -1)
|
if (reds->look_ahead_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->lookaheads[redno], k, 0)
|
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[redno], k, 0)
|
||||||
{
|
{
|
||||||
obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag);
|
obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
|
|||||||
16
src/state.c
16
src/state.c
@@ -102,7 +102,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->lookaheads = NULL;
|
res->look_ahead_tokens = NULL;
|
||||||
memcpy (res->rules, reds, rules_size);
|
memcpy (res->rules, reds, rules_size);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -219,26 +219,26 @@ state_errs_set (state *s, int num, symbol **tokens)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------.
|
/*---------------------------------------------------.
|
||||||
| Print on OUT all the lookaheads such that S wants to |
|
| Print on OUT all the look-ahead tokens such that S |
|
||||||
| reduce R. |
|
| wants to reduce R. |
|
||||||
`-----------------------------------------------------*/
|
`---------------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
state_rule_lookaheads_print (state *s, rule *r, FILE *out)
|
state_rule_look_ahead_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->lookaheads && red != -1)
|
if (reds->look_ahead_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->lookaheads[red], k, 0)
|
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[red], k, 0)
|
||||||
{
|
{
|
||||||
fprintf (out, "%s%s", sep, symbols[k]->tag);
|
fprintf (out, "%s%s", sep, symbols[k]->tag);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
|
|||||||
12
src/state.h
12
src/state.h
@@ -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 lookahead token
|
The two types of actions are shifts/gotos (push the look-ahead 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
|
||||||
lookahead token alone). When the states are generated, these
|
look-ahead 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
|
||||||
{
|
{
|
||||||
short int num;
|
short int num;
|
||||||
bitset *lookaheads;
|
bitset *look_ahead_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 lookahead is needed to decide what to do in state S. */
|
/* Nonzero if no look-ahead 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 lookaheads such that this STATE wants to
|
/* Print on OUT all the look-ahead tokens such that this STATE wants to
|
||||||
reduce R. */
|
reduce R. */
|
||||||
void state_rule_lookaheads_print (state *s, rule *r, FILE *out);
|
void state_rule_look_ahead_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);
|
||||||
|
|||||||
16
src/tables.c
16
src/tables.c
@@ -194,7 +194,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->lookaheads[i], j)
|
if (bitset_test (reds->look_ahead_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)))
|
||||||
{
|
{
|
||||||
@@ -215,8 +215,8 @@ conflict_row (state *s)
|
|||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Decide what to do for each type of token if seen as the lookahead |
|
| Decide what to do for each type of token if seen as the |
|
||||||
| token in specified state. The value returned is used as the |
|
| look-ahead 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 |
|
||||||
@@ -224,7 +224,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 lookahead |
|
| This is where conflicts are resolved. The loop over look-ahead |
|
||||||
| 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. |
|
||||||
| |
|
| |
|
||||||
@@ -249,17 +249,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->lookaheads)
|
if (reds->look_ahead_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
|
||||||
lookahead (in reverse order to give precedence to the first
|
look-ahead (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->lookaheads[i], j, 0)
|
BITSET_FOR_EACH (biter, reds->look_ahead_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. */
|
||||||
@@ -406,7 +406,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 |
|
||||||
| lookahead token type. |
|
| look-ahead 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. |
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Prepare the LALR and GLR parser tables.
|
/* Prepare the LALR and GLR parser tables.
|
||||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
Copyright (C) 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.
|
||||||
|
|
||||||
@@ -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 lookahead token's type is used to index that portion to find
|
The look-ahead 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
|
||||||
|
|||||||
@@ -494,8 +494,8 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
|
|||||||
#
|
#
|
||||||
# - test the action associated to `error'
|
# - test the action associated to `error'
|
||||||
#
|
#
|
||||||
# - check the lookahead that triggers an error is not discarded
|
# - check the look-ahead that triggers an error is not discarded
|
||||||
# when we enter error recovery. Below, the lookahead causing the
|
# when we enter error recovery. Below, the look-ahead 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.
|
||||||
#
|
#
|
||||||
@@ -509,7 +509,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 lookahead causing the error should not be discarded.
|
# POSIX says the look-ahead causing the error should not be discarded.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [62],
|
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [62],
|
||||||
[1.9: syntax error, unexpected "number"
|
[1.9: syntax error, unexpected "number"
|
||||||
calc: error: 2222 != 1])
|
calc: error: 2222 != 1])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Torturing Bison. -*- Autotest -*-
|
# Torturing Bison. -*- Autotest -*-
|
||||||
# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
# Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
|
||||||
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -256,11 +256,11 @@ AT_CLEANUP
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# AT_DATA_LOOKAHEADS_GRAMMAR(FILE-NAME, SIZE)
|
# AT_DATA_LOOK_AHEAD_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 lookaheads.
|
# requiring SIZE look-ahead tokens.
|
||||||
m4_define([AT_DATA_LOOKAHEADS_GRAMMAR],
|
m4_define([AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR],
|
||||||
[AT_DATA([[gengram.pl]],
|
[AT_DATA([[gengram.pl]],
|
||||||
[[#! /usr/bin/perl -w
|
[[#! /usr/bin/perl -w
|
||||||
|
|
||||||
@@ -359,13 +359,13 @@ mv stdout $1
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
## ----------------- ##
|
## ------------------------ ##
|
||||||
## Many lookaheads. ##
|
## Many look-ahead tokens. ##
|
||||||
## ----------------- ##
|
## ------------------------ ##
|
||||||
|
|
||||||
AT_SETUP([Many lookaheads])
|
AT_SETUP([Many look-ahead tokens])
|
||||||
|
|
||||||
AT_DATA_LOOKAHEADS_GRAMMAR([input.y], [1000])
|
AT_DATA_LOOK_AHEAD_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.
|
||||||
|
|||||||
Reference in New Issue
Block a user