# Fortran keyword categories

**URL:** <https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816>\
**Category:** Help\
**Created:** [September 9, 2021, 10:45pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816 "2021-09-09T22:45:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)\
**Post date:** [September 9, 2021, 10:45pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/1 "2021-09-09T22:45:45Z")

</div>

I have been recently trying to improve the Doxygen Fortran documenter (which could hopefully be merged with the Doxygen main branch in the future). Amidst the process, there was a need to modernize and update the list of all Fortran intrinsic keywords. But doing it cleanly requires a clean classification of Fortran keywords. The [Fortran WIKI page](http://fortranwiki.org/fortran/show/Keywords) provides a good chronological summary of intrinsic keywords. But it does not divide them based on their functionalities. For example, some keywords are attributes, while others could be intrinsic functions and instruction keywords. Are there any resources (or anyone) that can help further categorize the Fortran keywords based on their purposes and functionalities?

UPDATE: Further web search resulted in [this finding](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Introduction_to_Programming_using_Fortran_95_2003_2008_(Jorgensen)/27%3A_Appendix_7_-_Fortran_95_2003_2008_Keywords/27.01%3A_Fortran_95_2003_2008_Keywords). Still it does not look comprehensive.

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [September 10, 2021, 12:47am UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/2 "2021-09-10T00:47:43Z")

</div>

I don’t know if you can cleanly categorize the keywords that way. Most attributes can also be statements. `REAL` is both an intrinsic type and an intrinsic function. An easy way to build a list is to go through the index of the [standard](https://j3-fortran.org/doc/year/18/18-007r1.pdf) and look for entries in upper case that are followed by “statement”, “specifier”, etc…

---

<div class="post-metadata">

**Author:** ![nbehrnd](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nbehrnd](https://fortran-lang.discourse.group/u/nbehrnd)\
**Post date:** [September 6, 2024, 3:02pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/3 "2024-09-06T15:02:00Z")

</div>

@shahmoradi Did you visit the lexer for Fortran in pygments ([link](https://github.com/pygments/pygments/blob/master/pygments/lexers/fortran.py))? Their classification discerns statements, data types, operators, intrinsics, Booleans.

My knowledge about them is a bycatch of editing Bader’s draft about OOP in Fortran, specifically the different visual results of code blocks by Pandoc (version 3.3). The same block either labeled by `f90` for instance recognizes `CONTAINS` as a keyword, while the label `fortran` presumes `CONTAINS` were only a comment. This is because (as [outlined](https://github.com/jgm/pandoc/discussions/10099) by John MacFarlane) Pandoc uses two distinct lexers derived from the KDE project: a fence labeled with `fortran` presumes fixed-form [hence FORTRAN77, my addition], while a label `f90` presumes the free-form syntax [hence Fortran90+].

As test, I copy-pasted the snippet of the GitHub conversation into the discourse mask here. The present setup here does not yield a visible difference for either code fence label `f90`, or `fortran` (below with `f90`) while e.g., GitHub’s support seems incomplete.

```f90
TYPE :: sorted_list
   PRIVATE
   TYPE(sortable) :: data
   TYPE(sorted_list), POINTER :: next => null()
CONTAINS
   FINAL :: delete_sorted_list
END TYPE

```

An other resource may the [listings](https://ctan.org/pkg/listings) LaTeX usepackage (default dialect Fortran 95, additional dialects supported in the package’s version 1.10b are Fortran 03, 08, 18, 77, 90).

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [September 6, 2024, 5:58pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/4 "2024-09-06T17:58:48Z")

</div>

Without using a language parser is that possible? Fortran does not have  
reserved words except END in certain situations last I knew. It is common  
practice to avoid using them, and most context highlighters and editors  
do OK because of that but in the general case a lot of intrinsic names  
are used as variable names in a lot of code in particular. After all,  
this is a valid program:

```fortran
program contains
real :: character=kind(0.0)
character(len=*),parameter:: fmt='(*(g0))'
   write(*,fmt=fmt)real(100.0)
contains
function real(in) result(program)
type(real),intent(in) :: in
integer,parameter :: intent=kind(character)
real(kind=intent) :: program
result: associate (write=>program)
function: block
intrinsic :: real
real real
   write=real(in,kind=kind(in))**2
end block function
end associate result
end function real
end program contains

```

😆

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [September 6, 2024, 6:21pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/5 "2024-09-06T18:21:01Z")

</div>

I raise you a hundred against this one:

```fortran
program program

if = 0
then = 1
else = 2
endif = 3

if (if == then) then; then = else; else; else = endif; endif

read *, read
read = read + if + then

write = read + else + endif

print = read + write
print *, print
write (*, *) write

end program program

```

😆

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [September 6, 2024, 6:26pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/6 "2024-09-06T18:26:53Z")

</div>

a perfect poetic proof of point!

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [September 6, 2024, 8:27pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/7 "2024-09-06T20:27:19Z")

</div>

Many old Fortran codes defined a variable `sum`, making it impossible to use the Fortran 90 `sum` intrinsic function in the same program unit. Are there tools that warn about such masking and rename such variables?

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [September 6, 2024, 8:50pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/8 "2024-09-06T20:50:29Z")

</div>

You can rename the intrinsic with a module, or put an intrinsic declaration in a  
BLOCK construct. Not elegant but you can still get to the intrinsic. Would be nice if there were some other way like sum=intrinsic%sum(a,b,c) as that is an on-going issue as new intrinsics appear.

I know nvfortran warns about using intrinsic names; have seen other compilers warn about it. Do not know of a utility that does outside of the compilers myself.

Would be nice if there were some other way like sum=intrinsic%sum(a,b,c) as that is an on-going issue as new intrinsics appear. I am sure I use the variable names SORT and SPLIT which are intrinsic names as of f2023.

```fortran
module rename
implicit none
intrinsic sum
end module rename

program summit
use rename, only : summation=>sum
implicit none
real :: sum
   sum=0.0
   sum=sum + summation([1.0,2.0,3.0,4.0,5.0])
   write(*,*)sum
   associate (sum_=>sum); block
      intrinsic sum
      sum_=sum_+sum([10.0,20.0,30.0,40.0])
   endblock; endassociate
   write(*,*)sum
end program summit

```

How easy is it to use different highlighters with Doxygen? LFortran does highlighting and actually parses the code so when installed it might be a good candidate. If Doxygen could (does it?) read AST there are some interesting possibilities.

---

<div class="post-metadata">

**Author:** ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)\
**Post date:** [September 6, 2024, 10:41pm UTC](https://fortran-lang.discourse.group/t/fortran-keyword-categories/1816/9 "2024-09-06T22:41:13Z")

</div>

No, I did not. I ended up doing what `sblionel` suggested above your comment, which led to this repository: [GitHub - cdslaborg/FortranKeywords: This repository contains a complete list of all Fortran 2018 Standard keywords, including intrinsic procedure argument names (specifiers).](https://github.com/cdslaborg/FortranKeywords)  
Glancing through pigments, I do not think their keywords list is complete. If I had enough time, I’d certainly create a pull request to expand the `Pygments` lexer for Fortran.
