mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc.
Apply the same changes as in yacc.c. Now yySymbol and yysymbol_type_t are aliases. We will remove the former later, to avoid cluttering this commit. * data/skeletons/glr.c: Use b4_declare_symbol_enum. Use YYSYMBOL_YYEOF etc. where appropriate. (YYUNDEFTOK, YYTERROR): Remove. (YYTRANSLATE, yySymbol, yyexpected_tokens, yysyntax_error_arguments): Adjust. (yy_accessing_symbol): New. Use it where appropriate.
This commit is contained in:
@@ -230,6 +230,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
|||||||
|
|
||||||
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
|
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
|
||||||
[b4_shared_declarations])[
|
[b4_shared_declarations])[
|
||||||
|
]b4_declare_symbol_enum[
|
||||||
|
|
||||||
/* Default (constant) value used for initialization for null
|
/* Default (constant) value used for initialization for null
|
||||||
right-hand sides. Unlike the standard yacc.c template, here we set
|
right-hand sides. Unlike the standard yacc.c template, here we set
|
||||||
@@ -332,16 +333,15 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
|
|||||||
/* YYFAULTYTOK -- Token number (for yychar) that denotes a
|
/* YYFAULTYTOK -- Token number (for yychar) that denotes a
|
||||||
syntax_error thrown from the scanner. */
|
syntax_error thrown from the scanner. */
|
||||||
#define YYFAULTYTOK (YYMAXUTOK + 1)]])[
|
#define YYFAULTYTOK (YYMAXUTOK + 1)]])[
|
||||||
/* YYUNDEFTOK -- Symbol number (for yytoken) that denotes an unknown
|
|
||||||
token. */
|
|
||||||
#define YYUNDEFTOK ]b4_undef_token_number[
|
|
||||||
|
|
||||||
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
||||||
as returned by yylex, with out-of-bounds checking. */
|
as returned by yylex, with out-of-bounds checking. */
|
||||||
]b4_api_token_raw_if(dnl
|
]b4_api_token_raw_if(dnl
|
||||||
[[#define YYTRANSLATE(YYX) (YYX)]],
|
[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_type_t, YYX)]],
|
||||||
[[#define YYTRANSLATE(YYX) \
|
[[#define YYTRANSLATE(YYX) \
|
||||||
(0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
|
(0 <= (YYX) && (YYX) <= YYMAXUTOK \
|
||||||
|
? YY_CAST (yysymbol_type_t, yytranslate[YYX]) \
|
||||||
|
: YYSYMBOL_YYUNDEF)
|
||||||
|
|
||||||
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
|
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
|
||||||
as returned by yylex. */
|
as returned by yylex. */
|
||||||
@@ -401,9 +401,6 @@ dnl We probably ought to introduce a type for confl.
|
|||||||
]b4_conflicting_rules[
|
]b4_conflicting_rules[
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Error token number */
|
|
||||||
#define YYTERROR 1
|
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
]b4_yylloc_default_define[
|
]b4_yylloc_default_define[
|
||||||
# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
|
# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
|
||||||
@@ -492,7 +489,7 @@ typedef int yy_state_t;
|
|||||||
typedef int yyRuleNum;
|
typedef int yyRuleNum;
|
||||||
|
|
||||||
/** Grammar symbol. */
|
/** Grammar symbol. */
|
||||||
typedef int yySymbol;
|
typedef yysymbol_type_t yySymbol;
|
||||||
|
|
||||||
/** Item references. */
|
/** Item references. */
|
||||||
typedef short yyItemNum;
|
typedef short yyItemNum;
|
||||||
@@ -599,6 +596,13 @@ yyMemoryExhausted (yyGLRStack* yystackp)
|
|||||||
YYLONGJMP (yystackp->yyexception_buffer, 2);
|
YYLONGJMP (yystackp->yyexception_buffer, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Accessing symbol of state YYSTATE. */
|
||||||
|
static inline yySymbol
|
||||||
|
yy_accessing_symbol (yy_state_t yystate)
|
||||||
|
{
|
||||||
|
return YY_CAST (yySymbol, yystos[yystate]);
|
||||||
|
}
|
||||||
|
|
||||||
#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[
|
#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[
|
||||||
/* The user-facing name of the symbol whose (internal) number is
|
/* The user-facing name of the symbol whose (internal) number is
|
||||||
YYSYMBOL. No bounds checking. */
|
YYSYMBOL. No bounds checking. */
|
||||||
@@ -824,9 +828,9 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
|
|||||||
YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([
|
YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([
|
||||||
yylloc = yyexc.location;])[
|
yylloc = yyexc.location;])[
|
||||||
yyerror (]b4_lyyerror_args[yyexc.what ());
|
yyerror (]b4_lyyerror_args[yyexc.what ());
|
||||||
// Map errors caught in the scanner to the undefined token
|
// Map errors caught in the scanner to the undefined token,
|
||||||
// (YYUNDEFTOK), so that error handling is started.
|
// so that error handling is started. However, record this
|
||||||
// However, record this with this special value of yychar.
|
// with this special value of yychar.
|
||||||
*yycharp = YYFAULTYTOK;
|
*yycharp = YYFAULTYTOK;
|
||||||
}
|
}
|
||||||
#endif // YY_EXCEPTIONS]], [[
|
#endif // YY_EXCEPTIONS]], [[
|
||||||
@@ -834,7 +838,8 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
|
|||||||
}
|
}
|
||||||
if (*yycharp <= YYEOF)
|
if (*yycharp <= YYEOF)
|
||||||
{
|
{
|
||||||
*yycharp = yytoken = YYEOF;
|
*yycharp = YYEOF;
|
||||||
|
yytoken = YYSYMBOL_YYEOF;
|
||||||
YY_DPRINTF ((stderr, "Now at end of input.\n"));
|
YY_DPRINTF ((stderr, "Now at end of input.\n"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -963,7 +968,7 @@ static void
|
|||||||
yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
|
yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
|
||||||
{
|
{
|
||||||
if (yys->yyresolved)
|
if (yys->yyresolved)
|
||||||
yydestruct (yymsg, yystos[yys->yylrState],
|
yydestruct (yymsg, yy_accessing_symbol (yys->yylrState),
|
||||||
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
|
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -974,7 +979,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
|
|||||||
YY_FPRINTF ((stderr, "%s unresolved", yymsg));
|
YY_FPRINTF ((stderr, "%s unresolved", yymsg));
|
||||||
else
|
else
|
||||||
YY_FPRINTF ((stderr, "%s incomplete", yymsg));
|
YY_FPRINTF ((stderr, "%s incomplete", yymsg));
|
||||||
YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULLPTR, &yys->yyloc);
|
YY_SYMBOL_PRINT ("", yy_accessing_symbol (yys->yylrState), YY_NULLPTR, &yys->yyloc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -995,7 +1000,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
|
|||||||
static inline yySymbol
|
static inline yySymbol
|
||||||
yylhsNonterm (yyRuleNum yyrule)
|
yylhsNonterm (yyRuleNum yyrule)
|
||||||
{
|
{
|
||||||
return yyr1[yyrule];
|
return YY_CAST (yySymbol, yyr1[yyrule]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define yypact_value_is_default(Yyn) \
|
#define yypact_value_is_default(Yyn) \
|
||||||
@@ -1390,7 +1395,7 @@ yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, ptrdiff_t yyk,
|
|||||||
{
|
{
|
||||||
YY_FPRINTF ((stderr, " $%d = ", yyi + 1));
|
YY_FPRINTF ((stderr, " $%d = ", yyi + 1));
|
||||||
yy_symbol_print (stderr,
|
yy_symbol_print (stderr,
|
||||||
yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
|
yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].yystate.yylrState),
|
||||||
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval]b4_locations_if([,
|
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval]b4_locations_if([,
|
||||||
&]b4_rhs_location(yynrhs, yyi + 1))[]dnl
|
&]b4_rhs_location(yynrhs, yyi + 1))[]dnl
|
||||||
b4_user_args[);
|
b4_user_args[);
|
||||||
@@ -1771,10 +1776,10 @@ yyreportTree (yySemanticOption* yyx, int yyindent)
|
|||||||
{
|
{
|
||||||
if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
|
if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
|
||||||
YY_FPRINTF ((stderr, "%*s%s <empty>\n", yyindent+2, "",
|
YY_FPRINTF ((stderr, "%*s%s <empty>\n", yyindent+2, "",
|
||||||
yysymbol_name (yystos[yystates[yyi]->yylrState])));
|
yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState))));
|
||||||
else
|
else
|
||||||
YY_FPRINTF ((stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "",
|
YY_FPRINTF ((stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "",
|
||||||
yysymbol_name (yystos[yystates[yyi]->yylrState]),
|
yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)),
|
||||||
YY_CAST (long, yystates[yyi-1]->yyposn + 1),
|
YY_CAST (long, yystates[yyi-1]->yyposn + 1),
|
||||||
YY_CAST (long, yystates[yyi]->yyposn)));
|
YY_CAST (long, yystates[yyi]->yyposn)));
|
||||||
}
|
}
|
||||||
@@ -1919,7 +1924,7 @@ yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
|
|||||||
if (yyflag != yyok)
|
if (yyflag != yyok)
|
||||||
{
|
{
|
||||||
yydestruct ("Cleanup: discarding incompletely merged value for",
|
yydestruct ("Cleanup: discarding incompletely merged value for",
|
||||||
yystos[yys->yylrState],
|
yy_accessing_symbol (yys->yylrState),
|
||||||
&yysval]b4_locuser_args[);
|
&yysval]b4_locuser_args[);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2088,7 +2093,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
|
|||||||
be less than YYNTOKENS). */
|
be less than YYNTOKENS). */
|
||||||
static int
|
static int
|
||||||
yyexpected_tokens (const yyGLRStack* yystackp,
|
yyexpected_tokens (const yyGLRStack* yystackp,
|
||||||
int yyarg[], int yyargn)
|
yySymbol yyarg[], int yyargn)
|
||||||
{
|
{
|
||||||
/* Actual size of YYARG. */
|
/* Actual size of YYARG. */
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
@@ -2104,7 +2109,7 @@ yyexpected_tokens (const yyGLRStack* yystackp,
|
|||||||
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
||||||
int yyx;
|
int yyx;
|
||||||
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
|
if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYERROR
|
||||||
&& !yytable_value_is_error (yytable[yyx + yyn]))
|
&& !yytable_value_is_error (yytable[yyx + yyn]))
|
||||||
{
|
{
|
||||||
if (!yyarg)
|
if (!yyarg)
|
||||||
@@ -2112,7 +2117,7 @@ yyexpected_tokens (const yyGLRStack* yystackp,
|
|||||||
else if (yycount == yyargn)
|
else if (yycount == yyargn)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
yyarg[yycount++] = yyx;
|
yyarg[yycount++] = YY_CAST (yySymbol, yyx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return yycount;
|
return yycount;
|
||||||
@@ -2133,7 +2138,7 @@ static int
|
|||||||
yyparse_context_token (const yyGLRStack *yystackp)
|
yyparse_context_token (const yyGLRStack *yystackp)
|
||||||
{
|
{
|
||||||
YYUSE (yystackp);
|
YYUSE (yystackp);
|
||||||
yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
|
yySymbol yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
|
||||||
return yytoken;
|
return yytoken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2150,9 +2155,9 @@ yyparse_context_location (const yyGLRStack *yystackp)
|
|||||||
[detailed\|verbose],
|
[detailed\|verbose],
|
||||||
[[static int
|
[[static int
|
||||||
yysyntax_error_arguments (const yyGLRStack* yystackp,
|
yysyntax_error_arguments (const yyGLRStack* yystackp,
|
||||||
int yyarg[], int yyargn)
|
yySymbol yyarg[], int yyargn)
|
||||||
{
|
{
|
||||||
yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
|
yySymbol yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
|
||||||
/* Actual size of YYARG. */
|
/* Actual size of YYARG. */
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
/* There are many possibilities here to consider:
|
/* There are many possibilities here to consider:
|
||||||
@@ -2183,7 +2188,7 @@ yysyntax_error_arguments (const yyGLRStack* yystackp,
|
|||||||
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 != YYEMPTY)
|
if (yytoken != YYSYMBOL_YYEMPTY)
|
||||||
{
|
{
|
||||||
int yyn;
|
int yyn;
|
||||||
yyarg[yycount++] = yytoken;
|
yyarg[yycount++] = yytoken;
|
||||||
@@ -2359,8 +2364,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
|||||||
int yyj = yypact[yys->yylrState];
|
int yyj = yypact[yys->yylrState];
|
||||||
if (! yypact_value_is_default (yyj))
|
if (! yypact_value_is_default (yyj))
|
||||||
{
|
{
|
||||||
yyj += YYTERROR;
|
yyj += YYSYMBOL_YYERROR;
|
||||||
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
|
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYSYMBOL_YYERROR
|
||||||
&& yyisShiftAction (yytable[yyj]))
|
&& yyisShiftAction (yytable[yyj]))
|
||||||
{
|
{
|
||||||
/* Shift the error token. */
|
/* Shift the error token. */
|
||||||
@@ -2369,7 +2374,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
|||||||
YYLTYPE yyerrloc;
|
YYLTYPE yyerrloc;
|
||||||
yystackp->yyerror_range[2].yystate.yyloc = yylloc;
|
yystackp->yyerror_range[2].yystate.yyloc = yylloc;
|
||||||
YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
|
YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
|
||||||
YY_SYMBOL_PRINT ("Shifting", yystos[yyaction],
|
YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yyaction),
|
||||||
&yylval, &yyerrloc);
|
&yylval, &yyerrloc);
|
||||||
yyglrShift (yystackp, 0, yyaction,
|
yyglrShift (yystackp, 0, yyaction,
|
||||||
yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
|
yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
|
||||||
|
|||||||
Reference in New Issue
Block a user