Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

Automata studio

Turn regular expressions into NFAs, DFAs and the smallest DFA, run your own state machines step by step and test if two expressions are equal.

Smallest DFA (→ start, * accepting)

How to use

  1. Write a regular expression with letters and digits as symbols, | for or, * for zero or more, + for one or more, ? for optional and brackets for grouping, for example (a|b)*abb. An empty bracket () or ε stands for the empty word.
  2. Press Build. You see how many states the NFA, the DFA and the smallest DFA need, the shortest words it accepts, the smallest DFA as a table and a diagram, and the answer for each test word.
  3. Extra symbols adds letters the expression does not use, so the machine also knows what to do with them (they lead to the dead state).
  4. Run your own machine: type start q0, accept q2 and moves like q0 a q1 or q0 eps q1, then run a word. Each step lists the state, or every possible state for an NFA.
  5. Same language? compares two expressions. If they differ, it gives the shortest word only one of them accepts.

Keyboard and touch

EnterIn a box: build, run or compare
TabMove between the tabs, the boxes and the buttons

Tips

  • The smallest DFA is unique (apart from the names of the states), so two expressions describe the same words exactly when their smallest DFAs match. The compare tab uses this.
  • The dead state is the trap a word falls into once it can no longer be accepted. Untick Hide the dead state to see the complete machine.
  • Try (a|b)*a(a|b)(a|b): the DFA needs 8 states for "the third letter from the end is a". Each extra letter doubles it, which is why NFAs are often much smaller.
  • Check a homework answer by comparing it with an expression you know is right: the counterexample shows exactly where it goes wrong.

About this tool

The studio follows the classic textbook route: Thompson's construction builds an NFA with empty moves from the expression, the subset construction turns it into a complete DFA over the symbols in use, and Moore's partition refinement merges states that no word can tell apart. The equivalence check walks both smallest DFAs side by side in breadth-first order, so the first difference it finds is a shortest word, and the first in alphabet order among those.

Expressions here are the mathematical kind (union, concatenation, star), not the larger syntax of programming languages: there are no character classes, anchors, back-references or lazy repeats. A word is accepted only if the whole word matches. Shortest words are listed up to 12 symbols long. Everything runs in your browser.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product