Formal Languages and Automata Theory: Damascus University
Formal Languages and Automata Theory: Damascus University
Formal Languages and Automata Theory: Damascus University
BATTERY
input: s witch
output: lig ht bulb
actions: flip s witch
states: on, off
A s imple “computer”
input: s witch
output: lig ht bulb bulb is on if a nd only if
there wa s a n odd
actions: f for “flip s witch” number of flips
states: on, off
Thes e devices ca n model ma ny thing s
• They ca n des cribe the operation of a ny “sma ll
computer”, like the control component of a n
a larm clock or a microwa ve
• They are a ls o us ed in lexica l a na lyzers to
recog nize well formed expres s ions in
progra mming la ng ua g es :
ab1 is a leg a l na me of a varia ble in C
5u= is not
Different kinds of a utomata
• This wa s only one exa mple of a computationa l
device, a nd there are others
• We will look at different devices , a nd look at the
following questions :
– What ca n a g iven type of device compute, a nd what
are its limitations ?
– Is one type of device more powerful tha n a nother?
S ome devices we will s ee
finite automata Devices with a finite amount of memory.
Used to model “small” computers.
Xian
Chengdu Shanghai
Guangzhou
Hong Kong
• E xa mples
S1 = {a, b, c, d, …, z}: the s et of letters in E ng lis h
S2 = {0, 1, …, 9}: the s et of (ba s e 10) dig its
S3 = {a, b, …, z, #}: the s et of letters plus the
s pecia l s ymbol #
S4 = {(, )}: the s et of open a nd clos ed bra ckets
1
String s
4
– ∑* = ∑0 U ∑1 U ∑2 U …
– ∑+ = ∑1 U ∑2 U ∑3 U …
1
La ng ua g es
6
E xa mple:
Let w = 100011
Q) Is w the la ng ua g e of string s with equa l
number of 0s a nd 1s ?
F inite Automata
E xa mple of a finite a utomaton
off on
0 1 0,1
q0 1 q1 0 q2
state s
q1 q2 q1
q2 q2 q2
La ng ua g e of a DFA
M: off on
0 1
1
q0 q1
0
0 1 0,1
q0 1 q1 0 q2
L = {010, 1} ( S = {0, 1} )
E xa mples
• Construct a DFA that a ccepts the la ng ua g e
L = {010, 1} ( S = {0, 1} )
• Ans wer
q0 1 q01 0 q010
0
0 1
q 0, 1
1 0, 1
q1 qdie
0, 1
E xa mples
• Construct a DFA over a lpha bet {0, 1} that a ccepts
a ll string s that end in 101
E xa mples
• Construct a DFA over a lpha bet {0, 1} that a ccepts
a ll string s that end in 101
…
q
1 q101
0 q10
1
q1 …
…
1
q11 1
q111 1
2
9
What does a DFA do on rea ding a n input string ?
• Input: a word w in ∑*
• Question: Is w a ccepta ble by the DFA?
• Ste ps :
– Start at the “start state” q 0
– F or every input s ymbol in the s equence w do
• Compute the next state from the current state , g iven the
current input symbol in w a nd the tra ns ition function
– If a fter a ll s ymbols in w are cons umed, the current
state is one of the a ccepting state s (F ) then ac c e pt w;
– Otherwis e, re je c t w.
3
R eg ular La ng ua g es
0
Regular Context-
(DFA) free Context-
Recursively-
(PDA) sensitive
enumerable
(LBA)
(TM)
3
E xa mple
2
1 0,1 • ∑ = {0,1}
0
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
q0 q1 q0
• What if the language allows
states
q1 q1 q2
empty strings? *q2 q2 q2
3