This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Help fixing parser for negative exponents to **
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Mon, 24 May 2004 12:46:51 -0700
- Subject: Re: Help fixing parser for negative exponents to **
- References: <Pine.LNX.4.44.0405241258220.4415-100000@www.eyesopen.com>
On Mon, May 24, 2004 at 01:17:41PM -0600, Roger Sayle wrote:
>
> Unfortunately, I don't have access to the official grammars for
> fortran95 and fortran2003, but I suspect that there's a bug in
> gfortran's parser for processing power expressions. Currently,
> we fail to parse unary minus (and unary plus) expressions
> immediately following an exponentiation/power operator.
>
> X = 2.0
> Y = X**-1.5D0
> PRINT 10, Y
> 10 FORMAT (F8.5)
> END
>
> X = 2.0
> Y = X**+1.5D0
> PRINT 10, Y
> 10 FORMAT (F8.5)
> END
>
> X = 2.0
> Y = 1.5
> Z = X**-Y
> PRINT 10, Z
> 10 FORMAT (F8.5)
> END
>
>
> I believe these are all valid, and compile fine with g77. They might
> however be a "common" extension, so I thought I'd check with this list
> first. The examples in gfortran.fortran-torture/execute/power.f90 all
> use parenthesis around negative exponents.
These are all illegal with respect to the standard. From page 136 of
the draft standard, Note 7.31, we have
As a consequence of the general form (7.1.1), only the first add-operand
of a level-2-expr may be preceded by the identity (+) or negation (-)
operator. These formation rules do not permit expressions containing
two consecutive numeric operators, such as A ** -B or A + -B. However,
expressions such as A ** (-B) and A + (-B) are permitted. The rules do
allow a binary operator or an intrinsic unary operator to be followed
by a defined unary operator, such as:
The above discussion concerns operator precedence in 7.1.1.
You can get a draft of the upcoming standard Fortran 200x at
http://www.j3-fortran.org/. You want ISO_IEC_1539-1.pdf. From
my reading of comp.lang.fortran, where many members of the
standards committee provide advice, ISO_IEC_1539-1.pdf should
be nearly identical to forthcoming ratified standard.
I also have PDF versions of the F66 and F77 standards, but
I don't remember where I found them on the net.
> Rather than just file a bug report, I'd like some advice on how best
> to fix this problem. It looks as though the parser in matchexp.c
> is based upon some official/formal description, using terms like
> "level 1" expression and "level 2" expression.
Yep. See page 117 and following pages in ISO_IEC_1539-1.pdf.
However, you are correct that this is a common extension, and
if g77 supports this construct, then we need to provide for it.
gfortran should be backward compatible with g77.
--
Steve