Unfortunately, you are right.
IMHO, this was an oversight (or perhaps to simplify parsing???). A signed number should have been treated as a "primary", rather than treated in the more general case as a unary operator and number. You will also note that "not" has been given the highest priority, yet it's arithmetic counterpart ("-" sign) has merely been given the same priority as an "adding operator". This seems a bit inconsistent, to me. Oh well, I guess we have to "live with it"! :-/
Joe.
-----Original Message----- From: J. David Bryan [SMTP:dbryan@bcpl.net] Sent: Monday, September 10, 2001 12:17 PM To: GNU Pascal List Subject: Re: pow operator miscalculation
On 10 Sep 2001, at 9:57, da Silva, Joe wrote:
I'm not good on the jargon, but is "-2" really a unary "-" and a number (2), or is "-2" a number in itself (ie. the sign is not an operator)?
The Extended Pascal standard, section 6.8.1, "Expressions, General," says that the expression "-2" is a simple-expression, which is defined as a sign followed by a term. So "-" is the sign, and "2" is the term. The standard therefore treats any expression with a leading sign as a unary operator applied to an unsigned expression.
To continue, "-2 pow 2" is parsed as the sign "-" and the term "2 pow 2".
The term is parsed as a factor, which is defined as a primary, followed by
an exponentiating-operator (in this case, "pow"), followed by another primary. "2" is a primary because primaries may be unsigned-constants.
This is what Maurice suggested in his second posting, and is the natural/intuitive interpretation of "-2".
Unfortunately, "intuitive interpretations" don't count when a standard says otherwise.... :-)
-- Dave