bison-patches
[Top][All Lists]
Advanced

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

Re: {maint} yacc.c: initialize yylval in pure-parser mode


From: Akim Demaille
Subject: Re: {maint} yacc.c: initialize yylval in pure-parser mode
Date: Wed, 19 Sep 2012 15:05:24 +0200

Hi Paul,

I have not seen answers to this message.  I really believe we should
initialize yylval here.  Because of the warnings issued in one place
of our generated code, the users disable warnings in the whole file.
And this precise warning does not tell us anything serious about
possible mistakes in the scanner.  So I see _no_ value in it at all.

Le 3 sept. 2012 à 17:18, Akim Demaille a écrit :

> 
> Le 1 sept. 2012 à 15:26, Paul Eggert a écrit :
> 
>> On 09/01/2012 02:26 AM, Akim Demaille wrote:
>>> If one writes a parser that does not manipulate semantic
>>> values, these warnings are legitimate from the point
>>> of view of the compiler, but do not help and are not
>>> legitimate from the point of view of the Bison user.
>> 
>> This is the key point, I expect.
>> 
>> So why don't we modify Bison so that, if one writes
>> a parser like that, the generated parser doesn't
>> use yylval or semantic values at all?  That way,
>> the warnings will continue to be useful, and we
>> won't need to add this useless initialization
>> to the code.
> 
> Hi Paul,
> 
> This is only half of the story I told.  See also my example:
> 
>> %pure-parser
>> %code
>> {
>> # include <stdio.h>
>> # include <stdlib.h>
>> 
>> void yyerror (const char *msg);
>> int yylex (YYSTYPE *lvalp);
>> }
>> 
>> %%
>> 
>> exp: 'a' {};
>> 
>> %%
>> 
>> void yyerror (const char *msg)
>> {
>>  fprintf (stderr, "%s\n", msg);
>> }
>> 
>> int yylex (YYSTYPE *lvalp)
>> {
>>  return 0;
>> }
>> 
>> int main (void)
>> {
>>  return yyparse ();
>> }
> 
> This triggers no warning although yylval is never
> initialized in yylex (which it is pointed to by lvalp).
> 
> But the same example with the following yylex:
> 
>> int yylex (YYSTYPE *lvalp)
>> {
>> static size_t toknum = 0;
>> int res = toknum++;
>> *lvalp = toknum;
>> return res;
>> }
> 
> triggers warnings, although yylval _is_ initialized!
> 
> So while the case you focused on is legitimate, there is also
> the case where our users see warnings that are not legitimate,
> and they have to use pragmas to nuke them.
> 
> 




reply via email to

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