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
- About the Project
- Getting Started
- Example Testcases
- Contributing
- License
- Contributors
- Contact
- Acknowledgements
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. 😄
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
We will first compile the Lexial analyzer, Syntax analyzer and Code generator using gcc
- gcc
sudo apt update
sudo apt install build-essential
sudo apt-get install manpages-dev
gcc --version
- 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
- 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
- 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
- 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
- Sample Testcase 1
count = 5;
c = 'a';
while (count < 100) {
print("count is: ", count, "\n");
count = count + 5;
}
Output for above testcase:
-
Sample Testcase 2
/*
Comments supported
*/
number = 5;
if(number<10){
print(number, "\n");
}
Output for above testcase:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
- Shivam Kumar - Initial work - @shivamkumard107
- Shashank Kumar - Initial work - @shashank
- Shikhar Malik - Initial work - @shikharmaxx
Shivam Kumar - @shivamkumard107 - [email protected]