Metamodel for fortran 2003 and higher

Hello to all,

I want to build a metamodel for fortran 2003 and higher.

I only want to model high level concepts (i.e. not at instruction level, for now). I have this diagram for now.

Am I missing something?
Any suggestions for improvement?

Can this metamodel (if correct) work for Fortran77 (I guess not, as there were no modules and I don’t have the blockdata here).

For Fortran77 something like this:

all suggestions are welcome.

Thank you in advance.

4 Likes

This is neat. Good job. A few comments.

  • For procedures, they are called arguments, not parameters.
  • You should also include submodules.
  • For types of variables, they are either intrinsic or derived (not necessarily user defined, as there are some derived types defined in the intrinsic module iso_fortran_env).
  • You many want to include named constants alongside variables.
  • The Fortran Standard says nothing about files. I understand include doesn’t make a whole lot of sense without them, and 99+% of the time the source code is in files.

Keep up the good work. This could be quite valuable learning material.

Thank you for the encouraging feedback.

  • I agree, they are not parameters but rather arguments.

  • If I understand correctly, a submodule allows you to implement a module? I followed your youtube channel on the circle module (in tdd) to learn modern fortran. I work on fortran code but I don’t use fortran so I only have the basics.

  • okay I’ll take that into account

  • I will add them

  • I didn’t understand, include is no longer supported in modern fortran ? which is understandable with the use of modules.

and thanks again and if you have any other ideas or suggestions, don’t hesitate.

It is the other way around. Modern fortran does support include, but f77 and earlier did not. Many f77 compilers supported include as an extension, but it was not part of the standard language. Include is problematic because, although it is part of the language, the actual file names are dependent on the OS and file system conventions. Specifically, are directories denoted with slashes or colons or backslashes, are the file names folded to upper or lower case, is the filesystem case sensitive or case insensitive, and so on.

A submodule is where you can put (hidden) implementations of procedures declared in a module.

It’s still “supported” (i.e. the statement is still part of the standard), but see the relevant text from the standard

Additional text can be incorporated into the source text of a program unit during processing. This is accomplished with the INCLUDE line, which has the form
INCLUDE char-literal-constant

The interpretation of char-literal-constant is processor dependent.

It’s typically interpreted as the name of a file, but as I said, the Fortran standard doesn’t say that Fortran source code is necessarily contained in files.

I update the metamodel and now I have this one:

What do you think? it’s more like Fortran2003?

For Fortran77:

  • can a programUnit contain other programUnits?

  • can a blockdata contain a body (instructions like accesses )?

  • any feedback on the fortran77 metamodel?

Okay thanks, I added it.

So if I understand correctly, I don’t need this “include” link, I can delete it (by the way, it can be replaced, and often is in the source I have to process, by the #include directive)

I would say no.

The closest to this idea in f77 is a statement function, which is somewhere in between the concept of a contained procedure and a macro expansion.

Another possibility is a routine with entry points. In this case the entry points can be called from outside the procedure, but they cannot be called from within the procedure. Before modules were introduced in f90, entry points were the only way to share data that is local within the procedure among the entry points.

Entry points were also sometimes used to simply alias two external names to the same procedure code. That is now done typically by renaming the entity within the USE statement.

* can a blockdata contain a body (instructions like accesses )?

No, a block data contains only local variable and parameter declarations and data statements. Block data is required any time common block variables are initialized. Some f77 compilers allowed initialization of common block variables in other places, such as, for example, a main program, but I don’t think that was ever allowed by any fortran standard.

Thank you for this useful comment.

This is also my understanding.

I have updated both metamodels accordingly to take into account your feedback.

uNouss’s version of Feb 16 still says Parameter where it should say Argument.

Oh yes.

Here are the latest versions of two metamodels: