Sujet : Re: question about linker
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 12. Dec 2024, 06:35:27
Autres entêtes
Organisation : None to speak of
Message-ID : <878qslwjj4.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> writes:
[...]
For (yet another) example; my K&R shows a syntax for expressions like
>
expression := binary
binary := binary + binary
binary := binary * binary
That's odd. Is that an exact quotation?
An actual expression x = 2 + 3 * 4 would be "ambiguous" (without
precedence rules).
[...]
My copy of K&R 1st edition (1978) has, among other things:
multiplicative-expression:
expression * expression
expression / expression
expression % expression
additive-expression:
expression + expression
expression - expression
That's ambiguous (presumably precedence is defined elsewhere).
The second edition has something similar to what's in the C standard:
multiplicative-expression:
cast-expression
multiplicative-expression * cast-expression
multiplicative-expression / cast-expression
multiplicative-expression % cast-expression
additive-expression:
multiplicative-expression
additive-expression + multiplicative-expression
additive-expression - multiplicative-expression
Which means that the precedence is defined by the grammar -- but
it also means that categories like "multiplicative-expression"
and "additive-expression" are broader than one might naively
expect. For example, 42 is both a multiplicative-expression and
an additive-expression, even though it contains no multiplicative
or additive operators. (Solving both issues would have required
using even more convoluted names for the categories.)
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */