Readers’ FeedbackIf you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.
Automatic Syntax Checking
I read in a recent "Readers' Feedback" column that some versions of BASIC have what is called instant syntax checking. I own a Commodore 64, which does not have this feature. Is there any way to reprogram the Kernal so that it checks program lines for syntax errors as they are entered?
- Leon Ingleright
The October 1985 issue of COMPUTE!’s GAZETTE contains a Commodore 64 program called "Automatic Syntax Checker," which does exactly what you're looking for. That program is far too long to include in this column, and, unfortunately, the October 1985 issue is out of print. However, you can probably find a copy through a local Commodore user group or public library. If you type in the program from that issue, note that the correct MIX starting and ending addresses for Automatic Syntax Checker are 2049 and 3008, respectively. Since the Commodore 64's BASIC doesn't check for errors when you type in a line (only when it runs the program), you must reprogram BASIC as well as part of the Kernal operating system to add syntax checking. (Portions of a few BASIC statements are found in the 64's Kernal ROM, not BASIC ROM.) When it sets up, Automatic Syntax Checker copies BASIC and the Kernal from ROM into underlying RAM, modifies them extensively, and wedges itself into BASIC'S main loop. When you type a program line, the syntax checker turns off the computer's ROM and uses the modified BASIC and Kernal. The modified BASIC performs a phantom execution of the line which includes BASIC'S normal error checking, but stops short of actually completing the commands in that line, If the line doesn't contain any errors, it's added to the program as usual. Otherwise, the Automatic Syntax Checker prints the same error message you would see if you ran a program containing the erroneous line. After it processes the new line, the program turns the ROM back on for normal operation. Syntax checking at the time of entry poses some interesting problems. For the most part, you can use the same checks that BASIC itself performs when it executes the line in a program. The checker must look for misspelled keywords, missing or extra parentheses, misplaced punctuation, and so forth. However, as the name implies, an automatic checker can only catch errors of syntax. That is, it checks the line to see whether it contains meaningful BASIC statements. There are many other runtime errors which can't be detected at the time of entry. For instance, if you enter the line 1000 NEXT, there's no rational way for a checker to tell whether the NEXT will be matched correctly with a FOR when you finish typing the program. A logic error of this type can only be found by running the complete program. A second class of errors results from some condition external to the program, such as whether a printer is turned on or a disk is in the drive. A checker can evaluate statements such as OPEN or PRINT # for correct syntax, but it has no way to look into the future to determine whether those statements will execute correctly when you run the program.