Bonjour,
J'ai besoin d'aide SVP, avec un compilateur lexical Pascal. J'ai un problème avec les mots-clés et le if in then
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
program analyseur;
uses crt;
var
 ligne, mot : string;
 i, j, cpt_chaines, cpt_operateurs, cpt_ponctuations,cpt_motcle,cpt_chaineslittereaux : integer;
 chaines, operateurs, ponctuations,motcle,chaineslittereaux : array [1 .. 100] of string;
 
begin
 WriteLn('Veuillez entrer une ligne de code à analyser :');
 ReadLn(ligne);
 i := 1;
 cpt_chaines := 0;
 cpt_operateurs := 0;
 cpt_ponctuations := 0;
 while TRUE do
  begin
   while ligne[i] = ' ' do
    Inc(i);
   j := i;
   while ligne[j] in ['a' .. 'z', 'A' .. 'Z', '0' .. '9'] do
    Inc(j);
   mot := Copy(ligne, i, j - i);
   if mot <> '' then
    begin
     Inc(cpt_chaines);
     chaines[cpt_chaines] := mot;
    end;
 
if (chaines[i]='begin')or(chaines[i]='end')or(chaines[i]='if')or(chaines[i]='else')or(chaines[i]='while')or(chaines[i]='intger')or
    (chaines[i]='real')or(chaines[i]='string')or(chaines[i]='char')or(chaines[i]='for')or(chaines[i]='do')or(chaines[i]='function')or
   (chaines[i]='var')or(chaines[i]='procedure')then
 
	begin
	Inc(cpt_motcle);
	motcle[cpt_motcle]:= chaines[i]
	end
 
	else if (chaine[i] in ['0'..'9']
	Inc(cpt_chaineslittereaux);
	chaineslittereaux[cpt_chaineslittereaux]:=chianes[i]
	end
 
  if ligne[j] = ':' then
    begin
	 if (j + 1 <= Length(ligne)) and (ligne[j + 1] = '=') then
	  begin
	   Inc(j);
	   Inc(cpt_operateurs);
	   operateurs[cpt_operateurs] := ':='
	  end
	 else
	  begin
	   Inc(cpt_ponctuations);
	   ponctuations[cpt_ponctuations] := ':'
	  end
    end
   else if (ligne[j] = ',') or (ligne[j] = ';') or (ligne[j] = '(') or (ligne[j] = ')') then
	begin
	 Inc(cpt_ponctuations);
	 ponctuations[cpt_ponctuations] := ligne[j]
	end
   else if (ligne[j] = '+') or (ligne[j] = '-') or (ligne[j] = '*') or (ligne[j] = '/') then
	begin
	 Inc(cpt_operateurs);
	 operateurs[cpt_operateurs] := ligne[j]
	end;
   i := j + 1;
   if i > Length(ligne) then
    break
  end;
 WriteLn('--------------------------------------------------------------------------------');
 WriteLn('Chaînes littérale ou identificateur (', cpt_chaines, ') :');
 for i := 1 to cpt_chaines do
  WriteLn(i, ') : ', chaines[i]);
 
WriteLn('les mots clés (', cpt_motcle, ') :');
 for i := 1 to cpt_motcle do
  WriteLn(i, ') : ', motcle[i]);
 
  WriteLn('Opérateurs (', cpt_operateurs, ') :');
 for i := 1 to cpt_operateurs do
  WriteLn(i, ') : ', operateurs[i]);
 
 
  WriteLn('Ponctuations (', cpt_ponctuations, ') :');
 for i := 1 to cpt_ponctuations do
  WriteLn(i, ') : ', ponctuations[i]);
 ReadLn
end.