help-bison
[Top][All Lists]
Advanced

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

yytname woes


From: James K. Lowden
Subject: yytname woes
Date: Thu, 9 Nov 2023 19:57:59 -0500

I can't seem to look up token names in yytname correctly using enum
yytokentype.

At the end of enum yytokentype, I have

    END_UNSTRING = 893,            /* END_UNSTRING  */
    END_WRITE = 894,               /* END_WRITE  */
    END_IF = 895,                  /* END_IF  */
    THRU = 896,                    /* THRU  */
    OR = 897,                      /* OR  */
    AND = 898,                     /* AND  */
    NOT = 899,                     /* NOT  */
    NE = 900,                      /* NE  */
    LE = 901,                      /* LE  */
    GE = 902,                      /* GE  */
    NEG = 903,                     /* NEG  */
    POW = 904                      /* POW  */

but in yytname, where we transition from terminals to nonterminals, I
have this:

    "END_UNSTRING",
    "END_WRITE",
    "END_IF",
    "THRU",
    "OR",
    "AND",
    "NOT",
    "'<'",
    "'>'",
    "'='",
    "NE",
    "LE",
    "GE",
    "'-'",
    "'+'",
    "'*'",
    "'/'",
    "NEG",
    "POW",
    "'.'",
    "'&'",
    "'S'",
    "'('",
    "')'",
    "':'",
    "$accept",
    "top",
    "programs",

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

The tail end of my token definitions might account for it:

    ...
    END_IF
    %left  THRU
    %left  OR
    %left  AND
    %right NOT
    %left '<' '>' '=' NE LE GE
    %left '-' '+'
    %left '*' '/'
    %precedence NEG
    %right POW

It looks like an error to me.  Is there something I should (or
conventionally would) do differently?

I see in the manual it says "This feature is obsolescent, avoid it in
new projects."  It doesn't recommend an alternative, and ISTM being
able to look up the name of a token is a useful feature.

The entire program may be found at:

https://gitlab.cobolworx.com/COBOLworx/gcc-cobol/-/blob/master+cobol/gcc/cobol/parse.y

--jkl



reply via email to

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