Git Product home page Git Product logo

ex-9-implementation-of-the-back-end-of-the-compiler-'s Introduction

Ex-9-IMPLEMENTATION-OF-THE-BACK-END-OF-THE-COMPILER-

NAME:RANJAN K

REGISTER NO:212222230116

DATE:

IMPLEMENTATION OF THE BACK END OF THE COMPILER

Aim :

To write a program to implement the back end of the compiler.

ALGORITHM

  1. Start the program.
  2. Get the three variables from statements and stored in the text file k.txt.
  3. Compile the program and give the path of the source file.
  4. Execute the program.
  5. Target code for the given statement is produced.
  6. Stop the program.

PROGRAM

Exp9.c

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main() {
int i = 2, j = 0, k = 2, k1 = 0;
char ip[10], kk[10];
FILE *fp;
printf("Enter the filename of the intermediate code: ");
scanf("%s", kk);
fp = fopen(kk, "r");
if (fp == NULL) {
printf("\nError in opening the file\n");
return 1;
}
printf("\nStatement\tTarget Code\n\n");
while (fscanf(fp, "%s", ip) != EOF) {
printf("%s\tMOV %c,R%d SUB ", ip, ip[i + k], j);
if (ip[i + 1] == '+')
printf("ADD ");
else
printf("SUB ");
if (islower(ip[i]))
printf("%c,R%d\n", ip[i + k1], j);
else
printf("%c,%c\n", ip[i], ip[i + 2]);
j++;
k1 = 2;
k = 0;
}
fclose(fp);
return 0;
}

Exp9.txt

X=a-b Y=a-c Z=a+b C=a-b C=a-b

OUTPUT

image

Result

The back end of the compiler is implemented successfully, and the output is verified.

ex-9-implementation-of-the-back-end-of-the-compiler-'s People

Contributors

ramachandransec avatar ranjanranjan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.