in msys2/usr/share/bison/skeletons/lalr1.d [464:717]
public bool parse ()
{
/// Lookahead and lookahead in internal form.
int yychar = yyempty_;
int yytoken = 0;
/* State. */
int yyn = 0;
int yylen = 0;
int yystate = 0;
YYStack yystack;
/* Error handling. */
int yynerrs_ = 0;
]b4_locations_if([/// The location where the error started.
]b4_location_type[ yyerrloc = null;
/// ]b4_location_type[ of the lookahead.
]b4_location_type[ yylloc;
/// @@$.
]b4_location_type[ yyloc;])[
/// Semantic value of the lookahead.
]b4_yystype[ yylval;
int yyresult;
yycdebug ("Starting parse\n");
yyerrstatus_ = 0;
]m4_ifdef([b4_initial_action], [
m4_pushdef([b4_at_dollar], [yylloc])dnl
m4_pushdef([b4_dollar_dollar], [yylval])dnl
/* User initialization code. */
b4_user_initial_action
m4_popdef([b4_dollar_dollar])dnl
m4_popdef([b4_at_dollar])])dnl
[ /* Initialize the stack. */
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
int label = YYNEWSTATE;
for (;;)
final switch (label)
{
/* New state. Unlike in the C/C++ skeletons, the state is already
pushed when we come here. */
case YYNEWSTATE:
yycdebug (format("Entering state %d\n", yystate));
if (yydebug > 0)
yystack.print (yyDebugStream);
/* Accept? */
if (yystate == yyfinal_)
return true;
/* Take a decision. First try without lookahead. */
yyn = yypact_[yystate];
if (yy_pact_value_is_default_ (yyn))
{
label = YYDEFAULT;
break;
}
/* Read a lookahead token. */
if (yychar == yyempty_)
{
yycdebug ("Reading a token: ");
yychar = yylex ();]
b4_locations_if([[
static if (yy_location_is_class) {
yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos);
} else {
yylloc = ]b4_location_type[(yylexer.startPos, yylexer.endPos);
}]])
yylval = yylexer.semanticVal;[
}
/* Convert token to internal form. */
if (yychar <= YYTokenType.EOF)
{
yychar = yytoken = YYTokenType.EOF;
yycdebug ("Now at end of input.\n");
}
else
{
yytoken = yytranslate_ (yychar);
yy_symbol_print ("Next token is",
yytoken, yylval]b4_locations_if([, yylloc])[);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
label = YYDEFAULT;
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
if (yy_table_value_is_error_ (yyn))
label = YYERRLAB;
else
{
yyn = -yyn;
label = YYREDUCE;
}
}
else
{
/* Shift the lookahead token. */
yy_symbol_print ("Shifting", yytoken,
yylval]b4_locations_if([, yylloc])[);
/* Discard the token being shifted. */
yychar = yyempty_;
/* Count tokens shifted since error; after three, turn off error
* status. */
if (yyerrstatus_ > 0)
--yyerrstatus_;
yystate = yyn;
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
label = YYNEWSTATE;
}
break;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
case YYDEFAULT:
yyn = yydefact_[yystate];
if (yyn == 0)
label = YYERRLAB;
else
label = YYREDUCE;
break;
/*-----------------------------.
| yyreduce -- Do a reduction. |
`-----------------------------*/
case YYREDUCE:
yylen = yyr2_[yyn];
label = yyaction (yyn, yystack, yylen);
yystate = yystack.stateAt (0);
break;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
case YYERRLAB:
/* If not already recovering from an error, report this error. */
if (yyerrstatus_ == 0)
{
++yynerrs_;
if (yychar == yyempty_)
yytoken = yyempty_;
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
}
]b4_locations_if([yyerrloc = yylloc;])[
if (yyerrstatus_ == 3)
{
/* If just tried and failed to reuse lookahead token after an
* error, discard it. */
if (yychar <= YYTokenType.EOF)
{
/* Return failure if at end of input. */
if (yychar == YYTokenType.EOF)
return false;
}
else
yychar = yyempty_;
}
/* Else will try to reuse lookahead token after shifting the error
* token. */
label = YYERRLAB1;
break;
/*-------------------------------------------------.
| errorlab -- error raised explicitly by YYERROR. |
`-------------------------------------------------*/
case YYERROR:
]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
yystack.pop (yylen);
yylen = 0;
yystate = yystack.stateAt (0);
label = YYERRLAB1;
break;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
case YYERRLAB1:
yyerrstatus_ = 3; /* Each real token shifted decrements this.xb */
for (;;)
{
yyn = yypact_[yystate];
if (!yy_pact_value_is_default_ (yyn))
{
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. */
if (yystack.height == 1)
return false;
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
yystack.pop ();
yystate = yystack.stateAt (0);
if (yydebug > 0)
yystack.print (yyDebugStream);
}
]b4_locations_if([
/* Muck with the stack to setup for yylloc. */
yystack.push (0, yy_semantic_null, yylloc);
yystack.push (0, yy_semantic_null, yyerrloc);
yyloc = yylloc_from_stack (yystack, 2);
yystack.pop (2);])[
/* Shift the error token. */
yy_symbol_print ("Shifting", yystos_[yyn],
yylval]b4_locations_if([, yyloc])[);
yystate = yyn;
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
label = YYNEWSTATE;
break;
/* Accept. */
case YYACCEPT:
return true;
/* Abort. */
case YYABORT:
return false;
}
}