Skip to content

shivamkumard107/AtmanirbharCompilerProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Atmanirbhar Compiler Project

A basic compiler made using C language, using Extended Backus–Naur form(EBNF) for defining the grammar of the formal language.
Explore the docs »

View Demo(Youtube) · Report Bug · Request Improvements

Table of Contents

About The Project

A compiler is a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer.

This(actually every) Compiler is build into two sections known as frontend and backend.

Frontend contains:

  • Lexical analyzer
  • Syntax analyzer
  • Semantic analysis
  • Intermediate code generator

Backend contains:

  • Code optimizer
  • Code generator

The Atmanirbhar compiler is divided into three parts. In the frontend we build lexical and syntax analyzer giving output an intermediate form and backend contains code generator which outputs assembly code finally. 😄

EBNF Code

Extended Backus–Naur form (EBNF) is a family of metasyntax notations, any of which can be used to express a context-free grammar. EBNF is used to make a formal description of a formal language such as a computer programming language. They are extensions of the basic Backus–Naur form (BNF) metasyntax notation. EBNFcode

Built With

Logo

Getting Started

We will first compile the Lexial analyzer, Syntax analyzer and Code generator using gcc

Prerequisites

  • gcc
sudo apt update

sudo apt install build-essential

sudo apt-get install manpages-dev

gcc --version

Running and Compiling

  1. Compile the Lexical, Syntax analyzer and Code generator
gcc Code/Lexical.c -o lex
gcc Code/Syntax.c -o syntax
gcc Code/CodeGen.c -o codegen
  1. Use the given testcases(testcase1.txt, testcase2.txt) as an input in lex analyzer and redirect output to lexOutput.txt
./lex testcase1.txt > lexOut.txt
  1. Lexial analyzer outputs stream of tokens which consists of identifier, keywords,separator,operator, and literals which goes as an input in Syntax analyzer
./syntax lexOut.txt > synOut.txt
  1. Syntax analyzer outputs a parse tree build from the grammar defined by EBNF(disscussed above) which goes as an input in Code generator
./codegen synOut.txt > codeGen.txt

Example Testcases

  • Sample Testcase 1
count = 5;
c = 'a';
 while (count < 100) {
     print("count is: ", count, "\n");
     count = count + 5;
 }

Output for above testcase:

/*
  Comments supported
 */
number = 5;

if(number<10){

	print(number, "\n");
}

Output for above testcase:

Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contributors

Contact

Shivam Kumar - @shivamkumard107 - [email protected]

Acknowledgements

About

Basic Compiler Made using C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages