Skip to content

KebanFiru/theory_of_computation_simulator

Repository files navigation

Computation Theory Simulator

Computation Theory Simulator is an interactive, canvas-first web application for building, editing, converting, and simulating multiple automata models used in formal languages and automata theory courses.

It is designed for education, experimentation, and fast visual iteration solo or with a class/team working on the same automaton together.

Computation Theory Simulator Main Page

Supported Models

  • Finite Automata (FA): NFA and DFA workflows
  • Pushdown Automata: PDA and NDPA
  • Turing Machines: deterministic and nondeterministic, single-tape and multi-tape transitions
  • Mealy Machines
  • Moore Machines
  • GNFA (Generalized NFA) — for FA → regex extraction
  • CFG (Context-Free Grammar) — skeleton extraction from saved automata

What You Can Do

Canvas Modeling

  • Create and place states on a zoomable/pannable canvas
  • Create and edit transitions directly from canvas interactions
  • Use mode-aware controls so each machine family enforces appropriate transition syntax
  • Move, duplicate, and re-place generated/saved automata on the workspace

Save, Edit, Import, Export

  • Save selected automata regions as reusable cards
  • Reopen saved automata in edit mode
  • Duplicate selected automata
  • Export a selected automaton as JSON
  • Import automata JSON (including backward compatibility handling for legacy snapshots)
  • Save and load full workspace snapshots
  • Clear workspace safely through confirmation flow

Conversion and Generation Tools

  • Regex → NFA via Thompson's construction
  • NFA → minimal DFA via subset construction and minimization
  • FA → GNFA for regular expression extraction via state elimination
  • CFG skeleton generation from saved finite automata

Simulation and Visual Feedback

  • Test strings/inputs from saved cards
  • Transition-path highlighting on canvas during simulation
  • Stack activity visualization for PDA/NDPA runs
  • Output-sequence feedback for Mealy and Moore machine simulations

Inspection Views

  • Transition table rendering per model
  • Regex summary views for finite automata cards
  • Machine summaries (model-specific tuple/style summaries)

Teams & Collaboration

Sign up (or log in) to unlock cloud-synced automata and Teams — a shared workspace for a class or study group.

  • Teams — create a team or join one with an invite code. Every team has a roster with owner / admin / member roles; owners and admins can promote/demote members, remove or ban them, and regenerate the invite code.
  • Real-time shared canvas — a team's live canvas is collaborative: everyone in the team scope sees states and transitions appear as teammates draw them, synced over Supabase Realtime.
  • Projects — organize assignments into (optionally foldered) projects. Team members submit automatons from the shared pool to a project; owners/admins review submissions. Projects can be configured with a submission deadline and a member cap — members join a project before they can submit to it.
  • Team settings — owners/admins can rename the team, cap the number of members and projects, and manage a ban list that blocks re-joining via invite code (with the option to also remove a banned member's contributed automatons).
  • Personal cloud library — automatons you save while signed in (outside a team) sync to your account and follow you across devices; local, signed-out use still works entirely in the browser via localStorage.

AI Accessibility — MCP Server

The simulator exposes an HTTP Model Context Protocol endpoint at POST /api/mcp. AI agents (Claude Code, Cursor, GPT, etc.) can use it to simulate and build automata without touching the canvas.

The endpoint implements JSON-RPC 2.0 and exposes 26 tools — 17 stateless simulate/convert/build tools (no auth needed) plus 9 account/Teams tools that require a personal access token.

Simulate

Tool Description
simulate_fa Test a string against a DFA or NFA
simulate_pda Test a string against a deterministic PDA
simulate_ndpa Test a string against a nondeterministic PDA
simulate_tm Test a string against a single/multi-tape TM
simulate_mealy Run a Mealy machine, return output sequence
simulate_moore Run a Moore machine, return output sequence

Convert

Tool Description
regex_to_nfa Convert regex to NFA via Thompson's construction
nfa_to_dfa Determinize NFA → minimal DFA
fa_to_regex Extract regex from FA via GNFA elimination
get_transition_table Render any automaton as a transition table
get_automata_info Full reference: types, tuple definitions, syntax

Canvas links — returns a URL that opens the automaton directly on the simulator canvas

Tool Machine
build_fa_link DFA / NFA
build_pda_link Deterministic PDA
build_ndpa_link Nondeterministic PDA
build_tm_link Single/multi-tape Turing Machine
build_mealy_link Mealy machine
build_moore_link Moore machine

Account & Teams — require Authorization: Bearer <personal-access-token> (token self-service UI is planned but not shipped yet)

Tool Description
list_my_teams List the teams the authenticated user belongs to, with role
create_team Create a new team owned by the authenticated user
join_team Join a team by invite code
list_team_members List a team's members and roles
list_team_projects List a team's folders/projects
create_project Create a project (assignment) in a team — owner/admin only
list_my_automatons List the user's personal automatons, or a team's if team_id is given
save_automaton Save (or overwrite by name) an automaton, personal or team-scoped
submit_automaton_to_project Attach/detach a team automaton to a project

Quick test:

curl -X POST https://www.theoryofcomputationsimulator.com/api/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

An OpenAPI 3.1 spec is available at /openapi.json. Full reference for LLM agents is at /llms.txt.

Typical Workflows

1) Build from Regex

  1. Open the tools menu.
  2. Use the regex conversion action.
  3. Place the generated automaton on canvas.
  4. Save and test strings from the saved card panel.

2) Convert NFA to DFA

  1. Select a saved NFA card.
  2. Trigger NFA to DFA conversion.
  3. Place the converted automaton.
  4. Compare transition tables and run test inputs.

3) Generate GNFA/CFG Artifacts

  1. Select a compatible saved automaton.
  2. Trigger FA to GNFA or CFG generation.
  3. Place/use generated artifacts for analysis.

4) Work with Full Workspace Snapshots

  1. Save canvas to JSON.
  2. Reload later from the workspace loader.
  3. Continue editing with previous state and saved cards restored.

5) Use with an AI Agent

Ask an AI agent to design an automaton. It calls build_fa_link and returns a URL that opens it on the canvas:

curl -X POST https://www.theoryofcomputationsimulator.com/api/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0", "id": 1,
    "method": "tools/call",
    "params": {
      "name": "build_fa_link",
      "arguments": {
        "states": ["q0","q1","q2"],
        "alphabet": ["a","b"],
        "transitions": [
          {"from":"q0","to":"q1","symbol":"a"},
          {"from":"q1","to":"q2","symbol":"b"},
          {"from":"q2","to":"q2","symbol":"b"}
        ],
        "start_state": "q0",
        "accept_states": ["q2"]
      }
    }
  }'

The response includes a url field. Open it and the automaton appears on the canvas with states positioned automatically.

Technology Stack

  • Next.js 16 (App Router)
  • React 19
  • TypeScript 6 (strict mode)
  • Tailwind CSS 4
  • Lucide React
  • Biome (linting & formatting)
  • Supabase (Postgres, Auth, and Realtime — accounts, the blog, Teams data, and the live shared canvas)
  • Jest 29 (unit tests — 352 tests across 25 suites)

Notes

  • This project is actively evolving; conversion and simplification paths may continue to improve over time.
  • If you use exported JSON from older versions, import compatibility logic attempts to normalize legacy shapes.

About

Computation Theory Simulator is an interactive, canvas-first web application for building, editing, converting, and simulating multiple automata models used in formal languages and automata theory courses.

Topics

Resources

License

Code of conduct

Contributing

Stars

16 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors