home *** CD-ROM | disk | FTP | other *** search
- -- ++
- -- A simple stack for integers.
- -- --
-
- package Stack is
-
- type Stack ( Max : Natural ) is limited private;
-
- Empty_Stack : constant Stack;
-
- procedure Push ( The_Stack : in out Stack; Value : in Integer );
-
- procedure Pop ( The_Stack : in out Stack; Value : out Integer );
-
- function "=" ( The_Stack : in Stack; A_Stack : in Stack ) return Boolean;
-
- function Empty ( The_Stack : in Stack ) return Boolean;
-
- function Full ( The_Stack : in Stack ) return Boolean;
-
- Underflow : exception;
- Overflow : exception;
-
- pragma INLINE ( Empty, Full );
-
- private
-
- type Vector is array ( Integer range <> ) of Integer;
-
- type Stack ( Max : Natural ) is record
- S : Vector ( 1 .. Max );
- Top : Natural := 0; -- can't use Max, discriminant not allowed in range constraint
- end record;
-
- -- there should be a discriminant on Stack here but the compiler barfs.
- -- The following seems to work ok.
- Empty_Stack : constant Stack := ( Max => 0, S => ( 1..0 => 0 ), Top => 0 );
-
- end Stack;