Formal Language Theory & Parsing ~3 min read

Chomsky Normal Form (CNF) ConverterFlask Web App

system://chomsky-normal-form-cnf-converterflask-web-app/walkthrough

Overview & Purpose

An interactive web application that converts any user-defined Context-Free Grammar (CFG) into Chomsky Normal Form (CNF) while clearly displaying each transformation step. Built using Python, Flask, HTML, CSS, and a clean UI for easy grammar visualization.

Problem & Motivation

Converting Context-Free Grammars into Chomsky Normal Form is a core step in formal language theory and parsing algorithms, yet manual multi-step reductions are tedious and error-prone. This web tool automates each transformation step with clear visual feedback.

Architecture & Implementation

  • Grammar Production Parser: Parses user-defined grammar rules into formal non-terminal and terminal representations, validating syntax rules.
  • Four-Stage Algebraic Reduction: Sequentially eliminates null productions, removes unit productions, isolates single terminals with proxy non-terminals, and chains variables into strictly binary forms.
  • Step-by-Step Visualization: Retains intermediate rule states after each reduction phase so users can verify the mathematical transformation.

Key Technical Decisions

  • Deterministic Pipeline: Standardized the sequence of grammar reduction stages to ensure consistent and valid CNF output.
  • Input Validation: Verifies grammar completeness and syntax before executing the transformation pipeline.

Engineering Challenges & Lessons

  • Transitive Unit-Production Resolution: Addressed cascading unit-production chains by computing transitive closures across production graphs.

Technologies & Specifications

Python HTML CSS
Deployment Standalone Local Implementation / Open Source
Showcase Tier Portfolio Implementation