Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

📘 Grammar Ambiguity Checker & LR(1) Parser

A full-stack application that analyzes context-free grammars (CFGs) using LR(1) parsing. The system calculates FIRST & FOLLOW sets, builds LR(1) item sets, generates the LR(1) parsing table, detects grammar ambiguity (shift/reduce or reduce/reduce conflicts), and supports parse simulation for input strings.

🚀 Project Overview

This project combines:

  • 🔹 Python Backend — Grammar processing, LR(1) construction, and parsing logic
  • 🔹 React + Vite Frontend — Interactive UI for entering grammars and simulating parsing

The system guides users through fundamental compiler concepts such as FIRST/FOLLOW set calculation, LR(1) table construction, and conflict detection.

🧠 What It Does

  • 📌 Computes FIRST and FOLLOW sets for CFGs
  • 📌 Constructs LR(1) item sets
  • 📌 Generates LR(1) parsing tables
  • 📌 Detects ambiguity via parsing table conflicts
  • 📌 Simulates parsing of input strings
  • 📌 Displays step-by-step parse actions

💻 Features

📊 Grammar Analysis

  • Validates CFG input
  • Handles ε (epsilon) productions
  • Displays computed FIRST & FOLLOW sets

📈 LR(1) Table Generation

  • Shows item sets and transitions
  • Highlights shift/reduce and reduce/reduce conflicts
  • Indicates ambiguity clearly

▶️ Parse Simulation

  • Step through input parsing
  • View stack, input, and action transitions
  • Debug grammars interactively

🧠 Learning Focus

This tool is perfect for students and developers learning compilers, automata, and formal languages.

🛠️ Tech Stack

Component Technology
Frontend React, Vite
Backend Python
UI Libraries (React components you use)
Grammar Engine Custom Python parser logic

🗂 Project Structure

CD-PROJECT/
├── backend/      # Python grammar and parser logic
├── frontend/     # React + Vite UI
├── README.md
└── .gitignore

⚙️ How It Works

  1. Enter CFG:
    Define grammar productions in the frontend.

  2. Compute FIRST & FOLLOW:
    Backend calculates sets using standard CFG algorithms.

  3. Build LR(1) Items:
    Generates canonical LR(1) item sets.

  4. Create Parsing Table:
    Produces ACTION and GOTO tables.

  5. Check Ambiguity:
    Detects shift/reduce and reduce/reduce conflicts.

  6. Simulate Parsing:
    Step through stack/input transitions for given input strings.

🏃 Running the App

Clone the Repository

git clone https://github.com/tanikaaaa/CD-PROJECT.git
cd CD-PROJECT

Backend (Python)

  1. Navigate to backend:

    cd backend
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate      # macOS/Linux
    .\venv\Scripts\activate       # Windows
  3. Install dependencies:

    pip install -r requirements.txt
  4. Run the backend server:

    python app.py

Frontend (React + Vite)

  1. Navigate to frontend:

    cd frontend
  2. Install node dependencies:

    npm install
  3. Start dev server:

    npm run dev

    Visit the app at the URL shown in the terminal (usually http://localhost:5173).

🤝 Use Cases

  • Grammar validation and debugging
  • Educational tool for compilers coursework
  • Visualizing parsing steps and conflicts
  • Understanding FIRST/FOLLOW and LR(1) mechanics

Process:

  1. FIRST/FOLLOW sets computed
  2. LR(1) item sets built
  3. Parsing table generated
  4. Ambiguity detected
  5. Input simulation executed

🛠 Future Enhancements

  • Support for other parser types (LL(1), SLR(1), LALR(1))
  • Visual graph representation of item sets
  • Export parsing tables and reports
  • Web deployment & hosting

About

This is a Grammar Ambiguity Checker using LR(1) parsing. It takes a context-free grammar, computes FIRST and FOLLOW sets, builds LR(1) items, generates parsing table, and detects ambiguity through shift/reduce or reduce/reduce conflicts. It also supports parse simulation for input strings, helping us understand LR(1) parsing and analyze grammars.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages