mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 21:03:04 +00:00
tokens: properly define the YYEOF token kind
Currently EOF is handled in an adhoc way, with a #define YYEOF 0 in the implementation file. As a result, the user has to define her own EOF token if she wants to use it, which is a pity. Give the $end token a visible kind name, YYEOF. Except that in C, where enums are not scoped, we would have collisions between all the definitions of YYEOFs in the header files, so in C, make it <api.PREFIX>EOF. * data/skeletons/c.m4 (YYEOF): Override its name to avoid collisions. Unless the user already gave it a different name. * data/skeletons/glr.c (YYEOF): Remove. Use ]b4_symbol(0, [id])[ instead. Add support for "pre_epilogue", for glr.cc. * data/skeletons/glr.cc: Remove dead code (never emitted #undefs). * data/skeletons/yacc.c * src/parse-gram.c * src/reader.c * src/symtab.c * tests/actions.at * tests/input.at
This commit is contained in:
@@ -900,7 +900,6 @@ enum { YYENOMEM = -2 };
|
||||
#define yyerrok (yyerrstatus = 0)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define YYEMPTY (-2)
|
||||
#define YYEOF 0
|
||||
|
||||
#define YYACCEPT goto yyacceptlab
|
||||
#define YYABORT goto yyabortlab
|
||||
@@ -1950,9 +1949,9 @@ yybackup:
|
||||
yychar = yylex (&yylval, &yylloc);
|
||||
}
|
||||
|
||||
if (yychar <= YYEOF)
|
||||
if (yychar <= GRAM_EOF)
|
||||
{
|
||||
yychar = YYEOF;
|
||||
yychar = GRAM_EOF;
|
||||
yytoken = YYSYMBOL_YYEOF;
|
||||
YYDPRINTF ((stderr, "Now at end of input.\n"));
|
||||
}
|
||||
@@ -2643,10 +2642,10 @@ yyerrlab:
|
||||
/* If just tried and failed to reuse lookahead token after an
|
||||
error, discard it. */
|
||||
|
||||
if (yychar <= YYEOF)
|
||||
if (yychar <= GRAM_EOF)
|
||||
{
|
||||
/* Return failure if at end of input. */
|
||||
if (yychar == YYEOF)
|
||||
if (yychar == GRAM_EOF)
|
||||
YYABORT;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -778,11 +778,16 @@ check_and_convert_grammar (void)
|
||||
/* If the user did not define her ENDTOKEN, do it now. */
|
||||
if (!endtoken)
|
||||
{
|
||||
endtoken = symbol_get ("$end", empty_loc);
|
||||
endtoken = symbol_get ("YYEOF", empty_loc);
|
||||
endtoken->content->class = token_sym;
|
||||
endtoken->content->number = 0;
|
||||
/* Value specified by POSIX. */
|
||||
endtoken->content->user_token_number = 0;
|
||||
{
|
||||
symbol *alias = symbol_get ("$end", empty_loc);
|
||||
symbol_class_set (alias, token_sym, empty_loc, false);
|
||||
symbol_make_alias (endtoken, alias, empty_loc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Report any undefined symbols and consider them nonterminals. */
|
||||
|
||||
@@ -70,9 +70,12 @@ bool tag_seen = false;
|
||||
static bool
|
||||
symbol_is_user_defined (symbol *sym)
|
||||
{
|
||||
const bool eof_is_user_defined
|
||||
= !endtoken->alias || STRNEQ (endtoken->alias->tag, "$end");
|
||||
return sym->tag[0] != '$'
|
||||
&& (eof_is_user_defined || (sym != endtoken && sym->alias != errtoken))
|
||||
&& sym != errtoken && sym->alias != errtoken
|
||||
&& sym != undeftoken && sym->alias != undeftoken;
|
||||
&& sym != undeftoken && sym->alias != undeftoken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user