Intermediate code generation in c programming Saturday, September 14, 2013 /** * Problem: Intermediate code generation * Author: Md. Mahedi Azad * Date 12-Sep-2013 * */ #include #include #include int i=1,j=0,no=0,tmpch=90; char str[100],left[15],right[15]; void findopr(); void explore(); void fleft(int); void fright(int); struct exp { int pos; char op; }k[15]; int main() { printf("\t\tINTERMEDIATE CODE GENERATION\n\n"); printf("Enter the Expression :"); scanf("%s",str); printf("The intermediate code:\t\tExpression\n"); findopr(); explore(); } void findopr() { for(i=0;str[i]!='\0';i++) if(str[i]==':') { k[j].pos=i; k[j++].op=':'; } for(i=0;str[i]!='\0';i++) if(str[i]=='/') { k[j].pos=i; k[j++].op='/'; } for(i=0;str[i]!='\0';i++) if(str[i]=='*') { k[j].pos=i; k[j++].op='*'; } for(i=0;str[i]!='\0';i++) if(str[i]=='+') { k[j].pos=i; k[j++].op='+'; } for(i=0;str[i]!='\0';i++) if(str[i]=='-') { k[j].pos=i; k[j++].op='-'; } } void explore() { i=1; while(k[i].op!='\0') { fleft(k[i].pos); fright(k[i].pos); str[k[i].pos]=tmpch--; printf("\t%c := %s%c%s\t\t",str[k[i].pos],left,k[i].op,right); for(j=0;j Output: Labels: C
Intermediate code generation in c programming Saturday, September 14, 2013 /** * Problem: Intermediate code generation * Author: Md. Mahedi Azad * Date 12-Sep-2013 * */ #include #include #include int i=1,j=0,no=0,tmpch=90; char str[100],left[15],right[15]; void findopr(); void explore(); void fleft(int); void fright(int); struct exp { int pos; char op; }k[15]; int main() { printf("\t\tINTERMEDIATE CODE GENERATION\n\n"); printf("Enter the Expression :"); scanf("%s",str); printf("The intermediate code:\t\tExpression\n"); findopr(); explore(); } void findopr() { for(i=0;str[i]!='\0';i++) if(str[i]==':') { k[j].pos=i; k[j++].op=':'; } for(i=0;str[i]!='\0';i++) if(str[i]=='/') { k[j].pos=i; k[j++].op='/'; } for(i=0;str[i]!='\0';i++) if(str[i]=='*') { k[j].pos=i; k[j++].op='*'; } for(i=0;str[i]!='\0';i++) if(str[i]=='+') { k[j].pos=i; k[j++].op='+'; } for(i=0;str[i]!='\0';i++) if(str[i]=='-') { k[j].pos=i; k[j++].op='-'; } } void explore() { i=1; while(k[i].op!='\0') { fleft(k[i].pos); fright(k[i].pos); str[k[i].pos]=tmpch--; printf("\t%c := %s%c%s\t\t",str[k[i].pos],left,k[i].op,right); for(j=0;j Output: Labels: C