0% found this document useful (0 votes)
6 views2 pages

Intermediate Code Generation

Uploaded by

kumshubham9870
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Intermediate Code Generation

Uploaded by

kumshubham9870
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

#include <string.h>

#include <ctype.h>

// Structure to represent intermediate code instruc ons

struct Instruc on {

char op[5]; // operator

char arg1[5]; // first argument

char arg2[5]; // second argument

char result[5]; // result

} instruc ons[10];

int instrCount = 0;

// Func on to generate intermediate code

void generateInstruc on(char* op, char* arg1, char* arg2, char* result) {

strcpy(instruc ons[instrCount].op, op);

strcpy(instruc ons[instrCount].arg1, arg1);

strcpy(instruc ons[instrCount].arg2, arg2);~~

strcpy(instruc ons[instrCount].result, result);

instrCount++;

// Func on to display the intermediate code

void displayInstruc ons() {

prin ("Three Address Code (TAC):\n");

for (int i = 0; i < instrCount; i++) {

prin ("%s = %s %s %s\n", instruc ons[i].result, instruc ons[i].arg1, instruc ons[i].op,


instruc ons[i].arg2);

}
int main() {

char tempVar[5], op1[5], op2[5], result[5];

// Let's assume the expression: a = b + c * d

// Step 1: c * d -> temp1

generateInstruc on("*", "c", "d", "t1");

// Step 2: b + temp1 -> a

generateInstruc on("+", "b", "t1", "a");

// Display the instruc ons

displayInstruc ons();

return 0;

You might also like