On Friday, November 10, 2023 1:57:59 AM CET James K. Lowden wrote:
> 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).
[...]

Are you aware that yytname[] is indexed by "symbol-number", not by "token-
number", as it contains terminals and non-terminals?

/Christian




Reply via email to