spécification du paquetage générique pile_symbole
generic
type T is private;
package pile_symbole is
pile_vide:exception;
type Pile is private;
function sommet(p:Pile) return
T;
function estVide(p:Pile) return
Boolean;
procedure empiler(e:in T;p:in
out Pile);
procedure depiler(p:in out Pile);
function vide return Pile;
private
type Cellule;
type Pile is access Cellule;
type Cellule is
record
valeur:T;
suivant:Pile;
end record;
end pile_symbole;
corps du paquetage générique du paquetage générique pile_symbole
with Ada.Text_io;use Ada.Text_io;
package body pile_symbole is
function estVide(p:Pile) return
Boolean is
begin
return p=NULL;
end estVide;
function vide return Pile is
begin
return NULL;
end vide;
function sommet(p:Pile) return
T is
begin
if estVide(p)
then raise pile_vide;
else
return p.valeur;
end if;
end sommet;
procedure empiler(e:in T;p:in
out Pile) is
begin
p:=new Cellule'(e,p);
end empiler;
procedure depiler(p:in out Pile)
is
begin
if estVide(p)
then raise pile_vide;
else
p:=p.suivant;
end if;
exception
when pile_vide =>
put_line(" la pile est
vide : impossible de dépiler !");
end depiler;
end pile_symbole;