ifodalar identifikatorlardan tashkil topgan, konstantalar 0 va 1, o’zlashtirish belgisi :q, amal
25
5.4-rasm. Masalaning qo’yilishining grafik chizmasi.
Dastur matni
#include
#pragma hdrstop
#include "Unit2.h"
G’G’---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
G’G’---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
SG->Cells[0][0]q"
";
SG->Cells[1][0]q"Znachenie leksemo’";
SG->Cells[2][0]q"Tip leksemo’";
OD->InitialDirqExtractFilePath(Application->ExeName);
SD->InitialDirqExtractFilePath(Application->ExeName);
}
G’G’---------------------------------------------------------------------------
26
void __fastcall TForm2::BitBtn1Click(TObject *Sender)
{if(FileExists(ExtractFilePath(Application->ExeName)Q"Test.txt")qq1) Memo->Lines-
>LoadFromFile(ExtractFilePath(Application->ExeName)Q"Test.txt");
else if (OD->Execute()) Memo->Lines->LoadFromFile(OD->FileName);}
G’G’---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn2Click(TObject *Sender) {if (SD->Execute()) Memo->Lines-
>SaveToFile(SD->FileName);}
G’G’---------------------------------------------------------------------------
AnsiString KeyWords[]q{"or","xor","and","not"};
AnsiString SI[]q{" ","g’n","g’t",")","(",":",";"};
int *A;
AnsiString ParseString(AnsiString Src,int StP,int &EnP)
{
for(int iqStP;i
for(int jq0;j<7;jQQ)
if (Src.SubString(i,1)qqSI[j] || Src[i]qq'g’n' || iqqSrc.Length())
{
EnPqi;
if(Src[i]qq'g’n') return Src.SubString(StP,EnP-StP-1);
else return Src.SubString(StP,EnP-StP);
}
}
bool kaq0;
void __fastcall TForm2::GoBtnClick(TObject *Sender)
{
Memo->TextqMemo->TextQ" ";
AnsiString TEMP;int xq0,scq1,ZSq0;
G’G’
for(int iq1;i
Text.Length();)
{
if(Memo->Text[i]qq'{') {kaq1;iQQ;continue;}
if(Memo->Text[i]qq'}') {kaq0;iQQ;continue;}
if(kaqq1) {iQQ;continue;}
if(int(Memo->Text[i])qq13) {iQQ;continue;}
if(Memo->Text.SubString(i,2)qq":q")
{
SG->Cells[1][sc]qMemo->Text.SubString(i,2);SG->Cells[0][sc]qsc;scQQ;
SG->RowCountqsc;iQq2;continue;
}
TEMPqParseString(Memo->Text,i,x);
if(x!qi && Memo->Text[i]!q'g’n')
{
SG->Cells[1][sc]qTEMP; SG->Cells[0][sc]qsc;scQQ;
SG->RowCountqsc;
iqx;
}
27
else
{
if(Memo->Text[i]qq'(' || Memo->Text[i]qq')' || Memo->Text[i]qq';' || Memo-
>Text[i]qq':')
{
SG->Cells[1][sc]qMemo->Text[i];SG->Cells[0][sc]qsc;scQQ;
SG->RowCountqsc;
}
iQQ;}}
Aqnew int[SG->RowCount];
for(int iq1;iRowCount;iQQ)
{
if (SG->Cells[1][i]qq"") {SG->Cells[2][i]q"";goto end;}
for(int jq0;j<4;jQQ)
if(SG->Cells[1][i]qqKeyWords[j])
{SG->Cells[2][i]q"Logicheskiy operator ";goto end;}
if (SG->Cells[1][i]qq":q") {SG->Cells[2][i]q"Operator prisvaivaniya";goto end;}
if (SG->Cells[1][i]qq'0' || SG->Cells[1][i]qq'1')
{SG->Cells[2][i]q"Binarnaya konstanta";goto end;}
if (SG->Cells[1][i]qq';') {SG->Cells[2][i]q"Razdelitel";goto end;}
if (SG->Cells[1][i]qq'(') {SG->Cells[2][i]q"Otro’vayuhayasya skobka";goto end;}
if (SG->Cells[1][i]qq')') {SG->Cells[2][i]q"Zakro’vayuhayasya skobka";goto
end;}
for(int jq1;j
Cells[1][i].Length();jQQ)
if((int(SG->Cells[1][i][j])<65 || int(SG->Cells[1][i][j])>90) &&
(int(SG->Cells[1][i][j])<97 || int(SG->Cells[1][i][j])>122))
{SG->Cells[2][i]q"Nedopustimo’y simvol";A[ZS]qi;ZSQQ;goto
end;}
SG->Cells[2][i]q"Identifikator";
end:;
}
delete[] A;
}
G’G’---------------------------------------------------------------------------
void __fastcall TForm2::SGDrawCell(TObject *Sender, int ACol, int ARow,
TRect &Rect, TGridDrawState State)
{
int x,y;
G’G’----------- Poluchenie koordinat dlya vo’voda teksta i sam vo’vod ----------------
xqRect.leftQ2; G’G’ (Rect.Width()-SG1->Canvas->TextWidth(SG1-
>Cells[ACol][ARow]))G’2;
yqRect.topQ3; G’G’(Rect.Height()-SG1->Canvas->TextHeight(SG1-
>Cells[ACol][ARow]))G’2;
SG->Canvas->Font->ColorqclBlack;
SG->Canvas->TextOut(x,y,SG->Cells[ACol][ARow]);
G’G’---------------------- Zakraska tekuhey vo’delennoy stroki --------------------
28
if(A!qNULL && ARow!q0)
for(int iq0;iRowCount;iQQ)
if(ARowqqA[i])
{SG->Canvas->Brush->ColorqclRed;SG->Canvas->Font->ColorqclWhite;
SG->Canvas->FillRect(Rect);
SG->Canvas->TextOut(x,y,SG->Cells[ACol][ARow]);}
}
Dastur natijasi
Xulosa: Tajriba ishini bajarish natijasida C++ Builder 7 muxitida dastur matni
yozildi
97>65>
Do'stlaringiz bilan baham: