mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Fuse yyval and yyloc into yylhs.
* data/lalr1.cc (b4_lhs_value, b4_lhs_location): Adjust to using yylhs. (parse): Replace yyval and yyloc with yylhs.value and yylhs.location. After a user action, compute yylhs.state earlier. (yyerrlab1): Do not play tricks with yylhs.location, rather, use a fresh error_token.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2008-11-09 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
Fuse yyval and yyloc into yylhs.
|
||||||
|
* data/lalr1.cc (b4_lhs_value, b4_lhs_location): Adjust to using
|
||||||
|
yylhs.
|
||||||
|
(parse): Replace yyval and yyloc with yylhs.value and
|
||||||
|
yylhs.location.
|
||||||
|
After a user action, compute yylhs.state earlier.
|
||||||
|
(yyerrlab1): Do not play tricks with yylhs.location, rather, use a
|
||||||
|
fresh error_token.
|
||||||
|
|
||||||
2008-11-09 Di-an Jan <dianj@freeshell.org>
|
2008-11-09 Di-an Jan <dianj@freeshell.org>
|
||||||
|
|
||||||
Remove unused variable.
|
Remove unused variable.
|
||||||
|
|||||||
131
data/lalr1.cc
131
data/lalr1.cc
@@ -46,6 +46,20 @@ m4_define([b4_assert_if],
|
|||||||
[b4_percent_define_ifdef([[assert]], [$1], [$2])])
|
[b4_percent_define_ifdef([[assert]], [$1], [$2])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_value([TYPE])
|
||||||
|
# --------------------
|
||||||
|
# Expansion of $<TYPE>$.
|
||||||
|
m4_define([b4_lhs_value],
|
||||||
|
[b4_symbol_value([yylhs.value], [$1])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_location()
|
||||||
|
# -----------------
|
||||||
|
# Expansion of @$.
|
||||||
|
m4_define([b4_lhs_location],
|
||||||
|
[yylhs.location])
|
||||||
|
|
||||||
|
|
||||||
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
||||||
@@ -797,11 +811,10 @@ b4_percent_code_get[]dnl
|
|||||||
/// The locations where the error started and ended.
|
/// The locations where the error started and ended.
|
||||||
data_type yyerror_range[2];
|
data_type yyerror_range[2];
|
||||||
|
|
||||||
/// $$.
|
/// $$ and @@$.
|
||||||
semantic_type yyval;
|
data_type yylhs;
|
||||||
/// @@$.
|
|
||||||
location_type yyloc;
|
|
||||||
|
|
||||||
|
/// The return value of parse().
|
||||||
int yyresult;
|
int yyresult;
|
||||||
|
|
||||||
YYCDEBUG << "Starting parse" << std::endl;
|
YYCDEBUG << "Starting parse" << std::endl;
|
||||||
@@ -910,22 +923,22 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
/* Variants are always initialized to an empty instance of the
|
/* Variants are always initialized to an empty instance of the
|
||||||
correct type. The default $$=$1 rule is NOT applied when using
|
correct type. The default $$=$1 rule is NOT applied when using
|
||||||
variants */
|
variants */
|
||||||
]b4_symbol_variant([[yyr1_@{yyn@}]], [yyval], [build])[],[
|
]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
|
||||||
/* If YYLEN is nonzero, implement the default value of the action:
|
/* If YYLEN is nonzero, implement the default value of the action:
|
||||||
`$$ = $1'. Otherwise, use the top of the stack.
|
`$$ = $1'. Otherwise, use the top of the stack.
|
||||||
|
|
||||||
Otherwise, the following line sets YYVAL to garbage.
|
Otherwise, the following line sets YYLHS.VALUE to garbage.
|
||||||
This behavior is undocumented and Bison
|
This behavior is undocumented and Bison
|
||||||
users should not rely upon it. */
|
users should not rely upon it. */
|
||||||
if (yylen)
|
if (yylen)
|
||||||
yyval = yystack_@{yylen - 1@}.value;
|
yylhs.value = yystack_@{yylen - 1@}.value;
|
||||||
else
|
else
|
||||||
yyval = yystack_@{0@}.value;])[
|
yylhs.value = yystack_@{0@}.value;])[
|
||||||
|
|
||||||
// Compute the default @@$.
|
// Compute the default @@$.
|
||||||
{
|
{
|
||||||
slice<data_type, stack_type> slice (yystack_, yylen);
|
slice<data_type, stack_type> slice (yystack_, yylen);
|
||||||
YYLLOC_DEFAULT (yyloc, slice, yylen);
|
YYLLOC_DEFAULT (yylhs.location, slice, yylen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the reduction.
|
// Perform the reduction.
|
||||||
@@ -936,18 +949,27 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], yyval, yyloc);
|
// Compute post-reduction state.
|
||||||
|
yyn = yyr1_[yyn];
|
||||||
|
yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
|
||||||
|
if (0 <= yystate && yystate <= yylast_
|
||||||
|
&& yycheck_[yystate] == yystack_[yylen].state)
|
||||||
|
yystate = yytable_[yystate];
|
||||||
|
else
|
||||||
|
yystate = yydefgoto_[yyn - yyntokens_];
|
||||||
|
yylhs.state = yystate;
|
||||||
|
YY_SYMBOL_PRINT ("-> $$ =", yyn, yylhs.value, yylhs.location);
|
||||||
]b4_variant_if([[
|
]b4_variant_if([[
|
||||||
// Destroy the lhs symbols.
|
// Destroy the lhs symbols.
|
||||||
for (int i = 0; i < yylen; ++i)
|
for (int i = 0; i < yylen; ++i)
|
||||||
// Destroy a variant which value may have be swapped with yyval.
|
// Destroy a variant which value may have be swapped with
|
||||||
// The value of yyval (hence maybe one of these lhs symbols)
|
// yylhs.value. The value of yylhs.value (hence maybe one of
|
||||||
// depends on what does the default contruction for this type.
|
// these lhs symbols) depends on what does the default
|
||||||
// In the case of pointers for instance, nothing is done, so the
|
// contruction for this type. In the case of pointers for
|
||||||
// value is junk. Therefore do not try to report the content in
|
// instance, nothing is done, so the value is junk. Therefore
|
||||||
// the debug trace, it's junk. Hence yymsg = 0. Besides, that
|
// do not try to report the content in the debug trace, it's
|
||||||
// keeps exactly the same traces as with the other Bison
|
// junk. Hence yymsg = 0. Besides, that keeps exactly the same
|
||||||
// skeletons.
|
// traces as with the other Bison skeletons.
|
||||||
yydestruct_ (0,
|
yydestruct_ (0,
|
||||||
yystos_[yystack_[i].state],
|
yystos_[yystack_[i].state],
|
||||||
yystack_[i].value, yystack_[i].location);]])[
|
yystack_[i].value, yystack_[i].location);]])[
|
||||||
@@ -957,14 +979,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
YY_STACK_PRINT ();
|
YY_STACK_PRINT ();
|
||||||
|
|
||||||
/* Shift the result of the reduction. */
|
/* Shift the result of the reduction. */
|
||||||
yyn = yyr1_[yyn];
|
yypush_ (0, yylhs.state, yylhs.value, yylhs.location);
|
||||||
yystate = yypgoto_[yyn - yyntokens_] + yystack_[0].state;
|
|
||||||
if (0 <= yystate && yystate <= yylast_
|
|
||||||
&& yycheck_[yystate] == yystack_[0].state)
|
|
||||||
yystate = yytable_[yystate];
|
|
||||||
else
|
|
||||||
yystate = yydefgoto_[yyn - yyntokens_];
|
|
||||||
yypush_ (0, yystate, yyval, yyloc);
|
|
||||||
goto yynewstate;
|
goto yynewstate;
|
||||||
|
|
||||||
/*------------------------------------.
|
/*------------------------------------.
|
||||||
@@ -1026,42 +1041,42 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
`-------------------------------------------------------------*/
|
`-------------------------------------------------------------*/
|
||||||
yyerrlab1:
|
yyerrlab1:
|
||||||
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
||||||
|
{
|
||||||
|
data_type error_token;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
yyn = yypact_[yystate];
|
||||||
|
if (yyn != yypact_ninf_)
|
||||||
|
{
|
||||||
|
yyn += yyterror_;
|
||||||
|
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
|
||||||
|
{
|
||||||
|
yyn = yytable_[yyn];
|
||||||
|
if (0 < yyn)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (;;)
|
// Pop the current state because it cannot handle the error token.
|
||||||
{
|
if (yystack_.size () == 1)
|
||||||
yyn = yypact_[yystate];
|
YYABORT;
|
||||||
if (yyn != yypact_ninf_)
|
|
||||||
{
|
|
||||||
yyn += yyterror_;
|
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
|
|
||||||
{
|
|
||||||
yyn = yytable_[yyn];
|
|
||||||
if (0 < yyn)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pop the current state because it cannot handle the error token.
|
yyerror_range[0].location = yystack_[0].location;
|
||||||
if (yystack_.size () == 1)
|
yydestruct_ ("Error: popping",
|
||||||
YYABORT;
|
yystos_[yystate],
|
||||||
|
yystack_[0].value, yystack_[0].location);
|
||||||
|
yypop_ ();
|
||||||
|
yystate = yystack_[0].state;
|
||||||
|
YY_STACK_PRINT ();
|
||||||
|
}
|
||||||
|
|
||||||
yyerror_range[0].location = yystack_[0].location;
|
yyerror_range[1].location = yylloc;
|
||||||
yydestruct_ ("Error: popping",
|
YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);
|
||||||
yystos_[yystate],
|
|
||||||
yystack_[0].value, yystack_[0].location);
|
|
||||||
yypop_ ();
|
|
||||||
yystate = yystack_[0].state;
|
|
||||||
YY_STACK_PRINT ();
|
|
||||||
}
|
|
||||||
|
|
||||||
yyerror_range[1].location = yylloc;
|
/* Shift the error token. */
|
||||||
// Using YYLLOC is tempting, but would change the location of
|
yystate = yyn;
|
||||||
// the lookahead. YYLOC is available though.
|
yypush_ ("Shifting", yystate, error_token.value, error_token.location);
|
||||||
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
|
}
|
||||||
|
|
||||||
/* Shift the error token. */
|
|
||||||
yystate = yyn;
|
|
||||||
yypush_ ("Shifting", yystate, yylval, yyloc);
|
|
||||||
goto yynewstate;
|
goto yynewstate;
|
||||||
|
|
||||||
/* Accept. */
|
/* Accept. */
|
||||||
|
|||||||
Reference in New Issue
Block a user