Regarding main program structure


According to specification R1401, a Fortran main program must have an “end statement” whereas other parts are optional.

// R1401 main-program →

// [program-stmt] [specification-part] [execution-part]

// [internal-subprogram-part] end-program-stmt

Thus, the below case.f90 is a legitimate fortran program:

[user@localhost ~/F18]$ cat -n case.f90

1 end !only end-program-stmt is specified.

[user@localhost ~/F18]$

The implementation of MainProgram structure (“lib/parser/parse-tree.h”) shows that only “ProgramStmt” and “InternalSubprogramPart” are optional.

struct MainProgram {


std::tuple<std::optional<Statement>, SpecificationPart,

ExecutionPart, std::optional,




Why “SpecificationPart” and “ExecutionPart” are not implemented as optional (std::optional), while these are optional similar to “ProgramStmt” and “InternalSubprogramPart”?

Thanks in anticipation.

SpecificationPart is made up of lists of other nodes. When the specification-part of a program is absent, it is represented by a SpecificationPart containing only empty lists. So there is no need to make it optional. The same applies to ExecutionPart.