Re: yytname woes

"James K. Lowden" <[email protected]> Sun, 12 Nov 2023 12:18:30 -0500
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
On Mon, 13 Nov 2023 12:33:57 +0100
Christian Schoenebeck <[email protected]> wrote:

> > When I look up #899, NOT, I get "NOT".  But when I look up #900,
> > NE, I get "'<'" because that's the next element in yytname (900 -
> > 255).
> [...]
>=20
> Are you aware that yytname[] is indexed by "symbol-number", not by
> "token- number", as it contains terminals and non-terminals?

That's interesting.  No, I'm not.  Respectfully, how could I be? =20

The term "symbol-number" does not appear in the Bison info manual.  The
%token-table directive says

	"?yytname[I]? is the name of the token whose internal
	 Bison token code is I.'=20

You tell me: what is a "Bison token code"? =20

in Appendix A, a distinction is drawn, but not defined:=20

 -- Type: yytoken_kind_t
     An enum of all the ?token kinds? declared with ?%token? (*note
     Token Decl::).  These are the return values for ?yylex?.  They
     should not be confused with the _symbol kinds_, used internally by
     the parser.

Well, I'm not confused, but I am flummoxed.  What I have is an
integer, the token returned by yylex, as derived from whatever was
provided it by the header file generated by Bison.  What I want is the
token's name.  The only translation between the two that I know of is
yytname. =20

If I'm not supposed to use yytokentype to index into yytname, and
should use yytoken_kind_t instead (assuming that's what you mean), then
how do I get from yytokentype to yytoken_kind_t? =20

Asking for a friend. =20

--jkl