File: instructions.adb

package info (click to toggle)
gnat-gps 4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 49,096 kB
  • ctags: 20,461
  • sloc: ada: 274,120; ansic: 154,849; python: 9,890; tcl: 9,812; sh: 8,192; xml: 7,970; cpp: 4,737; yacc: 3,520; makefile: 2,136; lex: 2,043; java: 1,638; perl: 302; awk: 265; sed: 161; asm: 14; fortran: 2; lisp: 1
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;