A DFA is a deterministic finite automaton, a simple model of computation. It is one way to model regular languages. Each DFA consists of a finite set of states and a transition function between those states describing how the state of the machine changes in response to new input. DFAs are closely related to regular expressions in the sense that they can be converted into each other. Thus, DFAs are often used to implement regular expression matchers.
Questions tagged [dfa]
569 questions
10
votes
2 answers
Capture groups using DFA-based (linear-time) regular expressions: possible?
Is it possible to implement capture groups with DFA-based regular expressions while maintaining a linear time complexity with respect to the input length?
Intuitively I think not, because the subset construction procedure does not know which capture…

user541686
- 205,094
- 128
- 528
- 886
10
votes
4 answers
Regular Expression for Binary Numbers Divisible by 3
I am self-studying regular expressions and found an interesting practice problem online that involves writing a regular expression to recognize all binary numbers divisible by 3 (and only such numbers). To be honest, the problem asked to construct a…

John Roberts
- 5,885
- 21
- 70
- 124
10
votes
1 answer
DFAs vs Regexes when implementing a lexical analyzer?
(I'm just learning how to write a compiler, so please correct me if I make any incorrect claims)
Why would anyone still implement DFAs in code (goto statements, table-driven implementations) when they can simply use regular expressions? As far as I…

Marco Petersen
- 303
- 3
- 13
10
votes
1 answer
Implementing a code to simulate a finite automaton nondeterministic in c++
I'm doing an assignment for automata theory, which I have to determine whether a word is accepted or not by a transition function for a deterministic finite automaton
I have this input file:
6 8 0 2
2
5
0 0 a
0 1 a
1 1 b
1 2 c
1 3 c
3 4 d
4 4 d
4 5…

novaKid
- 233
- 2
- 4
- 11
9
votes
2 answers
Derive minimal regular expression from input
I have a remote "agent" that returns "yes" or "no" when handed a string. Communicating with this agent is expensive, so I'm hoping to find a library that will allow me to iteratively build a regular expression given positive and negative feedback,…

tgoodhart
- 3,111
- 26
- 37
9
votes
1 answer
Parser vs. lexer and XML
I'm reading about compilers and parsers architecture now and I wonder about one thing...
When you have XML, XHTML, HTML or any SGML-based language, what would be the role of a lexer here and what would be the tokens?
I've read that tokens are like…

SasQ
- 14,009
- 7
- 43
- 43
9
votes
1 answer
How to convert a DFA to a Turing machine?
Having the diagram of a DFA, how can I convert it to a Turing Machine? Do I have to find the language that the DFA accepts and then create the Turing Machine? Or is there a direct way?
Thank you.

user2880113
- 345
- 1
- 5
- 13
9
votes
3 answers
self-taught compiler courses / good introductory compiler books?
Does anyone know of online course / university lectures that comprise a typical compiler course? I've had theory of computing but unfortunately my school didn't offer a course in compiler construction.
I know there are lectures out there; I was…

larryq
- 15,713
- 38
- 121
- 190
9
votes
4 answers
Efficient (basic) regular expression implementation for streaming data
I'm looking for an implementation of regular expression matching that operates on a stream of data -- i.e., it has an API that allows a user to pass in one character at a time and report when a match is found on the stream of characters seen so far.…

Brendan Dolan-Gavitt
- 647
- 6
- 21
8
votes
1 answer
Regular expression that generates a DFA with dead or superfluous states
I'm looking to implement a DFA minimizer in my lexer, but I can't seem to produce a DFA that doesn't look like it's already the minimal DFA for the expression.
I'm constructing the DFA from a NFA that is built using thomson construction from a…

Dervall
- 5,736
- 3
- 25
- 48
8
votes
3 answers
A succinct description of NFA to DFA conversion?
Can someone much brighter than I succinctly describe to the SO community the NFA to DFA conversion algorithm? (Preferably in 500 words or less.) I've seen diagrams and lectures that have only served to confuse what I thought I once knew. I'm mostly…

Old McStopher
- 6,295
- 10
- 60
- 89
8
votes
1 answer
How to efficiently implement longest match in a lexer generator?
I'm interested in learning how to write a lexer generator like flex. I've been reading "Compilers: Principles, Techniques, and Tools" (the "dragon book"), and I have a basic idea of how flex works.
My initial approach is this: the user will supply a…

gsgx
- 12,020
- 25
- 98
- 149
8
votes
3 answers
Need Regular Expression for Finite Automata: Even number of 1s and Even number of 0s
My problem may sounds different to you.
I am a beginner and I am learning Finite Automata. I am googing over Internet to find the
Regular Expression for Finite Automata of Given Machine Below.
Can anyone help me to write "Regular Expression…

jyoti
- 350
- 1
- 5
- 15
7
votes
2 answers
Minimize a DFA with don't care transitions
I have a DFA (Q, Σ, δ, q0, F) with some “don't care transitions.” These transitions model symbols which are known not to appear in the input in some situations. If any such transition is taken, it doesn't matter whether the resulting string is…

fuz
- 88,405
- 25
- 200
- 352
7
votes
1 answer
time complexity trade offs of nfa vs dfa
I am looking for a discussion on which is better used and in what circumstances in a compiler an nfa or dfa. what are the time complexity trade-offs of simulating an nfa vs dfa and which one is more suitable during what circumstances in a compiler??

Lilly_Code
- 150
- 1
- 8