Sujet : Re: question about linker
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.cDate : 11. Dec 2024, 14:59:52
Autres entêtes
Organisation : To protect and to server
Message-ID : <vjc5sm$1aith$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 07.12.2024 16:33, Bart wrote:
An unambiguous grammar is something quite essential; how would you
parse code if it were ambiguous?
You use different grammar for parsing. As Ike noted C has "dangling
else" problem, this is well known and silently corrected by parser
generators (they use different grammar than the one you gave them).
If take grammar from C standard you will notice that it can not
parse C regardless of "dangling else" problem. The situation is
resonably well described by word "disconnected". In C90 grammar
the is one nonterminal that can not be produced by any grammar rule
(IIRC this is 'type-name'). If you try to correct the problem by
adding rule that identifier can be a type name you get grammar that
does not work with usual tools (I think that this grammar is
unambiguous, but is quite inconvenient for parsing).
Usial approach for parsing C uses semantic rules: 'type-name'
is produced from 'identifier' after symbol-table loopup. But
the effect is that syntax of C language is not described by the
grammar from the standard alone.
One approach that was advocated for C (and I used in different
context) is superset approach: you write unambigious grammar for
bigger language which produces resonably similar parse tree.
Then semantic information + local tree transformations are used
to reject invalid programs and to transform parse tree.
So there is unambigious grammar, but this grammar is an artifact
of parsing process, not the official language grammar.
-- Waldek Hebisch