bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] Fix handling of yychar manipulation in user semantic actions


From: Akim Demaille
Subject: Re: [PATCH] Fix handling of yychar manipulation in user semantic actions.
Date: Wed, 30 Dec 2009 16:16:28 +0100

Le 17 déc. 2009 à 03:29, Joel E. Denny a écrit :

> The following patch is next.  The problem it addresses is that users 
> sometimes write semantic actions that manipulate yychar.

Wow, really?  What is a typical use of this feature?

Toying with codesearch I have found some ancient versions of G++ using this, 
but is it really common?

IMHO it is too low-level, and we should not be authorized to play with a single 
aspect of a symbol, not with a single one at a time (especially not its type!).


> Of course, they 
> can do this with YYBACKUP or yyclearin.

Well, I have found a project which does use yychar.  As follows :)

/***************************************************************/
/*  Replace Bison's BACKUP macro with one that fixes a bug --  */
/*  must update state after popping the stack -- and allows    */
/*  popping multiple terms at one time.                        */
/***************************************************************/

#define YYNEWBACKUP(token, value)                               \
   do                                                           \
     if (yychar == YYEMPTY )                                    \
       { yychar = (token);                                      \
         memcpy( &yylval, &(value), sizeof(value) );            \
         yychar1 = YYTRANSLATE (yychar);                        \
         while (yylen--) YYPOPSTACK;                            \
         yystate = *yyssp;                                      \
         goto yybackup;                                         \
       }                                                        \
     else                                                       \
       { yyerror ("syntax error: cannot back up"); YYERROR; }   \
   while (0)

http://www.google.com/codesearch/p?hl=en#4FSOSMZ6Pxc/distfiles/cfitsio2510.tar.gz%7CAUMDxfAqXhw/cfitsio/eval.y&q=yychar%20=%20file:%5C.y$

(the macro appears not to be used).

BTW, YYBACKUP is not documented.  And the documentation does not really invite 
to alter yychar.

> lalr1.cc does not define yychar and does not document its
> replacement, yyla, for users.

No, indeed.  But I don't know exactly what kind of games users would like to 
play, and which ones we want to support.



reply via email to

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