Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Compiler Design CSE314 Banner

๐Ÿ› ๏ธ Compiler Design โ€” CSE314

A hands-on journey through lexical analysis, parsing, and compiler construction.

Language Flex Bison License Stars


Overview โ€ข Features โ€ข Tech Stack โ€ข Project Structure โ€ข Build & Run โ€ข Example Output โ€ข What I Learned โ€ข Contributing โ€ข Author


๐Ÿ“– Overview

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.


โœจ Features

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

๐Ÿ› ๏ธ Tech Stack

Tool Purpose
C Core implementation language
๐ŸฆŠ Flex Lexical analyzer (scanner) generator
๐Ÿฆฌ Bison Parser generator (LALR)
๐Ÿง GCC GNU C Compiler for building executables
๐Ÿ“„ Make Build automation (optional)

๐Ÿ“ Project Structure

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

๐Ÿš€ Build & Run

Prerequisites

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

Building a Flex + Bison Project

# 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

Building a C-only Program

# Navigate to any weekly exercise
cd week-03/

# Compile and run
gcc lexical_analysis_mini_programme.c -o lexer
./lexer

๐Ÿ–ฅ๏ธ Example Output

๐Ÿงฎ Calculator Parser (Task_01)

$ ./calc
Enter expression:
3 + 5 * 2
= 13
(10 - 4) / 2
= 3

๐Ÿ”ค Flex Lexer (lab_01_flex)

$ ./lexer
int x = 42 + 3.14 end

keyword: int
Identifier: x
Operator: =
Number : 42
Count : 1
Operator: +
Float : 3.14
Count : 2

๐Ÿ“ Lexical Analysis (Week 3 โ€” C Implementation)

$ ./lexer
Enter source code: int main() { return 0; }

Keywords:   int, return
Identifiers: main
Operators:  (none)
Symbols:    ( ) { ; }
Numbers:    0

๐Ÿง  What I Learned

Compiler Theory

  • How compilers break source code into tokens (lexical analysis)
  • Context-free grammars and BNF notation
  • LALR parsing and shift-reduce strategies
  • Syntax-directed translation and semantic actions

Practical Skills

  • Writing regular expressions for token patterns
  • Designing .l (Flex) files for scanner generation
  • Defining .y (Bison) files with grammar rules
  • Debugging parser conflicts and ambiguous grammars

C Programming

  • String manipulation and memory management
  • File I/O and stream processing
  • Building tokenizers from scratch
  • Working with function pointers and enums

Tooling & Workflow

  • Unix build pipelines (Flex โ†’ Bison โ†’ GCC)
  • Reading and understanding generated C code
  • Version control with Git for academic projects
  • Writing clear documentation and lab reports

๐Ÿค Contributing

Contributions, improvements, and suggestions are always welcome! Here's how you can help:

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch
    git checkout -b feature/your-improvement
  3. ๐Ÿ’ป Commit your changes
    git commit -m "Add: your improvement description"
  4. ๐Ÿš€ Push to the branch
    git push origin feature/your-improvement
  5. ๐Ÿ“ฌ Open a Pull Request

๐Ÿ’ก Ideas for Contributions

  • Add more parser examples (e.g., while loops, function declarations)
  • Create a Makefile for easy one-command builds
  • Add syntax diagrams or railroad diagrams for grammars
  • Write unit tests for the parsers
  • Translate documentation to other languages

๐Ÿ‘ค Author & Contact

๐Ÿ‘จโ€๐Ÿ’ป Name Md. Emon Hossain
๐ŸŽ“ Department Computer Science & Engineering (CSE)
๐Ÿ“ง Email emonemran677@gmail.com
๐Ÿ™ GitHub @mohammademon10

โญ Show Your Support

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.

Star this repo


Made with โค๏ธ for the open-source and academic community

ยฉ 2026 Md. Emon Hossain โ€” CSE314 Compiler Design

About

Compiler Design (CSE314) repository covering lexical analysis, parsing, and compiler construction using C, Flex, and Bison with lab tasks and mini-projects.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages