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.
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.
- 📌 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
- Validates CFG input
- Handles ε (epsilon) productions
- Displays computed FIRST & FOLLOW sets
- Shows item sets and transitions
- Highlights shift/reduce and reduce/reduce conflicts
- Indicates ambiguity clearly
- Step through input parsing
- View stack, input, and action transitions
- Debug grammars interactively
This tool is perfect for students and developers learning compilers, automata, and formal languages.
| Component | Technology |
|---|---|
| Frontend | React, Vite |
| Backend | Python |
| UI Libraries | (React components you use) |
| Grammar Engine | Custom Python parser logic |
CD-PROJECT/
├── backend/ # Python grammar and parser logic
├── frontend/ # React + Vite UI
├── README.md
└── .gitignore
-
Enter CFG:
Define grammar productions in the frontend. -
Compute FIRST & FOLLOW:
Backend calculates sets using standard CFG algorithms. -
Build LR(1) Items:
Generates canonical LR(1) item sets. -
Create Parsing Table:
Produces ACTION and GOTO tables. -
Check Ambiguity:
Detects shift/reduce and reduce/reduce conflicts. -
Simulate Parsing:
Step through stack/input transitions for given input strings.
git clone https://github.com/tanikaaaa/CD-PROJECT.git
cd CD-PROJECT-
Navigate to backend:
cd backend -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Run the backend server:
python app.py
-
Navigate to frontend:
cd frontend -
Install node dependencies:
npm install
-
Start dev server:
npm run dev
Visit the app at the URL shown in the terminal (usually
http://localhost:5173).
- Grammar validation and debugging
- Educational tool for compilers coursework
- Visualizing parsing steps and conflicts
- Understanding FIRST/FOLLOW and LR(1) mechanics
Process:
- FIRST/FOLLOW sets computed
- LR(1) item sets built
- Parsing table generated
- Ambiguity detected
- Input simulation executed
- 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