An interactive finite automaton simulator built with Next.js and TypeScript. Convert regular expressions into NFAs via Thompson's construction, transform them into DFAs using subset construction, visualize state diagrams, and simulate string acceptance — all in the browser.
Live Demo: https://fa.rakeshan.me/
- Regex → NFA — Converts regular expressions to non-deterministic finite automata using Thompson's construction
- NFA → DFA — Optional conversion to a deterministic finite automaton via subset construction
- DFA Minimization — Reduces DFA states using partition refinement (Hopcroft's algorithm)
- State Diagram Visualization — Interactive graph rendering of NFA/DFA state diagrams
- String Simulation — Step-by-step simulation of input strings to check acceptance
- Regex Validation — Input validation and tokenization of regular expressions
| Layer | Technology |
|---|---|
| Framework | Next.js 16 (App Router) |
| Language | TypeScript 5 |
| Styling | Tailwind CSS 4 |
| Linting | Biome |
| UI Library | React 19 |
# Clone the repository
git clone https://github.com/KRakeesh04/FA-simulator.git
cd FA-simulator
# Install dependencies
bun install
# Start the development server
bun devOpen http://localhost:3000 in your browser.
| Command | Description |
|---|---|
bun dev |
Start development server |
bun run build |
Create production build |
bun start |
Serve production build |
bun run lint |
Run Biome linter |
bun run format |
Auto-format code with Biome |
- Enter a regular expression (e.g.
(a|b)*abb) in the input field. - Click Build NFA to generate the non-deterministic finite automaton.
- Optionally convert to a DFA or minimize the DFA using the control buttons.
- View the resulting state diagram in the visualization panel.
- Enter a test string and run the simulation to check whether it is accepted or rejected.
src/
├── app/
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main page
├── components/
│ ├── Controls.tsx # Build / convert / minimize buttons
│ ├── DiagramView.tsx # State diagram visualization
│ ├── RegexInput.tsx # Regex input field with validation
│ └── SimulationPanel.tsx # String simulation interface
├── core/
│ ├── graphAdapter.ts # Converts automata to graph data
│ ├── minimizeDFA.ts # DFA minimization (Hopcroft's)
│ ├── postfix.ts # Infix-to-postfix regex conversion
│ ├── simulator.ts # NFA / DFA string simulation
│ ├── subsetConstruction.ts # NFA → DFA subset construction
│ ├── thompson.ts # Thompson's construction (regex → NFA)
│ └── tokenizer.ts # Regex tokenizer
├── types/
│ └── automata.ts # Type definitions for states & transitions
└── utils/
└── validation.ts # Regex input validation helpers
Converts a regular expression into an equivalent ε-NFA by recursively building small automata for each operator (concatenation, union, Kleene star) and composing them.
Transforms an NFA into a DFA by computing the ε-closure of state sets and mapping each unique set to a single DFA state.
Reduces the number of DFA states by iteratively partitioning states into equivalence classes based on transition behavior, producing the minimal equivalent DFA.
Converts an infix regular expression with explicit concatenation operators into postfix notation, enabling straightforward recursive construction of the NFA.
aaba|ba*(ab)*a+(ab)+a?(a|b)*(a|b)*abba(b|c)d(a|b)(c|d)((a|b)*c)*(a|b)*a(a|b)*(a|b|c)*
- Animated step-by-step NFA/DFA simulation with state highlighting
- Export state diagrams as SVG / PNG
- Support for extended regex operators (
+,?, character classes) - Shareable URLs encoding the automaton state
- Dark / light theme toggle
- Mobile-responsive layout
- Unit tests for core algorithms
This project is licensed under the MIT License.