mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
glr2.cc: start the transition to using symbol_type
Currently glr2.cc uses three variables/struct members to denote the
symbols' kind (or state), value and location. lalr1.cc has two types
for "complete" symbols: symbol_type and stack_symbol_type. Let's use
that model in glr2.cc too.
For a start use yyla (a symbol_type) to denote the lookahead, instead
of the triple yytoken, yylval and yylloc. This will make easier the
introduction of the "context" subclass, used in parse.error=custom.
It simplifies the code in several places. For instance from:
symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
value_type yylval_current;
]b4_symbol_variant([this->yytoken],
[yylval_current], [move], [this->yylval])], [[
value_type yylval_current = this->yylval;]])[]b4_locations_if([
location_type yylloc_current = this->yylloc;])[
to:
symbol_type yyla_current = std::move (this->yyla);
* data/skeletons/glr2.cc (yytoken, yylval, yylloc): Replace by...
(yyla): this.
Adjust all dependencies.
(yyloc_default): Remove, unused.
* tests/c++.at, tests/glr-regression.at, tests/types.at: C++11 is
required for glr2.cc.
Adjust to changes in glr2.cc.
This commit is contained in:
@@ -181,8 +181,8 @@ m4_define([b4_yylex],
|
|||||||
[b4_function_call([yylex],
|
[b4_function_call([yylex],
|
||||||
[symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
|
[symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
|
||||||
[b4_function_call([yylex], [int],
|
[b4_function_call([yylex], [int],
|
||||||
[[value_type *], [&this->yylval]][]dnl
|
[[value_type *], [&this->yyla.value]][]dnl
|
||||||
b4_locations_if([, [[location_type *], [&this->yylloc]]])dnl
|
b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl
|
||||||
m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
|
m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
|
||||||
|
|
||||||
|
|
||||||
@@ -219,6 +219,9 @@ m4_define([b4_shared_declarations],
|
|||||||
|
|
||||||
]b4_YYDEBUG_define[
|
]b4_YYDEBUG_define[
|
||||||
|
|
||||||
|
class glr_stack;
|
||||||
|
class glr_state;
|
||||||
|
|
||||||
]b4_namespace_open[
|
]b4_namespace_open[
|
||||||
|
|
||||||
]b4_bison_locations_if([m4_ifndef([b4_location_file],
|
]b4_bison_locations_if([m4_ifndef([b4_location_file],
|
||||||
@@ -331,6 +334,10 @@ m4_define([b4_shared_declarations],
|
|||||||
location_type& yyloc]])[);
|
location_type& yyloc]])[);
|
||||||
|
|
||||||
]b4_parse_param_vars[
|
]b4_parse_param_vars[
|
||||||
|
// Needs access to report_syntax_error, etc.
|
||||||
|
friend glr_stack;
|
||||||
|
// Needs access to yy_destroy_.
|
||||||
|
friend glr_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
]b4_token_ctor_if([b4_yytranslate_define([$1])[
|
]b4_token_ctor_if([b4_yytranslate_define([$1])[
|
||||||
@@ -396,8 +403,7 @@ typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
|
|||||||
right-hand sides. Unlike the standard yacc.c template, here we set
|
right-hand sides. Unlike the standard yacc.c template, here we set
|
||||||
the default value of $$ to a zeroed-out value. Since the default
|
the default value of $$ to a zeroed-out value. Since the default
|
||||||
value is undefined, this behavior is technically correct. */
|
value is undefined, this behavior is technically correct. */
|
||||||
static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;]b4_locations_if([[
|
static ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default;
|
||||||
static ]b4_namespace_ref[::]b4_parser_class[::location_type yyloc_default][]b4_yyloc_default;])[
|
|
||||||
|
|
||||||
]b4_user_post_prologue[
|
]b4_user_post_prologue[
|
||||||
]b4_percent_code_get[]dnl
|
]b4_percent_code_get[]dnl
|
||||||
@@ -1079,7 +1085,7 @@ private:
|
|||||||
/** During nondeterministic operation, yylookaheadNeeds tracks which
|
/** During nondeterministic operation, yylookaheadNeeds tracks which
|
||||||
* stacks have actually needed the current lookahead. During deterministic
|
* stacks have actually needed the current lookahead. During deterministic
|
||||||
* operation, yylookaheadNeeds[0] is not maintained since it would merely
|
* operation, yylookaheadNeeds[0] is not maintained since it would merely
|
||||||
* duplicate yytoken != ]b4_symbol(empty, kind)[. */
|
* duplicate !yyla.empty (). */
|
||||||
std::vector<bool> yylookaheadNeeds;
|
std::vector<bool> yylookaheadNeeds;
|
||||||
|
|
||||||
/** The last stack we invalidated. */
|
/** The last stack we invalidated. */
|
||||||
@@ -2007,24 +2013,26 @@ public:
|
|||||||
class glr_stack
|
class glr_stack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind symbol_kind;
|
typedef ]b4_namespace_ref[::]b4_parser_class[ parser_type;
|
||||||
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type symbol_kind_type;
|
typedef parser_type::symbol_kind symbol_kind;
|
||||||
typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[
|
typedef parser_type::symbol_kind_type symbol_kind_type;
|
||||||
typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[
|
typedef parser_type::symbol_type symbol_type;
|
||||||
|
typedef parser_type::value_type value_type;]b4_locations_if([[
|
||||||
|
typedef parser_type::location_type location_type;]])[
|
||||||
|
|
||||||
glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
|
glr_stack (size_t yysize, ]b4_namespace_ref[::]b4_parser_class[& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[)
|
||||||
: yyerrState (0)
|
: yyerrState (0)
|
||||||
, yystateStack (yysize)
|
, yystateStack (yysize)
|
||||||
, yyerrcnt (0)
|
, yyerrcnt (0)
|
||||||
, yytoken (]b4_symbol(empty, kind)[)
|
, yyla ()
|
||||||
, yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
|
, yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~glr_stack ()
|
~glr_stack ()
|
||||||
{
|
{
|
||||||
if (this->yytoken != ]b4_symbol(empty, kind)[)
|
if (!this->yyla.empty ())
|
||||||
yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
|
yyparser.yy_destroy_ ("Cleanup: discarding lookahead",
|
||||||
this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);
|
this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);
|
||||||
popall_ ();
|
popall_ ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2033,9 +2041,7 @@ public:
|
|||||||
glr_stack_item yyerror_range[3];]])[
|
glr_stack_item yyerror_range[3];]])[
|
||||||
state_stack yystateStack;
|
state_stack yystateStack;
|
||||||
int yyerrcnt;
|
int yyerrcnt;
|
||||||
symbol_kind_type yytoken;
|
symbol_type yyla;
|
||||||
value_type yylval;]b4_locations_if([[
|
|
||||||
location_type yylloc;]])[
|
|
||||||
YYJMP_BUF yyexception_buffer;
|
YYJMP_BUF yyexception_buffer;
|
||||||
]b4_namespace_ref[::]b4_parser_class[& yyparser;
|
]b4_namespace_ref[::]b4_parser_class[& yyparser;
|
||||||
|
|
||||||
@@ -2063,11 +2069,9 @@ public:
|
|||||||
|
|
||||||
YYCDEBUG << "Starting parse\n";
|
YYCDEBUG << "Starting parse\n";
|
||||||
|
|
||||||
this->yytoken = ]b4_symbol(empty, kind)[;]b4_variant_if([], [[
|
this->yyla.clear ();
|
||||||
this->yylval = yyval_default;]])[]b4_locations_if([
|
|
||||||
this->yylloc = yyloc_default;])[
|
|
||||||
]m4_ifdef([b4_initial_action], [
|
]m4_ifdef([b4_initial_action], [
|
||||||
b4_dollar_pushdef([this->yylval], [], [], [this->yylloc])dnl
|
b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl
|
||||||
b4_user_initial_action
|
b4_user_initial_action
|
||||||
b4_dollar_popdef])[]dnl
|
b4_dollar_popdef])[]dnl
|
||||||
[
|
[
|
||||||
@@ -2078,7 +2082,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
case 2: goto yyexhaustedlab;
|
case 2: goto yyexhaustedlab;
|
||||||
default: goto yybuglab;
|
default: goto yybuglab;
|
||||||
}
|
}
|
||||||
this->yyglrShift (create_state_set_index(0), 0, 0, this->yylval]b4_locations_if([, this->yylloc])[);
|
this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[);
|
||||||
yyposn = 0;
|
yyposn = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
@@ -2098,7 +2102,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
const rule_num yyrule = yy_default_action (yystate);
|
const rule_num yyrule = yy_default_action (yystate);
|
||||||
if (yyrule == 0)
|
if (yyrule == 0)
|
||||||
{]b4_locations_if([[
|
{]b4_locations_if([[
|
||||||
this->yyerror_range[1].getState().yyloc = this->yylloc;]])[
|
this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
|
||||||
this->yyreportSyntaxError ();
|
this->yyreportSyntaxError ();
|
||||||
goto yyuser_error;
|
goto yyuser_error;
|
||||||
}
|
}
|
||||||
@@ -2108,28 +2112,25 @@ b4_dollar_popdef])[]dnl
|
|||||||
{
|
{
|
||||||
yyget_token ();
|
yyget_token ();
|
||||||
const short* yyconflicts;
|
const short* yyconflicts;
|
||||||
const int yyaction = yygetLRActions (yystate, this->yytoken, yyconflicts);
|
const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
|
||||||
if (*yyconflicts != 0)
|
if (*yyconflicts != 0)
|
||||||
break;
|
break;
|
||||||
if (yy_is_shift_action (yyaction))
|
if (yy_is_shift_action (yyaction))
|
||||||
{
|
{
|
||||||
YY_SYMBOL_PRINT ("Shifting", this->yytoken, this->yylval, this->yylloc);
|
YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location);
|
||||||
yyposn += 1;
|
yyposn += 1;
|
||||||
// FIXME: we should move yylval.
|
// FIXME: we should move yylval.
|
||||||
this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yylval]b4_locations_if([, this->yylloc])[);]b4_variant_if([[
|
this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
|
||||||
// FIXME: User destructors.
|
yyla.clear ();
|
||||||
// Value type destructor.
|
|
||||||
]b4_symbol_variant([[this->yytoken]], [[this->yylval]], [[template destroy]])])[
|
|
||||||
this->yytoken = ]b4_symbol(empty, kind)[;
|
|
||||||
if (0 < this->yyerrState)
|
if (0 < this->yyerrState)
|
||||||
this->yyerrState -= 1;
|
this->yyerrState -= 1;
|
||||||
}
|
}
|
||||||
else if (yy_is_error_action (yyaction))
|
else if (yy_is_error_action (yyaction))
|
||||||
{]b4_locations_if([[
|
{]b4_locations_if([[
|
||||||
this->yyerror_range[1].getState().yyloc = this->yylloc;]])[
|
this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[
|
||||||
/* Don't issue an error message again for exceptions
|
/* Don't issue an error message again for exceptions
|
||||||
thrown from the scanner. */
|
thrown from the scanner. */
|
||||||
if (this->yytoken != ]b4_symbol(error, kind)[)
|
if (this->yyla.kind () != ]b4_symbol(error, kind)[)
|
||||||
this->yyreportSyntaxError ();
|
this->yyreportSyntaxError ();
|
||||||
goto yyuser_error;
|
goto yyuser_error;
|
||||||
}
|
}
|
||||||
@@ -2141,7 +2142,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
|
for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys)
|
||||||
this->yystateStack.yytops.setLookaheadNeeds(yys, this->yytoken != ]b4_symbol(empty, kind)[);
|
this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty ());
|
||||||
|
|
||||||
/* yyprocessOneStack returns one of three things:
|
/* yyprocessOneStack returns one of three things:
|
||||||
|
|
||||||
@@ -2163,27 +2164,27 @@ b4_dollar_popdef])[]dnl
|
|||||||
on yylval in the event of memory exhaustion. */
|
on yylval in the event of memory exhaustion. */
|
||||||
|
|
||||||
for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
|
for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
|
||||||
YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yylloc])[));
|
YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[));
|
||||||
this->yystateStack.yytops.yyremoveDeletes ();
|
this->yystateStack.yytops.yyremoveDeletes ();
|
||||||
if (this->yystateStack.yytops.size() == 0)
|
if (this->yystateStack.yytops.size() == 0)
|
||||||
{
|
{
|
||||||
this->yystateStack.yytops.yyundeleteLastStack ();
|
this->yystateStack.yytops.yyundeleteLastStack ();
|
||||||
if (this->yystateStack.yytops.size() == 0)
|
if (this->yystateStack.yytops.size() == 0)
|
||||||
this->yyFail (]b4_locations_if([&this->yylloc, ])[YY_("syntax error"));
|
this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error"));
|
||||||
YYCHK1 (this->yyresolveStack ());
|
YYCHK1 (this->yyresolveStack ());
|
||||||
YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
|
YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[
|
||||||
this->yyerror_range[1].getState ().yyloc = this->yylloc;]])[
|
this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[
|
||||||
this->yyreportSyntaxError ();
|
this->yyreportSyntaxError ();
|
||||||
goto yyuser_error;
|
goto yyuser_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If any yyglrShift call fails, it will fail after shifting. Thus,
|
/* If any yyglrShift call fails, it will fail after shifting. Thus,
|
||||||
a copy of yylval will already be on stack 0 in the event of a
|
a copy of yylval will already be on stack 0 in the event of a
|
||||||
failure in the following loop. Thus, yytoken is set to ]b4_symbol(empty, kind)[
|
failure in the following loop. Thus, yyla is emptied
|
||||||
before the loop to make sure the user destructor for yylval isn't
|
before the loop to make sure the user destructor for yylval isn't
|
||||||
called twice. */
|
called twice. */
|
||||||
yysymbol_kind_t yytoken_to_shift = this->yytoken;
|
yysymbol_kind_t yytoken_to_shift = this->yyla.kind ();
|
||||||
this->yytoken = ]b4_symbol(empty, kind)[;
|
this->yyla.kind_ = ]b4_symbol(empty, kind)[;
|
||||||
yyposn += 1;
|
yyposn += 1;
|
||||||
for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
|
for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys)
|
||||||
{
|
{
|
||||||
@@ -2192,15 +2193,15 @@ b4_dollar_popdef])[]dnl
|
|||||||
const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
|
const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
|
||||||
/* Note that yyconflicts were handled by yyprocessOneStack. */
|
/* Note that yyconflicts were handled by yyprocessOneStack. */
|
||||||
YYCDEBUG << "On stack " << yys.get() << ", ";
|
YYCDEBUG << "On stack " << yys.get() << ", ";
|
||||||
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yylval, this->yylloc);
|
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location);
|
||||||
this->yyglrShift (yys, yyaction, yyposn, this->yylval]b4_locations_if([, this->yylloc])[);
|
this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[);
|
||||||
YYCDEBUG << "Stack " << yys.get() << " now in state "
|
YYCDEBUG << "Stack " << yys.get() << " now in state "
|
||||||
<< this->topState(yys)->yylrState << '\n';
|
<< this->topState(yys)->yylrState << '\n';
|
||||||
}
|
}
|
||||||
]b4_variant_if([[
|
]b4_variant_if([[
|
||||||
// FIXME: User destructors.
|
// FIXME: User destructors.
|
||||||
// Value type destructor.
|
// Value type destructor.
|
||||||
]b4_symbol_variant([[yytoken_to_shift]], [[this->yylval]], [[template destroy]])])[
|
]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[
|
||||||
|
|
||||||
if (this->yystateStack.yytops.size () == 1)
|
if (this->yystateStack.yytops.size () == 1)
|
||||||
{
|
{
|
||||||
@@ -2212,7 +2213,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
yyuser_error:
|
yyuser_error:
|
||||||
this->yyrecoverSyntaxError (]b4_locations_if([&this->yylloc])[);
|
this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[);
|
||||||
yyposn = this->firstTopState()->yyposn;
|
yyposn = this->firstTopState()->yyposn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2229,7 +2230,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
goto yyreturn;
|
goto yyreturn;
|
||||||
|
|
||||||
yyexhaustedlab:
|
yyexhaustedlab:
|
||||||
yyparser.error (]b4_locations_if([this->yylloc, ])[YY_("memory exhausted"));
|
yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted"));
|
||||||
yyresult = 2;
|
yyresult = 2;
|
||||||
goto yyreturn;
|
goto yyreturn;
|
||||||
|
|
||||||
@@ -2275,15 +2276,15 @@ b4_dollar_popdef])[]dnl
|
|||||||
yynewOption.setNext(yystate->firstVal());
|
yynewOption.setNext(yystate->firstVal());
|
||||||
if (yystateStack.yytops.lookaheadNeeds(yyk))
|
if (yystateStack.yytops.lookaheadNeeds(yyk))
|
||||||
{
|
{
|
||||||
yynewOption.yytoken = this->yytoken;]b4_variant_if([[
|
yynewOption.yytoken = this->yyla.kind ();]b4_variant_if([[
|
||||||
]b4_symbol_variant([this->yytoken],
|
]b4_symbol_variant([this->yyla.kind ()],
|
||||||
[yynewOption.yyval], [copy], [this->yylval])], [[
|
[yynewOption.yyval], [copy], [this->yyla.value])], [[
|
||||||
yynewOption.yyval = this->yylval;]])[]b4_locations_if([
|
yynewOption.yyval = this->yyla.value;]])[]b4_locations_if([
|
||||||
yynewOption.yyloc = this->yylloc;])[
|
yynewOption.yyloc = this->yyla.location;])[
|
||||||
}
|
}
|
||||||
yystate->setFirstVal(&yynewOption);
|
yystate->setFirstVal (&yynewOption);
|
||||||
|
|
||||||
yyreserveGlrStack();
|
yyreserveGlrStack ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ]b4_api_PREFIX[DEBUG
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
@@ -2299,7 +2300,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
return;
|
return;
|
||||||
]b4_parse_error_bmatch(
|
]b4_parse_error_bmatch(
|
||||||
[simple],
|
[simple],
|
||||||
[[ yyparser.error (]b4_locations_if([this->yylloc, ])[YY_("syntax error"));]],
|
[[ yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("syntax error"));]],
|
||||||
[[ {
|
[[ {
|
||||||
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
|
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
|
||||||
/* Arguments of yyformat. */
|
/* Arguments of yyformat. */
|
||||||
@@ -2332,10 +2333,10 @@ b4_dollar_popdef])[]dnl
|
|||||||
one exception: it will still contain any token that will not be
|
one exception: it will still contain any token that will not be
|
||||||
accepted due to an error action in a later state.
|
accepted due to an error action in a later state.
|
||||||
*/
|
*/
|
||||||
if (yytoken != ]b4_symbol(empty, kind)[)
|
if (!yyla.empty ())
|
||||||
{
|
{
|
||||||
const int yyn = yypact[firstTopState()->yylrState];
|
const int yyn = yypact[firstTopState()->yylrState];
|
||||||
yyarg[yycount++] = yytoken;
|
yyarg[yycount++] = yyla.kind ();
|
||||||
if (!yypact_value_is_default (yyn))
|
if (!yypact_value_is_default (yyn))
|
||||||
{
|
{
|
||||||
/* Start YYX at -YYN if negative to avoid negative indexes in
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
@@ -2388,7 +2389,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
yymsg += *yyp;
|
yymsg += *yyp;
|
||||||
yyparser.error (]b4_locations_if([[yylloc, ]])[yymsg);
|
yyparser.error (]b4_locations_if([[yyla.location, ]])[yymsg);
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
yyerrcnt += 1;
|
yyerrcnt += 1;
|
||||||
@@ -2406,28 +2407,28 @@ b4_dollar_popdef])[]dnl
|
|||||||
reductions. Skip tokens until we can proceed. */
|
reductions. Skip tokens until we can proceed. */
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (this->yytoken == ]b4_symbol(eof, kind)[)
|
if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
|
||||||
yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
|
yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
|
||||||
if (this->yytoken != ]b4_symbol(empty, kind)[)
|
if (this->yyla.kind () != ]b4_symbol(empty, kind)[)
|
||||||
{]b4_locations_if([[
|
{]b4_locations_if([[
|
||||||
/* We throw away the lookahead, but the error range
|
/* We throw away the lookahead, but the error range
|
||||||
of the shifted error token must take it into account. */
|
of the shifted error token must take it into account. */
|
||||||
glr_state *yys = firstTopState();
|
glr_state *yys = firstTopState();
|
||||||
yyerror_range[1].getState().yyloc = yys->yyloc;
|
yyerror_range[1].getState().yyloc = yys->yyloc;
|
||||||
yyerror_range[2].getState().yyloc = this->yylloc;
|
yyerror_range[2].getState().yyloc = this->yyla.location;
|
||||||
YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
|
YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
|
||||||
yyparser.yy_destroy_ ("Error: discarding",
|
yyparser.yy_destroy_ ("Error: discarding",
|
||||||
this->yytoken, this->yylval]b4_locations_if([, this->yylloc])[);]b4_variant_if([[
|
this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[
|
||||||
// Value type destructor.
|
// Value type destructor.
|
||||||
]b4_symbol_variant([[this->yytoken]], [[this->yylval]], [[template destroy]])])[
|
]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[
|
||||||
this->yytoken = ]b4_symbol(empty, kind)[;
|
this->yyla.kind_ = ]b4_symbol(empty, kind)[;
|
||||||
}
|
}
|
||||||
yyget_token ();
|
yyget_token ();
|
||||||
int yyj = yypact[firstTopState()->yylrState];
|
int yyj = yypact[firstTopState()->yylrState];
|
||||||
if (yypact_value_is_default (yyj))
|
if (yypact_value_is_default (yyj))
|
||||||
return;
|
return;
|
||||||
yyj += this->yytoken;
|
yyj += this->yyla.kind ();
|
||||||
if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yytoken)
|
if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ())
|
||||||
{
|
{
|
||||||
if (yydefact[firstTopState()->yylrState] != 0)
|
if (yydefact[firstTopState()->yylrState] != 0)
|
||||||
return;
|
return;
|
||||||
@@ -2454,12 +2455,12 @@ b4_dollar_popdef])[]dnl
|
|||||||
/* Shift the error token. */]b4_locations_if([[
|
/* Shift the error token. */]b4_locations_if([[
|
||||||
/* First adjust its location.*/
|
/* First adjust its location.*/
|
||||||
location_type yyerrloc;
|
location_type yyerrloc;
|
||||||
yyerror_range[2].getState().yyloc = this->yylloc;
|
yyerror_range[2].getState().yyloc = this->yyla.location;
|
||||||
YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
|
YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[
|
||||||
YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
|
YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]),
|
||||||
yylval, yyerrloc);
|
this->yyla.value, yyerrloc);
|
||||||
yyglrShift (create_state_set_index(0), yytable[yyj],
|
yyglrShift (create_state_set_index(0), yytable[yyj],
|
||||||
yys->yyposn, yylval]b4_locations_if([, yyerrloc])[);
|
yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[);
|
||||||
yys = firstTopState();
|
yys = firstTopState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2512,7 +2513,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
yystateStack.yytops.setLookaheadNeeds(yyk, true);
|
yystateStack.yytops.setLookaheadNeeds(yyk, true);
|
||||||
yyget_token ();
|
yyget_token ();
|
||||||
const short* yyconflicts;
|
const short* yyconflicts;
|
||||||
const int yyaction = yygetLRActions (yystate, this->yytoken, yyconflicts);
|
const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts);
|
||||||
|
|
||||||
for (; *yyconflicts != 0; ++yyconflicts)
|
for (; *yyconflicts != 0; ++yyconflicts)
|
||||||
{
|
{
|
||||||
@@ -2585,7 +2586,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
# undef YYRECOVERING
|
# undef YYRECOVERING
|
||||||
# define YYRECOVERING() (yyerrState != 0)
|
# define YYRECOVERING() (yyerrState != 0)
|
||||||
# undef yytoken
|
# undef yytoken
|
||||||
# define yytoken this->yytoken
|
# define yytoken this->yyla.kind_
|
||||||
# undef yyclearin
|
# undef yyclearin
|
||||||
# define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
|
# define yyclearin (yytoken = ]b4_symbol(empty, kind)[)
|
||||||
# undef YYBACKUP
|
# undef YYBACKUP
|
||||||
@@ -2958,7 +2959,7 @@ private:
|
|||||||
{
|
{
|
||||||
yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
|
yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for",
|
||||||
yy_accessing_symbol (yys.yylrState),
|
yy_accessing_symbol (yys.yylrState),
|
||||||
this->yylval]b4_locations_if([, *yylocp])[);
|
this->yyla.value]b4_locations_if([, *yylocp])[);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
|
yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[
|
||||||
@@ -3016,28 +3017,18 @@ private:
|
|||||||
/* Set default location. */
|
/* Set default location. */
|
||||||
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
|
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
|
||||||
{
|
{
|
||||||
symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
|
symbol_type yyla_current = std::move (this->yyla);
|
||||||
value_type yylval_current;
|
this->yyla.kind_ = yyopt.yytoken;]b4_variant_if([[
|
||||||
]b4_symbol_variant([this->yytoken],
|
]b4_symbol_variant([this->yyla.kind ()],
|
||||||
[yylval_current], [move], [this->yylval])], [[
|
[this->yyla.value], [move], [yyopt.yyval])], [[
|
||||||
value_type yylval_current = this->yylval;]])[]b4_locations_if([
|
this->yyla.value = yyopt.yyval;]])[]b4_locations_if([
|
||||||
location_type yylloc_current = this->yylloc;])[
|
this->yyla.location = yyopt.yyloc;])[
|
||||||
|
|
||||||
this->yytoken = yyopt.yytoken;]b4_variant_if([[
|
|
||||||
]b4_symbol_variant([this->yytoken],
|
|
||||||
[this->yylval], [move], [yyopt.yyval])], [[
|
|
||||||
this->yylval = yyopt.yyval;]])[]b4_locations_if([
|
|
||||||
this->yylloc = yyopt.yyloc;])[
|
|
||||||
yyflag = yyuserAction (yyopt.yyrule, yynrhs,
|
yyflag = yyuserAction (yyopt.yyrule, yynrhs,
|
||||||
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
|
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
|
||||||
create_state_set_index (-1),
|
create_state_set_index (-1),
|
||||||
yyvalp]b4_locations_if([, yylocp])[);
|
yyvalp]b4_locations_if([, yylocp])[);
|
||||||
|
|
||||||
this->yytoken = yytoken_current;]b4_variant_if([[
|
this->yyla = std::move (yyla_current);
|
||||||
]b4_symbol_variant([this->yytoken],
|
|
||||||
[this->yylval], [move], [yylval_current])], [[
|
|
||||||
this->yylval = yylval_current;]])[]b4_locations_if([
|
|
||||||
this->yylloc = yylloc_current;])[
|
|
||||||
}
|
}
|
||||||
return yyflag;
|
return yyflag;
|
||||||
}]b4_locations_if([[
|
}]b4_locations_if([[
|
||||||
@@ -3090,45 +3081,33 @@ private:
|
|||||||
yyget_token ()
|
yyget_token ()
|
||||||
{
|
{
|
||||||
]b4_parse_param_use()dnl
|
]b4_parse_param_use()dnl
|
||||||
[ if (this->yytoken == ]b4_symbol(empty, kind)[)
|
[ if (this->yyla.empty ())
|
||||||
{
|
{
|
||||||
YYCDEBUG << "Reading a token\n";
|
YYCDEBUG << "Reading a token\n";
|
||||||
int yychar;
|
|
||||||
#if YY_EXCEPTIONS
|
#if YY_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
|
||||||
#endif // YY_EXCEPTIONS
|
#endif // YY_EXCEPTIONS
|
||||||
{]b4_token_ctor_if([[
|
{]b4_token_ctor_if([[
|
||||||
typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_type symbol_type;
|
symbol_type yylookahead (]b4_yylex[);
|
||||||
symbol_type yylookahead = ]b4_yylex[;
|
yyla.move (yylookahead);]], [[
|
||||||
this->yytoken = yylookahead.kind ();]b4_variant_if([[
|
yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[
|
||||||
]b4_symbol_variant([this->yytoken],
|
|
||||||
[this->yylval], [move], [yylookahead.value])], [[
|
|
||||||
this->yylval = yylookahead.value;]])[]b4_locations_if([
|
|
||||||
this->yylloc = yylookahead.location;
|
|
||||||
yylookahead.kind_ = symbol_kind::S_YYEMPTY;])[]], [[
|
|
||||||
yychar = ]b4_yylex[;]])[
|
|
||||||
}
|
|
||||||
#if YY_EXCEPTIONS
|
|
||||||
}
|
}
|
||||||
|
#if YY_EXCEPTIONS
|
||||||
catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
|
catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc)
|
||||||
{
|
{
|
||||||
YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
|
YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([
|
||||||
this->yylloc = yyexc.location;])[
|
this->yyla.location = yyexc.location;])[
|
||||||
yyparser.error (]b4_locations_if([this->yylloc, ])[yyexc.what ());
|
yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ());
|
||||||
// Map errors caught in the scanner to the error token, so that error
|
// Map errors caught in the scanner to the error token, so that error
|
||||||
// handling is started.]b4_token_ctor_if([[
|
// handling is started.
|
||||||
this->yytoken = ]b4_symbol(error, kind)[;]], [[
|
this->yyla.kind_ = ]b4_symbol(error, kind)[;
|
||||||
yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, id)[;]])[
|
|
||||||
}
|
}
|
||||||
#endif // YY_EXCEPTIONS]b4_token_ctor_if([], [[
|
|
||||||
this->yytoken
|
|
||||||
= ]b4_namespace_ref[::]b4_parser_class[::yytranslate_ (yychar);]])[
|
|
||||||
}
|
}
|
||||||
if (this->yytoken == ]b4_symbol(eof, kind)[)
|
#endif // YY_EXCEPTIONS
|
||||||
|
if (this->yyla.kind () == ]b4_symbol(eof, kind)[)
|
||||||
YYCDEBUG << "Now at end of input.\n";
|
YYCDEBUG << "Now at end of input.\n";
|
||||||
else
|
else
|
||||||
YY_SYMBOL_PRINT ("Next token is", this->yytoken, this->yylval, this->yylloc);
|
YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3465,6 +3444,12 @@ static void yypdumpstack (const glr_stack& yystack)
|
|||||||
#endif // ]b4_api_PREFIX[DEBUG
|
#endif // ]b4_api_PREFIX[DEBUG
|
||||||
|
|
||||||
]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
|
]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[
|
||||||
|
|
||||||
|
]b4_token_ctor_if([], [[
|
||||||
|
/*---------.
|
||||||
|
| symbol. |
|
||||||
|
`---------*/
|
||||||
|
]b4_public_types_define([cc])])[
|
||||||
]b4_namespace_close[]dnl
|
]b4_namespace_close[]dnl
|
||||||
b4_epilogue[]dnl
|
b4_epilogue[]dnl
|
||||||
b4_output_end
|
b4_output_end
|
||||||
|
|||||||
@@ -1031,6 +1031,7 @@ yylex (yy::parser::value_type *lval)
|
|||||||
AT_BISON_CHECK([[-o input.cc input.yy]])
|
AT_BISON_CHECK([[-o input.cc input.yy]])
|
||||||
|
|
||||||
AT_FOR_EACH_CXX([
|
AT_FOR_EACH_CXX([
|
||||||
|
AT_GLR2_CC_IF([AT_REQUIRE_CXX_STD(11, [echo "$at_std not supported"; continue])])
|
||||||
AT_LANG_COMPILE([[input]], [[input.cc scan.cc]])
|
AT_LANG_COMPILE([[input]], [[input.cc scan.cc]])
|
||||||
|
|
||||||
# Leave enough valid tokens to make sure we recovered from the
|
# Leave enough valid tokens to make sure we recovered from the
|
||||||
|
|||||||
@@ -42,13 +42,12 @@ yyparse ()
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
m4_define([AT_PRINT_LOOKAHEAD_DECLARE],
|
m4_define([AT_PRINT_LOOKAHEAD_DECLARE],
|
||||||
[AT_GLR2_CC_IF(
|
[AT_GLR2_CC_IF(
|
||||||
[[ static void
|
[[static void
|
||||||
print_lookahead (int yytoken, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
print_lookahead (yy::parser::symbol_type yylookahead, char const *reduction);
|
||||||
char const *reduction);
|
|
||||||
#define PRINT_LOOKAHEAD(Msg) \
|
#define PRINT_LOOKAHEAD(Msg) \
|
||||||
print_lookahead (yytoken, &yylval, &yylloc, Msg)
|
print_lookahead (yyla, Msg)
|
||||||
]],
|
]],
|
||||||
[[ static void
|
[[static void
|
||||||
print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
||||||
char const *reduction);
|
char const *reduction);
|
||||||
#define PRINT_LOOKAHEAD(Msg) \
|
#define PRINT_LOOKAHEAD(Msg) \
|
||||||
@@ -60,8 +59,7 @@ m4_define([AT_PRINT_LOOKAHEAD_DECLARE],
|
|||||||
m4_define([AT_PRINT_LOOKAHEAD_DEFINE],
|
m4_define([AT_PRINT_LOOKAHEAD_DEFINE],
|
||||||
[AT_GLR2_CC_IF(
|
[AT_GLR2_CC_IF(
|
||||||
[[static void
|
[[static void
|
||||||
print_lookahead (int yytoken, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
print_lookahead (yy::parser::symbol_type yylookahead, char const *reduction)
|
||||||
char const *reduction)
|
|
||||||
]],
|
]],
|
||||||
[[static void
|
[[static void
|
||||||
print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
||||||
@@ -80,11 +78,12 @@ print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
|||||||
// | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// 117 | : '?';
|
// 117 | : '?';
|
||||||
// | ~~~~~
|
// | ~~~~~
|
||||||
|
int yytoken = yylookahead.kind ();
|
||||||
int yychr
|
int yychr
|
||||||
= yytoken == yy::parser::symbol_kind::S_YYEMPTY ? -2
|
= yytoken == yy::parser::symbol_kind::S_YYEMPTY ? -2
|
||||||
: yytoken == yy::parser::symbol_kind::S_YYEOF ? 0
|
: yytoken == yy::parser::symbol_kind::S_YYEOF ? 0
|
||||||
: yytoken == yy::parser::yytranslate_ ('a') ? 'a'
|
: yytoken == yy::parser::symbol_kind::S_3_a_ ? 'a'
|
||||||
: yytoken == yy::parser::yytranslate_ ('b') ? 'b'
|
: yytoken == yy::parser::symbol_kind::S_4_b_ ? 'b'
|
||||||
: '?';
|
: '?';
|
||||||
]])[
|
]])[
|
||||||
printf ("%s:\n yychar=", reduction);
|
printf ("%s:\n yychar=", reduction);
|
||||||
@@ -94,12 +93,17 @@ print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp,
|
|||||||
printf ("YYEOF");
|
printf ("YYEOF");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("'%c', yylval='", yychr);
|
printf ("'%c', yylval='", yychr);]AT_GLR2_CC_IF([[
|
||||||
|
if (yylookahead.value.value > ' ')
|
||||||
|
printf ("%c", yylookahead.value.value);
|
||||||
|
printf ("', yylloc=(%d,%d),(%d,%d)",
|
||||||
|
yylookahead.location.]AT_FIRST_LINE[, yylookahead.location.]AT_FIRST_COLUMN[,
|
||||||
|
yylookahead.location.]AT_LAST_LINE[, yylookahead.location.]AT_LAST_COLUMN[);]], [[
|
||||||
if (yylvalp->value > ' ')
|
if (yylvalp->value > ' ')
|
||||||
printf ("%c", yylvalp->value);
|
printf ("%c", yylvalp->value);
|
||||||
printf ("', yylloc=(%d,%d),(%d,%d)",
|
printf ("', yylloc=(%d,%d),(%d,%d)",
|
||||||
yyllocp->]AT_FIRST_LINE[, yyllocp->]AT_FIRST_COLUMN[,
|
yyllocp->]AT_FIRST_LINE[, yyllocp->]AT_FIRST_COLUMN[,
|
||||||
yyllocp->]AT_LAST_LINE[, yyllocp->]AT_LAST_COLUMN[);
|
yyllocp->]AT_LAST_LINE[, yyllocp->]AT_LAST_COLUMN[);]])[
|
||||||
}
|
}
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ start: $3;
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_LANG_FOR_EACH_STD([
|
AT_LANG_FOR_EACH_STD([
|
||||||
|
AT_GLR2_CC_IF([AT_REQUIRE_CXX_STD(11, [echo "$at_std not supported"; continue])])
|
||||||
$7
|
$7
|
||||||
AT_FULL_COMPILE([[test]])
|
AT_FULL_COMPILE([[test]])
|
||||||
AT_PARSER_CHECK([[test]], 0, [[$6
|
AT_PARSER_CHECK([[test]], 0, [[$6
|
||||||
|
|||||||
Reference in New Issue
Block a user