Pattis, Richard E.; Roberts, Jim; & Stehlik, Mark (1995), Karel the Robot: A Gentle Introduction to the Art of Programming, Second Edition (New York: John Wiley & Sons).
SYNTAX
(what the instruction looks like in Karel's lang |
SEMANTICS
(what the instruction means (i.e., what Karel does) |
---|---|
1. move | IF Karel sees no walls,
THEN Karel moves forward 1 block in direction he's facing ELSE IF Karel sees a wall, THEN "error shutoff" |
2. turnleft | Karel pivots 90° left |
3. pickbeeper | IF there is at least one beeper
on Karel's corner, THEN Karel picks up one beeper & puts it in his bag ELSE error shutoff |
4. putbeeper | IF there is at least one beeper
in Karel's bag, THEN Karel puts it on his corner ELSE error shutoff |
5. turnoff | Karel turns himself off |
3. CONDITIONAL (OR "CHOICE", OR "SELECTION")
INSTRUCTIONS
7. if <test>
then
<instruction>
8. if <test>
then
<instruction>
else
<instruction>
10. while <test> do
<instruction>
5. MECHANISM FOR DEFINING (OR "NAMING")
NEW INSTRUCTIONS
define-new-instruction <new-name> as
<instruction>
<instruction> | Any of Karel's instructions 1 - 10 |
<new-name> | Any new non-reserved word,
using lower-case letters, numbers, &/or "-") |
<positive-number> | Any positive number |
<test> | Any of the following:
front-is-clear, front-is-blocked left-is-clear, left-is-blocked right-is-clear, right-is-blocked next-to-a-beeper, not-next-to-a-beeper facing-north, not-facing-north facing-south, not-facing-south facing-east, not-facing-east facing-west, not-facing-west any-beepers-in-beeper-bag, no-beepers-in-beeper-bag |