G95-XML provides a fortran parser based on the well known g95 ( by Andy Vaught, see g95 website ). The original g95 parser has been modified to output not only all the exact semantics of any Fortran 95 program in XML, but also the layout of the source code. G95-XML brings in the power of a real Fortran compiler for source code analysis.
The aim is to be able to analyse any Fortran code, and provide capabilities to inspect Fortran code, modify Fortran source code, generate new code, interface automatically with other languages, etc...
The XML output of the g95-xml parser, though describing very acurately Fortran code is pretty hard to deal with. I have written Perl scripts to handle its output and make something usable out of it.
The approach I used was to write scripts so that I could reproduce a compiling environment; therefore, g95-xml provides scripts named f95, ar, ld. All these Perl scripts behave like a Fortran compiler and associated binary management utilities.
For instance, parsing a Fortran source file named main.f90 is just the matter of typing ( assuming g95-xml's f95, ar, ld are in your PATH ):
$ f95 -c -html -keep-xml main.f90 $ ls -l main.* -rw-rw-r-- 1 phi001 phi001 50 avr 26 19:42 main.f90 -rw-r--r-- 1 phi001 phi001 24576 avr 26 19:49 main.o -rw-r--r-- 1 phi001 phi001 5075 avr 26 19:49 main.xml
The command we issued produced an XML file containing the full description of our source code, and a .o file which contains the table of global symbols of main.f90 and a frozen Perl structure which has been re-built from the XML.
The -html option was added to generate HTML code for this Fortran unit; it is embedded in the .o file.
Hence you see that you can parse your Fortran code using the Makefile ( or a more elaborate build system ) you have already written.
| big_integer_module.f95 | Source | XML | Browse |
| celf.f90 | Source | XML | Browse |
| gen_ll.f90 | Source | XML | Browse |
| integer_set.f90 | Source | XML | Browse |
| iso_varying_string.f95 | Source | XML | Browse |
| kiss.f90 | Source | XML | Browse |
| qsort_c.f95 | Source | XML | Browse |
| quick_sort1.f | Source | XML | Browse |
| quick_sort2.f | Source | XML | Browse |
| random1.f | Source | XML | Browse |
| random2.f | Source | XML | Browse |
| roman_numerals.f90 | Source | XML | Browse |
| unix_time.f | Source | XML | Browse |
Please note that the Apache+mod_perl browser is much more easier to use; its possible to browse executables and libraries as well. In fact, it is possible to configure Apache so that a particular handler takes care of some requests ( and let others to the standard Apache webserver ). I use this feature so that regular files and directories be served directly by Apache, and .exe, .o, .a files be processed by a dedicated handler.
You can download the howto here.
You can download the latest version of g95-xml here.
I would like to express my gratitude to Andy Vaught, who wrote a very nice piece of software and allowed everybody to use it and access its source code.