- ✅ Lexical Analysis using Flex
- ✅ Syntax Analysis using Bison
- ✅ Token Recognition
- ✅ Parsing and Grammar Validation
- ✅ Symbol Table Generation
- ✅ Intermediate Instruction Generation
- ✅ Error Detection and Reporting
- ✅ Command-Line Based Compiler Workflow
Source Code
│
▼
Lexical Analyzer (Flex)
│
▼
Token Stream
│
▼
Parser (Bison)
│
▼
Syntax Tree / Validation
│
▼
Symbol Table Generation
│
▼
Intermediate Instructions
| Technology | Purpose |
|---|---|
| C | Core Implementation |
| Flex (Lex) | Lexical Analysis |
| Bison (YACC) | Syntax Analysis & Parsing |
| GCC | Compilation |
| Ubuntu 24.04 | Development Environment |
| Oracle VirtualBox | Virtualized Environment |
| Git & GitHub | Version Control |
mini_compiler/
│
├── lexer.l
├── parser.y
├── input.txt
├── input2.txt
├── compiler
├── README.md
├── LICENSE
└── .gitignore
sudo apt update
sudo apt install flex bison gcc make git -yGenerate lexer and parser files:
flex lexer.l
bison -d parser.yCompile the compiler:
gcc lex.yy.c parser.tab.c -o compiler -lfl./compiler < input.txt./compiler < input2.txtint a;
a = 10;
if (a > 5) {
int b;
b = a + 2;
while (b > 0) {
int c;
c = b - 1;
b = b - 1;
}
}| Category | Supported Elements |
|---|---|
| Data Types | int, float |
| Conditional Statements | if, else |
| Loops | while |
| Arithmetic Operators | +, -, *, / |
| Relational Operators | ==, !=, <, >, <=, >= |
| Delimiters | ; |
| Brackets | (), {} |
| Variable Declarations | Supported |
| Assignments | Supported |
Through this project, the following compiler design concepts were explored:
- Compiler Construction Fundamentals
- Lexical Analysis
- Syntax Analysis
- Parsing Techniques
- Context-Free Grammars
- Symbol Table Management
- Intermediate Code Representation
- Flex & Bison Integration
- Linux-Based Development Workflow
This project was developed as part of Compiler Design coursework and serves as a practical demonstration of how programming language source code is analyzed and processed during compilation.
- Semantic Analysis
- Abstract Syntax Tree (AST) Generation
- Type Checking
- Optimization Passes
- Three-Address Code Generation
- Assembly Code Generation
- Enhanced Error Recovery
Department of Computer Science & Engineering (CSE)
University of Asia Pacific (UAP)
GitHub: https://github.com/tausif112
This project is licensed under the MIT License.