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: Sat, 11 Nov 2023 18:06:03 -0500

On Sat, 11 Nov 2023 18:03:59 +0100
Hans Åberg <haberg-1@telia.com> wrote:

> On Nov 10, 2023, at 01:57, James K. Lowden <jklowden@schemamania.org>
> wrote:
> > 
> > I can't seem to look up token names in yytname correctly using enum
> > yytokentype.
> ?
> > 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).
> 
> In Bison, being compatible with POSIX Yacc, it is allowed use
> characters as token numbers, so those numbers are reserved for that
> purpose.

Yes, Hans, thanks.  I'm actually depending on that feature, as I
mentioned: 

>     %right NOT
>     %left '<' '>' '=' NE LE GE

The problem is this: because NOT and NE have adjacent yytokentype
values, but are not adjacent in the yytname array, the NE token name
cannot be looked up in yytname.  That appears to me to be a bug,
although I acknowledge the feature is hardly documented except as
"obsolescent".  

I think the purpose of the yytname array is simple: for each token
(that is not a character), it holds a string with the token's name.  I
see no need for an entry like 

>     "'<'",

because that token's value is 60, an ASCII '<'.  There's no reason for
it to occupy space in yytname. 

Apparently it's being put there because of the precedence
declarations.  I reported the problem because I suspect that's
inadvertent, and because I see no good alternative to using this
supposedly obsolescent feature.  

--jkl



reply via email to

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