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) |
| ๐ง Email | 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