mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
d: remove yychar from YYParse.parse()
The yychar variable was keeping the external form of the token (the TokenKind). As the D parser translates the token to its internal form (the SymbolKind) inside the struct Symbol, there is no need for yychar anymore. * data/examples/lalr1.d (yychar): Remove. Use only yytoken.
This commit is contained in:
committed by
Akim Demaille
parent
cc04459cfe
commit
6692df8992
@@ -420,8 +420,6 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
|
|||||||
*/
|
*/
|
||||||
public bool parse ()
|
public bool parse ()
|
||||||
{
|
{
|
||||||
// Lookahead token kind.
|
|
||||||
int yychar = TokenKind.]b4_symbol(empty, id)[;
|
|
||||||
// Lookahead symbol kind.
|
// Lookahead symbol kind.
|
||||||
SymbolKind yytoken = ]b4_symbol(empty, kind)[;
|
SymbolKind yytoken = ]b4_symbol(empty, kind)[;
|
||||||
|
|
||||||
@@ -489,17 +487,16 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read a lookahead token. */
|
/* Read a lookahead token. */
|
||||||
if (yychar == TokenKind.]b4_symbol(empty, id)[)
|
if (yytoken == ]b4_symbol(empty, kind)[)
|
||||||
{]b4_parse_trace_if([[
|
{]b4_parse_trace_if([[
|
||||||
yycdebugln ("Reading a token");]])[
|
yycdebugln ("Reading a token");]])[
|
||||||
Symbol yysymbol = yylex();
|
Symbol yysymbol = yylex();
|
||||||
yychar = yysymbol.token();
|
yytoken = yysymbol.token();
|
||||||
yylval = yysymbol.value();]b4_locations_if([[
|
yylval = yysymbol.value();]b4_locations_if([[
|
||||||
yylloc = yysymbol.location();]])[
|
yylloc = yysymbol.location();]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert token to internal form. */
|
/* Token already converted to internal form. */]b4_parse_trace_if([[
|
||||||
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
|
|
||||||
yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
||||||
|
|
||||||
if (yytoken == ]b4_symbol(error, kind)[)
|
if (yytoken == ]b4_symbol(error, kind)[)
|
||||||
@@ -508,7 +505,6 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
// to error recovery. But do not keep the error token as
|
// to error recovery. But do not keep the error token as
|
||||||
// lookahead, it is too special and may lead us to an endless
|
// lookahead, it is too special and may lead us to an endless
|
||||||
// loop in error recovery. */
|
// loop in error recovery. */
|
||||||
yychar = TokenKind.]b4_symbol(undef, id)[;
|
|
||||||
yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
|
yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
|
||||||
yyerrloc = yylloc;]])[
|
yyerrloc = yylloc;]])[
|
||||||
label = YYERRLAB1;
|
label = YYERRLAB1;
|
||||||
@@ -543,7 +539,7 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
||||||
|
|
||||||
/* Discard the token being shifted. */
|
/* Discard the token being shifted. */
|
||||||
yychar = TokenKind.]b4_symbol(empty, id)[;
|
yytoken = ]b4_symbol(empty, kind)[;
|
||||||
|
|
||||||
/* Count tokens shifted since error; after three, turn off error
|
/* Count tokens shifted since error; after three, turn off error
|
||||||
* status. */
|
* status. */
|
||||||
@@ -586,8 +582,6 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
if (yyerrstatus_ == 0)
|
if (yyerrstatus_ == 0)
|
||||||
{
|
{
|
||||||
++yynerrs_;
|
++yynerrs_;
|
||||||
if (yychar == TokenKind.]b4_symbol(empty, id)[)
|
|
||||||
yytoken = ]b4_symbol(empty, kind)[;
|
|
||||||
yyreportSyntaxError(new Context(]b4_lac_if([[this, ]])[yystack, yytoken]b4_locations_if([[, yylloc]])[));
|
yyreportSyntaxError(new Context(]b4_lac_if([[this, ]])[yystack, yytoken]b4_locations_if([[, yylloc]])[));
|
||||||
}
|
}
|
||||||
]b4_locations_if([
|
]b4_locations_if([
|
||||||
@@ -597,14 +591,14 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse lookahead token after an
|
||||||
* error, discard it. */
|
* error, discard it. */
|
||||||
|
|
||||||
if (yychar <= TokenKind.]b4_symbol(eof, [id])[)
|
if (yytoken <= ]b4_symbol(eof, [kind])[)
|
||||||
{
|
{
|
||||||
/* Return failure if at end of input. */
|
/* Return failure if at end of input. */
|
||||||
if (yychar == TokenKind.]b4_symbol(eof, [id])[)
|
if (yytoken == ]b4_symbol(eof, [kind])[)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yychar = TokenKind.]b4_symbol(empty, id)[;
|
yytoken = ]b4_symbol(empty, kind)[;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse lookahead token after shifting the error
|
||||||
|
|||||||
Reference in New Issue
Block a user