Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #67628 > unrolled thread

Re: Parentheses as operators

Started byJames Kuyper <jameskuyper@verizon.net>
First post2015-08-17 16:26 -0400
Last post2015-08-17 14:45 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Parentheses as operators James Kuyper <jameskuyper@verizon.net> - 2015-08-17 16:26 -0400
    Re: Parentheses as operators Keith Thompson <kst-u@mib.org> - 2015-08-17 14:45 -0700

#67628 — Re: Parentheses as operators

FromJames Kuyper <jameskuyper@verizon.net>
Date2015-08-17 16:26 -0400
SubjectRe: Parentheses as operators
Message-ID<55D24379.9090205@verizon.net>
On 08/17/2015 02:50 PM, Stefan Ram wrote:
>   To me, an operator is a sequence of fixed tokens and gaps
>   that yields an expression, when expressions are inserted
>   into the gaps. For example:
> 
>     .-----.     .-.     .-----.     .-.     .-----.
> --->| gap |--->( ? )--->| gap |--->( : )--->| gap |--->
>     '-----'     '-'     '-----'     '-'     '-----'
> 
>   yields the expression »0?1:2«, when the expressions
>   »0«, »1«, and »2« are inserted into the gaps.
> 
>   Therefore, to me, this is also an operator:
> 
>      .-.     .-----.     .-.
> --->( ( )--->| gap |--->( ) )--->
>      '-'     '-----'     '-'
> 
>   , it yields the expression »(0)«, when the expression »0«
>   is inserted into the gap.
> 
>   But the parentheses usually do not count as an operator:
> 
> 6.5.3 Unary operators
> Syntax
> 1 unary-expression:
> postfix-expression
> ++ unary-expression
> -- unary-expression
> unary-operator cast-expression
> sizeof unary-expression
> sizeof ( type-name )
> _Alignof ( type-name )
> unary-operator: one of
> & * + - ~ !
> 
>   . The parentheses are given in
> 
> 6.5.1 Primary expressions
> Syntax
> 1 primary-expression:
> identifier
> constant
> string-literal
> ( expression )
> generic-selection
> 
>   . Of course, the parentheses are there in the syntax.
>   I do not want to deny this. But they never seemed to be called
>   an »operator«, not in the standard nor by people as far as
>   I am aware of. So I wonder why they are not called »operator«.

On 1999-12-08, I referred to them as operators, but Paul Jarc objected.

>   Some people might say that the parentheses are not an
>   operator because they are not compiled into an operation,
>   but isn't this also true of »+« as in »+0«, which also is
>   not compiled into an operation? Yet, the »+« /is/ called
>   an »operator«.
> 
>   Would it be wrong to call the parentheses an »operator«?

Paul Jarc thought so. Uncharacteristically, I didn't argue with him - I
wonder why?. It could be because this is one of the less clear parts of
the standard.

6.4.6p1 defines what constitutes a punctuator; parentheses are included.

"A punctuator is a symbol that has independent syntactic and semantic
significance. Depending on context, it may specify an operation to be
performed (which in turn may yield a value or a function designator,
produce a side effect, or some combination thereof) in which case it is
known as an _operator_ (other forms of operator also exist in some
contexts)." (6.4.6p2). The word "operator" is italicized, an ISO
convention indicating that this clause is the official definition of
that term.

One argument against calling parentheses operators could be that they
don't specify any operation to be performed - a parenthesized expression
is almost entirely equivalent to the expression itself, except that it
qualifies as primary-expression, which affects how it is parsed in
combination with other operators and operands.
Also, every sub-section of 6.5 has a name that includes the word
"operator", except for 6.5.1, which implies that none of the things
described there are operators.

Against this I would cite 6.5p1: "An _expression_ is a sequence of
operators and operands ...". Again, "expression" is italicized, so this
is a definition of that term. A parenthesized expression is itself a
primary-expression, and therefore an expression. If the parentheses
aren't operators in a parenthesized expression, that only leaves the
option, according to 6.5p1, of them being operands, which makes even
less sense.

The standard frequently refers to particular things as operators (and it
never does so for parentheses), but it seldom says anything about
operators in general, only specific operators. I was going to write
"never" rather than "seldom", but I found one exception:
6.2.6.1p8: "Where an operator is applied to a value that has more than
one object representation, which object representation is used shall not
affect the value of the result."

If parentheses are not operators, then this clause doesn't apply to
parenthesized expressions.

[toc] | [next] | [standalone]


#67633

FromKeith Thompson <kst-u@mib.org>
Date2015-08-17 14:45 -0700
Message-ID<lnegj1612i.fsf@kst-u.example.com>
In reply to#67628
James Kuyper <jameskuyper@verizon.net> writes:
[...]
> 6.4.6p1 defines what constitutes a punctuator; parentheses are included.
>
> "A punctuator is a symbol that has independent syntactic and semantic
> significance. Depending on context, it may specify an operation to be
> performed (which in turn may yield a value or a function designator,
> produce a side effect, or some combination thereof) in which case it is
> known as an _operator_ (other forms of operator also exist in some
> contexts)." (6.4.6p2). The word "operator" is italicized, an ISO
> convention indicating that this clause is the official definition of
> that term.

`(` is a punctuator, as is `)`.  `()` is not.

If () were an operator, it would be one of the "other forms of
operator".  I suppose you could call it an "outfix operator".

Other examples of "other forms of operator" are sizeof (since it's a
keyword, not a punctuator), [], and ?: since they're not single
punctuators).

The standard provides no single complete definition of "operator".  I
suspect the authors simply felt it wasn't important to do so.

[...]

> The standard frequently refers to particular things as operators (and it
> never does so for parentheses), but it seldom says anything about
> operators in general, only specific operators. I was going to write
> "never" rather than "seldom", but I found one exception:
> 6.2.6.1p8: "Where an operator is applied to a value that has more than
> one object representation, which object representation is used shall not
> affect the value of the result."
>
> If parentheses are not operators, then this clause doesn't apply to
> parenthesized expressions.

True, but I don't think it needs to; it's covered by 6.5.1p5:

    A parenthesized expression is a primary expression. Its type and
    value are identical to those of the unparenthesized expression.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web