kaby76 / fortran

MIT License
0 stars 0 forks source link

Lexer issues #2

Open kaby76 opened 3 weeks ago

kaby76 commented 3 weeks ago

The FortranLexer.g4 was copied from https://github.com/AkhilAkkapelli/Fortran2023Grammar/blob/553123a023f70e9a524e2a4036be128978834c42/Fortran2023Lexer.g4. But, it contains many problems.

Comments

The 2023 Spec clearly states:

The character “!” initiates a comment except where it appears within a character context. The comment extends to the end of the line. If the first nonblank character on a line is an “!”, the line is a comment line. Lines containing only blanks or containing no characters are also comment lines. Comments may appear anywhere in a program unit and may precede the first statement of a program unit or follow the last statement of a program unit. Comments have no effect on the interpretation of the program unit.

INCLUDE

=>

ivan-pi commented 2 weeks ago

In practice include is handled by the preprocessor (after the C-like preprocessor has been applied). See for instance here: https://flang.llvm.org/docs/Preprocessing.html#in-short-a-fortran-preprocessor-should-work-as-if

Saving files with a capitalized extension, e.g. .F or .F90, will automatically invoke the C-like Fortran preprocessor that responds to statements like #include, #define and others. On the other hand include always get processed, because it is a Fortran-specific mechanism.