Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Syntax errors for valid Fortran #5

Description

@melven

The Fortran grammar specification has several issues:

  1. Kind-specifiers for constants are not supported, e.g. 1.0_8 or 1.0_myKindParameter
  2. kind is not only a keyword inside a declaration, but also an intrinsic function, e.g. i = kind(1.)
  3. Fortran explicitly allows reusing keywords of the language. Keywords are not reserved, you can for example name a variable value or kind. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions