Re: Operator precedence

Liste des GroupesRevenir à cl awk 
Sujet : Re: Operator precedence
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.awk
Date : 24. May 2024, 05:32:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240523210755.307@kylheku.com>
References : 1 2 3 4 5
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-05-24, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
After pondering a bit more I think this is my personal resume...
>
On 24.05.2024 01:53, Janis Papanagnou wrote:
[...]
Moreover, what seams reasonable (to me) is that _unary_ operators
should (typically/always?) bind tighter than _binary_ operators!
>
An example may make things probably more apparent; in the expression
>
    5 * -3 ^ 2
>
it would never occur to me to not consider the "-3" as an entity.
Because of the typical inherently tight coupling of unary operators.
>
(Assuming an interpretation of
>
    5 * -(3 ^ 2)
>
would look just wrong to me.)

That interpretation is required if - 3 ^ 2  is to correspond to:

    2
  -3

Indeed the ^ circumflex is intended to mean "we don't have support
for superscripts in this notation, but pretend that the 2 is raised up".

(In TeX/LaTeX, ^ is used for marking up superscripts: x^y.)

Now in the C grammar, we have multiplication also occuping a
precedence rung between unary plus/minus and additive expressions.

Thus -A*B means (-A)*B, whereas X - A*B means X-(A*B).

In this case it doesn't matter because the unary minus is
a kind of product. -A can be regarded as a shorthand for (-1)*A.

More importantly the identity (-A)*B = -(A*B) holds.

This creates a problem if we naively wedge exponentiation into
the grammar, by sticking it into a precedence level above
multiplication, but below unary.

The identity does not hold in exponentiation: (-A)**B
is not -(A**B).

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
23 May 24 * Operator precedence27Janis Papanagnou
23 May 24 `* Re: Operator precedence26Kaz Kylheku
23 May 24  `* Re: Operator precedence25Axel Reichert
24 May 24   +* Re: Operator precedence21Janis Papanagnou
24 May 24   i+* Re: Operator precedence17Janis Papanagnou
24 May 24   ii`* Re: Operator precedence16Kaz Kylheku
25 May 24   ii +* Re: Operator precedence13Axel Reichert
25 May 24   ii i`* Re: Operator precedence12Janis Papanagnou
26 May 24   ii i `* Re: Operator precedence11Janis Papanagnou
26 May 24   ii i  +* Re: Operator precedence4Kaz Kylheku
30 May 24   ii i  i`* Re: Operator precedence3Janis Papanagnou
30 May 24   ii i  i `* Re: Operator precedence2Axel Reichert
31 May 24   ii i  i  `- Re: Operator precedence1Janis Papanagnou
26 May 24   ii i  +* Re: Operator precedence4Christian Weisgerber
26 May 24   ii i  i+* Re: Operator precedence2Kaz Kylheku
30 May 24   ii i  ii`- Re: Operator precedence1Janis Papanagnou
30 May 24   ii i  i`- Re: Operator precedence1Janis Papanagnou
30 May 24   ii i  `* Re: Operator precedence2Axel Reichert
31 May 24   ii i   `- Re: Operator precedence1Janis Papanagnou
25 May 24   ii `* Re: Operator precedence2Janis Papanagnou
26 May 24   ii  `- Re: Operator precedence1Kaz Kylheku
30 May 24   i`* Re: Operator precedence3Axel Reichert
31 May 24   i `* Re: Operator precedence2Janis Papanagnou
1 Jun 24   i  `- Re: Operator precedence1Axel Reichert
24 May 24   `* Re: Operator precedence3Kaz Kylheku
25 May 24    `* Re: Operator precedence2Axel Reichert
26 May 24     `- Re: Operator precedence1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal