From 3464967690258272597
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,13ce76b24fcf616c
X-Google-Attributes: gidf78e5,public
From: James Kuyper <kuyper@wizard.net>
Subject: Re: Operator precedence
Date: 1999/12/29
Message-ID: <386A128E.AB5C1644@wizard.net>#1/1
X-Deja-AN: 566160178
X-NNTP-Posting-Host: 209.8.153.27
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <3868B1A1.D47627B4@kobasoft.nl> <3868DE6D.5C90C109@sensor.com> <38692702.FCB626F4@kobasoft.nl>
X-Accept-Language: en,de,es,ru
Content-Type: text/plain; charset=us-ascii
X-Trace: tw11.nn.bcandid.com 946475609 209.8.153.27 (Wed, 29 Dec 1999 06:53:29 MST)
Organization: bCandid - Powering the world's discussions - http://bCandid.com
Mime-Version: 1.0
NNTP-Posting-Date: Wed, 29 Dec 1999 06:53:29 MST
Newsgroups: comp.std.c++
Originator: clamage@taumet


Pieter van Beek wrote:
> 
> Ron Natalie wrote:
....
> > Precedence is not defined by that table, even in C, it is implied by
> > the language grammar.  The inclusion of the table in K&R and Stroustrup
> > is purely informational.  Note the comment from Stroustrup at the bottom
> > of page 121:
> >         A few grammar rules cannot be expressed in terms of precedence
> >         (also known as binding strength) and associativity.
> >
> > This has lead to some confusion with the ?: operator interpretation.
> 
> If this is so, then how know, from the standard, how for example
> *array_of_arrays[3] will be interpreted? Or *foo->bar() ?

Here are the relevant grammar rules:

5.1 p1:
	_primary-expression_:
		...
		_id-expression_

	_id-expression_:
		_unqualified-id_
		_qualified-id_

	_unqualified-id_:
		_identifier_
		...

5.2 p1:
	_postfix-expression_:
		_primary-expression_
		_postfix-expression_ [ _expression_ ]
		...

5.3 p1:
	_unary-expression_:
		_postfix-expression_
		...
		_unary-operator_ _cast-expression_
		...

	_unary-operator_: one of
		*   &   +   -   |  ~

5.4 p2:
	_cast-expression_:
		_unary-expression_
		( _type-id_ ) _cast-expression_


Thus, *array_of_arrays[3] is parsed as follows:

	        *          array_of_arrays    [       3      ]
	                    _identifier_
	                   _unqualified-id_
	                   _id-expression_
	                 _primary-expression_ [ _expression_ ]
	                         _postfix-expression_       
	                          _unary_expression_
        _unary-operator_          _cast_expression_
                    _unary-expression_

The fact that [] is applies ahead of * is therefore encoded in the
grammar itself, without need for separate precedence rules.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




