[TUHS] > there is no way that FORTRAN can be described in any syntax

Paul Winalski paul.winalski at gmail.com
Tue Dec 4 06:10:32 AEST 2018

On 12/3/18, Ron Young <rly1 at embarqmail.com> wrote:
>   John Levine wrote a ftn77 subset parser using lex and yacc (the shar
>   file that I have is dated Nov 1988).
Just curious--what parts of Fortran 77 did he leave out?

Unfortunately the Fortran language was being developed at the same
time that Chomsky was first doing his research on formal grammars.
Languages such as Algol, C, PL/I, and Pascal were designed to be
easily split into a lexical regular grammar and a context-free grammar
(the lex/yacc paradigm).  Fortran has some nasty grammatical quirks
that make it a bear to parse--context-sensitive lexical analysis, for
example.  Given the string:


you don't know whether to lex it as:

    <identifier> DO10I
    <operator> =
    <integer constant> 1


    <keyword> DO
    <integer constant> 10
    <identifier> I
    <operator> =
    <integer constant> 1

until you see the comma.

Yes, full Fortran can be expressed in BNF and other formal syntax
mechanisms.  But I don't think you can use lex and yacc to generate a
compiler for it.

-Paul W.

More information about the TUHS mailing list