File: values.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 (52 lines) | stat: -rw-r--r-- 1,292 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
with Except;
with Input;  use Input;
with Stack;

package body Values is

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

   procedure Process (V : Value) is
   begin
      Stack.Push (V);
   end Process;

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

   function Read (Word : String) return Value is
      Int_Val  : Integer;
      Real_Val : Float;
      Kind     : Input.Number_Kind;

   begin
      Input.Read_Number (Word, Int_Val, Real_Val, Kind);

      if Kind /= Int_Number then
         raise Except.User_Error;
      end if;

      return new Value_Info'(E => Int_Val);
      --  Allocate a new Value_Info (which is a record with one field)
      --  on the heap and initialize its only field "E" to be "Int_Val".
      --  NOTE: the ' in Value_Info'(...) must be there.
   end Read;

   ---------------
   -- To_String --
   ---------------

   function To_String (V : Value) return String is
   begin
      return Integer'Image (V.E);
      --  V is a pointer to a Value_Info record. V.all is the
      --  actual Value_Info record pointed by V. Thus, strictly speaking,
      --  we shoudl have written V.all.E above. However, Ada allows to
      --  remove the ".all" because the meaning of expression "V.E" is
      --  clear from its context.
   end To_String;

end Values;