home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / compiler / 2076 < prev    next >
Encoding:
Text File  |  1993-01-02  |  2.3 KB  |  65 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!spool.mu.edu!think.com!spdcc!iecc!compilers-sender
  3. From: uesu03@giac1.oscs.montana.edu (Lou Glassy)
  4. Subject: Complex Constants in Fortran
  5. Reply-To: uesu03@giac1.oscs.montana.edu (Lou Glassy)
  6. Organization: Compilers Central
  7. Date: Sat, 2 Jan 1993 00:31:45 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <93-01-003@comp.compilers>
  10. Keywords: Fortran, parse, question, comment
  11. Sender: compilers-sender@iecc.cambridge.ma.us
  12. Lines: 51
  13.  
  14. A question for those of you who have written Fortran compilers..
  15.  
  16. Does the scanner resolve complex constants in Fortran, or does 
  17. the parser?
  18.  
  19. Here's where the question arises.  Say you have a hunk of code like
  20. the following...
  21.  
  22.    X = FU ( 1.0, 3.4 )     ! has to be a function call, but
  23.                            ! the scanner doesn't know that...
  24.  
  25. I'd guess the scanner would return a stream of tokens like
  26.  
  27.    X      IDENTIFIER
  28.    =      ASSIGNMENT_OPERATOR
  29.    FU     IDENTIFIER
  30.    
  31. and now comes the part I'm curious about.  Should the scanner return
  32.  
  33.    (      LEFT_PAREN
  34.    1.0    REAL_CONSTANT
  35.    ,      COMMA
  36.    3.4    REAL_CONSTANT
  37.    )      RIGHT_PAREN
  38.  
  39.    or should the scanner return
  40.  
  41.    (1.0,3.4)   COMPLEX_CONSTANT
  42.  
  43.    ???
  44.  
  45. If I go the first route, then a COMPLEX_CONSTANT must be resolved (or
  46. 'constructed') by the parser -- which is no great disaster.  Conceptually,
  47. though, it seems that constants of any type should be resolvable by the
  48. scanner.  Is there not enough contextual information available to the
  49. scanner to do this?
  50.  
  51. Thanks in advance --
  52. --
  53. Lou Glassy (uesu03@giac1.oscs.montana.edu)
  54. [In INfort I constructed complex constants in the parser because it was
  55. easier to do that way, and while I was at it I allowed (exp,exp) as a general
  56. complex expression constructor.  It wouldn't have been very hard to do in
  57. the scanner; there are so many lexical hacks in parsing Fortran already that
  58. telling whether a complex constant is allowed is easy.  In the case above,
  59. the scanner had better return the list of primitive tokens unless you want to
  60. add a lot of extra glop to the parser to take complex constants apart in the
  61. places where they turn out to be pairs of procedure arguments. -John]
  62. -- 
  63. Send compilers articles to compilers@iecc.cambridge.ma.us or
  64. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  65.