Error Messages in the F Programming Language, II

David Epstein
Imagine1, Inc.
david@imagine1.com

David is one of the designers of the F programming language. He wrote the front-end of the F compiler in F. David is also the project editor of the proposed Part 3 of the Fortran standard regarding Conditional Compilation.

Part I of this article may be accessed here

The Set-Up

This is the second (and hopefully final) article in a series of articles about the error messages in the F compilers. The first article explained how a misspelling of the word ``integer'' is handled. As a freshman, I had a punchcard that looked like ``intger i'' and it took a frustrating twenty-four hours to figure it out. In this article, instead of declaring success against the off-by-one syntax error, I describe this month's humbling experience--a test case that led to the dreaded uninformative message ``syntax error'' in today's F compilers.

With many hundreds of specific error messages designed to tell the student exactly what to change for a successful compilation, Imagine1 has been quite pleased with the results reported from colleges teaching with the F programming language compilers. My confidence that no student shall suffer through the painful deciphering of a vague error message like ``syntax error'' was partially shattered, however, in a recent report from Bob Hancock from Orange Coast College:

``... Syntax errors are identified, pointed to, and usually explained correctly. There is still the good old ``Syntax Error''-- but at least it is pointing to the wayward line.''

For the entire report, see the file


orange.htm

This I found hard to believe as I have never come across ``syntax error'' while writing F code, and found it extremely difficult to construct a test case that results in such a message. I know that ``syntax error'' is possible, as some scenarios in the compiler were too difficult to report anything concise without risking the possibility of being wrong. It simply seemed that these few cases were not likely to surface.

Reality

While reviewing the upcoming Programming in F by Miles Ellis and Ivor Philips (Addison-Wesley-Longman), I decided to see how the F compiler did on exercise 2.2 (included below with permission of the authors). Practically every line in this exercise has a syntax error. It is presented as:

2.2 The following simple program contains a number of errors. Identify them and produce a corrected version.

        program exercise 2.2
         real : number
         ! This program contains a number of errors &
           is not a good example of F at all!
           print *,"This &             ! Trailing
                    is a silly         ! comments!
                    program
           print *, "type a number"
           read *, "number"
           print *,"thank you. &
                    Your number was" number
        end exercise

One can only assume that this complete disrespect for syntax rules is either a contrived example from a hideous professor, or an actual example from a troubled, absolute beginning student.

Debugging?

What follows is a series of error messages from the F compiler and the potential responses from a soon-to-be-waiting-on-tables student (I worked at McDonald's during high school, so I'm allowed to say this). The responses assumes this student did not remember to bring the lecture notes or the textbook to the computer lab; a safe assumption given the example of their code.

[Note that the error messages will be the same on the PowerPC Macintosh, PC Linux and Unix as they are on Windows 95/NT (our best seller). The difference is that the student using the F_world tutor IDE on Windows is asked to ``Press Enter to continue'' after each error. Below, I put a blank line after each error to represent the pause between errors.]

Initial Run
program exercise 2.2
 real : number
 ! This program contains a number of errors &
   is not a good example of F at all!
!  ^^
!ERROR (#13121) on line number: 4 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is not recognized.  The first word usually categorizes  !!
!a statement and this first word is not recognized as a word that can   !!
!start a statement.                                                     !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   print *,"This &             ! Trailing
            is a silly         ! comments!
!           ^^
!ERROR (#13121) on line number: 6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is not recognized.  The first word usually categorizes  !!
!a statement and this first word is not recognized as a word that can   !!
!start a statement.                                                     !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            program
   print *, "type a number"
   read *, "number"
   print *,"thank you. &
            Your number was" number
!           ^--^
!ERROR (#13121) on line number: 11 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is not recognized.  The first word usually categorizes  !!
!a statement and this first word is not recognized as a word that can   !!
!start a statement.                                                     !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!..............
end exercise
!----------!
!ERROR (#15353) on line number: 12 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!An ENDMODULE stmt or ENDPROGRAM stmt is expected.                      !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Did not find a ENDMODULE stmt or a ENDPROGRAM stmt.
Initial Run Summary

It appears that the F compiler has prioritized statement recognition, particularly the ending statement, over syntax errors within statements. Who's to say if this is bad or good? (If you are happy with the results from your Fortran compiler on this example, please send them to me.) From here, it is anybody's guess what this student would do.

Suppose the student is in a lab and bothers the neighbor programmer who glances at the screen and says, ``You need to start comments with an exclamation mark (!) and strings with a double quote (")''. Our student adds a ! and two "s. Also, the final error seems easy enough, so ``end'' is made ``endprogram''.

Second Run
program exercise 2.2
!                ^
!ERROR (#10010) on line number: 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is suppose to end before here.                          !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 real : number
!     ^
!ERROR (#95158) on line number: 2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!Expecting a double colon for this declaration stmt.                    !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 ! This program contains a number of errors &
 ! is not a good example of F at all!
   print *,"This &              ! Trailing
!          ^-----------------------------^
!ERROR (#50969) on line number: 5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This string must be completed before the end of the line.              !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            "is a silly"        ! comments!
!           ^----------^
!ERROR (#13121) on line number: 6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is not recognized.  The first word usually categorizes  !!
!a statement and this first word is not recognized as a word that can   !!
!start a statement.                                                     !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            program
!           ^-----^
!ERROR (#12323) on line number: 7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This stmt does not belong with the action stmts.                       !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   print *, "type a number"
   read *, "number"
!          ^------^
!ERROR (#81777) on line number: 9 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!The EXPR that ends here is not a valid STOR.                           !!
!A STOR must be a valid left-hand-side to be stored into.               !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   print *,"thank you." &
           "Your number was" number
!                            ^----^
!ERROR (#60200) on line number: 10 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This name is not known.  It has not been seen before this point.       !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

endprogram exercise
Second Run Summary

There are many fantastic ideas here in the error messages. For example, BNF terms EXPR and STOR are used in error #81777. What makes this nice is that F_world uses these sorts of BNF terms in the tutor and on-line references. On the other hand, we can claim that this is AWFUL. This poor student fixed a couple of errors, and now has no less than seven errors reported! I quite expect that this course and potentially computers as a whole will be dropped forever.

To continue this article anyway, let's assume this student is wise enough not to sit on the corner, giving the opportunity to lean over and ask the other neighboring student for some help. As each error is shown, the neighbor points to the screen and gives some guidance. For example, ``You cannot put a blank in a name'', for the first error.

In F_world, these errors cannot be fixed on the fly, so the student attempts to remember the advice, write down a few notes, and give it another try. Here is a somewhat optimistic guess at the result. [Note that the student removed the blank from the name on the first line. Also, error #81777 was not addressed as it was hoped the double colon fix would do the trick.]

Third Run
program exercise2.2
!                ^
!ERROR (#10010) on line number: 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is suppose to end before here.                          !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 real :: number
 ! This program contains a number of errors &
 ! is not a good example of F at all!
   print *,"This" &              ! Trailing
            "is a silly"        ! comments!
            "program"
!           ^-------^
!ERROR (#13121) on line number: 7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This statement is not recognized.  The first word usually categorizes  !!
!a statement and this first word is not recognized as a word that can   !!
!start a statement.                                                     !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   print *, "type a number"
   read *, "number"
!          ^------^
!ERROR (#81777) on line number: 9 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!The EXPR that ends here is not a valid STOR.                           !!
!A STOR must be a valid left-hand-side to be stored into.               !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   print *,"thank you." &
           "Your number was" number
endprogram exercise
!          ^------^
!ERROR (#11050) on line number: 12 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!stmt syntax:  endprogram NAME                                          !!
!                         ^--^ mismatch                                 !!
!This name is not the same name given for this program.                 !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Third Run Summary

The final message deserves some attention. The idea was to show, as visually as possible, what the error is. Actually reading of the error message becomes less likely as frustration grows. As well, messages with this style are easier to translate to languages other than English. Many of the error messages that F reports are of this style; it just turns out that this is the only ``stmt syntax:'' error in this example.

For the final run, we give the student the fix on the first line, a well-placed ampersand(&) and the correct READ stmt.

Fourth Run
program exercise
 real :: number
 ! This program contains a number of errors &
 ! is not a good example of F at all!
   print *,"This" &              ! Trailing
            "is a silly" &       ! comments!
            "program"
!ERROR on line number: 6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!syntax error                                                           !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   print *, "type a number"
   read *, number
   print *,"thank you." &
           "Your number was" number
!ERROR on line number: 10 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!syntax error                                                           !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

endprogram exercise
Forth Run Summary

My worst nightmare! After all that work, the student is left high-and-dry with the default message. Finally, unless the student has become curious or is extra patient, it's back to underwater basketweaving or some form of art other than computers!

Post Mortem

This experience, as I mentioned, was a humbling one. Reliving it to write this article has helped only slightly. Why was the student not told simply to place a comma in the PRINT stmts? The answer lies in the fact that the computer (the compiler) is not smart enough to ``see'' what we can see ... or is it? It turns out that a concatenation (//) could be the missing characters, not necessarily a comma. Given that operators can be overloaded in Fortran and F, a plus (+) could be the missing characters, not to mention a potentially unlimited number of possibilities.

Conclusion

It's not clear that the readers of the Fortran Forum are college or high school professors. For those of you that are, it's likely that you are now teaching C, C++ or Java instead of Fortran. Worth mentioning, however, is that professional programmers are not hurt by the specific error messages provided by F. Quite the contrary, being told specifically where and what the error is (most of the time) allows one to focus on solving the initial problem instead of being diverted to referencing potential syntax from a textbook. Unfortunately, having a language syntax half the size of Fortran's does not prevent the occasional unhelpful message ``syntax error''.