Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:FullCollection / Программы / MYMAG
.CPP// Task : have to realize a magazin automat for constant declaration
// Syntax: const <variable name> [ = <value> ] ;
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
// const
char lenta [120];
char *pread = lenta;
char stek [120];
char *pstek;
char priz [120];
int errkod;
// My declarations;
char *ppriz;
char s0[] = "111111222123 while(AIC)S";
char s1[] = "1111111222123 switch(AIC)S";
char s2[] = "112122213 doS(AIC)";
char s3[] = "11113 null";
char a0[] = "223 BM";
char b0[]= "13 a";
char b1[]= "13 b";
char b2[]= "13 c";
char b3[]= "13 d";
char b4[]= "13 e";
char b5[]= "13 f";
char b6[]= "13 g";
char b7[]= "13 h";
char b8[]= "13 i";
char b9[]= "13 j";
char b10[]= "13 k";
char b11[]= "13 l";
char b12[]= "13 m";
char b13[]= "13 n";
char b14[]= "13 o";
char b15[]= "13 p";
char b16[]= "13 q";
char b17[]= "13 r";
char b18[]= "13 s";
char b19[]= "13 t";
char b20[]= "13 u";
char b21[]= "13 v";
char b22[]= "13 w";
char b23[]= "13 x";
char b24[]= "13 y";
char b25[]= "13 z";
char b26[]= "13 _";
char b27[]= "03";
char c0[] = "223 FD";
char d0[] = "23 C";
char d1[] = "03";
char f0[] = "13 0";
char f1[] = "13 1";
char f2[] = "13 2";
char f3[] = "13 3";
char f4[] = "13 4";
char f5[] = "13 5";
char f6[] = "13 6";
char f7[] = "13 7";
char f8[] = "13 8";
char f9[] = "13 9";
char f10[]= "03";
char z0[] = "13 a";
char z1[] = "13 b";
char z2[] = "13 c";
char z3[] = "13 d";
char z4[] = "13 e";
char z5[] = "13 f";
char z6[] = "13 g";
char z7[] = "13 h";
char z8[] = "13 i";
char z9[] = "13 j";
char z10[]= "13 k";
char z11[]= "13 l";
char z12[]= "13 m";
char z13[]= "13 n";
char z14[]= "13 o";
char z15[]= "13 p";
char z16[]= "13 q";
char z17[]= "13 r";
char z18[]= "13 s";
char z19[]= "13 t";
char z20[]= "13 u";
char z21[]= "13 v";
char z22[]= "13 w";
char z23[]= "13 x";
char z24[]= "13 y";
char z25[]= "13 z";
char z26[]= "13 _";
char z27[]= "13 0";
char z28[]= "13 1";
char z29[]= "13 2";
char z30[]= "13 3";
char z31[]= "13 4";
char z32[]= "13 5";
char z33[]= "13 6";
char z34[]= "13 7";
char z35[]= "13 8";
char z36[]= "13 9";
char z37[]= "03";
char i0[] ="13 <";
char i1[] ="13 >";
char i2[] ="113 ==";
char i3[] ="113 !=";
char i4[] ="113 <=";
char i5[] ="113 =>";
char m0[] ="23 H";
char m1[] ="03";
char h[] ="223 ZN";
char n0[] ="23 H";
char n1[] ="03";
struct prod
{
int m;
char* pr[63];
} S, A, B, C, D, F, I, M, H, Z, N;
void sintx()
{
S.m = 4;
S.pr[0] = s0;
S.pr[1] = s1;
S.pr[2] = s2;
S.pr[3] = s3;
A.m = 1;
A.pr[0] = a0;
B.m = 27;
B.pr[0] = b0;
B.pr[1] = b1;
B.pr[2] = b2;
B.pr[3] = b3;
B.pr[4] = b4;
B.pr[5] = b5;
B.pr[6] = b6;
B.pr[7] = b7;
B.pr[8] = b8;
B.pr[9] = b9;
B.pr[10] = b10;
B.pr[11] = b11;
B.pr[12] = b12;
B.pr[13] = b13;
B.pr[14] = b14;
B.pr[15] = b15;
B.pr[16] = b16;
B.pr[17] = b17;
B.pr[18] = b18;
B.pr[19] = b19;
B.pr[20] = b20;
B.pr[21] = b21;
B.pr[22] = b22;
B.pr[23] = b23;
B.pr[24] = b24;
B.pr[25] = b25;
B.pr[26] = b26;
B.pr[27] = b27;
C.m = 1;
C.pr[0] = c0;
D.m = 2;
D.pr[0] = d0;
D.pr[1] = d1;
F.m = 10;
F.pr[0] = f0;
F.pr[1] = f1;
F.pr[2] = f2;
F.pr[3] = f3;
F.pr[4] = f4;
F.pr[5] = f5;
F.pr[6] = f6;
F.pr[7] = f7;
F.pr[8] = f8;
F.pr[9] = f9;
F.pr[10]= f10;
I.m = 6;
I.pr[0] = i0;
I.pr[1] = i1;
I.pr[2] = i2;
I.pr[3] = i3;
I.pr[4] = i4;
I.pr[5] = i5;
H.m = 1;
H.pr[0]= h;
M.m = 2;
M.pr[0] = m0;
M.pr[1] = m1;
N.m = 2;
N.pr[0] = n0;
N.pr[1] = n1;
Z.m = 37;
Z.pr[0] = z0;
Z.pr[1] = z1;
Z.pr[2] = z2;
Z.pr[3] = z3;
Z.pr[4] = z4;
Z.pr[5] = z5;
Z.pr[6] = z6;
Z.pr[7] = z7;
Z.pr[8] = z8;
Z.pr[9] = z9;
Z.pr[10] = z10;
Z.pr[11] = z11;
Z.pr[12] = z12;
Z.pr[13] = z13;
Z.pr[14] = z14;
Z.pr[15] = z15;
Z.pr[16] = z16;
Z.pr[17] = z17;
Z.pr[18] = z18;
Z.pr[19] = z19;
Z.pr[20] = z20;
Z.pr[21] = z21;
Z.pr[22] = z22;
Z.pr[23] = z23;
Z.pr[24] = z24;
Z.pr[25] = z25;
Z.pr[26] = z26;
Z.pr[27] = z27;
Z.pr[28] = z28;
Z.pr[29] = z29;
Z.pr[30] = z30;
Z.pr[31] = z31;
Z.pr[32] = z32;
Z.pr[33] = z33;
Z.pr[34] = z34;
Z.pr[35] = z35;
Z.pr[36] = z36;
Z.pr[37] = z37;
}
prod* nprod ( char* ps )
{
switch ( *ps )
{
case 'S' : return &S;
case 'A' : return &A;
case 'B' : return &B;
case 'C' : return &C;
case 'D' : return &D;
case 'H' : return &H;
case 'F' : return &F;
case 'I' : return &I;
case 'M' : return &M;
case 'N' : return &N;
case 'Z' : return &Z;
default:
{
cout << "error = 1" << endl;
return (char*) 0;
}
}
}
void razbor ( )
{
prod* pprod;
int i, j;
errkod = 0;
pread = lenta;
pstek = &stek[108];
ppriz = &priz[108];
char* psimvol;
stek [109] = 'K';
stek [108] = 'S';
priz [108] = '2';
while ( ( ( *pstek ) != 'K' ) && ( errkod == 0 ))
{
switch ( *ppriz )
{
case '1':
if ((*pstek) == ( *pread ))
{
ppriz++;
pstek++;
pread++;
}
else errkod = 1; break;
case '2':
pprod = nprod ( pstek );
i = 0;
for ( j = 1; j <= (*pprod).m; j++)
{
psimvol = ( *pprod ).pr[j-1];
switch ( *psimvol )
{
case '1':
if ( (*(psimvol+18))!=(*pread))
break;
else
{
i = j;
j = (*pprod).m;break;
};
case '2': case '0':
i = j;
j = (*pprod).m; break;
// default : cout << "error = 2" << endl;
}
}
if ( i == 0 )
{
errkod = 2;
break;
}
psimvol = (*pprod).pr[i-1];
ppriz ++;
pstek ++;
if ( ( *psimvol)!='0')
{
while ( (*psimvol)!='3')
psimvol++;
psimvol--;
while ( psimvol >= ( *pprod ).pr[i-1])
{
ppriz--;
pstek--;
(*ppriz) = (*psimvol);
(*pstek) = (*(psimvol+18));
psimvol--;
}
}else;
break;
default :
{
cout << "error = 3" << endl;
errkod = 3;
}
}
}
}
void main()
{
clrscr();
sintx ();
gets(lenta);
pread = lenta;
strlwr(lenta);
razbor();
while ( *pread == 32 )
for ( char x = (pread-lenta); x < strlen ( lenta ); x++)
lenta [ x ] = lenta [ x+1 ];
if ( errkod || *pread != '\0' )
{
cout << endl << "The sentence has an error ";
cout << pread;
}
else
cout << endl << "Processed";
}