On 12/3/18, Ron Young <rly1(a)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:
DO10I=1,10
you don't know whether to lex it as:
<identifier> DO10I
<operator> =
<integer constant> 1
or:
<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.