bug-bison
[Top][All Lists]
Advanced

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

Re: Bug in demonstration code in texinfo documentation.


From: Scott A Crosby
Subject: Re: Bug in demonstration code in texinfo documentation.
Date: 23 Sep 2003 13:15:41 -0500
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

On 23 Sep 2003 09:48:16 -0700, Paul Eggert <address@hidden> writes:

> Scott A Crosby <address@hidden> writes:
> 
> > There's also a second bug in, in that one must return $yytoknum[i]$,
> > and not $i$.
> 
> Sorry, I don't have enough context here to understand this comment.

In 1.875a texinfo:

   * `yylex' can find the multicharacter token in the `yytname' table.
     The index of the token in the table is the token type's code.  The
     name of a multicharacter token is recorded in `yytname' with a
     double-quote, the token's characters, and another double-quote.
     The token's characters are not escaped in any way; they appear
     verbatim in the contents of the string in the table.

     Here's code for looking up a token in `yytname', assuming that the
     characters of the token are stored in `token_buffer'.

          for (i = 0; i < YYNTOKENS; i++)
            {
              if (yytname[i] != 0
                  && yytname[i][0] == '"'
                  && ! strncmp (yytname[i] + 1, token_buffer,
                                strlen (token_buffer))
                  && yytname[i][strlen (token_buffer) + 1] == '"'
                  && yytname[i][strlen (token_buffer) + 2] == 0)
                break;
            }

     The `yytname' table is generated only if you use the
     `%token-table' declaration.  *Note Decl Summary::.

However, the value $ i $ cannot be used as a token value. It must be
indexed into the array $ yytoknum[i] $ to work correctly. (yytoknum is
not documented in 1.875a texinfo.)

Observe this in the working code below:

/* Lookup literal names */
static int lookup(char *token_buffer) {
    int i;
    for (i = 0; i < YYNTOKENS; i++)
       {                
       if (yytname[i] != 0
            && yytname[i][0] == '"'
            && !strncmp (yytname[i] + 1, token_buffer,
                              strlen (token_buffer))
            && yytname[i][strlen (token_buffer) + 1] == '"'
            && yytname[i][strlen (token_buffer) + 2] == 0) {
                printf("---Match Success: %s, %d\n",token_buffer,i,yytname[i]);
                yylval.literalVal=token_buffer;
                return yytoknum[i];
            }
       }
       printf("---Match Fail: %s\n",token_buffer);
       yylval.literalVal=token_buffer;
       return LITERAL_TOK;
   }


Scott




reply via email to

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