The Eli based Fortran 95 parser

Return to the Fortran tools home page

The main topic of information on this page is my Eli based Fortran 95 parser, but this page provides additional information on my Eli based Fortran 95 semantics analyzer.

Fortran 95 Parser

The parser is currently being treated as having a minimally copyrighted document, i.e., use at your own risk and a request for credit if the document is used directly.

This parser addresses the Fortran 95 version of the various Fortran Standards . Those interested in parsing Fortran 77 should seek one of the simpler tools given on my other Fortran tools page. It is is based on the Fortran 77 and Fortran 90 parsers of William Waite, of the University of Colorado. All three parsers are implemented using the Eli Compiler Generator system, which requires LALR(1) grammars. Waite's parsers are given as examples in the online documentation for Eli. The three parsers all rely on Waite's Fortran lexical analyzer which is also given as an example in the online documentation.

Waite's grammar makes excellent use of the literate programming capabilities of Eli. It combines the Fortran 77 and Fortran 90 analyses into one document, which highlights Fortran 90's additions. In addition to the usual Fortran constructs that have to be recognized semantically, e.g., statement functions and DO loops, Waite's grammar deliberately accepts other illegal constructs, e.g., statements out of order, in order to allow better error reporting. In order to simplify the analysis, many of the productions, particularly those that are used in only one context, are chain rule eliminated.

The Fortran 95 parser differs from that of Waite in several respects. Obviously it includes the additions and deletions Fortran 95 made to Fortran 90. In addition, Waite's attempt to combine the Fortran 77 and Fortran 90 analyses into one document means that the Fortran 90 grammar does not have the same order as that of the standard and some of the terminology is closer to that of the Fortran 77 standard than to the Fortran 90 standard. This makes it more difficult to verify that the Fortran 90 grammar is correct. The Fortran 95 grammar more closely follows the current standard's grammar and terminology. Still the language described by the grammar is sufficiently complicated that I consider it likely that problems remain. Finally, Waite had not attempted to use his syntax as input to a Fortran 90 semantics analyzer so that the grammar is not optimized for Fortran 90 semantics analysis. I have started work on a Fortran 95 semantics analyzer, which has suggested some changes in the grammar, particularly the identification of semantically equivalent grammar symbols.

Eli allows the presentation of the grammar in several forms. For interested parties the following links are available:

No attempt is made to provide the grammar in the TexInfo form allowed by Eli. I may eventually download the C code that Eli's parser generator generates from the grammar. Until then it will be provided to interested parties on request. Note the grammar assumes the availability of Waite's lexical analyzer for Fortran.

The grammar has been tested on a moderately large test suite, about 3.5 Mbytes of files. No attempt has been made to determine what fraction of those files is code and what fraction is comments. No attempt has been made to use those files to test the ability to find and report erroneous constructs. Instead the components are selected to test the analyzer's ability at parsing correct code without reporting spurious errors. The test suite was selected as follows:

My additions to Waite's suite have deliberately emphasized character handling, as a particularly complicated aspect of the language. Because only the flagged portion of the code was examined in detail, and the grammar was deliberately designed to accept a superset of the Fortran language, it is possible that some syntactically incorrect code is included in the suite. Note that so far I have only one test code which includes the newer F95 constructs, the latest version of the ISO Varying String Module.

The test suite is not made available on the net at this time as it exceeds the AOL limits on cost free storage. Interested parties can contact me using the comments link at the bottom of the page.

Fortran 95 Semantics Analysis

In addition to his parsers Waite has developed a semantics analysis for Fortran 77. I have started a semantics analysis for Fortran 95, based on Waite's work, but it is not yet ready for public viewing. It's completion will wait until effects of repetitive strain on my trick shoulder are gone. At that time it will be essentially Waite's Fortran 77 semantics analysis extended to comparable Fortran 90 productions. It will lack many analyses specific to Fortran 90/95 productions, e.g., modules and interfaces, and the documentation will roughly follow Waite's sequence, which is based on the Fortran 77 standard and not later standards. I then hope to go through the Fortran 95 standard from the beginning, moving constructs to match their appearance in the standard, and completing other aspects of the semantic analysis required by the standard as they are encountered. It is possible that I will combine the syntactical analysis and semantic analysis into one document at that time.

I have not yet decided what restrictions to place on the semantics analysis. Because it will involve more effort, and is probably more useful to people, I will probably want a more restrictive license to protect it better. I am considering the standard GNU general public licence or the GNU library general public license.

Links

Links within the page:

Return to the Fortran tools home page



Comments and questions to wclodius@aol.com

W.B. Clodius, wclodius@aol.com, Revised 1999-12-03