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 @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.
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.
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.
As mentioned in another thread, you might check out grammars-v4/fortran/fortran77 at 6d13b1068d0fc9eba30a3f291fe62026fbc71c2f · antlr/grammars-v4 · GitHub. This is an Antlr4 grammar, but I cannot attest to how good it is because there are only 5 files for testing. (A proper test-suite for f77 is needed.) I tested the grammar for ambiguity, and none is detected. Antlr4 parsers output CSTs, not ASTs. But, you can work with these easily in a visitor or listener tree walker. Or, if you want, use the Trash toolkit (GitHub - kaby76/Trash: Toolkit for grammars) to query parts of the tree using XPath expressions. E,g., find all variables assigned in an assignment statement.