home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 202_01 / uguide.doc < prev   
Text File  |  1979-12-31  |  26KB  |  925 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.                               USER'S GUIDE FOR KED
  33.  
  34.                           A syntax-directed editor for
  35.                                  KAREL the Robot
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.             A  file  is  a conceptual device used to indicate a  place
  75.           where your program is stored.  Creating  or modifying a file
  76.           is called editing the file.  KED is a syntax-directed editor
  77.           for  the language used by KAREL the Robot [1] [2]. It allows
  78.           you to  create  or modify syntactically correct programs for
  79.           KAREL. This does not  mean  that  your  program is a correct
  80.           solution to  the  problem you are trying to solve or that no
  81.           "error shutoffs" will result; it means only that  there  are
  82.           no lexical or syntactic errors in your program (see Sec. 2.6
  83.           in [1] for a detailed description  of  the  various kinds of
  84.           programming errors). 
  85.  
  86.             You can use (or invoke) KED by typing:
  87.  
  88.                ked newfilename1 newfilename2
  89.  
  90.           Use any legal filenames you wish.  If this is a  new program
  91.           the names  should  be different from any in your directory. 
  92.           The  first file  is  used  by  KED  to  keep  track  of  the
  93.           relationships in your program.  The  second  file is used to
  94.           hold the  text  of  your  program in case you should want to
  95.           make a printed copy. 
  96.  
  97.             If these are new files KED will respond with:
  98.  
  99.                TYPE MN TO SEE MENU
  100.                  BEGINNING-OF-PROGRAM
  101.                    <instruction>
  102.  
  103.           This indicates that the first line  of your program has been
  104.           typed in for you.  The flashing  underscore  indicates where
  105.           your typing will  start  and  the word between brackets what
  106.           sort of command is legal at this point.  Now you can use KED
  107.           to create your program.  See Editing Session I which creates
  108.           a new file. 
  109.  
  110.             If  you  wish  to edit an old file, simply  use  the  same
  111.           format:
  112.  
  113.                ked oldfilename1 oldfilename2
  114.  
  115.           Here, the first file should be  one  created  in  an earlier
  116.           session.  KED will respond by getting  your  files  and then
  117.           printing out  the first 20 lines of your program followed by
  118.           a ?  prompt.   Now  you  can  modify  your program using the
  119.  
  120.           ----------
  121.  
  122.           1. Richard  E.  Pattis,KAREL the Robot A Gentle Introduction
  123.           to the Art of  Programming  (New  York:  John  Wiley & Sons,
  124.           1981)
  125.  
  126.           2. All programs are written in C.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.           insert and delete commands. 
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.             If by mistake you  give  an  old  filename  that  does not
  207.           contain a  KAREL  program  you may exit gracefully by typing
  208.           "q"  and  not saving the program.  This will  allow  you  to
  209.           start over and not cause any damage to your old file. 
  210.  
  211.             Constructs  or control structures are used in a program to
  212.           change  the order of execution of instructions.  In  KAREL's
  213.           language, the constructs begin  with  IF,  WHILE or ITERATE.
  214.           Inside  the constructs there may be a  single  statement  or
  215.           several  statements  (a compound statement).  If a  compound
  216.           statement is used, it is included between the reserved words
  217.           BEGIN and END. If only a single statement is used,  in order
  218.           to make it clear to KED that the construct is completed, you
  219.           must type the NDC (end of construct) command.  An NDC is not
  220.           needed  to  complete  a   construct  containing  a  compound
  221.           statement, since an END  automatically  causes KED to supply
  222.           an NDC.  An  NDC  would  be  required  as  indicated  in the
  223.           following program segment:
  224.  
  225.                ITERATE 6 TIMES
  226.                  turnleft;
  227.                NDC (entered by user to complete ITERATE)
  228.                IF front-is-blocked
  229.                  THEN
  230.                    turnoff
  231.                NDC (entered by user to complete THEN)
  232.                  ELSE
  233.                    move;
  234.                NDC (entered by user to complete ELSE)
  235.                WHILE not-facing-north DO
  236.                  BEGIN
  237.                    move;
  238.                    turnleft
  239.                  END
  240.               (no NDC is required to complete WHILE since a compound
  241.                statement is used inside the construct)
  242.  
  243.             NDC  does  not  add any statements to your program; it  is
  244.           only  used   by   KED  to  structure  relationships  between
  245.           constructs.   For editing purposes, IF, THEN  and  ELSE  are
  246.           considered to be separate  constructs.  If any construct but
  247.           ELSE follows THEN, KED will automatically perform the NDC so
  248.           the instruction will follow the IF.
  249.  
  250.               IF facing-west
  251.                 THEN
  252.                   turnleft;
  253.               NDC (entered by user to complete THEN)
  254.               NDC (automatically performed by KED since the next entry is a
  255.                    not an ELSE)
  256.               pickbeeper;
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.             This  can cause some problems if there are several  nested
  273.           IF's.
  274.  
  275.  
  276.                   IF facing-west
  277.             (5)     THEN
  278.               (4)     IF facing-north
  279.                  (3)    THEN
  280.                    (2)    IF facing-south
  281.                      (1)    THEN
  282.                               move;
  283.                   NDC
  284.                   NDC
  285.                   NDC
  286.                   NDC
  287.                   NDC
  288.                   move;
  289.  
  290.           In order to add the  "move" after the outermost IF (the only
  291.           legal  location, since none of the statements is  compound),
  292.           NDC  must  be  entered  five  times  to  end  the  indicated
  293.           constructs. 
  294.  
  295.             To add  any  of  KAREL's  instructions  or  tests  to your
  296.           program, simply type the  one-  to  three-letter commands at
  297.           the desired location and it will be automatically added.  If
  298.           you  make a typing  error,  the  backspace  character  won't
  299.           correct the  entry;  simply  let  KED  give  you  an INVALID
  300.           COMMAND error message and re-enter the desired instruction. 
  301.           KED  will  attempt to guide you through  this  process  with
  302.           appropriate prompts for the  kind  of  command to enter.  Of
  303.           course, you should always  have written the complete program
  304.           you wish to enter before you sit down at the terminal! 
  305.  
  306.             After an instruction has been added,  KED  will prompt for
  307.           the next  legal  entry: <instruction>, <test>, <new-name> or
  308.           <positive-number>.  Instructions  are  always  automatically
  309.           added to the end of the program. 
  310.  
  311.             When  you  have  added   a   DEFINE-NEW-INSTRUCTION,   KED
  312.           automatically adds a BEGIN and then  will  prompt  for a new
  313.           name; when you have added a WHILE or IF, KED will prompt for
  314.           a test; when you have added an  ITERATE, KED will prompt for
  315.           a positive number.  In any  of  these  three situations, you
  316.           must respond to the prompt; the only other alternative is to
  317.           see the menu.  Except  for these situations, you can use any
  318.           of the edit commands to examine  your  program  at  any time
  319.           while adding instructions.  Whenever you type MN, an updated
  320.           menu  will  be  printed  at  your  terminal.    User-defined
  321.           instructions are added  to  the  menu  following the list of
  322.           INSTRUCTIONS.
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.             After an instruction has been added, KED will respond with
  339.           a prompt for the next kind of entry.  After an edit  command
  340.