[Top]
- [Next] - [Previous]The Annotated Karel Program
The following is a listing of the simulator's annotated Karel program for an incorrect version of the stair cleaning task. It illustrates the form of an annotated program file, but the spacing has been somewhat altered to allow for a better presentation in this users' manual.
Annotated Karel Program: Line BEGIN/END Numbers Nesting Program Text 1 BEGINNING-OF-PROGRAM 2 3 DEFINE-NEW-INSTRUCTION turnright AS 4 BEGIN 5 1 turnleft; 6 1 turnleft; 7 1 turnleft 8 END; 9 10 DEFINE-NEW-INSTRUCTION climb-stair AS 11 BEGIN 12 1 turnleft; 13 1 move; 14 1 turnroght ^ ***PROBLEM***
Lexical Error:
I'll assume that you misspelled: "turnright". You wrote: "turnroght".
The program continues...
14 1 turnroght; 15 1 move 16 END; 17 18 19 BEGINNING-OF-EXECUTION 20 1 climb-stair; 21 1 pickbeeper ^ ***PROBLEM*** 22 1 climb-stair
Syntax Error:
Instructions in a block must be separated by semicolons. This program also contains at least 1 misspelling(s). Program aborted; please revise and resubmit.
The line numbers in the program are used by Explain Mode and the Slow Speed in Monitor Mode to tell you information about your Karel program. For example, in Explain Mode the following explanation may appear:
Ready to execute the "turnleft" instruction (Line= 12).
The counting of BEGIN/END block nesting levels shows you which BEGINs match which ENDs. Every instruction between a BEGIN and END has a nesting level one higher than that of the enclosing BEGIN and END reserved words themselves. If you are having trouble matching BEGIN/END blocks, this is a good place to tart looking for a solution to your problem.
The simulator temporarily ignores misspellings of instruction names and reserved words. Each time it detects a spelling error, it prints an appropriate warning message in the program annotation and continues reading the program. But a program will not be executed by the simulator unless every word is spelled correctly. So if a program contains any spelling errors, you must correct all its misspelled words and then run the simulator again.
Finally, the simulator aborts after the first error that is not a simple misspelling. You should look at the program annotation, make corrections in your program, and then re-run the Karel simulator. To save time while you are correcting the simulator-spotted error, you should quickly review your entire program and check it for similar lexical or syntactic errors.
[Top]
- [Next] - [Previous]