Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran numbers

Valued Contributor II

I have just been reading a book on FLEX and BISON, the book suggests that one form of Fortran numbers requires a very complex pattern spelt out above. 

The book is interesting. 

0 Kudos
4 Replies
Black Belt Retired Employee

Technically, that first [-+]? is not part of a number in Fortran. See here. But this is the same pattern used in many languages.


Valued Contributor II

For example, consider the surprisingly difficult job of writing a pattern to match Fortran-style numbers, which consist of an optional sign, a string of digits that may contain a decimal point, optionally an exponent that is the letter E, an optional sign, and a string of digits. A pattern for an optional sign and a string of digits is simple enough:


Levine's book on Flex and Bison discusses in some detail the issue of Fortran and other language numbers.  it is quite interesting, what is rather interesting is the ability to write simple programs using grammar rules rather than coding, the development of the rules to read all those numbers recently in a csv file brings to mind the horror's, but this is a bit simpler - pity we do not have this option in Fortran. 

/* even more like Unix wc */
%option noyywrap
int chars = 0;
int words = 0;
int lines = 0;


[a-zA-Z]+  { words++; chars += strlen(yytext); }
\n         { chars++; lines++; }
.          { chars++; }


  It is all just learning and fun. 

Honored Contributor II

BNF metasyntax used by the Fortran standard is, in the instance of a REAL literal constant, helpful in understanding the pattern.

In Fortran, a different aspect of the above quoted pattern is the use of `D` to denote double precision.  This does get nonintuitive relative to any math instruction during one's education and it also gets in the way of electronic exchange of data with/from the Fortran processor 

Valued Contributor II

Interestingly the B in BNF is the developer of Fortran. A Bison and Flex for Fortran would be interesting.  But the syntax for Bison and Flex is obscure and the manuals all use the same samples from the original and they exactly repeat the instructions.  

Like all things improving one's knowledge helps with the Fortran.