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: Fri, 19 Jun 2020 00:41:24 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 19/06/2020 00:13, Akim Demaille wrote:
> Hi Daniele,
> 
>> Le 18 juin 2020 à 19:20, Akim Demaille <akim@lrde.epita.fr> a écrit :
>>
>>> 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));
>>> }
>>
>> It looks reasonable.
> 
> Actually, why do you check the token name rather than the token kind itself?

Don't ask me, I didn't write the tests :)

The tests are written in Python (as most of the application). It may be
that when they were written it was deemed easier to emit the token names
from the lexer rather than export an enum mapping token names to token
kinds.

Cheers,
Dan



reply via email to

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