Path: utzoo!utgpu!attcan!uunet!husc6!cs.utexas.edu!oakhill!steve From: steve@oakhill.UUCP (steve) Newsgroups: comp.lang.fortran Subject: Re: Is DO WHILE difficult? Summary: Actually only one is hard. Message-ID: <1643@devsys.oakhill.UUCP> Date: 7 Nov 88 19:56:26 GMT References: <75326@sun.uucp> <75328@sun.uucp> <604@quintus.UUCP> <11222@cgl.ucsf.EDU> Organization: Motorola Inc. Austin, Tx Lines: 58 In article <11222@cgl.ucsf.EDU>, seibel@cgl.ucsf.edu (George Seibel) writes: > In article <2848@ima.ima.isc.com> johnl@ima.UUCP (John R. Levine) writes: > to apparently simple fortran extensions/features as being either > difficult or (equivalently) expensive to implement. I'm not a > compiler writer, but for the life of me I can't see how some features > like blank line == comment, or "!" == inline comment, or the > implementation of a DO WHILE are all that tough! Wouldn't these > all be performed in a modern compiler's front end, i.e. the "easy" part? > Am I just being naive about the complexity of these problems or > what? If some of you compiler writers out there would fill me in on > this, I'd appreciate it. > And while you're at it, could anyone tell me if there are any > important compilers out there that actually insist on no more than > six character identifiers? I'm thinking of allowing myself eight, > but I rather much like portable code. > > George Seibel, UCSF Having written from scratch the total front end of a FORTRAN compiler, I think I can justify myself as experienced in the problem. The first problem - blank lines as comments, is a pain. The real pain is actually the archaic method of lexical analysis required in a FORTRAN compiler. Lexical analysis tends to be two parts, reading in a complete statement, and deciding what that statement is. Blank lines comments only effects the first of these (Second is by far the harder, but can be done quickly by some very nasty tricks). The real problem in the first part is deciding when you read the end of an actual line. Since you do not know wheather you have a contiuation without reading the first six characters of the next line and that comments can occur between contiuations, one must read all of the comments that follows a line in order to decide if you have finished the statement. Then you must store the first six characters of the next line if they are significant. In other words you can haveee almost infinite amount of lookahead before finishing reading a statement. The biggest headache actually is putting errors out in an appropriate place. If you have seen FORTRAN compiliers where the errors appear after the comments after the line in question, you now know why, and you know they did not want to bother with this question. Also be aware that blanks a pulled out of the FORTRAN (The varaibles A BAD MU and ABADMU are the same). End of line comments suffer the same problem. The second question - DO WHILE - is actually very easy. The compiler we wrote contained the DO WHILE. If you are doing a regular DO statement, DO WHILE is very easy, with very little overhead in the parser or in the sematic anaylsis (sematic analysis for DOWHILE and DO UNTIL is actually easier than that of DO). enough from this mooncalf - Steven ---------------------------------------------------------------------------- These opinions aren't necessarily Motorola's or Remora's - but I'd like to think we share some common views. ---------------------------------------------------------------------------- Steven R Weintraub cs.utexas.edu!oakhill!devsys!steve Motorola Inc. Austin, Texas (512) 440-3023 (office) (512) 453-6953 (home) ----------------------------------------------------------------------------