Introduction to Formal Languages

Lecture 8
Deterministic Finite Automata
CS 241: Foundations of Sequential Programs
Spring 2017
Troy Vasiga et al. (where Dan Holtby ∈ al)
University of Waterloo
1
Review
I
formal languages give a theoretical basis for communication and
organizing processes
I
terminology (alphabet, word, language)
I
specification vs. recognition
I
studying language levels that increase in power/complexity
I
regular languages are composed of union, concatenation and
repetition
2
Recognizers: Finite Automata
Regular languages can be recognized by finite automata.
We begin with deterministic finite automata, also called DFAs.
I
alphabet (Σ)
I
finite set of states (or it wouldn’t be a finite automata)
I
start state
I
accepting (final) states(s)
I
transition function (or table, or diagram)
3
Finite Automata Example 1
Example: selected opcodes from MIPS assembly language, where
alphabet is the ASCII characters.
4
Observations About Finite Automata
I
ability to trace
I
transitions out of a state are unique
I
errors
I
size of this language
I
DFA M and language L(M)
5
Finite Automata Example 2
Example: MIPS labels, where the alphabet is ASCII characters.
6
More Finite Automata Examples
Let Σ = {a, b, c}.
I strings with exactly one a and exactly one b and no c’s
I
strings with one a, one b and one c
I
strings with at least one a
I
string with an even number of a’s
7
More Finite Automata Examples
Let Σ = {a, b, c}.
I
strings with an even number a’s and odd number of b’s
I
strings with an even number a’s or odd number of b’s
8
More Finite Automata Examples
Let Σ = {a − z}.
I
All strings that contain ”dan”
I
All strings that contain ”adam”
9
DFA summary
I
a.k.a. finite state machines
I
start state
I
final/accepting states
I
implicit error state
I
accepted and rejected words
I
L(M) – the language recognized by DFA M
I
Notice that L(M) = L(M 0 ) even though M 6= M 0
10
Formal Definition
A DFA is a 5-tuple (Σ, Q, q0 , A, δ) where
I
finite alphabet Σ
I
finite set of states Q
I
start state q0
I
set of final/accepting states A ⊆ Q
I
transition function: δ : Q × Σ → Q
11
DFA Interpreter Algorithm
Input: A word w = w1 w2 ...wn where each wi ∈ Σ
Output: true if accepted, false if rejected
12
Implementing DFAs
Need to implement the transition function somehow
13
Where are DFAs used?
Everywhere!
I
A microwave is a DFA (probably).
I
A Turing machine is a DFA plus infinite memory (magnetic tape)
I
A CPU is a DFA plus finite memory (registers)
A computer is a CPU (DFA) plus a lot of finite memory (RAM)
I
I
I
4GB of RAM has 234359738368 states
Not a practical way to model a computer
14