home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / elan / cola / cola2mod.eln < prev    next >
Text File  |  1988-10-11  |  2KB  |  87 lines

  1.  
  2. PROC should be put command:
  3.   TEXT CONST box1 :: HEAD current symbol;
  4.   IF found (square symbol, triangle symbol)
  5.   THEN
  6.     IF found (on symbol)
  7.     THEN
  8.       TEXT CONST box2 :: HEAD current symbol;
  9.       IF found (square symbol)
  10.       THEN
  11.         IF found (newline symbol)
  12.         THEN evaluate command (put symbol, box1, box2)
  13.         FI
  14.       FI
  15.     FI
  16.   FI
  17. ENDPROC should be put command;
  18.  
  19. PROC evaluate command (TEXT CONST cmd, box1, box2):
  20.   IF cmd = put symbol
  21.   THEN evaluate puton command
  22.   ELIF cmd = take symbol
  23.   THEN evaluate takefrom command
  24.   FI.
  25.  
  26. evaluate puton command:
  27.   IF proper box found
  28.   THEN
  29.     towerheight [i] INCR 1;
  30.     shelf [i] [towerheight [i]] := box1;
  31.     read next line
  32.   ELSE semantic error ("no such box.")
  33.   FI.
  34.  
  35. proper box found:
  36.   FOR i FROM 1 UPTO shelfsize
  37.   REP
  38.     IF towerheight [i] > 0 AND towerheight [i] < maxheight
  39.     THEN
  40.       IF shelf [i] [towerheight [i]] = box2
  41.       THEN
  42.         LEAVE proper box found WITH true
  43.       FI
  44.     FI
  45.   ENDREP;
  46.   false.
  47.  
  48. evaluate takefrom command:
  49.   IF box2 <> HEAD square symbol
  50.   THEN
  51.     semantic error ("base box is not a square.")
  52.   ELIF proper box pair found
  53.   THEN
  54.     towerheight [i] DECR 1;
  55.     read next line
  56.   ELSE
  57.     semantic error ("no such box.")
  58.   FI.
  59.  
  60. proper box pair found:
  61.   FOR i FROM 1 UPTO shelfsize
  62.   REP
  63.     IF towerheight [i] > 1
  64.     THEN
  65.       IF shelf [i] [towerheight [i]] = box1 AND
  66.          shelf [i] [towerheight [i] - 1] = box2
  67.       THEN
  68.         LEAVE proper box pair found WITH true
  69.       FI
  70.     FI
  71.   ENDREP;
  72.   false.
  73.  
  74. ENDPROC evaluate command;
  75.  
  76. BOOL PROC found (TEXT CONST sym1, sym2):
  77.   IF ahead (sym1) OR ahead (sym2)
  78.   THEN
  79.     read next symbol;
  80.     true
  81.   ELSE
  82.     syntax error (sym1 + " " + sym2 + " ?");
  83.     false
  84.   FI
  85. ENDPROC found;
  86.  
  87.