![](/user_photo/2706_HbeT2.jpg)
- •Национальный исследовательский университет «Московский энергетический институт» Институт автоматики и вычислительной техники Кафедра математического моделирования
- •Оглавление
- •Void Prints(rez &r)
- •Void __fastcall tForm1::BitBtn1Click(tObject *Sender)
- •LeksBlok.H
- •Void Strcpy(char mas[], int n, char *txt, int m);
- •Void LeksichBlok(Ident &I, char *txt);
- •LeksBlok.Cpp
- •Void LeksichBlok(Ident &I, char *txt)
- •Sintaksis.H
- •Void Sint(Ident &I, rez &r);
- •Sintaksis.Cpp
- •Void Sint(Ident &I, rez &r)
- •Interpretator.H
- •Void Inter(Ident &I, rez &r);
- •Interpretator.Cpp
- •Void Inter(Ident &I, rez &r)
- •Data.Cpp
- •Ident::Ident()
- •Void Ident::Delete(elem el)
- •Stack_mass.H
Void LeksichBlok(Ident &I, char *txt)
{
elem el;
for(int i = 0, nom = 0; txt[i]>31 || txt[i]==13 || txt[i]==10; i += nom)
{
//Ключевые слова
switch(txt[i])
{
case 101: case 105: case 116: case 119:
el.clas = C_KEY_WORD;
nom = 2;
char IfStr[3];
Strcpy(IfStr, nom, txt, i);
if (strstr(IfStr,"if"))
{
strcpy(el.name, IfStr);
I.Add(el);
continue;
}
nom = 4;
char ThenOrElseStr[5];
Strcpy(ThenOrElseStr, nom, txt, i);
if (strstr(ThenOrElseStr,"then") || strstr(ThenOrElseStr,"else"))
{
strcpy(el.name, ThenOrElseStr);
I.Add(el);
continue;
}
nom = 5;
char WhileStr[6];
Strcpy(WhileStr, nom, txt, i);
if (strstr(WhileStr,"while"))
{
strcpy(el.name, WhileStr);
I.Add(el);
continue;
}
nom = 9;
char End_whileStr[10];
Strcpy(End_whileStr, nom, txt, i);
if (strstr(End_whileStr,"end_while"))
{
strcpy(el.name, End_whileStr);
I.Add(el);
continue;
}
}
//Идентификаторы
if(64 < txt[i] && txt[i] < 91 || 96 < txt[i] && txt[i] < 123)
{
el.clas = C_IDENTIF;
nom = 0;
for (char j = txt[i];
47<j && j<58 || 64<j && j<91 || j==95 || 96<j && j<123;
j = txt[++nom + i]) {}
Strcpy(el.name, nom, txt, i);
I.Add(el);
continue;
}
//Целые числа
if(47 < txt[i] && txt[i] < 58)
{
el.clas = C_INT;
el.value = 0;
nom = 0;
for (char j = txt[i + nom];
47<j && j<58;
j = txt[++nom + i]) {}
Strcpy(el.name, nom, txt, i);
for (int j = 1, k = 1; j <= nom; ++j, k *= 10)
el.value += (txt[i + nom - j] - '0') * k;
if (64<txt[i + nom] && txt[i + nom]<91 ||
96<txt[i + nom] && txt[i + nom]<123)
throw (ErrIdent());
I.Add(el);
continue;
}
//Конец текущей строки, пробел
if (txt[i] == 13 || txt[i] == 10 || txt[i] == 32)
{
nom = 1;
continue;
}
//Разделители
switch(txt[i])
{
case 35: case 40: case 41: case 42:
case 43: case 59: case 61: case 94:
el.clas = C_RAZDEL;
nom = 1;
Strcpy(el.name, nom, txt, i);
I.Add(el);
continue;
default :
throw ErrSimb();
}
}
//концевой маркер
el.clas = C_RAZDEL;
el.name[0] = 182;
el.name[1] = '\0';
I.Add(el);
}
#pragma package(smart_init)