[Top] - [Next] - [Previous]

Starting the Simulator

  1. Creating Files Containing Karel Programs
  2. Starting the Simulator
  3. Getting the Simulator to Read Karel's Program
  4. The Annotated Program File
  5. Getting the Simulator to Read the Initial Situation

This chapter presents a detailed protocol showing you how to start the Karel simulator and answer its opening questions. By closely following Chapters 2 through 5, you will be completely led through the simulation of one Karel program. You can simulate other programs by following these same instructions.

Creating Files Containing Karel Programs

Before running the simulator, you must have prepared a Karel program by using a text editor. The result of such an editing session is a file that contains your Karel program. A sample Karel program has been written (the stair cleaning program in Section 3.5 of KAREL the ROBOT), and it has been put in the file named STAIR.KRL on the simulator's diskette.

Starting the Simulator

To start the Karel simulator, respond to the > prompt by typing:

     >KAREL

The simulator will erase your screen and then print some information about where to find documentation about Karel; briefly skim this information. The following message will appear on the bottom line of your screen:

     To enter the simulator, press the RETURN key.*

After you have read this information and pressed the return key, the simulator will again erase your screen. It then will ask you to supply the name of the file in which your Karel program is located.

Getting the Simulator to Read Karel's Program

Now you are ready to tell the simulator which file contains your Karel program. You should answer this request by typing the name of your file, followed by pressing the return key. For our sample program, type the following response:

     Enter the name of the file containing Karel's Program:STAIR.KRL

If you accidentally mistype your file name and press return, the simulator will tell you that it cannot find a file with that name, and it will ask you again for the correct file name of your Karel program. This process will continue until you correctly enter the name of the file containing your Karel program.

The Annotated Program File

After you have successfully entered the name of the file containing your Karel program, the simulator will next ask you in which file to put its annotation of your program. The simulator's annotation of your program is just a copy of the program, augmented by line numbers, nested BEGIN/END block counting, and any indications of lexical or syntactic errors that the simulator discovers. While reading your program, the simulator will automatically write this annotated program file. For our sample program, you can answer this request by typing the following reply:

     Enter the name of the file to print the annotated program in:
     [SCREEN:]:STAIR.ANN

Now the simulator reads the program in file STAIR.KRL and writes what it reads into the file STAIR.ANN, along with any annotations. If the program contains any lexical or syntactic errors, they would be listed in STAIR.ANN along with the program. If any errors are present, after the file STAIR.ANN has been written, the simulator will print the following message on your screen:

          Program aborted; check annotated program for details.

In this case, look at the file STAIR.ANN for a further indication of what went wrong (you can TYPE the file on the screen or PRINT it on a printer). For more information about annotated programs, see the example and discussion in Chapter 9.

Another possible reply to the annotation request is to type SCREEN: instead of a file name (note that SCREEN: is also the default answer for this question). By replying with SCREEN: or just pressing return, the simulator will immediately print the annotated program on your screen.

There are both advantages and disadvantages to selecting the SCREEN: option. The advantage of this option is that you can see your program annotation immediately, without having to wait and see the annotated file. The disadvantage of using the SCREEN: option is that the annotation won't be written into a permanent file that you can print and review later. When asked for an annotation file, you should go ahead and reply with SCREEN: (or just press return and get the default answer); if you ever need a printed version of the annotated program, you can always quickly re-run the simulator, this time supplying a file name for the annotated program.

If the simulator finds any lexical or syntactic errors in your program, you would then edit your program (in our example, STAIR.KRL), correct the errors, and then start the simulator again. You would continue this correction process until no lexical or syntactic errors remain in your program.

Getting the Simulator to Read the Initial Situation

After reading a program containing neither lexical nor syntactic errors, the simulator will next ask whether you want to read Karel's initial situation from a file, or whether you want to build an initial situation. An initial situation for the stair cleaning task has been prepared and placed in the file STAIR.WOL on the simulator's diskette.

Because you need to use this initial situation, you should reply to the simulator's request by typing an R. (The World Builder is invoked by replying to this request with a B, and it is fully discussed in Chapter 7 of this manual.) Thus, you should type the following answer to the question asking where to get Karel's initial situation:

     Where to get initial situation([B]uild or [R]ead from a file)[B]:R

After doing so, the screen will once again be cleared, and the simulator will then ask you for the name of the file that contains Karel's initial situation. If your Karel program file name ended in .KRL, the default for this prompt will be the same file name before the ".", but ended in .WOL

     Enter the name of the file containing the initial situation:
     [STAIR.WOL]:

After you issue this command, the simulator will first read the file STAIR.WOL, which is a description of Karel's initial situation, and then it will draw Karel and his initial situation on your screen.

[Top] - [Next] - [Previous]