Looking for parsers for fortran77

Hello to all.

For my internship, I am looking for a parser able to parse fortran77 and to provide me with an AST.

Thank you for your suggestions of parser fulfilling this requirement.
I found this fortran-src parser which does about what I want but it is in haskell (unknown language for me).
I would like to know if there are others to compare them.

As a reminder, I am new with Fortran too.

Check out LLVM flang: Welcome to Flang’s documentation — The Flang Compiler

Maybe not helpful, but a recently announced implementation of a Flex/Bison parser for Fortran 66 can be found here: GitHub - FrankLhota56/fortran66-flex: Flex grammar for Fortran 66. It shouldn’t be too hard to make it work for Fortran 77.

LFortran has a FORTRAN 77 parser GitHub - lfortran/lfortran: Official main repository for LFortran and you can get the AST or ASR quite easily with --show-ast and --show-asr.

As @kargl said we need more info. What do you plan to do with the AST? What is the end objective? If you want to use an existing parser get the AST and then do stuff with it I suspect it won’t be simple. There is no standard AST format so you’ll need to write a lot of glue code between the parser and your application.

1 Like

As @gnikit said, LFortran can parse F77 and provide you with a nice AST. Let me know what you need, or if you discover any bugs and we are happy to fix them.

Hello all: @gak @gnikit @certik @kargl
Thank you all for your answers, which I will be sure to watch carefully. I am sick right now and am taking time to recover and will see all your suggestions.

@gnikit , @certik For Lfortran, I already tested it around April and at that time, it didn’t allow me to get ASTs from the fortran77 files I submitted to it. I guess it has improved since then and is now better at handling fortran77. I will try again.

@kargl @gnikit @certik My goal is to be able to develop a tool that can analyze and then migrate fortran77 code to more modern fortran. So I need to get the ASTs to do my processing.

1 Like

Yes, we didn’t have a dedicated fixed-form parser back then. We have one now, it can parse all of SciPy for example. If it fails for your code, please report a bug and we’ll fix it.