Saturday, April 4, 2009

source code

#include
#include
#include
#include
#include
struct table
{
char op[5],arg1[5],arg2[5];
}t[10];
void main()
{
clrscr();
int i,j=0,k=0;
char s[30];
cout<<"\n Generation of 3 addr code triple implementation";
while(1)
{
cout<<"\n For exit press ~ \n else enter the expression";
gets(s);
if(!strcmp(s,"~"))
break;
i=strlen(s)-1;
t[j].arg2[k]=s[i];
t[j].op[k]=s[i-1];
t[j].arg1[k]=s[i-2];
cout<for(int l=0;l<50;l++)
if(l==8)
cout<<"+";
else
cout<<"-";
cout<j++;
for( i=strlen(s)-4;i>0;i-=2)
{
t[j].op[k]=s[i];
t[j].arg1[k]=s[i-1];
itoa(j-1,t[j].arg2,10);
cout<j++;
}
}
cout<<"the end";
getch();
}

OUTPUT:

Generation of 3 addr code triple implementation
For exit press ~
else enter the expression a=b*c+d*e


temp var op oprnd1 oprnd2
----------+---------------------------------------------------------
0 * d e
1 + c (0)
2 * b (1)
3 = a (2)
For exit press ~
else enter the expression ~
the end