> A(
H/0|DTimes New Romanp5D,0DWo
0DTahomaew Romanp5D,0DWo
0D" DMonotype Sortsp5D,0DWo
00DSymbole Sortsp5D,0DWo
0D@DLucida Sans Unicode,0DWo
0D"a.
@n?" dd@ @@``3.
!"#$%&'()*+,-.c$ 33f33ff̙@g4JdJd08ppp@uʚ;2Nʚ;<4!d!ddЁ
0P<4dddddЁ
0P___PPT9t/0X@?O=}8Equivalence of PDA, CFG1Conversion of CFG to PDA
Conversion of PDA to CFGOverviewWhen we talked about closure properties of regular languages, it was useful to be able to jump between RE and DFA representations.
Similarly, CFG s and PDA s are both useful to deal with properties of the CFL s.,9 Overview (2)Also, PDA s, being algorithmic, are often easier to use when arguing that a language is a CFL.
Example: It is easy to see how a PDA can recognize balanced parentheses; not so easy as a grammar.
But all depends on knowing that CFG s and PDA s both define the CFL s.&a33,Converting a CFG to a PDALet L = L(G).
Construct PDA P such that N(P) = L.
P has:
One state q.
Input symbols = terminals of G.
Stack symbols = all symbols of G.
Start symbol = start symbol of G.&9q9q
Intuition About PGiven input w, P will step through a leftmost derivation of w from the start symbol S.
Since P can t know what this derivation is, or even what the end of w is, it uses nondeterminism to guess the production to use at each step./Intuition (2)At each step, P represents some left-sentential form (step of a leftmost derivation).
If the stack of P is a, and P has so far consumed x from its input, then P represents left-sentential form xa.
At empty stack, the input consumed is a string in L(G).L f8V:Transition Function of Pr(q, a, a) = (q, ). (Type 1 rules)
This step does not change the LSF represented, but moves responsibility for a from the stack to the consumed input.
If A -> a is a production of G, then (q, , A) contains (q, a). (Type 2 rules)
Guess a production for A, and represent the next LSF in the derivation.%uwuVuHuf N(!f HuProof That L(P) = L(G)3fWe need to show that (q, wx, S) "* (q, x, a) for any x if and only if S =>*lm wa.
Part 1: only if is an induction on the number of steps made by P.
Basis: 0 steps.
Then a = S, w = , and S =>*lm S is surely true.1
+f>3f
Induction for Part 1 3ffConsider n moves of P: (q, wx, S) "* (q, x, a) and assume the IH for sequences of n-1 moves.
There are two cases, depending on whether the last move uses a Type 1 or Type 2 rule.^"
off Use of a Type 1 Rule& f\The move sequence must be of the form (q, yax, S) "* (q, ax, aa) " (q, x, a), where ya = w.
By the IH applied to the first n-1 steps, S =>*lm yaa.
But ya = w, so S =>*lm wa.2AP*'8
Use of a Type 2 Rule& fThe move sequence must be of the form (q, wx, S) "* (q, x, Ab) " (q, x, gb), where A -> g is a production and a = gb.
By the IH applied to the first n-1 steps, S =>*lm wAb.
Thus, S =>*lm wgb = wa.1
2,*},Proof of Part 2 ( if )3fPWe also must prove that if S =>*lm wa, then (q, wx, S) "* (q, x, a) for any x.
Induction on number of steps in the leftmost derivation.
Ideas are similar; read in text.Z g/w$Proof Completion3fWe now have (q, wx, S) "* (q, x, a) for any x if and only if S =>*lm wa.
In particular, let x = a = .
Then (q, w, S) "* (q, , ) if and only if S =>*lm w.
That is, w is in N(P) if and only if w is in L(G). !7
From a PDA to a CFGNow, assume L = N(P).
We ll construct a CFG G such that L = L(G).
Intuition: G will have variables generating exactly the inputs that cause P to have the net effect of popping a stack symbol X while going from state p to state q.
P never gets below this X while doing so.:*B ̙*#Variables of GG s variables are of the form [pXq].
This variable generates all and only the strings w such that (p, w, X) "*(q, , ).
Also a start symbol S we ll talk about later.H1%Productions of G.Each production for [pXq] comes from a move of P in state p with stack symbol X.
Simplest case: (p, a, X) contains (q, ).
Then the production is [pXq] -> a.
Note a can be an input symbol or .
Here, [pXq] generates a, because reading a is one way to pop X and go from p to q.%TQ
3&*>|4J',Productions of G (2)Next simplest case: (p, a, X) contains (r, Y) for some state r and symbol Y.
G has production [pXq] -> a[rYq].
We can erase X and go from p to q by reading a (entering state r and replacing the X by Y) and then reading some w that gets P from r to q while erasing the Y.
Note: [pXq] =>* aw whenever [rYq] =>* w.rp13[-s3f-b` ),Productions of G (3)Third simplest case: (p, a, X) contains (r, YZ) for some state r and symbols Y and Z.
Now, P has replaced X by YZ.
To have the net effect of erasing X, P must erase Y, going from state r to some state s, and then erase Z, going from s to q.03*Picture of Action of P->Third-Simplest Case ConcludedSince we do not know state s, we must generate a family of productions:
[pXq] -> a[rYs][sZq]
for all states s.
[pXq] =>* awx whenever [rYs] =>* w and [sZq] =>* x.(H*4K
.Productions of G: General Case.Suppose (p, a, X) contains (r, Y1,& Yk) for some state r and k > 3.
Generate family of productions
[pXq] ->
a[rY1s1][s1Y2s2]& [sk-2Yk-1sk-1][sk-1Ykq]c53P$?/Completion of the ConstructionWe can prove that (q0, w, Z0)"*(p, , ) if and only if [q0Z0p] =>* w.
Proof is in text; it is two easy inductions.
But state p can be anything.
Thus, add to G another variable S, the start symbol, and add productions S -> [q0Z0p] for each state p.G-
-{/h
!"
$&(+,012 ` ̙33` ` ff3333f` 333MMM` f` f` 3>?" dd@,?udd@ w " @ ` n?" dd@ @@``PR @ ` `p>>f(
6m P
T Click to edit Master title style!
!
0p
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
0lu ``
>*
0z `
@*
0 `
@*Z
Byh@ ? ̙33 Default Design
0zrP
(
0 P
P*
0\
R*
d
c$ ?
0
@
RClick to edit Master text styles
Second level
Third level
Fourth level
Fifth level!
S
6 `P
P*
6 `
R*
H
0h ? ̙330$(
r
S(pp
r
Sx `
H
0h ? ̙33
` $(
r
SX#P
r
S$
H
0h ? ̙33
,$(
,r
, S*P
r
, S$.
H
,0h ? ̙33
4$(
4r
4 S:P
r
4 ST;
H
40h ? ̙33
8$(
8r
8 SEP
r
8 SF
H
80h ? ̙33
<$(
<r
< S\QP
r
< SR
H
<0h ? ̙33
L:(
Lr
L SXP
L Sxւ``
"p`PpH
L0h ? ̙33
T$(
Tr
T SzP
r
T Sz
H
T0h ? ̙33
@\$(
\r
\ SP
r
\ Sh
H
\0h ? ̙33
`d$(
dr
d S|4P
r
d S|`
H
d0h ? ̙33
l0(
lx
l c$P
x
l c$`
H
l0h ? ̙33
t$(
tr
t S0P
r
t S
H
t0h ? ̙33
|P(
|r
| S`P
| S@<$
0
H
|0h ? ̙33
$(
r
SPP
r
S
H
0h ? ̙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CS154 slidesoJeff UllmanJeffUll42fMicrosoft PowerPointP@`q| @}J@lD,G.g +& &&#TNPP2OMi
&
TNPP &&TNPP
&&--&&-$0>$>L$LZ*$*Zh8$8hvF-$FvT$Tb$bp-$p~$~$-$-$$-$$-$-$,$,:
-$
:H$HV&-$&Vd4-$4drB-$BrP$P^-$^k-$ky-$y-$-$-$-$-$-$-$-$'-$'5-$5C-$CQ!-$!Q_/-$/_m=-$=m{K-$K{Y-$Yg-$gu-$u-$-$-$-$-$-$-$-$#-$#1-$1?-$?M-$M[+-$+[i9-$9iwG-$GwU-$Uc-$cq-$q-$-$-$-$-$-$-$-$-$--$-;-$;I-$IW'-$'We5-$5erB-$BrP-$P^-$^l-$lz-$z-$-$-$-$-$$-$-$($(6-$6D-$DR"$"R`0-$0`n>$>n|L-$L|Z$Zh$hv-$v$$$&&&-&$&&-&&
&&-&&&&-$0>$>L$LZ*$*Zh8$8hvF-$FvT$Tb$bp-$p~$~$-$-$$-$$-$-$,$,:
-$
:H$HV&-$&Vd4-$4drB-$BrP$P^-$^k-$ky-$y-$-$-$-$-$-$-$-$'-$'5-$5C-$CQ!-$!Q_/-$/_m=-$=m{K-$K{Y-$Yg-$gu-$u-$-$-$-$-$-$-$-$#-$#1-$1?-$?M-$M[+-$+[i9-$9iwG-$GwU-$Uc-$cq-$q-$-$-$-$-$-$-$-$-$--$-;-$;I-$IW'-$'We5-$5erB-$BrP-$P^-$^l-$lz-$z-$-$-$-$-$$-$-$($(6-$6D-$DR"$"R`0-$0`n>$>n|L-$L|Z$Zh$hv-$v$$$&-
--&&&y&/-w`0w}
:&-w`0wfg- @Times New Roman\-w`0wfg- . 2
f1 .--iyH-- @"Tahomaw}
:&\-w`0wfg- .*2
CEquivalence of PDA, CFG!!!
! !(##'.--Q1-- @"Tahomaw~
s9&\-w`0wfg- .+2
Conversion of CFG to PDA
. .+2
Conversion of PDA to CFG
.--"Systemgfg
G-&TNPP &՜.+,0,
(On-screen ShowStanford University, CS Dept.o1j Times New RomanTahomaMonotype SortsSymbolLucida Sans UnicodeDefault DesignEquivalence of PDA, CFG OverviewOverview (2)Converting a CFG to a PDAIntuition About PIntuition (2)Transition Function of PProof That L(P) = L(G)Induction for Part 1Use of a Type 1 RuleUse of a Type 2 RuleProof of Part 2 (if)Proof CompletionFrom a PDA to a CFGVariables of GProductions of GProductions of G (2)Productions of G (3)Picture of Action of P Third-Simplest Case ConcludedProductions of G: General CaseCompletion of the ConstructionFonts UsedDesign Template
Slide Titles_
JeffJeff
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXZ[\]^_`abcdefghijklmnoprstuvwxz{|}~Root EntrydO)Current UserySummaryInformation(YP/PowerPoint Document(1DocumentSummaryInformation8qRoot EntrydO)o<Current UserPSummaryInformation(YP/PowerPoint Document(1
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXZ[\]^_`abcdefghijklmnoprstuvwx(_
'Michael GoodrichMichael Goodrich