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
|
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char tmp[15];
char str[15], csf[15]={"E"};
int ssm=0, i, j, v, k, pos=0, a;
clrscr();
char pt[6][5][4]={"" , "i" , "+" , "*" , "/",
"E", "TX", "n" , "n" , "n",
"X", "n" , "TX", "n" , "" ,
"T", "VY", "n" , "n" , "n",
"Y", "n" , "" , "VY", "" ,
"V", "i" , "n" , "n" , "n"};
cout<<"\n Enter An Expression: "<<endl;
cin>>str;
while(str[ssm]!='/')
{
pos=0;
while(csf[pos]!='E' &&
csf[pos]!='X' &&
csf[pos]!='T' &&
csf[pos]!='Y' &&
csf[pos]!='V' && csf[pos]!='\0')
pos++;
if (csf[pos]=='\0')
break;
for(i=1; i<6; i++)
{
if(csf[pos]==pt[i][0][0])
break;
}
for(j=1; j<5; j++)
{
if(str[ssm]==pt[0][j][0])
break;
}
if(strcmp(pt[i][j], "n")==0)
{
cout<<"\n Null Value: "<<endl;
cout<<pt[i][j];
exit;
}
for(k=0; k<pos; k++)
tmp[k]=csf[k];
tmp[k]='\0';
strcat(tmp, pt[i][j]);
int l= strlen(tmp);
k=l;
for(a=pos+1; csf[a]!='\0'; a++, k++)
tmp[k]=csf[a];
strcpy(csf, tmp);
}
strcat(csf, "/");
if(strcmp(csf, str)==0)
{
cout<<"\t csf"<<csf;
cout<<"\tstr"<<str;
cout<<"\n Valid Expression: "<<endl;
}
else
{
cout<<"\n Invalid Expression:"<<endl;
}
getch();
return 0;
}
|