help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redefining the literal string associated to the YYerror symbol


From: Daniele Nicolodi
Subject: Re: Redefining the literal string associated to the YYerror symbol
Date: Thu, 18 Jun 2020 02:35:48 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 18/06/2020 00:44, Akim Demaille wrote:
> There is no way to rename it, and it wouldn't make sense as the error
> token is never presented as an "expected token".  The error token never
> shows to the (end) user.  It appears in the debug traces, but that's
> for the developer.

What about YYEOF and YYUNDEF? Those appear in error messages.

I use a function like this to get token names to used to print a dump of
the token stream of a lexer:

const char* token_name(int token)
{
    return yysymbol_name(YYTRANSLATE(token));
}

However I have a ton of tests that expect the lexer to emit a
"LEX_ERROR" token on error and I am considering to use YYerror special
token to report errors instead. Thus the question if I can rename
YYerror from "error" to "LEX_ERROR".

The fix is rather easy:

const char* token_name(int token)
{
    if (token == YYerror)
        return "LEX_ERROR";
    return yysymbol_name(YYTRANSLATE(token));
}

I just anted to check if there is a built in mechanism to achieve the
same. However, to support renaming YYEOF and YYUNDEF (which appear in
ereor messages, if I am not mistaken) would probably be something good
to have.

Cheers,
Dan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]