You are on page 1of 2

Ex 6

Implement intermediate code generator for the Boolean expression in three


address code formats.
#include <stdio.h> k[j++].op = str[i];
break;
#include <string.h> }
#include <stdlib.h> }
}
int i = 1, j = 0, no = 0, tmpch = 90;
char str[100], left[15], right[15]; void explore() {
i = 1;
struct exp { while (k[i].op != '\0') {
int pos; fleft(k[i].pos);
char op; fright(k[i].pos);
} k[15]; str[k[i].pos] = tmpch--;
printf("\t%c := %s%c%s\t\t", str[k[i].pos],
void findopr(); left, k[i].op, right);
void explore(); for (j = 0; j < strlen(str); j++) {
void fleft(int); if (str[j] != '$') {
void fright(int); printf("%c", str[j]);
}
int main() { }
printf("\n");
printf("\t\tINTERMEDIATE CODE i++;
GENERATION\n\n"); }
printf("Enter the Expression :"); fright(-1);
scanf("%s", str); if (no == 0) {
printf("The intermediate fleft(strlen(str));
code:\t\tExpression\n"); printf("\t%s := %s", right, left);
findopr();
explore(); exit(0);
}
return 0; printf("\t%s := %c", right, str[k[--i].pos]);
}
}
void findopr() {
for (i = 0; str[i] != '\0'; i++) { void fleft(int x) {
switch (str[i]) { int w = 0, flag = 0;
case ':': x--;
case '/': while (x != -1 && str[x] != '+' && str[x] != '*'
case '*': && str[x] != '=' && str[x] != '\0' && str[x] != '-'
case '+': && str[x] != '/') {
case '-': if (str[x] != '$' && flag == 0) {
k[j].pos = i; left[w++] = str[x];
Ex 6

left[w] = '\0'; while (x != -1 && str[x] != '+' && str[x] != '*'


str[x] = '$'; && str[x] != '\0' && str[x] != '=' && str[x] != '-'
flag = 1; && str[x] != '/') {
} if (str[x] != '$' && flag == 0) {
x--; right[w++] = str[x];
} right[w] = '\0';
} str[x] = '$';
flag = 1;
void fright(int x) { }
int w = 0, flag = 0; x++;
x++; }
}

You might also like