Complex Constants in Fortran (Lou Glassy)
Sat, 2 Jan 1993 00:31:45 GMT

          From comp.compilers

Related articles
Complex Constants in Fortran (1993-01-02)
Re: Complex Constants in Fortran (1993-01-04)
Re: Complex Constants in Fortran (1993-01-04)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Lou Glassy)
Organization: Compilers Central
Date: Sat, 2 Jan 1993 00:31:45 GMT
Keywords: Fortran, parse, question, comment

A question for those of you who have written Fortran compilers..

Does the scanner resolve complex constants in Fortran, or does
the parser?

Here's where the question arises. Say you have a hunk of code like
the following...

      X = FU ( 1.0, 3.4 ) ! has to be a function call, but
                                                      ! the scanner doesn't know that...

I'd guess the scanner would return a stream of tokens like


and now comes the part I'm curious about. Should the scanner return

      ( LEFT_PAREN
      , COMMA

      or should the scanner return

      (1.0,3.4) COMPLEX_CONSTANT


If I go the first route, then a COMPLEX_CONSTANT must be resolved (or
'constructed') by the parser -- which is no great disaster. Conceptually,
though, it seems that constants of any type should be resolvable by the
scanner. Is there not enough contextual information available to the
scanner to do this?

Thanks in advance --
Lou Glassy (
[In INfort I constructed complex constants in the parser because it was
easier to do that way, and while I was at it I allowed (exp,exp) as a general
complex expression constructor. It wouldn't have been very hard to do in
the scanner; there are so many lexical hacks in parsing Fortran already that
telling whether a complex constant is allowed is easy. In the case above,
the scanner had better return the list of primitive tokens unless you want to
add a lot of extra glop to the parser to take complex constants apart in the
places where they turn out to be pairs of procedure arguments. -John]

Post a followup to this message

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