Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!ut-sally!utastro!anita From: anita@utastro.UUCP (Anita Cochran) Newsgroups: comp.lang.fortran Subject: Re: "Interesting" error interpretation by f77. Message-ID: <2131@utastro.UUCP> Date: Thu, 17-Sep-87 11:36:56 EDT Article-I.D.: utastro.2131 Posted: Thu Sep 17 11:36:56 1987 Date-Received: Sat, 19-Sep-87 14:57:29 EDT References: <5117@jade.BERKELEY.EDU> Organization: U. Texas, Astronomy, Austin, TX Lines: 52 Keywords: FORTRAN parsing, error interpretation. Summary: no bug In article <5117@jade.BERKELEY.EDU>, lagache@violet.berkeley.edu (Edouard Lagache) writes: > In our introductory FORTRAN classes we have just switched to the > f77 compiler. Our first assignment involves students deliberately > inserting errors in the code in order to gain familiarity with the > compiler's characteristics. This is fine when the teaching staff > understands the errors, but a few days ago I hit an error that I > couldn't! > PROGRAM PRACT > REAL NUM1,NUM2,SUM > WRITE(*,*) 'Enter two numbers to be added to each other:' > READ(*,*) NUM1, NUM2 > SUM = NUM1 + NUM2 > WRITE(*,*) > WRITE(*,*) 'The sum of the two numbers is : ',SUM > STOP > END > %f77 practice.f > practice.f: > MAIN pract: > Error on line 4 of practice.f: syntax error > Warning on line 9 of practice.f: local variable num2 never used > Warning on line 9 of practice.f: local variable read never used > ^^^^ > ----------------------------------------------> ???? <--------- > My question to the SIG is does this sort of interpretation > represent a bug? I am no expert on FORTRAN compiler design, but > given this sort of funny business, I wonder what sort of weird > code would be passed on as correct!?! > Edouard Lagache This is not the result of a bug in the compiler but a true error by you. On line 5 (which is what actually caused the error), you have the variable "sum" too far to the left (presummably your on purpose error) and the "U" is in the continuation statement column. Thus, the compiler interprets both lines 4 and 5 together as line 4. It scans along until it hits the equal and decides everything prior to that is the left hand side of the equation. The first problem it has, is that you have a "statement number" (s) in the middle of the equation, and an illegal statement number at that. Even if it discards that, it now has read(*,*)num1,num2m as the left hand side of the equation. It cannot figure out what to do with this. The only thing it can decide is that read must be an undeclared 2 dimensional array. Thus, it throws up its (figurative) hands and ignores statement 4/5 leading to the further errors. -- Anita Cochran uucp: {noao, ut-sally, ut-ngp}!utastro!anita arpa: anita@astro.as.utexas.edu snail: Astronomy Dept., The Univ. of Texas, Austin, TX, 78712 at&t: (512) 471-1471