Friday, April 1, 2011

3ADDRESS CODE


#include<stdio.h>
#include<ctype.h>
main()
{
char expr[20],stack[20];
int i,top=0,k=0,num[20];
printf("enter the postfix expression\n");
scanf("%s",&expr);
for(i=0;expr[i]!='\0';i++)
if(isalnum(expr[i]))
stack[top++]=expr[i];
else
{
printf("T%d=",k);
if(stack[top-2]=='T')
printf("%c%d",stack[top-2],num[top-2]);
else
printf("%c",stack[top-2]);
printf("%c",expr[i]);
if(stack[top-1]=='T')
printf("%c%d",stack[top-1],num[top-1]);
else
printf("%c",stack[top-1]);
printf("\n");
top=top-2;
stack[top]='T';
num[top++]=k++;
}
}

No comments:

Post a Comment