This simulator supports visualization and step-by-step execution of several types of automata and formal language models:
The easiest way to explain the input file format is by example; see several examples below.
Type | File | Description |
---|---|---|
DFA | no-000-end.dfa | Rejects strings ending in "000" |
NFA | 0-three-from-end.nfa | Accepts strings with "0" as third symbol from end |
NFA | 0s1s2s.nfa | Recognizes 0*1*2* with ε-transitions |
TM | double.tm | Doubles the input: 0^n → 0^{2n} |
TM | palindrome-single-tape.tm | Recognizes palindromes using one tape |
TM | count-a-wildcard.tm | Demonstrates wildcard usage |
CFG | balanced-parens.cfg | Generates balanced parentheses |
Regex | contains-010.regex | Binary strings containing "010" |
For DFA, NFA, and TM models, you can step through the computation:
All automaton definitions use YAML (YAML Ain't Markup Language) format. YAML is a human-readable data serialization standard.
Arrays: Lists of items can be written in two ways:
states: [q0, q1, q2] # Inline format
states: # Block format - q0 - q1 - q2
Objects: Key-value mappings use colons:
delta: q0: a: q1 b: q0
Comments: Use #
for documentation
# This is a comment explaining the automaton
Special Characters: Some characters need quotes in YAML, or if you want to avoid using quotes in state names and alphabet symbols, then avoid these YAML special characters:
!
- Start of YAML tags (use '!'
)@
- Reserved for future use (use '@'
)`
- Reserved for future use (use '`'
)|
, >
- Block scalars (use '|'
or '>'
)"123"
as text, not the number 123"true"
, "false"
, "yes"
,
"no"
if you want them as text
YAML automatically converts unquoted values that look like numbers. This can cause unexpected errors when using numeric state names with leading zeros:
Problem: Leading zeros collapse to the same number
# WRONG - 00 and 01 become numbers 0 and 1 states: [q0, 00, 01, 02] # 00 becomes 0, 01 becomes 1, etc. delta: q0: a: 00 # References state 0 (number) 00: # This is actually state 0 (number) b: 01 01: # This is actually state 1 (number) c: 02
Error you'll see: Map keys must be unique
or state reference errors if you have
both 0
and 00
in your states list.
When using numeric state names with leading zeros, always use quotes:
# CORRECT - All state names are strings states: [q0, '00', '01', '02'] # Preserves leading zeros delta: q0: a: '00' # References string state "00" '00': # String state "00" - different from "0" b: '01' '01': # String state "01" - different from "1" c: '02'
'0'
is always safer than unquoted
0
.
Required fields:
states
- Array of state namesinput_alphabet
- Array of input symbolsstart_state
- Initial stateaccept_states
- Array of accepting statesdelta
- Transition function mappingExample: DFA that rejects strings ending in 000
# DFA recognizing { x in {0,1}* | x does not end in 000 } states: [q, q0, q00, q000] input_alphabet: [0, 1] start_state: q accept_states: [q, q0, q00] delta: q: 1: q 0: q0 q0: 1: q 0: q00 q00: 1: q 0: q000 q000: 1: q 0: q000
Same fields as DFA, but delta
can map to either individual states (like DFA) or arrays of states for
nondeterminism. When there is only one target state, do not put it in an array. NFAs also support ε-transitions:
Example: NFA recognizing 0*1*2*
# NFA recognizing the language described by the regular expression 0*1*2* states: [q0, q1, q2] input_alphabet: [0, 1, 2] start_state: q0 accept_states: [q2] delta: q0: 0: q0 # Single target state (no array needed) "": q1 # ε-transition (empty string) q1: 1: q1 # Single target state "": q2 # ε-transition q2: 2: q2 # Single target state
For transitions with multiple target states, use arrays:
delta: q0: a: [q1, q2] # Nondeterministic: both q1 and q2 b: q0 # Single target: no array needed
""
for ε-transitions in NFAs. Only use arrays when there
are multiple target states.
Required fields:
states
- Array of state namesinput_alphabet
- Array of input symbolstape_alphabet_extra
- Additional tape symbols (beyond input alphabet)start_state
- Initial stateaccept_state
- Single accepting statereject_state
- Single rejecting statedelta
- Transition function with format: [new_state, new_symbols, moves]
Tape Alphabet: Automatically includes _
(blank) and all symbols from
input_alphabet
and tape_alphabet_extra
.
Transition Format: current_symbols: [new_state, new_symbols, moves]
moves
: L
(left), R
(right), S
(stay)0_
for tape 1 = '0', tape 2 = '_')Example: TM that doubles input (0^n → 0^{2n})
# TM computing the function f(0^n) = 0^{2n} states: [q0, q1, q2, qD, qA, qR] input_alphabet: [0] tape_alphabet_extra: ['!'] # ! needs quotes as it's a YAML special character start_state: q0 accept_state: qA reject_state: qR delta: q0: 0_: [q1, 0!, SR] # Mark first 0, move right on tape 2 q1: 0_: [q2, 00, SR] # For each 0, write two 0s on tape 2 __: [qD, __, SL] # End of input, start cleanup q2: 0_: [q1, 00, RR] # Continue processing qD: _0: [qD, _0, SL] # Move left to start of tape 2 _!: [qA, _!, SR] # Found marker, accept
Turing Machines support wildcard symbols (?
) in transition rules, allowing you to write more concise
and general transitions. The wildcard ?
matches any symbol in the tape alphabet.
When multiple transition rules could apply to the current configuration, the simulator follows these precedence rules:
Single-tape wildcards:
delta: q1: '?': [q2, x, R] # Replace any symbol with 'x', move right '0': [q3, '0', L] # Specific rule: if '0', stay '0', move left
Multi-tape wildcards:
delta: q1: '?_': [q1, '?_', RS] # Copy any symbol from tape 1, stay/right 'a_': [q2, 'a0', RR] # Specific: if 'a', also write '0' on tape 2
Precedence in action: For input symbol 'a' on tape 1 with blank on tape 2:
a_: [q2, a0, RR]
matches (specific)?_: [q1, ?_, RS]
also matches (wildcard)a_
takes precedence and is executedSee full example: count-a-wildcard.tm - Demonstrates wildcard usage for counting 'a' symbols
See full example: w-marker-w-wildcard.tm - Shows wildcards in palindrome recognition
For Turing Machines, the simulator displays both:
Define production rules using YAML mapping:
Example: Grammar for balanced parentheses
# CFG generating language of balanced () parentheses S: [(S), SS, '']
This defines: S → (S) | SS | ε
Define subexpressions and main expression:
Example: Binary strings containing "010"
# Matches any binary string containing the substring 010 B = (0|1)* # subexpression matching any binary string B 010 B
Your automaton definitions are automatically saved in your browser's local storage. This means your work persists between sessions, but it's stored locally on your device only.
Choose from multiple editor themes via View → Theme including:
#
comments liberally to document your automata. They help
understand complex logic and are ignored by the parser.
reading_zeros
instead of
q1
to make your automata more readable.
delta
are
declared in states
This simulator was built with SolidJS and TypeScript.