First, ensure that you have a recent version of Bison (I believe the minimum is v3.6, but the v3.7 versions have several useful bug fixes).
That will generate a static member function named symbol_name
with one of the following prototypes. Note that `token_symbol_kind is an internal token number, not the value produced by the scanner. (See below)
const char* yy::parser::symbol_name(token_symbol_kind) (1)
std::string yy::parser::symbol_name(token_symbol_kind) (2)
(1) if %define parse.error custom|detailed
(2) if %define parse.error verbose
If the option parse.error
is not defined, then you can still get the symbol_name
definition by using the deprecated %token-table
directive, or if you arrange for #define YYDEBUG
to be inserted in the generated code (see the -d
flag, for example). I have no idea why the return type differs depending on the definition of parse.error
.
As noted, the argument to symbol_name
is a bison internal token number, rather than the token type returned by the scanner. You can get the internal token number for a token type using the parser
member class by_kind
, with an expression like yy::parser::by_kind(yy::parser::token::«token-type-name»).type_get()
.