This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Help fixing parser for negative exponents to **
- From: Roger Sayle <roger at eyesopen dot com>
- To: fortran at gcc dot gnu dot org
- Date: Mon, 24 May 2004 13:17:41 -0600 (MDT)
- Subject: Help fixing parser for negative exponents to **
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.
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. If this is the case
there may just be a transcription problem encoding these functions.
Alternatively, handling negative exponents belongs either in
match_mult_operand itself, or instead of match_mult_operand directly
calling itself recursively, we need another class of operand to match.
Yet another possibility is for match_primary to handle unary plus and
minus operators.
Checking bugzilla it looks like this problem hasn't been reported
previously. My guess is that for an experienced front-end hacker
it might be a ten minute job to correct. If not, I can file a PR
so we can track the issue.
Many thanks.
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833