Sujet : Re: question about linker
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.cDate : 12. Dec 2024, 03:31:21
Autres entêtes
Organisation : To protect and to server
Message-ID : <vjdhtn$1hp82$1@paganini.bofh.team>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
On 11.12.2024 16:28, David Brown wrote:
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; [...]
>
[ dangling-else sample ]
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.)
I'm a bit ambivalent about that. - Yes, technically it's syntax, it's
syntactically probably correct, and it has a semantical ambiguity that
needs to be resolved. All languages with the dangling-else property do
resolve that. But the syntax could have been defined in a way that such
that a dangling else cannot appear in the first place. (Not in "C" and
descendant languages, of course; that ship has sailed.)
Of course nobody is going to retroactively change C standards.
However, it is well-known how to rewrite grammar so that there
is no "dangling else" ambiguity in the grammar and resulting
parse trees are equivalent to parse trees produced by the current
grammar. Drawback of such rewrite is that grammar is significantly
bigger, basically most things that can appear iside 'if' must
come in two versions. Such grammar is harder to understand,
so most languages make pragmatic choice of using simpler grammar
+ extra rule. And this simpler grammar can be fed into a parser
generator to get parser which resolves "dangling else" as
proscribed by the rule and such parser is likely to be smaller
and more efficient than parser for grammar with conflict
removed.
So, while "dangling else" problem is rather fundamental, using
ambigious grammar is a pragmatic choice.
The other things that I mentioned (type name trouble) is more
problematic: trying to fix it leads to grammar that is not
LR(1). I think that this grammar is unambigious, but it
would not work with standard parser generators ("dangling else"
rewrite preserves good propeties of grammar and only affects
size).
-- Waldek Hebisch