Modern Fortran to C transpiler

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.

4 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.

4 Likes