style: avoid explicit symbol numbers

This should have been part of commit "symbols: stop dealing with YYEMPTY
as b4_symbol(-2, ...)" (cd40ec9526).
Give names to all the special symbols: "eof", "error" and "undef".

* data/skeletons/bison.m4 (b4_symbol): Let `b4_symbol(eof, ...)` mean
`b4_symbol(0, ...)`, `b4_symbol(error, ...)` mean `b4_symbol(1, ...)`,
and , `b4_symbol(undef, ...)` mean `b4_symbol(2, ...)`..

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c:
Prefer symbols to numbers.
This commit is contained in:
Akim Demaille
2020-11-07 16:21:00 +01:00
parent 34e6e8815a
commit 5a31cda4c3
10 changed files with 82 additions and 75 deletions

View File

@@ -81,7 +81,12 @@ name, whether terminal, etc.), bison.exe defines one macro per (token,
field), where field can `has_id`, `id`, etc.: see field), where field can `has_id`, `id`, etc.: see
`prepare_symbols_definitions()` in `src/output.c`. `prepare_symbols_definitions()` in `src/output.c`.
The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: NUM can be:
- `empty` to denote the "empty" pseudo-symbol when it exists,
- `eof`, `error`, or `undef`
- a symbol number.
FIELD can be:
- `has_id`: 0 or 1 - `has_id`: 0 or 1
Whether the symbol has an `id`. Whether the symbol has an `id`.

View File

@@ -484,8 +484,10 @@ m4_define([b4_symbol_slot],
# #
# If FIELD = id, prepend the token prefix. # If FIELD = id, prepend the token prefix.
m4_define([b4_symbol], m4_define([b4_symbol],
[m4_if([$1], [empty], [m4_if([$1], [empty], [b4_symbol([-2], [$2])],
[b4_symbol([-2], [$2])], [$1], [eof], [b4_symbol([0], [$2])],
[$1], [error], [b4_symbol([1], [$2])],
[$1], [undef], [b4_symbol([2], [$2])],
[m4_case([$2], [m4_case([$2],
[id], [b4_symbol_token_kind([$1])], [id], [b4_symbol_token_kind([$1])],
[kind_base], [b4_symbol_kind_base([$1])], [kind_base], [b4_symbol_kind_base([$1])],

View File

@@ -504,7 +504,7 @@ static const b4_int_type_for([$2]) yy$1[[]] =
m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]]) m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]])
m4_define([b4_symbol(-2, tag)], [[No symbol.]]) m4_define([b4_symbol(-2, tag)], [[No symbol.]])
m4_if(b4_symbol(0, id), [YYEOF], m4_if(b4_symbol(eof, id), [YYEOF],
[m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])]) [m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])])
m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]]) m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]])
m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]]) m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]])

View File

@@ -829,14 +829,14 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals
// Map errors caught in the scanner to the undefined token, // Map errors caught in the scanner to the undefined token,
// so that error handling is started. However, record this // so that error handling is started. However, record this
// with this special value of yychar. // with this special value of yychar.
*yycharp = ]b4_symbol(1, id)[; *yycharp = ]b4_symbol(error, id)[;
} }
#endif // YY_EXCEPTIONS]], [[ #endif // YY_EXCEPTIONS]], [[
*yycharp = ]b4_lex[;]])[ *yycharp = ]b4_lex[;]])[
} }
if (*yycharp <= ]b4_symbol(0, [id])[) if (*yycharp <= ]b4_symbol(eof, [id])[)
{ {
*yycharp = ]b4_symbol(0, [id])[; *yycharp = ]b4_symbol(eof, [id])[;
yytoken = ]b4_symbol_prefix[YYEOF; yytoken = ]b4_symbol_prefix[YYEOF;
YY_DPRINTF ((stderr, "Now at end of input.\n")); YY_DPRINTF ((stderr, "Now at end of input.\n"));
} }
@@ -1034,7 +1034,7 @@ static inline int
yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts) yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts)
{ {
int yyindex = yypact[yystate] + yytoken; int yyindex = yypact[yystate] + yytoken;
if (yytoken == ]b4_symbol(1, kind)[) if (yytoken == ]b4_symbol(error, kind)[)
{ {
// This is the error token. // This is the error token.
*yyconflicts = yyconfl; *yyconflicts = yyconfl;
@@ -2112,7 +2112,7 @@ yypcontext_expected_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 != ]b4_symbol(1, kind)[ if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yytable_value_is_error (yytable[yyx + yyn])) && !yytable_value_is_error (yytable[yyx + yyn]))
{ {
if (!yyarg) if (!yyarg)
@@ -2320,7 +2320,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
{ {
yysymbol_kind_t yytoken; yysymbol_kind_t yytoken;
int yyj; int yyj;
if (yychar == ]b4_symbol(0, [id])[) if (yychar == ]b4_symbol(eof, [id])[)
yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
if (yychar != ]b4_symbol(empty, id)[) if (yychar != ]b4_symbol(empty, id)[)
{]b4_locations_if([[ {]b4_locations_if([[
@@ -2372,8 +2372,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 += ]b4_symbol(1, kind)[; yyj += ]b4_symbol(error, kind)[;
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(1, kind)[ if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, kind)[
&& yyisShiftAction (yytable[yyj])) && yyisShiftAction (yytable[yyj]))
{ {
/* Shift the error token. */ /* Shift the error token. */
@@ -2496,7 +2496,7 @@ b4_dollar_popdef])[]dnl
yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
/* Issue an error message unless the scanner already /* Issue an error message unless the scanner already
did. */ did. */
if (yychar != ]b4_symbol(1, id)[) if (yychar != ]b4_symbol(error, id)[)
yyreportSyntaxError (&yystack]b4_user_args[); yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error; goto yyuser_error;
} }

View File

@@ -241,10 +241,10 @@ m4_define([b4_glr_cc_setup],
#undef ]b4_symbol(empty, [id])[ #undef ]b4_symbol(empty, [id])[
#define ]b4_symbol(empty, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, [id])[ #define ]b4_symbol(empty, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, [id])[
#undef ]b4_symbol(0, [id])[ #undef ]b4_symbol(eof, [id])[
#define ]b4_symbol(0, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[ #define ]b4_symbol(eof, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(eof, [id])[
#undef ]b4_symbol(1, [id])[ #undef ]b4_symbol(error, [id])[
#define ]b4_symbol(1, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(1, [id])[ #define ]b4_symbol(error, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, [id])[
#ifndef ]b4_api_PREFIX[STYPE #ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type # define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
@@ -271,8 +271,8 @@ m4_define([b4_undef_symbol_kind],
# Remove redirections for glr.c. # Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup], m4_define([b4_glr_cc_cleanup],
[[#undef ]b4_symbol(empty, [id])[ [[#undef ]b4_symbol(empty, [id])[
#undef ]b4_symbol(0, [id])[ #undef ]b4_symbol(eof, [id])[
#undef ]b4_symbol(1, [id])[ #undef ]b4_symbol(error, [id])[
]b4_undef_symbol_kind(-2)dnl ]b4_undef_symbol_kind(-2)dnl
b4_symbol_foreach([b4_undef_symbol_kind])dnl b4_symbol_foreach([b4_undef_symbol_kind])dnl

View File

@@ -91,8 +91,8 @@ typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
# Remove redirections for glr.c. # Remove redirections for glr.c.
m4_define([b4_glr_cc_cleanup], m4_define([b4_glr_cc_cleanup],
[[#undef ]b4_symbol(empty, [id])[ [[#undef ]b4_symbol(empty, [id])[
#undef ]b4_symbol(0, [id])[ #undef ]b4_symbol(eof, [id])[
#undef ]b4_symbol(1, [id])[ #undef ]b4_symbol(error, [id])[
#undef ]b4_symbol_prefix[YYEMPTY #undef ]b4_symbol_prefix[YYEMPTY
#undef ]b4_symbol_prefix[YYerror #undef ]b4_symbol_prefix[YYerror
#undef ]b4_symbol_prefix[YYEOF #undef ]b4_symbol_prefix[YYEOF
@@ -1919,7 +1919,7 @@ public:
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 != ]b4_namespace_ref::b4_parser_class::b4_symbol(1, kind)[ if (yycheck[yyx + yyn] == yyx && yyx != ]b4_namespace_ref::b4_parser_class::b4_symbol(error, kind)[
&& !yytable_value_is_error (yytable[yyx + yyn])) && !yytable_value_is_error (yytable[yyx + yyn]))
{ {
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
@@ -1981,7 +1981,7 @@ public:
{ {
yysymbol_kind_t yytoken; yysymbol_kind_t yytoken;
int yyj; int yyj;
if (yychar == ]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[) if (yychar == ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[)
yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
if (yychar != ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[) if (yychar != ]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[)
{]b4_locations_if([[ {]b4_locations_if([[
@@ -2638,14 +2638,14 @@ yygetToken (int *yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_p
yyparser.error (]b4_locations_if([yylloc, ])[yyexc.what ()); yyparser.error (]b4_locations_if([yylloc, ])[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. // handling is started.
*yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(1, id)[; *yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(error, id)[;
} }
#endif // YY_EXCEPTIONS #endif // YY_EXCEPTIONS
} }
if (*yycharp <= ]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[) if (*yycharp <= ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[)
{ {
*yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[; *yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[;
yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(0, kind)[; yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(eof, kind)[;
YY_DEBUG_STREAM << "Now at end of input.\n"; YY_DEBUG_STREAM << "Now at end of input.\n";
} }
else else
@@ -2692,7 +2692,7 @@ static inline int
yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short** yyconflicts) yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short** yyconflicts)
{ {
int yyindex = yypact[yystate] + yytoken; int yyindex = yypact[yystate] + yytoken;
if (yytoken == ]b4_namespace_ref::b4_parser_class[::]b4_symbol(1, kind)[) if (yytoken == ]b4_namespace_ref::b4_parser_class[::]b4_symbol(error, kind)[)
{ {
// This is the error token. // This is the error token.
*yyconflicts = yyconfl; *yyconflicts = yyconfl;
@@ -2850,7 +2850,7 @@ b4_dollar_popdef])[]dnl
yystack.yyerror_range[1].getState().yyloc = yylloc;]])[ yystack.yyerror_range[1].getState().yyloc = yylloc;]])[
/* 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 (yychar != ]b4_namespace_ref::b4_parser_class::token::b4_symbol(1, id)[) if (yychar != ]b4_namespace_ref::b4_parser_class::token::b4_symbol(error, id)[)
yystack.yyreportSyntaxError (); yystack.yyreportSyntaxError ();
goto yyuser_error; goto yyuser_error;
} }

View File

@@ -918,13 +918,13 @@ b4_dollar_popdef])[]dnl
} }
YY_SYMBOL_PRINT ("Next token is", yyla); YY_SYMBOL_PRINT ("Next token is", yyla);
if (yyla.kind () == ]b4_symbol(1, kind)[) if (yyla.kind () == ]b4_symbol(error, kind)[)
{ {
// The scanner already issued an error message, process directly // The scanner already issued an error message, process directly
// 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. */
yyla.kind_ = ]b4_symbol(2, kind)[; yyla.kind_ = ]b4_symbol(undef, kind)[;
goto yyerrlab1; goto yyerrlab1;
} }
@@ -1061,7 +1061,7 @@ b4_dollar_popdef])[]dnl
error, discard it. */ error, discard it. */
// Return failure if at end of input. // Return failure if at end of input.
if (yyla.kind () == ]b4_symbol(0, kind)[) if (yyla.kind () == ]b4_symbol(eof, kind)[)
YYABORT; YYABORT;
else if (!yyla.empty ()) else if (!yyla.empty ())
{ {
@@ -1102,9 +1102,9 @@ b4_dollar_popdef])[]dnl
yyn = yypact_[+yystack_[0].state]; yyn = yypact_[+yystack_[0].state];
if (!yy_pact_value_is_default_ (yyn)) if (!yy_pact_value_is_default_ (yyn))
{ {
yyn += ]b4_symbol(1, kind)[; yyn += ]b4_symbol(error, kind)[;
if (0 <= yyn && yyn <= yylast_ if (0 <= yyn && yyn <= yylast_
&& yycheck_[yyn] == ]b4_symbol(1, kind)[) && yycheck_[yyn] == ]b4_symbol(error, kind)[)
{ {
yyn = yytable_[yyn]; yyn = yytable_[yyn];
if (0 < yyn) if (0 < yyn)
@@ -1296,8 +1296,8 @@ b4_dollar_popdef])[]dnl
for (int yyx = 0; yyx < YYNTOKENS; ++yyx) for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
{ {
symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx); symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
if (yysym != ]b4_symbol(1, kind)[ if (yysym != ]b4_symbol(error, kind)[
&& yysym != ]b4_symbol(2, kind)[ && yysym != ]b4_symbol(undef, kind)[
&& yyparser_.yy_lac_check_ (yysym)) && yyparser_.yy_lac_check_ (yysym))
{ {
if (!yyarg) if (!yyarg)
@@ -1319,7 +1319,7 @@ b4_dollar_popdef])[]dnl
int yychecklim = yylast_ - yyn + 1; int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx) for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[ if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yy_table_value_is_error_ (yytable_[yyx + yyn])) && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
{ {
if (!yyarg) if (!yyarg)

View File

@@ -480,14 +480,14 @@ m4_popdef([b4_at_dollar])])dnl
yytoken = yytranslate_ (yychar);]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(1, kind)[) if (yytoken == ]b4_symbol(error, kind)[)
{ {
// The scanner already issued an error message, process directly // The scanner already issued an error message, process directly
// 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(2, id)[; yychar = TokenKind.]b4_symbol(undef, id)[;
yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[ yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
yyerrloc = yylloc;]])[ yyerrloc = yylloc;]])[
label = YYERRLAB1; label = YYERRLAB1;
} }
@@ -569,10 +569,10 @@ 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(0, [id])[) if (yychar <= TokenKind.]b4_symbol(eof, [id])[)
{ {
/* Return failure if at end of input. */ /* Return failure if at end of input. */
if (yychar == TokenKind.]b4_symbol(0, [id])[) if (yychar == TokenKind.]b4_symbol(eof, [id])[)
return false; return false;
} }
else else
@@ -609,8 +609,8 @@ m4_popdef([b4_at_dollar])])dnl
yyn = yypact_[yystate]; yyn = yypact_[yystate];
if (!yyPactValueIsDefault(yyn)) if (!yyPactValueIsDefault(yyn))
{ {
yyn += ]b4_symbol(1, kind)[; yyn += ]b4_symbol(error, kind)[;
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(1, kind)[) if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(error, kind)[)
{ {
yyn = yytable_[yyn]; yyn = yytable_[yyn];
if (0 < yyn) if (0 < yyn)
@@ -772,7 +772,7 @@ m4_popdef([b4_at_dollar])])dnl
int yychecklim = yylast_ - yyn + 1; int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx) for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[ if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yyTableValueIsError(yytable_[yyx + yyn])) && !yyTableValueIsError(yytable_[yyx + yyn]))
{ {
if (yyarg is null) if (yyarg is null)
@@ -861,11 +861,11 @@ m4_popdef([b4_at_dollar])])dnl
immutable int code_max = ]b4_code_max[; immutable int code_max = ]b4_code_max[;
if (t <= 0) if (t <= 0)
return ]b4_symbol(0, kind)[; return ]b4_symbol(eof, kind)[;
else if (t <= code_max) else if (t <= code_max)
return SymbolKind(translate_table[t]); return SymbolKind(translate_table[t]);
else else
return ]b4_symbol(2, kind)[;]])[ return ]b4_symbol(undef, kind)[;]])[
} }
private static immutable int yylast_ = ]b4_last[; private static immutable int yylast_ = ]b4_last[;

View File

@@ -199,8 +199,8 @@ import java.util.ArrayList;
*/ */
public interface Lexer { public interface Lexer {
]b4_token_enums[ ]b4_token_enums[
/** Deprecated, use ]b4_symbol(0, id)[ instead. */ /** Deprecated, use ]b4_symbol(eof, id)[ instead. */
public static final int EOF = ]b4_symbol(0, id)[; public static final int EOF = ]b4_symbol(eof, id)[;
]b4_pull_if([b4_locations_if([[ ]b4_pull_if([b4_locations_if([[
/** /**
* Method to retrieve the beginning position of the last scanned token. * Method to retrieve the beginning position of the last scanned token.
@@ -643,14 +643,14 @@ b4_dollar_popdef[]dnl
yySymbolPrint("Next token is", yytoken, yySymbolPrint("Next token is", yytoken,
yylval]b4_locations_if([, yylloc])[);]])[ yylval]b4_locations_if([, yylloc])[);]])[
if (yytoken == ]b4_symbol(1, kind)[) if (yytoken == ]b4_symbol(error, kind)[)
{ {
// The scanner already issued an error message, process directly // The scanner already issued an error message, process directly
// 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 = Lexer.]b4_symbol(2, id)[; yychar = Lexer.]b4_symbol(undef, id)[;
yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[ yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
yyerrloc = yylloc;]])[ yyerrloc = yylloc;]])[
label = YYERRLAB1; label = YYERRLAB1;
} }
@@ -740,10 +740,10 @@ b4_dollar_popdef[]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 <= Lexer.]b4_symbol(0, id)[) if (yychar <= Lexer.]b4_symbol(eof, id)[)
{ {
/* Return failure if at end of input. */ /* Return failure if at end of input. */
if (yychar == Lexer.]b4_symbol(0, id)[) if (yychar == Lexer.]b4_symbol(eof, id)[)
]b4_push_if([{label = YYABORT; break;}], [return false;])[ ]b4_push_if([{label = YYABORT; break;}], [return false;])[
} }
else else
@@ -780,9 +780,9 @@ b4_dollar_popdef[]dnl
yyn = yypact_[yystate]; yyn = yypact_[yystate];
if (!yyPactValueIsDefault (yyn)) if (!yyPactValueIsDefault (yyn))
{ {
yyn += ]b4_symbol(1, kind)[.getCode(); yyn += ]b4_symbol(error, kind)[.getCode();
if (0 <= yyn && yyn <= YYLAST_ if (0 <= yyn && yyn <= YYLAST_
&& yycheck_[yyn] == ]b4_symbol(1, kind)[.getCode()) && yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode())
{ {
yyn = yytable_[yyn]; yyn = yytable_[yyn];
if (0 < yyn) if (0 < yyn)
@@ -964,8 +964,8 @@ b4_dollar_popdef[]dnl
for (int yyx = 0; yyx < YYNTOKENS_; ++yyx) for (int yyx = 0; yyx < YYNTOKENS_; ++yyx)
{ {
SymbolKind yysym = SymbolKind.get(yyx); SymbolKind yysym = SymbolKind.get(yyx);
if (yysym != ]b4_symbol(1, kind)[ if (yysym != ]b4_symbol(error, kind)[
&& yysym != ]b4_symbol(2, kind)[ && yysym != ]b4_symbol(undef, kind)[
&& yyparser.yylacCheck(yystack, yysym)) && yyparser.yylacCheck(yystack, yysym))
{ {
if (yyarg == null) if (yyarg == null)
@@ -988,7 +988,7 @@ b4_dollar_popdef[]dnl
int yychecklim = YYLAST_ - yyn + 1; int yychecklim = YYLAST_ - yyn + 1;
int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS; int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx) for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[.getCode() if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[.getCode()
&& !yyTableValueIsError(yytable_[yyx + yyn])) && !yyTableValueIsError(yytable_[yyx + yyn]))
{ {
if (yyarg == null) if (yyarg == null)
@@ -1282,11 +1282,11 @@ b4_dollar_popdef[]dnl
// Last valid token kind. // Last valid token kind.
int code_max = ]b4_code_max[; int code_max = ]b4_code_max[;
if (t <= 0) if (t <= 0)
return ]b4_symbol(0, kind)[; return ]b4_symbol(eof, kind)[;
else if (t <= code_max) else if (t <= code_max)
return SymbolKind.get(yytranslate_table_[t]); return SymbolKind.get(yytranslate_table_[t]);
else else
return ]b4_symbol(2, kind)[; return ]b4_symbol(undef, kind)[;
} }
]b4_integral_parser_table_define([translate_table], [b4_translate])[ ]b4_integral_parser_table_define([translate_table], [b4_translate])[
]])[ ]])[

View File

@@ -755,8 +755,8 @@ enum { YYENOMEM = -2 };
while (0) while (0)
/* Backward compatibility with an undocumented macro. /* Backward compatibility with an undocumented macro.
Use ]b4_symbol(1, id)[ or ]b4_symbol(2, id)[. */ Use ]b4_symbol(error, id)[ or ]b4_symbol(undef, id)[. */
#define YYERRCODE ]b4_symbol(2, id)[ #define YYERRCODE ]b4_symbol(undef, id)[
]b4_locations_if([[ ]b4_locations_if([[
]b4_yylloc_default_define[ ]b4_yylloc_default_define[
#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #define YYRHSLOC(Rhs, K) ((Rhs)[K])
@@ -1165,7 +1165,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
for (yyx = 0; yyx < YYNTOKENS; ++yyx) for (yyx = 0; yyx < YYNTOKENS; ++yyx)
{ {
yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx); yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
if (yysym != ]b4_symbol(1, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF) if (yysym != ]b4_symbol(error, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF)
switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]], switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]],
[[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[)) [[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[))
{ {
@@ -1194,7 +1194,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
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 != ]b4_symbol(1, kind)[ if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
&& !yytable_value_is_error (yytable[yyx + yyn])) && !yytable_value_is_error (yytable[yyx + yyn]))
{ {
if (!yyarg) if (!yyarg)
@@ -1820,20 +1820,20 @@ yyread_pushed_token:]])[
yychar = ]b4_lex[;]])[ yychar = ]b4_lex[;]])[
} }
if (yychar <= ]b4_symbol(0, [id])[) if (yychar <= ]b4_symbol(eof, [id])[)
{ {
yychar = ]b4_symbol(0, [id])[; yychar = ]b4_symbol(eof, [id])[;
yytoken = ]b4_symbol(0, [kind])[; yytoken = ]b4_symbol(eof, [kind])[;
YYDPRINTF ((stderr, "Now at end of input.\n")); YYDPRINTF ((stderr, "Now at end of input.\n"));
} }
else if (yychar == ]b4_symbol(1, [id])[) else if (yychar == ]b4_symbol(error, [id])[)
{ {
/* The scanner already issued an error message, process directly /* The scanner already issued an error message, process directly
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 = ]b4_symbol(2, [id])[; yychar = ]b4_symbol(undef, [id])[;
yytoken = ]b4_symbol(1, [kind])[;]b4_locations_if([[ yytoken = ]b4_symbol(error, [kind])[;]b4_locations_if([[
yyerror_range[1] = yylloc;]])[ yyerror_range[1] = yylloc;]])[
goto yyerrlab1; goto yyerrlab1;
} }
@@ -2026,10 +2026,10 @@ yyerrlab:
/* 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 <= ]b4_symbol(0, [id])[) if (yychar <= ]b4_symbol(eof, [id])[)
{ {
/* Return failure if at end of input. */ /* Return failure if at end of input. */
if (yychar == ]b4_symbol(0, [id])[) if (yychar == ]b4_symbol(eof, [id])[)
YYABORT; YYABORT;
} }
else else
@@ -2076,8 +2076,8 @@ yyerrlab1:
yyn = yypact[yystate]; yyn = yypact[yystate];
if (!yypact_value_is_default (yyn)) if (!yypact_value_is_default (yyn))
{ {
yyn += ]b4_symbol(1, kind)[; yyn += ]b4_symbol(error, kind)[;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(1, kind)[) if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(error, kind)[)
{ {
yyn = yytable[yyn]; yyn = yytable[yyn];
if (0 < yyn) if (0 < yyn)