















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An insight into ada programming language with a focus on implementing a stack data structure using packages and tagged types. It covers the concepts of extending tagged types and using generics. The document also touches upon the topic of concurrency in ada.
Typology: Slides
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















package body STACK is MAX: constant := 100; S : array (1..MAX) of INTEGER; TOP : INTEGER range 0..MAX;
procedure PUSH (x : INTEGER) is begin TOP := TOP + 1; S(TOP) := x; end PUSH;
function POP return integer is TOP := TOP - 1; return S(TOP + 1); end POP; begin TOP := 0; end STACK; Docsity.com
package STACKS is
type STACK is private; procedure PUSH (s : in out STACK; i : in integer);
procedure POP (s : in out STACK; o : out integer);
private MAX: constant := 100; type STACK is record ST : array (1..MAX) of INTEGER; TOP : INTEGER range 0..MAX := 0; end record;
end STACKS;
Procedure not a function?
package body STACKS is procedure PUSH (S: in out STACK; i : in INTEGER) is begin S.TOP := S.TOP + 1; S.ST(S.TOP) := i; end PUSH;
procedure POP (S: in out STACK; o : out INTEGER) is begin o := S.ST(S.TOP); S.TOP := S.TOP - 1; end POP;
end STACK;
package STACKS is
overFlow, underFlow : exception; type STACK is private; procedure PUSH (s : in out STACK; i : in integer); procedure POP (s : in out STACK; o : out integer);
private MAX: constant := 100; type STACK is record ST : array (1..MAX) of INTEGER; TOP : INTEGER range 0..MAX := 0; end record;
end STACKS;
package body STACKS is procedure PUSH (S: in out STACK; i : in INTEGER) is begin if S.TOP = MAX then raise overFlow; end if; S.TOP := S.TOP + 1; S.ST(S.TOP) := i; end PUSH;
procedure POP (S: in out STACK; o : out INTEGER) is begin if S.TOP = 0 then raise underFlow; end if; o := S.ST(S.TOP); S.TOP := S.TOP - 1; end POP;
end STACK;
Object Orientation – The Ada
Way
extending types through inheritance
concept of a class is overloaded
type Person is tagged record
Name : String(1..20); Age : Natural;
end record;
declare package myStack is new STACK(100, integer); use myStack;
begin
… push (i); …
O := pop; …
end;
procedure COOKING is
begin
cookMeat; cookRice; cookPudding;
end COOKING;
procedure COOKING is task cookMeat; task body cookMeat is begin -- follow instructions for cooking meat end cookMeat;
task cookRice; task body cookRice is begin -- follow instructions for cooking rice end cookRice;
begin cookPudding; end COOKING;