Форумчанин
Регистрация: 06.02.2008
Сообщений: 140
|
Странные ошибки.
Помогите найти ошибку.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Memo1: TMemo;
Memo2: TMemo;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure s1;
procedure s2;
procedure lex;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
j,o,l:integer;
bukva: set of 'A'..'z';
cifra: set of '0'..'9';
znak : set of char;
op : set of char;
ss,s:string;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
with stringgrid1 do
begin
cells[0,0]:='Ëåêñåìà';
cells[1,0]:='¹ Ëåêñåìû';
cells[0,1]:='program';
cells[1,1]:='1';
cells[0,2]:='var';
cells[1,2]:='2';
cells[0,3]:='begin';
cells[1,3]:='3';
cells[0,4]:='end';
cells[1,4]:='4';
cells[0,5]:=';';
cells[1,5]:='5';
cells[0,6]:=':';
cells[1,6]:='6';
cells[0,7]:='real';
cells[1,7]:='7';
cells[0,8]:='read';
cells[1,8]:='8';
cells[0,9]:='write';
cells[1,9]:='9';
cells[0,10]:='if';
cells[1,10]:='10';
cells[0,11]:='then';
cells[1,11]:='11';
cells[0,12]:='else';
cells[1,12]:='12';
cells[0,13]:='or';
cells[1,13]:='13';
cells[0,14]:='and';
cells[1,14]:='14';
cells[0,15]:='not';
cells[1,15]:='15';
cells[0,16]:='(';
cells[1,16]:='16';
cells[0,17]:='(';
cells[1,17]:='17';
cells[0,18]:='<';
cells[1,18]:='18';
cells[0,19]:='<=';
cells[1,19]:='19';
cells[0,20]:='>';
cells[1,20]:='20';
cells[0,21]:='>=';
cells[1,21]:='21';
cells[0,22]:='=';
cells[1,22]:='22';
cells[0,23]:='<>';
cells[1,23]:='23';
cells[0,24]:='+';
cells[1,24]:='24';
cells[0,25]:='-';
cells[1,25]:='25';
cells[0,26]:='*';
cells[1,26]:='26';
cells[0,27]:='/';
cells[1,27]:='27';
cells[0,28]:='E';
cells[1,28]:='28';
cells[0,29]:=':=';
cells[1,29]:='29';
cells[0,30]:='end.';
cells[1,30]:='30';
cells[0,31]:='do';
cells[1,31]:='31';
cells[0,32]:='while';
cells[1,32]:='32';
cells[0,33]:='[';
cells[1,33]:='33';
cells[0,34]:=']';
cells[1,34]:='34';
cells[0,35]:='id';
cells[1,35]:='35';
cells[0,36]:='con';
cells[1,36]:='36';
end;
bukva:=['A'..'Z']-['E']+['a'..'z'];
cifra:=['0'..'9'];
znak:=['+','-'];
op:=['/','/','(',')','[',']']
end;
procedure TForm1.s1;
begin
if s[j] in bukva then
begin
j:=j+1;
s2;
exit;
end;
if s[j] in cifra then
begin
j:=j+1;
end;
end;
procedure TForm1.s2;
var
k:integer;
begin
if s[j] = ' ' then
begin
for k:=1 to j-1 do
begin
ss:=ss+s[k];
end;
delete(s,1,j);
j:=1;
lex;
end;
if s[j] in bukva then
begin
j:=j+1;
s2;
end;
if s[j] in cifra then
begin
j:=j+1;
s2;
end;
for k:=1 to j-1 do
begin
ss:=ss+s[k];
end;
delete(s,1,j-1);
j:=1;
lex;
j:=1;
end;
procedure TForm1.lex;
var
p,len:integer;
f:boolean;
begin
f:=false;
for p:=0 to 36 do
if ss = form1.stringgrid1.Cells[0,p] then
begin
form1.stringgrid2.Cells[0,o]:=ss;
o:=o+1;
ss:='';
f:=true;
break;
end;
if f=false then
begin
form1.stringgrid3.Cells[0,l]:=ss;
l:=l+1;
ss:='';
end;
len:=length(s);
if len>j then
s1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
o:=1;
l:=1;
for i:=0 to memo1.Lines.Count-1 do
begin
s:=memo1.Lines[i];
j:=1;
s1;
end;
end;
end.
В процедуре s2 когда доходит до последнего end'a, то следующий шаг почему то не выход из процедуры и возвращение в предыдущую, а переход в середину этой же и так раз 5 где то.
Если убрать
Код:
if s[j] in bukva then
begin
j:=j+1;
s2;
end;
то такое не происходит, но не могу понять почуму и вообще всю логику Делфи .
|