Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GitHub License GitHub Stars GitHub Forks GitHub Issues GitHub Pull Requests Contributions Welcome

Last Commit Commit Activity Repo Size Code Size

Top Language Languages Count

Documentation Open Source Love

๐Ÿ”ง Compiler Construction Lab

A comprehensive collection of compiler construction laboratory exercises and projects, implementing lexical analyzers, parsers, and compiler components using Lex and Yacc tools.


๐Ÿ”— Links


๐Ÿ“‘ Table of Contents


๐Ÿš€ Installation

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • Flex (Fast Lexical Analyzer Generator)
  • Bison (Yacc-compatible parser generator)
  • GCC (GNU Compiler Collection)
  • Git

Setup Steps

  1. Clone the Repository

    git clone https://github.com/H0NEYP0T-466/Compiler_Construction.git
    cd Compiler_Construction
  2. Install Flex & Bison

    On Ubuntu/Debian:

    sudo apt-get update
    sudo apt-get install flex bison gcc

    On macOS:

    brew install flex bison

    On Windows:

    • Download Flex & Bison from GnuWin32
    • Add the binaries to your system PATH
  3. Verify Installation

    flex --version
    bison --version
    gcc --version

โšก Usage Examples

Generating a Lexical Analyzer

# Navigate to any lab directory
cd Lab#3/TASK#1

# Generate the lexical analyzer
lex filename.l

# Compile the generated C code
gcc lex.yy.c -o output

# Run the lexical analyzer
./output

Generating a Parser with Lex/Yacc

# Generate the parser
yacc -d filename.y

# Generate the lexical analyzer
lex filename.l

# Compile everything together
gcc y.tab.c lex.yy.c -o parser

# Run the parser
./parser

Example: Running Calculator Parser

cd Lab#5/Task#2

# Build the calculator
yacc -d parser.y
lex scanner.l
gcc parser.tab.c lex.yy.c -o calc

# Run the calculator
./calc

โœจ Features

  • ๐ŸŽฏ Lexical Analysis: Implementation of tokenizers using Flex
  • ๐Ÿ” Syntax Analysis: Parser generation using Bison/Yacc
  • ๐Ÿงฎ Expression Parsing: Arithmetic expression evaluation
  • ๐Ÿ“ Symbol Table Management: Variable and identifier tracking
  • ๐Ÿ”„ Three-Address Code Generation: Intermediate code representation
  • ๐Ÿ“š Comprehensive Lab Materials: Complete lab exercises with documentation
  • ๐ŸŽ“ Educational Focus: Designed for learning compiler construction concepts
  • ๐Ÿ”ง Multiple Implementations: Various compiler components across different labs

๐Ÿ“‚ Folder Structure

Compiler_Construction/
โ”œโ”€โ”€ ๐Ÿ“ Lab#3/                    # Lexical Analysis Fundamentals
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Lab#3.l              # Main lexical analyzer
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ TASK#1/              # Token recognition exercises
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Lab#4/                    # Parser Generation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ TASK#2/              # Basic parser implementation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ TASK#3/              # Grammar rules
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Lab#5/                    # Expression Parsing & Evaluation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Task#2/              # Calculator implementation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Task#3/              # Expression handling
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Lab#6/                    # Advanced Parsing Techniques
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Q#3/                 # Complex grammar implementation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Q#4/                 # Error handling
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Lab#7/                    # Syntax-Directed Translation
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Lab#9/                    # Code Generation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Task#3/              # Three-address code
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Task#4/              # Code optimization
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ OEL#1/                    # Open Ended Lab - Project 1
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ GROUP#1/             # Group project implementations
โ”‚   โ””โ”€โ”€ ๐Ÿ“ GROUP#3/             # Advanced projects
โ”œโ”€โ”€ ๐Ÿ“ OEL#2/                    # Open Ended Lab - Project 2
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ QUIZ#1/                   # Quiz Solutions
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Q1/                  # Quiz 1 solutions
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ Q2/                  # Quiz 2 solutions
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ Manuals/                  # Lab Manuals & Documentation
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Lab4-Manual.pdf
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Lab5-Manual.pdf
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ ๐Ÿ“„ README.md                 # This file

๐Ÿ›  Tech Stack

Languages

C Lex Yacc

Tools & Utilities

Flex Bison GCC Git GitHub

Operating Systems

Linux Windows macOS


๐Ÿ“ฆ Dependencies & Packages

Build Tools

Flex Bison GCC

Runtime Dependencies

This project has no external runtime dependencies. All components are built using standard C libraries and the Flex/Bison toolchain.

Development Dependencies

  • Flex - Fast lexical analyzer generator
  • Bison - Parser generator compatible with Yacc
  • GCC - GNU Compiler Collection for C compilation
  • Make - Build automation tool (optional)

Installation Commands

# Ubuntu/Debian
sudo apt-get install flex bison gcc make

# macOS
brew install flex bison

# Windows (using MSYS2)
pacman -S flex bison gcc make

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details on how to:

  • ๐Ÿด Fork and clone the repository
  • ๐Ÿ”ง Set up your development environment
  • ๐Ÿ“ Follow our code style and conventions
  • ๐Ÿงช Test your changes
  • ๐Ÿ“ค Submit pull requests

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.


๐Ÿ›ก Security

If you discover any security vulnerabilities, please review our Security Policy for responsible disclosure guidelines.


๐Ÿ“ Code of Conduct

This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.


Made with โค by H0NEYP0T-466

About

๐ŸŽ“ Compiler Construction Lab - Hands-on exercises implementing lexical analyzers, parsers & code generators using Lex/Flex & Yacc/Bison. Perfect for CS students! ๐Ÿ”งโœจ

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages