Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tamimehsan/c-compiler

A short subset of C Compiler
https://github.com/tamimehsan/c-compiler

bison c-compiler compiler intermediate-code-generation lexical-analysis semantic-analysis symbol-table yacc

Last synced: about 15 hours ago
JSON representation

A short subset of C Compiler

Awesome Lists containing this project

README

        

# **Simple C Compiler**

A very basic compiler of C with not so basic functionalities

### Quick Run
You need to install the following in your ubuntu machine
```
sudo apt install yacc
sudo apt install flex
```
also make sure you have gcc compiler installed. Yes, we will compile a compiler with a compiler!
Then finally run the script file to get the desired executable
```
bash script.h
```
The code generates a asm file. You will need 8086 emulator to run the intermediate code.
### Inner Workings
- Stage 1: Lexical Analysis
- Stage 2: Semantic Analysis
- Stage 3: Intermediate Code Generation
- Stage 4: Optimization

Lexical analyzer Flex is user to parse the tokens. Then the tokens are fed them to Yacc for semantic analysis. The identifiers are stored a in a symbol table. Then it generates executable intermediate 8086 codes. And finally it optimizes code using various optimization technique like peephole optimization. Then using 8086 emulator the asm can be executed to get the desired output.

### Supported functionalities
- Basic operations
- Type casting
- Simple IO
- Scope management
- Controll Statement
- Functions with parameters and return value
- Recursion
- Verbose error detection
- Single and Multi line comment

Supported data types are
- Integer
- Float
- Double
- Char