Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Wed, 11 Dec 2024 16:28:28 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID:
References:
<87plmfu2ub.fsf@nosuchdomain.example.com>
<87frnbt9jn.fsf@nosuchdomain.example.com>
<877c8nt255.fsf@nosuchdomain.example.com>
<20241129142810.00007920@yahoo.com>
<20241129161517.000010b8@yahoo.com>
<87ldwx10gv.fsf@bsb.me.uk>
<86ser1kgp5.fsf@linuxsc.com>
<87ldwtzlc0.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Dec 2024 16:28:28 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2219d0e81fc8abda50710a06e8939fe0";
logging-data="1683789"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nA0QJpd/9eAMFFVppZ+mw0BFT3V5GD+0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:A5hWX3Lzo15/PO+MHrBBPWTruQ0=
Content-Language: en-GB
In-Reply-To:
Bytes: 4069
On 11/12/2024 09:43, Ike Naar wrote:
> On 2024-12-09, Janis Papanagnou wrote:
>> An unambiguous grammar is something quite essential; how would you
>> parse code if it were ambiguous?
>
> Here's an ambiguity in the C grammar:
>
> :
> ...
>
> ...
>
> :
> ...
> if ( )
> if ( ) else
> ...
>
> The following selection-statement is grammatically ambiguous:
>
> if (E1) if (E2) S1 else S2
>
> it has two possible parsings:
>
> if (E1) else S2
>
> where expands to
>
> if (E2) S1
>
> or
>
> if (E1)
>
> where expands to
>
> if (E2) S1 else S2
>
> The grammatical ambiguity is resolved by an additional rule in the
> 'Semantics' section for selection-statement:
>
> 3 An else is associated with the lexically nearest preceding if that is
> allowed by the syntax.
>
Given that the resolution is in the "semantics" section rather than the
"syntax" section, it might seem like a grammatical ambiguity. But I
don't think it is, technically - the syntax rules say that the set of
tokens making up "if (E1) if (E2) S1 else S2" are valid syntax. It is
up to the semantics to determine what the code will do here. (And the
semantics are unambiguous.)
> gcc -Wall will issue a warning for such an ambiguous statement:
>
> warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
gcc is not warning about ambiguity - it is well specified exactly what
the code means in the language. It is warning because it might not be
clear to the human reader and/or programmer.
Certainly such nested "if" statements without braces can be confusing to
people, and they may require extra effort in a parser. But they are not
an ambiguity in the language.