[Top][All Lists]

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

Re: yacc.c: clarify the computation of yystate

From: Akim Demaille
Subject: Re: yacc.c: clarify the computation of yystate
Date: Wed, 24 Oct 2018 07:01:12 +0200

Hi Paul!

> Le 24 oct. 2018 à 02:39, Paul Eggert <address@hidden> a écrit :
> On 10/22/18 8:52 AM, Akim Demaille wrote:
>> +          const int yylhs = yyr1[yyrule] - YYNTOKENS;
> I used to work with someone who liked to declare C local variables ‘register 
> const':

That’s a beautiful one, agreed :)

>  'register' so that he wasn't tempted to take the variable's address, and 
> 'const' so that he wasn't tempted to modify the variable. I tried to talk him 
> out of it, because to me 'register' and 'const' are complete overkill for 
> local variables; the compiler and the human reader can easily deduce these 
> properties statically, and they're not worth the valuable screen real estate 
> that they take up. But I couldn't talk him into it, so 'register const int 
> this' and 'register const int that' it was.
> Anyway, my suggestion for Bison is to not bother with 'const' for locals. The 
> Bison code is already plenty verbose and these ‘const's are more trouble than 
> they're worth.

I see your point.  However, yacc.c is incredibly painful to read,
because yyparse generates long lived variables that are used for
several purposes.  It’s not easy to see which ones are live when
following a goto, and which ones are live when reaching a label.
yyn is quite a nice one on this regard.

There’s also a lot of code duplication, as a result of not using
auxiliary functions.

I would really like to make things crystal clear, at a glance.  I agree
that reducing scopes is the right way to do it, but I’d take anything
that could help the reader to immediately see the properties of
variables.  I’m eager to get rid of every useless side effect,
and using an ‘SSA’ form for clarity.  ‘const’ helps on this regard.

Wrt conciseness, I wish C had ‘let’ and type inference ;)

However, don’t worry, there’s way enough side effects in there,
there can’t be many ‘const’ :)

reply via email to

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