A very basic compiler of C with not so basic functionalities
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.
- 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.
- 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