A hands-on journey through lexical analysis, parsing, and compiler construction.
Overview • Features • Tech Stack • Project Structure • Build & Run • Example Output • What I Learned • Contributing • Author
This repository is a comprehensive collection of coursework, labs, and mini-projects from the Compiler Design (CSE314) course. It covers the foundational concepts of compiler construction — from lexical analysis with hand-written C programs, to scanner generation with Flex, to parser construction with Bison.
Whether you're a fellow student looking for reference material, or a curious developer wanting to understand how compilers work under the hood, this repo has something for you. Each directory is self-contained with source files, build artifacts, and documentation.
| Category | Highlights |
|---|---|
| 🔤 Lexical Analysis | Hand-written tokenizers in C — keywords, identifiers, operators, comments |
| ⚡ Flex (Scanner Generator) | .l files demonstrating pattern matching, token recognition, and lexer rules |
| 🌳 Bison (Parser Generator) | .y files with grammar rules, AST construction, and syntax-directed translation |
| 🧮 Calculator Parser | Full arithmetic expression evaluator with operator precedence |
| 🔀 Boolean Expression Parser | Recognizes and evaluates boolean logic expressions |
| 🔁 If-Else Parser | Parses conditional control-flow syntax |
| 📋 List Processor | Parses and processes structured list input |
| 📝 Weekly Lab Reports | Progressive exercises building toward full lexical analysis |
| 📄 Comprehensive Documentation | PDF reports, lab manuals, and notes included |
Compiler-Design-CSE314/
│
├── 📄 README.md
├── 🖼️ assets/
│ └── banner.png
│
├── 📂 Flex_&_Bison_Lab/ # ⚡ Core Flex & Bison labs
│ ├── lab_01_flex/ # └─ Basic Flex lexer (token recognition)
│ │ ├── abcd.l # Flex source with keyword/number rules
│ │ └── basic_syntax_of_flex # Syntax reference notes
│ │
│ ├── lab_02/ # └─ Lexer + Parser combo
│ │ ├── lexer.l # Flex scanner
│ │ └── parser.y # Bison grammar
│ │
│ ├── lab_03/ # └─ Full Flex-Bison integration
│ │ ├── abc.l # Flex scanner
│ │ ├── abc.y # Bison parser
│ │ └── baison_basic_&_Syntax # Quick reference notes
│ │
│ ├── Lab_Task_02/ # └─ 🎯 Mini-Projects
│ │ ├── Task_01/ # 🧮 Calculator (arithmetic parser)
│ │ │ ├── calc.l
│ │ │ └── calc.y
│ │ ├── Task_02/ # 📝 Assignment & expression parsing
│ │ ├── Task_03/ # 🔀 Boolean expression parser
│ │ ├── Task_4/ # 🔁 If-else control flow parser
│ │ └── Task_5/ # 📋 List processing parser
│ │
│ └── Flex_&_Bison_All_Notes_&_Documents/
│ ├── Flex Bison Lab Manual.pdf
│ ├── Flex Installation Guide.pdf
│ ├── flex and bison flow diagram.pdf
│ └── flex_bison_boolean_if_else_parser.pdf
│
├── 📂 LAB_REPORT/ # 📄 Formal Lab Reports (PDF/DOCX)
│ ├── CD_Lab_01_04_Emon_818.pdf
│ ├── Compiler_Lab_Report_05_10_Flex_Bison.pdf
│ └── Compilerlabreport.docx
│
├── 📂 week-01/ # 📅 Week 1 — String Operations in C
│ ├── P1_string_len.c
│ ├── P2_String_copy.C
│ ├── p3_concataning_two_string.c
│ ├── p4_comparing_two_string.c
│ └── p5_reverse_string.c
│
├── 📂 week-02/ # 📅 Week 2 — Whitespace & Tokenization
│ ├── p1_Whatespace.c
│ ├── p2.isspace.c
│ ├── p3_Count_Whitespace.c
│ ├── p4_remove_Whitespace.c
│ └── p5_tokenization.c
│
├── 📂 week-03/ # 📅 Week 3 — Lexical Analysis Programs
│ ├── p1_identifi_intiger_from_string.c
│ ├── p2_identify_keywords.c
│ ├── p3_identifiyer.c
│ ├── p4_valididentifier_check.c
│ ├── P5_Operators.c
│ ├── P6_special_Symbols.c
│ ├── p7_Extract_Comments.C
│ ├── Lexical_Analysis_use_Function.c
│ └── lexical_analysis_mini_programme.c
│
└── 📂 week-04/ # 📅 Week 4 — Regex & Advanced Parsing
├── Lab_task_regular_expression.c
├── Regular_expression_using_function.c
└── lexical_analysis.c
Make sure you have the following installed:
| Tool | Install Command (Ubuntu/Debian) | Windows |
|---|---|---|
| GCC | sudo apt install gcc |
MinGW |
| Flex | sudo apt install flex |
WinFlexBison |
| Bison | sudo apt install bison |
WinFlexBison |
# 1. Navigate to the project directory
cd Flex_&_Bison_Lab/Lab_Task_02/Task_01/
# 2. Generate the parser
bison -d calc.y
# 3. Generate the scanner
flex calc.l
# 4. Compile everything together
gcc lex.yy.c calc.tab.c -o calc -lfl
# 5. Run the calculator
./calc# Navigate to any weekly exercise
cd week-03/
# Compile and run
gcc lexical_analysis_mini_programme.c -o lexer
./lexer$ ./calc
Enter expression:
3 + 5 * 2
= 13
(10 - 4) / 2
= 3
$ ./lexer
int x = 42 + 3.14 end
keyword: int
Identifier: x
Operator: =
Number : 42
Count : 1
Operator: +
Float : 3.14
Count : 2
$ ./lexer
Enter source code: int main() { return 0; }
Keywords: int, return
Identifiers: main
Operators: (none)
Symbols: ( ) { ; }
Numbers: 0
|
Compiler Theory
|
Practical Skills
|
|
C Programming
|
Tooling & Workflow
|
Contributions, improvements, and suggestions are always welcome! Here's how you can help:
- 🍴 Fork the repository
- 🌿 Create a feature branch
git checkout -b feature/your-improvement
- 💻 Commit your changes
git commit -m "Add: your improvement description" - 🚀 Push to the branch
git push origin feature/your-improvement
- 📬 Open a Pull Request
- Add more parser examples (e.g.,
whileloops, function declarations) - Create a
Makefilefor easy one-command builds - Add syntax diagrams or railroad diagrams for grammars
- Write unit tests for the parsers
- Translate documentation to other languages
| 👨💻 Name | Md. Emon Hossain |
| 🎓 Department | Computer Science & Engineering (CSE) |
| emonemran677@gmail.com | |
| 🐙 GitHub | @mohammademon10 |
If this repository helped you understand compiler design concepts or saved you time on coursework,
please consider giving it a star! Every ⭐ motivates me to keep improving and sharing.
Made with ❤️ for the open-source and academic community
© 2026 Md. Emon Hossain — CSE314 Compiler Design