F2x
F2x copied to clipboard
Syntax errors for valid Fortran
The Fortran grammar specification has several issues:
- Kind-specifiers for constants are not supported, e.g.
1.0_8or1.0_myKindParameter -
kindis not only a keyword inside a declaration, but also an intrinsic function, e.g.i = kind(1.) - Fortran explicitly allows reusing keywords of the language. Keywords are not reserved, you can for example name a variable
valueorkind. The compiler only fails if the usage is ambigious.
Here is a valid Fortran file:
module test
implicit none
public
integer, parameter :: rk = kind(1.0)
real(kind=rk), parameter :: eps = epsilon(1._rk)
integer, parameter :: value = 10
end module test
And the respective errors I obtain:
> F2x -t @_bindc.f90.t -t @_ctypes.py.t test.f90
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home_local/zoel_ml/F2x/src/F2x/main.py", line 165, in main
src.parse()
File "/home_local/zoel_ml/F2x/src/F2x/source.py", line 180, in parse
self.tree = grammar.parse(self.source)
File "/home_local/zoel_ml/F2x/src/plyplus/plyplus.py", line 575, in parse
return self._grammar.parse(text)
File "/home_local/zoel_ml/F2x/src/plyplus/plyplus.py", line 716, in parse
raise ParseError('\n'.join(self.errors))
plyplus.plyplus.ParseError: Syntax error in input at 'kind' (type T_KIND) line 5 col 30
Syntax error in input at '_' (type T_UNDERSCORE) line 6 col 47
Syntax error in input at 'value' (type T_VALUE) line 7 col 25
Could not create parse tree!
I already fixed some minor other problems in this example, see the pull requests.