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

Double array access is not lexed

Open madgen opened this issue 8 years ago • 4 comments

program example
  arr(1)(1:1) = x
end program example

Need to check if this is even valid Fortran.

madgen avatar Jun 01 '16 16:06 madgen

I've seen this used in some of corpus. Here is an example which (for what its worth) is accepted by gfortran:

program dubsub
  implicit none
  character(5), dimension(10) :: x
  x(1)(1:3) = 'a'
end program

dorchard avatar Nov 02 '16 13:11 dorchard

Just because compiler handle it doesn't necessarily mean it is valid Fortran. Though this probably is. There is a grammatical reason that I didn't resolve it earlier. I will attend to it when I can.

madgen avatar Nov 02 '16 13:11 madgen

I think this might be a Fortran 90 feature. In the FORTRAN 77 standard section 5.3 suggests that we have to have an array name as the subject of a subcript a (s [,s]) (http://www.fortran.com/fortran/F77_std/rjcnf-5.html#sh-5.3). In Fortran 90, an array element is a 'data-ref' followed by zero or more subscripts (Section 6.2.2) and a data-ref can be a subscript expression itself (Section 6.1.2) (ftp://ftp.nag.co.uk/sc22wg5/N001-N1100/N692.pdf).

dorchard avatar Nov 02 '16 13:11 dorchard

If x is a rank-1 character array, x(1)(1:3) is valid Fortran 77 code for a substring formed by the first 3 characters of the element of the array with index 1.

If x is not a rank-1 character array, I can't think of any valid meaning of the expression x(1)(1:3).

Please bear in mind that section 5.3 of the Fortran 77 standard is about array elements - character substrings are discussed in section 5.7, see #63. The corresponding part of the Fortran 90 standard is section 6.1.1.

jme52 avatar Jan 28 '18 20:01 jme52