------------------------------------------------------------------------------
MC logo
Ada Int Stack Driver
[^] Names and Scope
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Java Class Scope] [Ada Int Stack Package] [Ada Int Stack Impl] [Ada Int Stack Driver] [Java Int Stack Class] [Java Int Stack Driver] [C++ Int Stack Class] [C++ Int Stack Impl] [C++ Int Stack Driver]
driver.adb
--
-- A simple client of the IntStack package.
--

-- Gnat I/O comes with the Gnat compiler.  It's not part of the Ada 
-- standard, AFAIK.
with Gnat.Io; use Gnat.Io;
with IntStackPkg; use IntStackPkg;

procedure Driver is
   IntIn: Integer;              -- Integer read in.
   Cnt: Integer;                -- Uh...  A counter.
   
   IntOut1, IntOut2: Integer;   -- Integers popped from the stack.
   
   S1, S2: IntStack;            -- Two test stacks.
begin
   -- Read in integers until -1, and push each on one stack, and each
   -- times the input ordinal on the other.
   Cnt := 1;
   loop
      Put("> ");
      Get(IntIn);
      exit when IntIn = -1;
      Push(S1, IntIn);
      Push(S2, Cnt*IntIn);
      Cnt := Cnt + 1;
   end loop;

   -- Pop 'em and print 'em
   while not IsEmpty(S1) loop
      Pop(S1, IntOut1);
      Pop(S2, IntOut2);
      Put(IntOut1);
      Put(" ");
      Put(IntOut2);
      New_Line;
   end loop;
end Driver;