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: 3 months ago
JSON representation
A short subset of C Compiler
- Host: GitHub
- URL: https://github.com/tamimehsan/c-compiler
- Owner: TamimEhsan
- Created: 2022-09-04T04:43:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-06T12:50:38.000Z (about 2 years ago)
- Last Synced: 2025-01-21T14:38:21.185Z (about 1 year ago)
- Topics: bison, c-compiler, compiler, intermediate-code-generation, lexical-analysis, semantic-analysis, symbol-table, yacc
- Language: Yacc
- Homepage:
- Size: 505 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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