G:
VT = {a, b}
VN = {A, S}

axiome: S

Règles :

1 : S ® aAS

2 : S ® b

3 : A ® a

4 : A ® bSA

Cette grammaire est LL(1) et nous avons déjà calculé les Init de A et de S :
  InitA) = Init(S) = {a,b} En nous servant du tableau précédent écrivons les plans d'action associés à A et S.
 
 
Plan A :

Activer(a) ;
Activer(b) ;
Saisie(SymLu) ;
si action = a alors
désactiver(a)
sinon
désactiver(b);
Plan S;
Plan A
fsi
désactiver(a) ;
désactiver(b) ;

Plan S :

Activer(a) ;
Activer(b) ;
Saisie(SymLu) ;
si action = a alors
désactiver(a) ;
Plan A ;
Plan S
sinon
désactiver(b);
fsi ;
désactiver(a) ;
désactiver(b) ;


 

Implantation en Delphi

Delphi.PlanAction \Plan1.dlfi
 

  Il appelle aussi à la fin la procédure PlanSuivant qui sert à passer au plan d'action suivant (dans l'exemple le plan suivant est l'état initial, il suffit de réactiver le bouton lancer).
 
procedure PlanSuivant;
begin
 Form1.ButtonLancer.enabled:=true;
end;

 
 

2.3 Interface de saisie du mini-français

Delphi.PlanAction PlanGF2.dlfi
 

Nous fournissons ici uniquement l'énoncé et les choix principaux de l'exemple, il est entièrement traité sur le CD.

La grammaire choisie est la grammaire LL(1) GF2 du mini-français déjà étudiée.
 

GF2 = (VN,VT,S,R) á   ñ
 
VT ={le, un, chat, chien, aime, poursuit, malicieusement, joyeusement, gentil, noir, blanc, beau, '.'}
VN = { á phraseñ, á GN ñ, áGVñ, á Artñ, á Nom ñ, á Adjñ, á Adv ñ, áverbeñ, á LeNom ñ, á Suite ñ }
Axiome : <phrase>
Règles :

1 :á phrase ñ ® á  GN  ñ á GV  ñ.
2 :á GN  ñ ® á Art ñ á LeNom ñ
3 :á LeNom ñ ® á Adj ñ á Nom  ñ | á Nom  ñ á Adj ñ
4 :á GV  ñ ® á verbe ñ á Suite ñ
5 :á Suite ñ ® á GN  ñ | á Adv  ñ á GN  ñ
6 :á Art ñ ® le | un
7 :á  Nom  ñ ® chien | chat
8 :á  verbe ñ ® aime | poursuit
9 :á Adj ñ ® blanc | noir | gentil | beau
10 :á Adv  ñ ® malicieusement | joyeusement
 

Nous laissons le lecteur écrire les diagrammes syntaxiques obtenus à partir des règles précédentes.

Afin que le lecteur puisse bien se pénétrer de la similitude des démarches entre les blocs d'analyse du chapitre " analyser des phrases " et la saisie par plan d'action, nous lui livrons ci-dessous deux plans et les blocs correspondants. Il lui est demandé de construire les autres plans d'action sur le même modèle et ensuite d'implanter son interface de saisie.
 

procedure Plan_phrase;
begin
 Plan_GN;
 Plan_GV;
 Plan_point;
end;

l'implantation en Delphi est immédiate :

procedure Plan_LeNom;
begin
 ...etc
end;

Code Delphi7 complet de l'exemple-2  Interface de saisie du mini-français


unit  UFplanGF2 ;
 
 interface
 
 uses
  
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons
;
  
 type
  
TFPPlanGF2  class (TForm)
  ButtonLe
TButton ;
  
ButtonUn TButton ;
  
Buttonblanc TButton ;
  
Buttonnoir TButton ;
  
Buttonbeau TButton ;
  
Buttongentil TButton ;
  
Buttonaime TButton ;
  
Buttonpoursuit TButton ;
  
Buttonchat TButton ;
  
Buttonmalicieus TButton ;
  
Buttonjoyeus TButton ;
  
ButtonLancer TButton ;
  
Edit_saisie TEdit ;
  
Buttonchien TButton ;
  
Buttonpoint TButton ;
  
BitBtnFermer TBitBtn ;
  procedure 
ButtonLancerClick( Sender TObject) ;
  procedure 
ButtonsClick( Sender TObject) ;
  procedure 
FormCreate( Sender TObject) ;
  procedure 
BitBtnFermerClick( Sender TObject) ;
 private
 
{ Déclarations privées }
 
public
 
{ Déclarations publiques }
 
SymLu :string ;
 
ActionFaite , stop  boolean ;
  procedure 
ActiverDesactiver(Elt : TButton ; const  etat :boolean ) ;
  procedure 
InitGN(active :boolean ) ;
  procedure 
InitLeNom(active :boolean ) ;
  procedure 
InitGV(active :boolean ) ;
  procedure 
InitSuite(active :boolean )
  procedure 
InitArt(active :boolean ) ;
  procedure 
InitNom(active :boolean ) ;
  procedure 
InitVerbe(active :boolean ) ;
  procedure 
InitAdj(active :boolean ) ;
  procedure 
InitAdv(active :boolean ) ;
  procedure 
RAZTout ;
  procedure 
AttenteSaisie ;
  procedure 
PlanSuivant ;
  procedure 
Plan_Art ;
  procedure 
Plan_Nom ;
  procedure 
Plan_Verbe ;
  procedure 
Plan_Adj ;
  procedure 
Plan_Adv ;
  procedure 
Plan_LeNom ;
  procedure 
Plan_GN ;
  procedure 
Plan_Suite ;
  procedure 
Plan_GV ;
  procedure 
Plan_point ;
  procedure 
Plan_phrase ;
end;

 var
  
FPPlanGF2 TFPPlanGF2 ;
  
implementation
 
 
 
{$R *.dfm }
 
 
procedure  TFPPlanGF2.ActiverDesactiver(Elt : TButton ;const  etat :boolean ) ;
 begin
  
Elt.enabled := etat ;
 end;
 
////////////////////  LES INIT ///////////////////////////
 
procedure  TFPPlanGF2.InitGN(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.ButtonLe,active) ;
  
ActiverDesactiver(FPPlanGF2.ButtonUn,active)
 
end;
 
 procedure 
TFPPlanGF2.InitLeNom(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonblanc,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonnoir,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonbeau,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttongentil,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonchat,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonchien,active)
 
end;
 
 procedure 
TFPPlanGF2.InitGV(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonaime,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonpoursuit,active)
 
end;
 
 procedure 
TFPPlanGF2.InitSuite(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.ButtonLe,active) ;
  
ActiverDesactiver(FPPlanGF2.ButtonUn,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonjoyeus,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonmalicieus,active)
 
end;
 
 procedure 
InitArt(active :boolean ) ;
 begin
  
InitGN(active)
 
end;
 
 procedure 
TFPPlanGF2.InitNom(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonchat,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonchien,active)
 
end;
 
 procedure 
TFPPlanGF2.InitVerbe(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonaime,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonpoursuit,active)
 
end;
 
 procedure 
TFPPlanGF2.InitAdj(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonblanc,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonnoir,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonbeau,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttongentil,active)
 
end;
 
 procedure 
TFPPlanGF2.InitAdv(active :boolean ) ;
 begin
  
ActiverDesactiver(FPPlanGF2.Buttonjoyeus,active) ;
  
ActiverDesactiver(FPPlanGF2.Buttonmalicieus,active)
 
end;
 
//////////////////// fin des INIT ////////////////////////
 
procedure  TFPPlanGF2.RAZTout ;
 begin
  with 
FPPlanGF2  do
  begin
   
InitArt(false) ;
   
InitNom(false) ;
   
InitVerbe(false) ;
   
InitAdj(false) ;
   
InitAdv(false) ;
   
Buttonpoint.Enabled := false ;
   
SymLu := '';
   
ActionFaite := false ;
   
Edit_saisie.text := '';
   
stop := false
  
end
 end;
 
 procedure 
TFPPlanGF2.AttenteSaisie ;
 procedure 
Attendre ;
 begin
  if 
not  ActionFaite  then
  begin
   repeat
    
Application.ProcessMessages
   
until
   
actionfaite  ;
   
ActionFaite := false
  
end
 end
{ Attendre} ;
 
 procedure 
saisie(ch :string ) ;
 begin
  if 
ActionFaite = false  then
   
FPPlanGF2.Edit_saisie.text :=  FPPlanGF2.Edit_saisie.text + ' ' + ch
  
else
   
actionfaite := false
 
end {saisie} ;
 
 begin
  
Attendre ;
  
saisie(SymLu) ;
 end
{AttenteSaisie} ;
 
 procedure 
TFPPlanGF2.PlanSuivant ;
 begin
  
FPPlanGF2.ButtonLancer.enabled := true ;
 end;
 
{--------------- Les procédures des plans d'actions ----------------}
 
procedure  TFPPlanGF2.Plan_Art ;
 begin
  
InitArt(true) ;
  
AttenteSaisie ;
  
InitArt(false) ;
 end;
 
 procedure 
TFPPlanGF2.Plan_Nom ;
 begin
  
InitNom(true) ;
  
AttenteSaisie ;
  
InitNom(false) ;
 end;
 
 procedure 
TFPPlanGF2.Plan_Verbe ;
 begin
  
InitVerbe(true) ;
  
AttenteSaisie ;
  
InitVerbe(false) ;
 end;
 
 procedure 
TFPPlanGF2.Plan_Adj ;
 begin
  
InitAdj(true) ;
  
AttenteSaisie ;
  
InitAdj(false) ;
 end;
 
 procedure 
TFPPlanGF2.Plan_Adv ;
 begin
  
InitAdv(true) ;
  
AttenteSaisie ;
  
InitAdv(false) ;
 end;
 
 procedure 
TFPPlanGF2.Plan_LeNom ;
 begin
  
InitLeNom(true) ;
  
AttenteSaisie ;
  
InitLeNom(false) ;
  
ActionFaite := true // action déjè saisie
  
if  (SymLu = 'chat' or  (SymLu = 'chien' then
  begin
   
Plan_Nom ;
   
Plan_Adj
  
end
  else  
// adjectif
  
begin
   
Plan_Adj ;
   
Plan_Nom
  
end;
 end;
 
 procedure 
TFPPlanGF2.Plan_GN ;
 begin
  
Plan_Art ;
  
Plan_LeNom ;
 end;
 
 procedure 
TFPPlanGF2.Plan_Suite ;
 begin
  
InitSuite(true) ;
  
AttenteSaisie ;
  
InitSuite(false) ;
  
ActionFaite := true // action déjè saisie
  
if  (SymLu = 'le' or  (SymLu = 'un' then
  begin
   
Plan_GN ;
  end
  else  
// adverbe
  
begin
   
Plan_Adv ;
   
Plan_GN
  
end;
 end;
 
 procedure 
TFPPlanGF2.Plan_GV ;
 begin
  
Plan_Verbe ;
  
Plan_Suite ;
 end;
 
 procedure 
TFPPlanGF2.Plan_point ;
 begin
  
FPPlanGF2.Buttonpoint.Enabled := true ;
  
AttenteSaisie ;
  
FPPlanGF2.Buttonpoint.Enabled := false ;
 end;
 
 procedure 
TFPPlanGF2.Plan_phrase ;
 begin
  
Plan_GN ;
  
Plan_GV ;
  
Plan_point ;
 end;
 
 procedure 
TFPPlanGF2.ButtonLancerClick( Sender TObject) ;
 begin
  
RAZTout ;
  
ButtonLancer.enabled := false ;
  
Plan_phrase ;
  
PlanSuivant ;
 end;
 
 procedure 
TFPPlanGF2.ButtonsClick( Sender TObject) ;
 begin
  
ActionFaite := true ;
  if 
stop  then
   
halt ; //l'utilisateur a demandé d'arrêter
  
Symlu := TButton( Sender ).caption
 
end;
 
 procedure 
TFPPlanGF2.FormCreate( Sender TObject) ;
 begin
  
RAZTout ;
 end;
 
 procedure 
TFPPlanGF2.BitBtnFermerClick( Sender TObject) ;
 begin
  
stop := true
 
end;
 
end.