home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_100
/
139_01
/
uguide.doc
< prev
next >
Wrap
Text File
|
1985-08-21
|
25KB
|
926 lines
USER'S GUIDE FOR KED
A syntax-directed editor for
KAREL the Robot
A file is a conceptual device used to indicate a place
where your program is stored. Creating or modifying a file
is called editing the file. KED is a syntax-directed editor
for the language used by KAREL the Robot [1] [2]. It allows
you to create or modify syntactically correct programs for
KAREL. This does not mean that your program is a correct
solution to the problem you are trying to solve or that no
"error shutoffs" will result; it means only that there are
no lexical or syntactic errors in your program (see Sec. 2.6
in [1] for a detailed description of the various kinds of
programming errors).
You can use (or invoke) KED by typing:
ked newfilename1 newfilename2
Use any legal filenames you wish. If this is a new program
the names should be different from any in your directory.
The first file is used by KED to keep track of the
relationships in your program. The second file is used to
hold the text of your program in case you should want to
make a printed copy.
If these are new files KED will respond with:
TYPE MN TO SEE MENU
BEGINNING-OF-PROGRAM
<instruction>
This indicates that the first line of your program has been
typed in for you. The flashing underscore indicates where
your typing will start and the word between brackets what
sort of command is legal at this point. Now you can use KED
to create your program. See Editing Session I which creates
a new file.
If you wish to edit an old file, simply use the same
format:
ked oldfilename1 oldfilename2
Here, the first file should be one created in an earlier
session. KED will respond by getting your files and then
printing out the first 20 lines of your program followed by
----------
1. Richard E. Pattis,KAREL the Robot A Gentle Introduction
to the Art of Programming (New York: John Wiley & Sons,
1981)
2. All programs are written in C and compiled by BD Software
C Compiler v1.5.
a ? prompt. Now you can modify your program using the
insert and delete commands.
If by mistake you give an old filename that does not
contain a KAREL program you may exit gracefully by typing
"q" and not saving the program. This will allow you to
start over and not cause any damage to your old file.
Constructs or control structures are used in a program to
change the order of execution of instructions. In KAREL's
language, the constructs begin with IF, WHILE or ITERATE.
Inside the constructs there may be a single statement or
several statements (a compound statement). If a compound
statement is used, it is included between the reserved words
BEGIN and END. If only a single statement is used, in order
to make it clear to KED that the construct is completed, you
must type the NDC (end of construct) command. An NDC is not
needed to complete a construct containing a compound
statement, since an END automatically causes KED to supply
an NDC. An NDC would be required as indicated in the
following program segment:
ITERATE 6 TIMES
turnleft;
NDC (entered by user to complete ITERATE)
IF front-is-blocked
THEN
turnoff
NDC (entered by user to complete THEN)
ELSE
move;
NDC (entered by user to complete ELSE)
WHILE not-facing-north DO
BEGIN
move;
turnleft
END
(no NDC is required to complete WHILE since a compound
statement is used inside the construct)
NDC does not add any statements to your program; it is
only used by KED to structure relationships between
constructs. For editing purposes, IF, THEN and ELSE are
considered to be separate constructs. If any construct but
ELSE follows THEN, KED will automatically perform the NDC so
the instruction will follow the IF.
IF facing-west
THEN
turnleft;
NDC (entered by user to complete THEN)
NDC (automatically performed by KED since the next entry is a
not an ELSE)
pickbeeper;
This can cause some problems if there are several nested
IF's.
IF facing-west
(5) THEN
(4) IF facing-north
(3) THEN
(2) IF facing-south
(1) THEN
move;
NDC
NDC
NDC
NDC
NDC
move;
In order to add the "move" after the outermost IF (the only
legal location, since none of the statements is compound),
NDC must be entered five times to end the indicated
constructs.
To add any of KAREL's instructions or tests to your
program, simply type the one- to three-letter commands at
the desired location and it will be automatically added. If
you make a typing error, the backspace character won't
correct the entry; simply let KED give you an INVALID
COMMAND error message and re-enter the desired instruction.
KED will attempt to guide you through this process with
appropriate prompts for the kind of command to enter. Of
course, you should always have written the complete program
you wish to enter before you sit down at the terminal!
After an instruction has been added, KED will prompt for
the next legal entry: <instruction>, <test>, <new-name> or
<positive-number>. Instructions are always automatically
added to the end of the program.
When you have added a DEFINE-NEW-INSTRUCTION, KED
automatically adds a BEGIN and then will prompt for a new
name; when you have added a WHILE or IF, KED will prompt for
a test; when you have added an ITERATE, KED will prompt for
a positive number. In any of these three situations, you
must respond to the prompt; the only other alternative is to
see the menu. Except for these situations, you can use any
of the edit commands to examine your program at any time
while adding instructions. Whenever you type MN, an updated
menu will be printed at your terminal. User-defined
instructions are added to the menu following the list of
INSTRUCTIONS.
After an instruction has been added, KED will respond with
a prompt for the next kind of entry. After an edit command
has been executed, KED will respond with a ?. No matter
where you are examining your program, the next addition will
always be at the end. The only way to add an instruction to
the middle of your program is to type "i" to get in insert
mode and that can only be done when your program has been
completed (after END-OF-EXECUTION has been added).
Suppose we had made the following errors when we entered
the program in Editing Session I:
1. omitted one turnleft from the definition
2. typed turnleft instead of turnright following the THEN
To correct these errors we can do the following (see
Editing Session II):
1. go to the top of the program
2. go to the end of the definition
3. insert a turnleft before the END
4. go to the turnleft before the END of the THEN
construct
5. delete the turnleft
6. insert a turnright
The following conditions must be observed when inserting:
1. Insertions can only be performed when a complete
program has been entered (after NDX has been added).
2. Insertions can only be made before END, DEFINE,
BEGINNING- OF-EXECUTION, END-OF-EXECUTION or before a
construct following BEGINNING-OF-EXECUTION that is not
indented more than one level. This is actually a
restriction on entering in the middle of a construct.
3. Once you are in "insert mode" you can continue adding
instructions as you did when the original program was
created. KED insures that a construct is always
completed before the insert mode is exited.
4. To exit the "insert mode", simply type any edit
command (except MN which will always print the menu
but leave you in the insert mode).
The following conditions must be observed when deleting:
1. You cannot delete:
1. BEGINNING-OF-PROGRAM
2. BEGINNING-OF-EXECUTION
3. END-OF-EXECUTION
2. You can only replace:
1. tests
2. new names
3. positive numbers
3. The replacement-only restriction for new names can be
used to the programmer's advantage by using a
shortened version of the actual name desired (e.g. ta
instead of turn-around) to reduce typing in the
instruction each time it is used in the program.
After all the entering and testing has been completed,
the user may then return to KED and substitute the
longer version in the definition. This will
automatically result in the new version's replacement
of the old version throughout the program without any
additional typing.
4. If you try to delete any capitalized word (reserved
word), KED will ask if you wish to delete the entire
construct. If you respond with a "Y", the entire
construct will be removed from your program. If you
delete a definition, all uses of the defined
instruction will be removed from your program as well
as the menu.
Editing Session III will illustrate some of the more
complicated insert and delete features of KED.
To save the program, type "s". You cannot save an
incomplete program, that is, NDX must always have been
added. If you are editing an old file, at that time, the
old file will be destroyed and the new version will be
saved. If you do not wish to lose your old copy you must
make a "back-up" and place it in your directory before you
start the editing session. If you are creating a new file,
a file will be placed in your directory containing your
program. Remember, the first file contains the
relationships and the second contains the text.
To end the editing session, type q (quit). KED will remind
you to save your program and then end after reading your
answer.
ERROR MESSAGES:
MISSING FILENAME(S)
You must enter two filenames after the KED command.
BAD LOCATION FOR BEGIN
You can only enter a BEGIN after THEN, ELSE, WHILE or ITERATE.
BAD LOCATION FOR BEGINNING-OF-EXECUTION (BX)
BEGINNING-OF-EXECUTION (BX) can only follow BEGINNING-OF-PROGRAM
or a complete definition.
STRUCTURE NOT A COMPOUND STATEMENT
An END must match a BEGIN and if more than one instruction
follows a THEN, ELSE, WHILE or ITERATE it must be part of a
compound statement.
BAD LOCATION FOR END PGM
END-OF-EXECUTION (NDX) can only be typed after all constructs
have been ended.
ELSE NOT PAIRED WITH THEN
Remember to do an NDC if THEN is not followed by a compound
statement.
COMMAND CAN'T BE INSERTED
BEGINNING-OF-EXECUTION and END-OF-EXECUTION cannot be inserted.
END REQUIRED
It isn't necessary to type an NDC to end a construct that
contains a compound statement. After END is typed an NDC is
automatically performed by KED.
ALREADY IN INSERT MODE
Typing "i" while in insert mode will produce this message.
INSERT ONLY AFTER END OF PROGRAM
Insert mode can only be used after END-OF-EXECUTION (NDX) has
been added.
CAN'T INSERT INSIDE CONSTRUCT
See insert restrictions.
LAST POSSIBLE LEVEL
NDC can't be performed beyond the last construct.
PLEASE COMPLETE CONSTRUCT
Exit from the insert mode is not allowed until all constructs
are completed.
BAD LOCATION FOR DEFINITION
A definition can only follow BEGINNING-OF-PROGRAM or a
complete definition.
MAXIMUM NUMBER OF DEFINITIONS EXCEEDED
A fixed number of definitions are allowed, even if some have been
deleted so that fewer than the maximum actually remain in the
program. Saving the program, quitting the editor and then
invoking KED will allow additional definitions to replace those
deleted in the earlier session, although you still may not have
more than the allowable number definitions in a program.
MAXIMUM NUMBER OF USES OF DEFINTION EXCEEDED
Only a fixed number of uses of each definition is allowed in your
program.
INVALID TEST
The menu lists valid KED commands for tests. No spaces should
precede or follow tests; a backspace or a control character will
produce an error.
NEW NAME MUST BE UNIQUE
Each user-defined name must be different from KAREL's
instructions, tests and the edit commands. Although you may use
any number of characters, only the first eight will be recognized.
INVALID CHARACTERS IN NEW NAME
Only letters, numbers and hyphens may be used in a new name and
the first character must be a letter.
INVALID COMMAND
Be sure to type commands correctly. It doesn't matter whether
you use capital or small letters but spaces before or after
entries, the backspace or any control character will all produce
an error.
INSERT ONLY
After END-OF-EXECUTUION (NDX) has been added, the only way to add
instructions is to enter the insert mode.
BAD LOCATION FOR COMMAND
An improper location has been chosen for a command.
CAN'T BE DELETED
BEGINNING-OF-PROGRAM, BEGINNING-OF-EXECUTION, and END-OF-EXECUTION
cannot be deleted.
USER'S GUIDE FOR SUBMIT KAREL
A World-Builder and Simulator for
KAREL the Robot
After a program has been written using KED (a
syntax-directed editor for KAREL the Robot), to create the
world in which the program will be run and to execute the
program, type:
submit karel filename1 filename2
Filename1 should contain the file created in KED. Filename2
is used to store KAREL's world. If filename2 is a new file,
an "empty world" will be printed. If filename2 is an old
file, the previously created world it contains will be
printed. Along with the new or old world, KAREL's street,
avenue and direction and the number of beepers in his beeper
bag will be shown. Then you will be asked if you want to
change KAREL's location, beeper locations or wall location.
If by mistake an old filename is given that does not contain
an old world, you can exit gracefully by not saving the
world. After a few system messages, you can start over and
no damage will have been done to your old file.
There are only ten streets (numbered 1 thru 10) and
seventeen avenues (numbered 1 thru 17) in this
representation of KAREL's world. Street 0, street 11,
avenue 0 and avenue 18 entries will be accepted for wall
building but are not legal locations for KAREL or beepers.
Although any number of beepers can be carried in KAREL's
beeper bag, only 9 may be put at any corner of his world.
No error shutoff will occur if more than 9 are put at a
given corner but only 9 will appear and a warning will be
printed on the screen; these beepers are effectively lost to
KAREL and cannot be recovered.
The following prompts will be given for changes to KAREL's
world; when entering a character (Y/N) only the character is
required (no RETURN need be typed) but a number entry
requires a RETURN.
(1) CHANGE KAREL'S LOCATION? (Y/N)
If "Y" is entered, you will be asked:
KAREL'S STREET?
KAREL'S AVENUE?
DIRECTION? (N/S/E/W)
At this point, KAREL will be shown on the screen.
IS KAREL'S LOCATION CORRECT? (Y/N)
If "N" is entered, the previous questions to change KAREL's
location will be repeated. If "Y" is entered or if "N"
is entered in response to (1) above, you will be asked:
(2) CHANGE BEEPERS IN WORLD? (Y/N)
If "Y" is entered, you will be asked:
STREET?
AVENUE?
ENTER A TO ADD OR D TO DELETE BEEPER
At this point the beeper will be added or deleted from the
world. If a beeper has been added, you will be asked:
IS BEEPER LOCATION CORRECT? (Y/N)
If "N" is entered, the beeper questions will be repeated.
If "Y" is entered or if a beeper has been deleted, you
will be asked:
OTHER BEEPER LOCATIONS? (Y/N)
If "Y" is entered, the beeper questions will be repeated.
If "N" is entered, you will be asked:
(3) CHANGE BEEPERS IN BAG? (Y/N)
If "Y" is entered, you will be asked:
HOW MANY BEEPERS IN BEEPER BAG?
0 BEEPERS IN BAG, CORRECT? (Y/N)
Here the number of beepers entered or 0 will be printed;
any non-number will be interpreted as 0. Since typing
errors cannot be corrected, simply enter "N". If "N" is
entered, the beeper bag questions will be repeated. If
"Y" is entered or if "N" is entered in response to (2),
you will be asked:
(4) CHANGE WALL LOCATIONS? (Y/N)
IF "Y" is entered, you will be asked:
BETWEEN WHAT STREETS?
?
BETWEEN WHAT AVENUES?
?
A number followed by a RETURN should follow each "?".
If a number outside the accepted values for streets or
avenues is entered, that question will be repeated.
If the difference between the streets is one, the wall is
assumed to be horizontal.
ENTER A TO ADD OR D TO DELETE WALL
At this point you can see the addition or deletion of the
wall; a "+" will appear at corners.
IS WALL LOCATION CORRECT? (Y/N)
If "N" is entered, the wall will be erased and the wall
questions will be repeated. If "Y" is entered, you will
be asked:
IS THIS THE LAST WALL? (Y/N)
If "N" is entered, the wall questions will be repeated.
If "Y" is entered or if "N" was entered in response to (3),
you will be asked:
(5) ANY FURTHER CHANGES TO THE WORLD? (Y/N)
IF "Y" is entered, all the questions will be repeated
starting with (1). If "N" is entered, you will be asked:
(6) EXECUTE PROGRAM? (Y/N)
If "Y" is entered, the world will be saved in filename2 and
the tree in filename1 will be translated. After a few
system messages are printed, the initial state of the
world will be printed and KAREL's execution of the program
will be shown on the screen. If there are problems (the
wrong file was used for filename2, for instance) then you
may enter "N". You will then be asked:
EXIT KAREL? (Y/N)
If "Y" is entered then after a few system messages the
program will end. If "N" is entered, you will be asked
again if you want to save the world (and start program
execution).
As KAREL executes your program, his direction is printed
at the street and avenue of his current location, unless
beepers are also located there. If both KAREL and any
beepers are at the same corner, only @ (one beeper), 2 (2
beepers), etc. will be shown.
When the execution has been completed successfully, "END
OF EXECUTION" will be printed and the final state of the
world will remain on the screen, along with KAREL's street,
avenue, direction and the number of beepers in his beeper
bag at the end of execution. At this point, you may invoke
KED to make any changes in your program then run the new
syntax tree and the old world and try again.
If an error shutoff occurs, the program will be terminated
and one of the following messages will be printed:
1. FRONT IS BLOCKED
A move was attempted while KAREL was facing a wall.
2. NO BEEPERS IN BAG
A putbeeper was attempted while there were no beepers in
KAREL's beeper bag.
3. NO BEEPERS ON CORNER
A pickbeeper was attempted at a location where there were
no beepers.
4. NO TURNOFF EXECUTED
The final turnoff instruction was omitted from the program.
You may study the state of the world which produced the
error and then invoke KED to make appropriate changes to
your program and try another run.
t, you may invoke
KED to make any ch