This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
The following fails to compile with fparser2 (but it works correctly with intel and gfortran):
module mymod
use, intrinsic :: ISO_C_BINDING
implicit none
private
integer(C_INT), parameter, public :: MY_SPECIAL_NUMBER = 5_C_INT
interface
subroutine fails(farg1)
integer(kind(MY_SPECIAL_NUMBER)), intent(in) :: farg1
end subroutine
end interface
end module
Error:
$ python test.py temp.f90
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fparser-0.0.7-py3.6.egg/fparser/two/Fortran2003.py", line 209, in __new__
return Base.__new__(cls, string)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fparser-0.0.7-py3.6.egg/fparser/two/utils.py", line 257, in __new__
raise NoMatchError(errmsg)
fparser.two.utils.NoMatchError: at line 12
>>> integer(kind(MY_SPECIAL_NUMBER)), intent(in) :: farg1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 11, in <module>
PROGRAM = F2008_PARSER(READER)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fparser-0.0.7-py3.6.egg/fparser/two/Fortran2003.py", line 211, in __new__
raise FortranSyntaxError(error)
fparser.two.utils.FortranSyntaxError: at line 12
>>> integer(kind(MY_SPECIAL_NUMBER)), intent(in) :: farg1
The module compiles with both intel 18 and GCC 7 (although Intel emits a warning that I don't quite understand):
$ gfortran-mp-7 -std=f2003 -c -Wall -Wextra temp.f90
$ ifort -stand f03 -warn stderrors -c temp.f90
temp.f90(9): warning #6717: This name has not been given an explicit type. [MY_SPECIAL_NUMBER]
integer(kind(MY_SPECIAL_NUMBER)), intent(in) :: farg1
-------------------------^
It looks like the parser doesn't understand the definition of a type without the kind = in this circumstance for some reason. The following routines all compile with Intel and GCC, but the ones marked as failing do not compile in fparser2:
The following fails to compile with fparser2 (but it works correctly with intel and gfortran):
Error:
The module compiles with both intel 18 and GCC 7 (although Intel emits a warning that I don't quite understand):
It looks like the parser doesn't understand the definition of a type without the
kind =
in this circumstance for some reason. The following routines all compile with Intel and GCC, but the ones marked as failing do not compile in fparser2: