Re: Complex Constants in Fortran

jlg@cochiti.lanl.gov (J. Giles)
Mon, 4 Jan 1993 19:31:59 GMT

          From comp.compilers

Related articles
Complex Constants in Fortran uesu03@giac1.oscs.montana.edu (1993-01-02)
Re: Complex Constants in Fortran burley@apple-gunkies.gnu.ai.mit.edu (1993-01-04)
Re: Complex Constants in Fortran jlg@cochiti.lanl.gov (1993-01-04)
| List of all articles for this month |
Newsgroups: comp.compilers
From: jlg@cochiti.lanl.gov (J. Giles)
Organization: Los Alamos National Laboratory
Date: Mon, 4 Jan 1993 19:31:59 GMT
References: 93-01-003
Keywords: Fortran, parse

uesu03@giac1.oscs.montana.edu (Lou Glassy) writes:
| [in this construct]
|> X = FU ( 1.0, 3.4 ) ! has to be a function call, but
|> ! the scanner doesn't know that...
|
| [should the scanner return (1.0,3.4) as a constant, or should it
| instead return separate ( 1.0 , 3.4 ) tokens?]


The question addresses the distinction between a literal and a
constructor. A literal is a lexical token which is recognized by its form
as a single data value. A constructor is a syntactic form that builds
data objects from simpler ones. A complex constant in Fortran is usually
treated as a constructor. It is recognized as a parenthesized list
containing two elements and not prefixed by an array or function name. If
Fortran had been designed with the intent to be extensible later to allow
derived types (records, structs, whatever you prefer to call them), the
design would probably have given the complex constructor a name:


            c = COMPLEX(1.2, 3.4)


instead of just a list syntax, since you can only have *one* type whose
constructor is simply a list (though obviously quaternions could have a
similar constructor with four elements, octonions with eight, etc.).
Fortran was, alas, designed before such ideas were seriously contemplated
for actual programming languages (though certainly the abstract idea of
such derived types was probably present even then).
--
J. Giles
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.