fortran-plugin icon indicating copy to clipboard operation
fortran-plugin copied to clipboard

Incorrect parsing of non-standard kind statement

Open dryabov opened this issue 5 years ago • 2 comments

The following variable declaration

REAL*8 Q1

is parsed incorrectly: the whole "8 Q1" string is considered as an expr in nonstandard_kind_selector because of the parser considers it as a double-precision number (note that DOUBLE_PRECISION_EXPONENT_PART allows spaces around [dDqQ]). I've locally replaced nonstandard_kind_selector by just

unsigned_int_literal ::= integerliteral
nonstandard_kind_selector ::= '*' unsigned_int_literal { pin = 1 }

but it looks like FortranNonstandardKindInspection takes into account possibility of non-integer kind value for complex data type. Is there some a rare Fortran dialect where it is actually possible?

dryabov avatar Nov 14 '19 19:11 dryabov

Hmm, the lexer should be modified as well. It's the problem...

dryabov avatar Nov 14 '19 19:11 dryabov

Here are valid Fortran codes to reproduce the issue and to see it's not so easy to introduce extra state in the lexer:

PROGRAM test_free
REAL*8 E1
REAL*8 real
  real = 8E1
  real = &
         real*8E1
  print *,real
END

and

      PROGRAM test_fixed
      REAL*8 E1
      REAL*8 real
        real = 8 E1
        real =
     *         real*8 E1
        print *,real
      END

As far as I understand, skipping of spaces in numbers in the lexer has been introduced to support legacy Fortran 77 codes (because of such numbers are not valid in Fortran 90+). Most likely it's better to more distinguish fixed and free form in the flex file, so that free form doesn't support spaces in numbers and fixed form may use an extra "first-statement-in-a-line" state to catch type name followed by * (note that above program in not a valid fixed-form code because of the difference in line continuation, and so non-space character in the 6th position may be used to reset "first-statement-in-a-line" state). Alternative way is have a very simple char-by-char lexer and move all logic to parser stage.

dryabov avatar Nov 14 '19 20:11 dryabov