1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
ligne : integer; //ligne qui doit être exécutée
procedure EXECUTE(var l : integer); // execute une instruction
procedure IFF(var l : integer); //execute une condition
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.EXECUTE(var l : integer);
begin
if Memo1.Lines[l] <> '' then
begin
if Memo1.Lines[l][1]+Memo1.Lines[l][2] = 'IF' then //Si code IF -> appele IFF
begin
IFF(l);
end else
if Memo1.Lines[l][1] = 'S' then //Si code S -> affiche Salut
begin
Caption:='Salut';
end else
if Memo1.Lines[l][1] = 'H' then //Si code H -> affiche Hello
begin
Caption:='Hello';
end;
end;
end;
procedure TForm1.IFF(var l : integer);
var i,j : integer;
L_ELSE,L_IF_END : integer; //ligne du ELSE et du IF_END de la condition
Nb_IF : integer; //Nombre de if imbriqué
S : string;
Bool : boolean; //valeur de la condition
begin
Nb_IF:=1;
//recherche de la ligne du ELSE
S:='';
For i:=l+1 to Memo1.lines.Count do
begin
if Memo1.Lines[i] <> '' then
begin
S:=''; //
S:=Memo1.Lines[i][1]+Memo1.Lines[i][2]+Memo1.Lines[i][3]; //recherche un if imbriqué
if S = 'IF ' then Nb_IF:=Nb_IF+1; //
S:='';
For j:=1 to 4 do s:=s+Memo1.Lines[i][j];
if S = 'ELSE' then
begin
Nb_IF:=Nb_IF-1;
if Nb_IF = 0 then
begin
L_ELSE:=i;
break;
end;
end;
end;
end;
//recherche de la ligne du IF_END
Nb_IF:=1;
S:='';
For i:=L_ELSE+1 to Memo1.lines.Count do
begin
if Memo1.Lines[i] <> '' then
begin
S:=''; //
S:=Memo1.Lines[i][1]+Memo1.Lines[i][2]+Memo1.Lines[i][3]; //recherche un if imbriqué
if S = 'IF ' then Nb_IF:=Nb_IF+1; //
S:='';
For j:=1 to 6 do s:=s+Memo1.Lines[i][j];
if S = 'IF_END' then
begin
Nb_IF:=Nb_IF-1;
if Nb_IF = 0 then
begin
L_IF_END:=i;
break;
end;
end;
end;
end;
//valeur du if
bool:=false;
S:='';
For j:=4 to 7 do S:=S+Memo1.Lines[l][j];
if S = 'TRUE' then bool:=true;
//Execution du THEN
if bool = true then
begin
For i:=l+1 to L_ELSE-1 do
begin
if i >= Ligne then
begin
EXECUTE(i);
Ligne:=Ligne+1;
end;
end;
end;
//execution du else
if bool = false then
begin
For i:=L_ELSE+1 to L_IF_END-1 do
begin
if i >= Ligne then
begin
EXECUTE(i);
Ligne:=Ligne+1;
end;
end;
end;
Ligne:=L_IF_END;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
For i:=0 to Memo1.Lines.Count do
begin
if i >= Ligne then
begin;
EXECUTE(i);
Ligne:=Ligne+1;
end;
end;
Ligne:=0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Ligne:=0;
end;
end. |
Partager