Liste des Groupes | Revenir à cl c |
On 11.12.2024 17:47, David Brown wrote:If C had that requirement, it would not be a workaround - it would be a fixed part of the grammar. The current definition of C, with optional braces and an extra "semantics" clause seems more like a workaround to me.On 11/12/2024 17:30, Janis Papanagnou wrote:Yes, sure. But, I can't help, it smells like a workaround.On 11.12.2024 09:43, Ike Naar wrote:>On 2024-12-09, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> 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:
>
[...]
>
The following selection-statement is grammatically ambiguous:
>
if (E1) if (E2) S1 else S2
Yes, the dangling else is a common ambiguity in many programming
languages.
>
That's why I prefer languages with syntaxes like in Algol 68 or
Eiffel (for example).
It is easy to avoid in a C-like language - simply require braces on "if"
statements, or at the very least, require them when there is an "else"
clause.
Most C coding standards and style guides make that requirementYes, true. (We had that in our standards, too.)
- not because the C compiler sees it as ambiguous, but because humans
often do. (Or they misinterpret it.)
Janis
Les messages affichés proviennent d'usenet.