Home▸Computer Science▸Compilers Simulation

Regex to DFA: Lexer Construction

Build a deterministic finite automaton from a regular expression via Thompson's construction and subset construction, then step a test string through the live DFA -- the exact mechanism every lexer generator (lex/flex) uses to turn source text into tokens.

Computer Science2DModerate60 FPS📱 Mobile-adapted
computer-science-compilers-simulation ↗ Open standalone

Every compiler front end starts the same way: a lexer turns raw source text into tokens using regular expressions compiled down to a single deterministic finite automaton. This simulator makes that compilation visible. Pick a regular expression (or type your own using literals, |, *, +, ? and grouping), and watch it become a nondeterministic automaton via Thompson's construction, then get determinized into a DFA via subset construction — rendered as a live 3D state graph. Type a test string and step or run it through the DFA to see exactly which state the scanner is in after each character, and whether the string is accepted, exactly the mechanism inside every lex/flex-generated tokenizer.

⚙ Under the hood

This simulation explores the role of compilers – programs that translate high-level programming languages into machine code. It demonstrates how these tools are essential for software development and execution.

Compilers SimulationCode Generation

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)