help-bison
[Top][All Lists]
Advanced

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

Re: yytname woes


From: James K. Lowden
Subject: Re: yytname woes
Date: Sun, 12 Nov 2023 12:18:30 -0500

On Mon, 13 Nov 2023 12:33:57 +0100
Christian Schoenebeck <schoenebeck@crudebyte.com> 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).
> [...]
> 
> 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?  

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.' 

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

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

 -- 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.  

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?  

Asking for a friend.  

--jkl




reply via email to

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