Using Codex I wrote a transpiler in Python from modern Fortran to C that handles much of the language. It could be used by people who prefer C code to Fortran code, be viewed as the front end of a WIP Fortran compiler, as f2c was for Fortran 77, and be used to learn what C equivalents are for common Fortran idioms. It post-processes generated C code to make it more readable. It handles fixed format Fortran code by first translating it to free format and handles common blocks by translating them to module variables. I want it to handle as much of Fortran 2023 (except coarrays) as possible to position it as a compiler front end. When finished with it I will branch from it to create a Fortran to C++ transpiler. The current transpiler handles some OO Fortran features, but more advanced features will be handled by the transpiler to C++. Please try it and report Fortran codes that fail to transpile. One example of its output is here, and many more are here.
6 Likes
If you want to join forces and improve our C and C++ generation from LFortran (we have both backends), that would be awesome. We can now do semantics for almost all Fortran, so just the backend has to be improved.
5 Likes
The project GitHub - abandoft/f2c: A modern, high-performance Fortran-to-C17 transpiler designed to generate portable, production-grade C code. · GitHub is implemented in C and translates more of modern Fortran to C than my transpiler does. It is more of a compiler in the spirit of the old f2c that translated from Fortran 77 to C. The generated C code is compilable but much longer than my translations and is not too readable.