Академический Документы
Профессиональный Документы
Культура Документы
Any questions?
Languages
Recall.
What is a language?
What is a class of languages?
V is a set of variables
T is a set of terminals
V and are disjoint (I.e. V = )
S V, is your start symbol
Pushdown Automata
Input tape
A is a rule
= 1A 2
= 1 2
Pushdown Automata
Lets formalize this:
A pushdown automata (PDA) is a 7-tuple:
M = (Q, , , q0, Z0, A, ) where
1
5
2
3
4
State machine
Stack
Pushdown Automata
About this transition function :
During a move of a PDA:
At most one character is read from the input tape
transitions are okay
0 or more symbols from the stack alphabet are pushed onto the
stack.
Basic idea
Such that
L(M) = L(G)
= V { Z0 }
A = { q2 }
Z0 (V )
Example:
M = (Q, , ,, q0, Z0 ,F)
Q = { q0, q1, q2 }
= { a, b }
= { a, b, S, Z0 }
F = { q2 }
Sa|b
SaSa|bSb
q0
, Z0 / SZ0
q1
, Z0 / Z0
Lots of moves
(see next slide)
Tape input
Stack
Move(s)
q1
q1
(q1, a)
(q1, b)
(q1, aSa)
(q1, bSb)
(q1, )
q1
(q1, )
q2
a (q1, a, aZ)
a (q1, , Z)
a (q2, , Z )
// push
// match
// push
// match
// push
// match
// match
// match
// accept
Pushdown Automata
Strings accepted by a PDA by Final State
Start at (q0, x, Z0)
Start state q0
X on the input tape
Empty stack
Pushdown Automata
q
Step 2: PDA CFG
a, A / B1Bm
q1
Meaning:
one way to pop A off the stack and to get from q to qm+1 is to
read an a
use some input to pop B1off the stack (bring you from q1 to
q2 in the process),
While in q2, use some input to pop B2 off the stack
(bringing you to q3 in the process)
And so on
1, X /
q0
0,Z / XZ
0,X / XX
Type 1 productions
Q = { q0, q1 }
= { 0, 1 }
= { X, Z }
Z0 = Z
F=
S [q0Zq1]
S [q0Zq0]
,X /
1,X /
,Z /
q1
Corresponding CFG
Corresponding CFG
Type 3 productions
Type 3 productions
Add productions
qb
q0
q1
q0
q1
qc
q0
q0
q1
q1
Corresponding CFG
Corresponding CFG
Type 3 productions
Type 3 productions
qb
q0
q1
q0
q1
qc
Add productions
q0
q0
q1
q1
[q0Xq0] ,
[q0Xq1] ,
[q1Xq0] ,
[q1Xq1] ,
[q1Xq1]
[q0Zq0] ,
[q0Zq1],
[q1Zq0],
[q1Zq1],
[q0Xq0] 0[q0Xq0][q0Xq0]
[q0Xq0] 0[q0Xq1][q1Xq0]
[q0Xq1] 0[q0Xq0][q0Xq1]
[q0Xq1] 0[q0Xq1][q1Xq1]
[q0Zq0] 0[q0Xq0][q0Zq0]
[q0Zq0] 0[q0Xq1][q1Zq0]
[q0Zq1] 0[q0Xq0][q0Zq1]
[q0Zq1] 0[q0Xq1][q1Zq1]
S [q0Zq1]
S [q0Zq0]
[q0Xq1] 1
[q1Xq1] 1
[q1Xq1]
[q1Zq1]
(1)
(2)
(3)
(4)
(5)
(6)
Summary
What we have really learned?
Given a CFG, we can build a PDA that accepts
the same language generated by the CFG
Given a PDA, we can define a CFG that can
generate the language accepted by the PDA.
Summary
What have we learned?
(We really dont need to see the CFG
corresponding to a PDA, do we?)
Next time
Closure Properties for CFLs
Decision Algorithms for CFLs
Just when you thought it was safe
The Pumping Lemma for CFLs
10