Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 2.03 KB

File metadata and controls

67 lines (52 loc) · 2.03 KB

Multi-Parser Visualizer with AI-Assisted Grammar Analysis

An interactive compiler design tool that compares LL(1), LR(0), SLR(1), CLR(1), and LALR(1) parsing techniques, now with an integrated Gemini AI grammar assistant.

Quick Start

# 1. Install dependencies
pip install -r requirements.txt

# 2. Set your Gemini API key (for AI features)
$env:GEMINI_API_KEY="your_api_key_here"

# 3. Run the app
streamlit run app.py

AI Features

The AI Grammar Assistant (powered by AI) is embedded directly in Step 1 and appears as a panel below the grammar editor. It:

  • Validates grammar structure
  • Detects left recursion, ambiguity, undefined/unreachable/non-productive symbols
  • Suggests fixes for detected issues
  • Generates valid sample strings from the grammar
  • Supports follow-up chat — ask Claude questions about your grammar

A compact AI summary also appears on the Step 6 Compare Results page.

All parsing functionality works without the API key.

File Structure

app.py              — Main Streamlit UI (integrated AI assistant)
ai_client.py        — Gemini API 
grammar.py          — Grammar class with aivalidate() and aiask() methods
first_follow.py     — FIRST / FOLLOW set computation
ll1_table.py        — LL(1) parsing table builder
parser.py           — LL(1) parser simulator
lr0_engine.py       — LR(0) DFA (closure / goto)
lr0_table.py        — LR(0) ACTION/GOTO table
slr1_table.py       — SLR(1) table builder
slr1_parser.py      — SLR(1) parser simulator
lr1_engine.py       — LR(1) canonical collection
clr_table.py        — CLR(1) table builder
lalr_table.py       — LALR(1) table builder (merges CLR states)
parse_tree.py       — Parse tree node and printer
requirements.txt    — Python dependencies

Grammar Format

E -> T E'
E' -> + T E' | ^
T -> F T'
T' -> * F T' | ^
F -> ( E ) | id
  • Use -> to separate LHS from RHS
  • Use | for alternatives
  • Use ^ for epsilon (empty production)
  • Non-terminals: Uppercase letters
  • Terminals: lowercase / symbols