File: instructions.adb

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (59 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download | duplicates (8)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
with Except;
with Screen_Output;
with Stack;
with Values;

package body Instructions is

   ----------
   -- Read --
   ----------

   function Read (Word : String) return Instruction is
   begin
      --  Loop through each instruction asking if its string representation
      --  matches the word we have just encountered in the input.

      for I in Instruction loop
         --  Technical Note: Given a scalar type (such as an integer, an
         --  enumeration, etc), Type'Image (X) returns the value of X
         --  converted to a string.

         if Instruction'Image (I) = Word then
            return I;
         end if;
      end loop;

      --  If we have found an unrecognized instruction raise an exception.

      raise Except.User_Error;
   end Read;

   -------------
   -- Process --
   -------------

   procedure Process (I : Instruction) is
   begin
      case I is
         when Clear =>
            Stack.Clear;

         when Print =>
            Screen_Output.Msg (" -> ", End_Line => False);

            if Stack.Empty then
               Screen_Output.Msg ("stack is empty");
            else
               Screen_Output.Msg (Values.To_String (Stack.Top));
            end if;

         when Quit =>
            raise Except.Exit_SDC;

      end case;
   end Process;

end Instructions;