Saturday, October 8

C Program to generate Intermediate code



#include<stdio.h>
#include<ctype.h>
#include<string.h>

main()
{
char a[20];
int i=2,n;
printf("Exp  :");
scanf("%s", a);
if(isdigit(a[0]))
printf("MVI A,%c\n",a[0]);
else printf("MOV A,%c\n",a[0]);
n=strlen(a);
while(i<n)
{
switch(a[i])
{
case '+':printf("ADD B\n");i+=3;break;
case '-':printf("SUB B\n");i+=3;break;



default:if(isdigit(a[i]))
printf("MVI B,%c\n",a[i]);
else
printf("MOV B,%c\n",a[i]);
i--;
}
}
}

4 comments :

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

I doesn't work

Neha pal said... Best Blogger Tips [Reply to comment] Best Blogger Templates

it's not working

Neha pal said... Best Blogger Tips [Reply to comment] Best Blogger Templates

it's not working

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

good one, nerd. doesn't work

Post a Comment