Context-Free Language(CFL)
- Generator: Context-Free Generator(CFG)
- Recoganizer: PushDown Automata(PDA)
- Pumping Theorem for CFL
- Example:
- S→aSb,S→A,A→cS\to aSb,S\to A,A\to cS→aSb,S→A,A→c
- a,ba,ba,b: terminal
- S,AS,AS,A: non-terminal
- SSS: start symbol
A CFL is a 4-tuple G=(V,Σ,R,S)G=(V,\Sigma,R,S)G=(V,Σ,R,S)
- VVV is a set of symbols
- Σ⊆V\Sigma\subseteq VΣ⊆V is the set of terminals, V−ΣV-\SigmaV−Σ is the set of non-terminals
- RRR is the set of rules, a finite subset of (V−Σ)×V∗(V-\Sigma)\times V^*(V−Σ)×V∗
- S∈V−ΣS\in V-\SigmaS∈V−Σ is the start symbol
Derives in one step: xAy⇒GxuyxAy\xRightarrow[G]{} xuyxAyGxuy if (A,u)∈R(A,u)\in R(A,u)∈R, for x,y,u∈V∗x,y,u\in V^*x,y,u∈V∗ and A∈V−ΣA\in V-\SigmaA∈V−Σ
- x⇒G∗yx\xRightarrow[G]{}^* yxG∗y if x=yx=yx=y or ∃w0,w1,…,wn\exists w_0,w_1,\dots,w_n∃w0,w1,…,wn satisfying:
- x=w0x=w_0x=w0
- wi−1⇒Gwi,i∈[1,n]w_{i-1}\xRightarrow[G]{} w_i, i\in[1,n]wi−1Gwi,i∈[1,n]
- y=wny=w_ny=wn
- Called derivation from w0w_0w0 to wnw_nwn of length nnn
GGG generates a string w∈Σ∗w\in\Sigma^*w∈Σ∗ if S⇒G∗wS\xRightarrow[G]{}^*wSG∗w
- L(G)={w∈Σ∗:GL(G)=\{w\in\Sigma^*:GL(G)={w∈Σ∗:G generates w}w\}w}, GGG generates L(G)L(G)L(G)
- A language is context-free if some CFG generates it
Exercise: Show that {w∈{a,b}∗:w=wR}\{w\in\{a,b\}^*:w=w^R\}{w∈{a,b}∗:w=wR} is a CFL
- ∣w∣=0,w=e=wR|w|=0,w=e=w^R∣w∣=0,w=e=wR, i.e. S→eS\to eS→e
- ∣w∣=1,w=a=b|w|=1,w=a=b∣w∣=1,w=a=b, i.e. S→aS\to aS→a and S→bS\to bS→b
- ∣w∣≥2,w=aua=bub,u=uR|w|\ge 2,w=aua=bub,u=u^R∣w∣≥2,w=aua=bub,u=uR(by induction), i.e. S→aSaS\to aSaS→aSa and S→bSbS\to bSbS→bSb
- Conclusively, S→e∣a∣b∣aSa∣bSbS\to e|a|b|aSa|bSbS→e∣a∣b∣aSa∣bSb
- w∈L(G)→w=wRw\in L(G)\to w=w^Rw∈L(G)→w=wR: by induction on # steps of derivation of www
- w=wR→w∈L(G)w=w^R\to w\in L(G)w=wR→w∈L(G): by induction on length of www
Exercise: Show that {w∈{(,)}∗:w\{w\in\{(,)\}^*:w{w∈{(,)}∗:w is a string of balanced parentheses }\}} is a CFL
- Derivation is not unique: leftmost or rightmost
Parse Tree
- Internal nodes: non-terminals
- Leaves: terminals or eee, and eee must be the only child of its parent
- Edges: spatial and temporal order
- Yields: reconstruct a string from its parse tree
- A CFG GGG is ambiguous if ∃w∈L(G)\exists w\in L(G)∃w∈L(G), there exists two or more parse trees with the same root SSS yielding www
- Fact: Some CFL is inherently ambiguous. That is, every CFG that generates this language is ambiguous
- For {aibjck:i=j∨j=k}\{a^ib^jc^k:i=j\lor j=k\}{aibjck:i=j∨j=k}, ambiguity occurs on a4b4c4a^4b^4c^4a4b4c4
Theorem: Every regular language is context-free
- Idea: DFA M=(K,Σ,δ,s,F)→M=(K,\Sigma,\delta,s,F)\toM=(K,Σ,δ,s,F)→ CFG G=(V,Σ,R,S)G=(V,\Sigma,R,S)G=(V,Σ,R,S), s.t. L(G)=L(M)L(G)=L(M)L(G)=L(M)
- V=K∪ΣV=K\cup\SigmaV=K∪Σ
- R={q→ap:δ(q,a)=p}∪{q→e:q∈F}R=\{q\to ap:\delta(q,a)=p\}\cup\{q\to e:q\in F\}R={q→ap:δ(q,a)=p}∪{q→e:q∈F}
- S=sS=sS=s
- ∀w∈Σ∗,(s,w)⊢M∗(q,e)\forall w\in \Sigma^*,(s,w)\vdash_M^*(q,e)∀w∈Σ∗,(s,w)⊢M∗(q,e) for some q∈F ⟺ s⇒G∗wq\in F\iff s\xRightarrow[G]{}^*wq∈F⟺sG∗w
- Claim: ∀w∈Σ∗,∀p,q∈K,(p,w)⊢M∗(q,e) ⟺ p⇒G∗wq\forall w\in \Sigma^*,\forall p,q\in K, (p,w)\vdash_M^*(q,e)\iff p\xRightarrow[G]{}^*wq∀w∈Σ∗,∀p,q∈K,(p,w)⊢M∗(q,e)⟺pG∗wq
- Therefore s⇒G∗wq⇒Gws\xRightarrow[G]{}^*wq\xRightarrow[G]{}wsG∗wqGw
- Proof:
- sufficiency by induction on # steps of computations
- Base case: # steps =0=0=0, w=e,p=q,p⇒G∗wqw=e,p=q,p\xRightarrow[G]{}^*wqw=e,p=q,pG∗wq (trivial)
- Inductive case: holds for # steps =k=k=k, then for # steps =k+1=k+1=k+1
- w=au,a∈Σ,u∈Σ∗,(p,w)⊢M(p′,u)⊢M∗(q,e)w=au,a\in\Sigma,u\in\Sigma^*,(p,w)\vdash_M(p',u)\vdash_M^*(q,e)w=au,a∈Σ,u∈Σ∗,(p,w)⊢M(p′,u)⊢M∗(q,e) if δ(p,a)=p′\delta(p,a)=p'δ(p,a)=p′
- Let $ p\to ap’\in R$,therefore p⇒Gap′⇒G∗auqp \xRightarrow[G]{}ap'\xRightarrow[G]{}^*auqpGap′G∗auq, with hypothesis p′⇒G∗uqp'\xRightarrow[G]{}^*uqp′G∗uq
- necessity by # steps of derivation(omitted)
PushDown Automata(PDA)
PDA(NFA+Stack) is a 6-tuple P=(K,Σ,Γ,Δ,s,F)P=(K,\Sigma,\Gamma,\Delta,s,F)P=(K,Σ,Γ,Δ,s,F)
- KKK is a set of states
- Σ\SigmaΣ is a set of input symbols
- Γ\GammaΓ is a set of stack symbols
- s∈Ks\in Ks∈K is the initial state
- F⊆KF\subseteq KF⊆K is the set of final states
- Δ\DeltaΔ, transition relation, is a finite subset of (K×(Σ∪{e})×Γ∗)×(K×Γ∗)(K\times(\Sigma\cup\{e\})\times \Gamma^*)\times(K\times\Gamma^*)(K×(Σ∪{e})×Γ∗)×(K×Γ∗)
A configuration for PPP is a member of K×Σ∗×Γ∗K\times\Sigma^*\times\Gamma^*K×Σ∗×Γ∗
Yields in one step: (p,x,α)⊢P(q,y,β)(p,x,\alpha)\vdash_P(q,y,\beta)(p,x,α)⊢P(q,y,β), if ∃((p,x,γ),(q,η))∈Δ\exists((p,x,\gamma),(q,\eta))\in\Delta∃((p,x,γ),(q,η))∈Δ where x=ay,α=γτ,β=ητx=ay,\alpha=\gamma\tau,\beta=\eta\taux=ay,α=γτ,β=ητ, for some τ∈Γ∗\tau\in\Gamma^*τ∈Γ∗
- (p,x,α)⊢P∗(q,y,β)(p,x,\alpha)\vdash_P^*(q,y,\beta)(p,x,α)⊢P∗(q,y,β) if (p,x,α)=(q,y,β)(p,x,\alpha)=(q,y,\beta)(p,x,α)=(q,y,β) or ∃(p0,x0,α0),…,(pn,xn,αn)\exists(p_0,x_0,\alpha_0),\dots,(p_n,x_n,\alpha_n)∃(p0,x0,α0),…,(pn,xn,αn) satisfying:
- (p,x,α)=(p0,x0,α0)(p,x,\alpha)=(p_0,x_0,\alpha_0)(p,x,α)=(p0,x0,α0)
- (pi−1xi−1αi−1)⊢P(pi,xi,αi),∀i∈[1,n](p_{i-1}x_{i-1}\alpha_{i-1})\vdash_P(p_i,x_i,\alpha_i),\forall i\in[1,n](pi−1xi−1αi−1)⊢P(pi,xi,αi),∀i∈[1,n]
- (q,y,β)=(pn,xn,αn)(q,y,\beta)=(p_n,x_n,\alpha_n)(q,y,β)=(pn,xn,αn)
PPP accepts w∈Σ∗w\in\Sigma^*w∈Σ∗ if (s,w,e)⊢P∗(q,e,e)(s,w,e)\vdash_P^*(q,e,e)(s,w,e)⊢P∗(q,e,e), for some q∈Fq\in Fq∈F
L(P)L(P)L(P): a set of all w∈Σ∗w\in\Sigma^*w∈Σ∗ accepted by PPP, uniquely
Exercise: Design a PDA to accept L={wwR:w∈{a,b}∗}L=\{ww^ R:w\in\{a,b\}^*\}L={wwR:w∈{a,b}∗}
- K={l,r}K=\{l,r\}K={l,r}
- Σ={a,b}\Sigma=\{a,b\}Σ={a,b}
- Γ={a,b}\Gamma=\{a,b\}Γ={a,b}
- s=ls=ls=l
- F={r}F=\{r\}F={r}
- Δ={((l,a,e),(l,a)),((l,b,e),(l,b)),((l,a,a),(l,e)),((l,b,b),(l,e)),((l,e,e),(l,e))}\Delta=\begin{aligned}\{&((l,a,e),(l,a)),((l,b,e),(l,b)),\\ &((l,a,a),(l,e)),((l,b,b),(l,e)),\\&((l,e,e),(l,e))\}\end{aligned}Δ={((l,a,e),(l,a)),((l,b,e),(l,b)),((l,a,a),(l,e)),((l,b,b),(l,e)),((l,e,e),(l,e))}
Exercise: Design a PDA to accept {w∈{0,1}∗:\{w\in\{0,1\}^*:{w∈{0,1}∗: # of 000’s equals to # of 111’s in w}w\}w}
- K={s,q,f}K=\{s,q,f\}K={s,q,f}
- Σ={0,1}\Sigma=\{0,1\}Σ={0,1}
- Γ={0,1,@}\Gamma=\{0,1,@\}Γ={0,1,@}
- s=ls=ls=l
- F={f}F=\{f\}F={f}
- Δ={((s,e,e),(q,@)),((q,e,@),(f,e)),((q,0,@),(q,0@)),((q,1,@),(q,1,@)),((q,0,0),(q,00)),((q,0,1),(q,e)),((q,1,1),(q,11)),((q,1,0),(q,e))}\Delta=\begin{aligned}\{&((s,e,e),(q,@)),((q,e,@),(f,e)),\\ &((q,0,@),(q,0@)),((q,1,@),(q,1,@)),\\ &((q,0,0),(q,00)),((q,0,1),(q,e)),\\ &((q,1,1),(q,11)),((q,1,0),(q,e))\}\end{aligned}Δ={((s,e,e),(q,@)),((q,e,@),(f,e)),((q,0,@),(q,0@)),((q,1,@),(q,1,@)),((q,0,0),(q,00)),((q,0,1),(q,e)),((q,1,1),(q,11)),((q,1,0),(q,e))}
Theorem
- For each CFG GGG, there exists a PDA PPP s.t. L(P)=L(G)L(P)=L(G)L(P)=L(G)
- For each PDA PPP, there exists a CFG GGG s.t. L(G)=L(P)L(G)=L(P)L(G)=L(P)
- G→PG\to PG→P, idea:
- non-deterministic generates a string in stack using GGG
- compare it to input
- accept input if they match
- Construction:
- G=(V,Σ,R,S)→P=(K,Σ,Γ,Δ,s,F)G=(V,\Sigma,R,S)\to P=(K,\Sigma,\Gamma,\Delta,s,F)G=(V,Σ,R,S)→P=(K,Σ,Γ,Δ,s,F)
- K={p,q}K=\{p,q\}K={p,q}
- Γ=V\Gamma=VΓ=V
- s=ps=ps=p
- F={q}F=\{q\}F={q}
- Δ={((p,e,e),(q,s)),((q,e,A),(q,u)),∀(A,u)∈R((q,a,a),(q,e)),∀a∈Σ}\Delta=\begin{aligned}\{&((p,e,e),(q,s)),\\ &((q,e,A),(q,u)),\forall(A,u)\in R\\ &((q,a,a),(q,e)),\forall a\in\Sigma\}\end{aligned}Δ={((p,e,e),(q,s)),((q,e,A),(q,u)),∀(A,u)∈R((q,a,a),(q,e)),∀a∈Σ}
- Prove L(G)=L(P)L(G)=L(P)L(G)=L(P):
- ∀w∈Σ∗\forall w\in\Sigma^*∀w∈Σ∗, s⇒∗ws\xRightarrow{}^*ws∗w if (p,w,e)⊢P(q,w,s)⊢P∗(q,e,e)(p,w,e)\vdash_P(q,w,s)\vdash_P^*(q,e,e)(p,w,e)⊢P(q,w,s)⊢P∗(q,e,e)
- Claim: ∀w∈Σ∗\forall w\in\Sigma^*∀w∈Σ∗ and ∀α∈((V−Σ)V∗)∪{e},S⇒L∗αw\forall\alpha\in((V-\Sigma)V^*)\cup\{e\},S\xRightarrow{L}^*\alpha w∀α∈((V−Σ)V∗)∪{e},SL∗αw iff (q,w,S)⊢P∗(q,e,α)(q,w,S)\vdash_P^*(q,e,\alpha)(q,w,S)⊢P∗(q,e,α)
- Prove sufficiency by induction
- Base case: # steps =0=0=0, S⇒L∗wαS\xRightarrow{L}^*w\alphaSL∗wα
- ⇒S=wα\Rightarrow S=w\alpha⇒S=wα
- ⇒w=e,α=S\Rightarrow w=e,\alpha=S⇒w=e,α=S
- ⇒(q,w,S)⊢P∗(q,e,α)\Rightarrow(q,w,S)\vdash_P^*(q,e,\alpha)⇒(q,w,S)⊢P∗(q,e,α)
- Inductive case: holds for # steps =k=k=k, then for # steps =k+1=k+1=k+1
- s⇒Lu1⇒Lu2⇒L⋯⇒L∗uk⇒Lαs\xRightarrow{L}u_1\xRightarrow{L}u_2\xRightarrow{L}\cdots\xRightarrow{L}^*u_k\xRightarrow{L}\alphasLu1Lu2L⋯L∗ukLα
- Let AAA be the leftmost non-terminal in uku_kuk
- uk=xAβu_k=xA\betauk=xAβ where x∈Σ∗x\in\Sigma^*x∈Σ∗ and β∈V∗\beta\in V^*β∈V∗,
- wα=xγβw\alpha=x\gamma\betawα=xγβ for some (A,γ)∈R(A,\gamma)\in R(A,γ)∈R
- ∃y∈Σ∗\exist y\in\Sigma^*∃y∈Σ∗ s.t. w=xyw=xyw=xy, therefore yα=γβy\alpha=\gamma\betayα=γβ
- S⇒L∗ukS\xRightarrow{L}^*u_kSL∗uk
- ⇒(q,x,S)⊢P∗(q,e,Aβ)⊢P(q,e,γβ)\Rightarrow(q,x,S)\vdash_P^*(q,e,A\beta)\vdash_P(q,e,\gamma\beta)⇒(q,x,S)⊢P∗(q,e,Aβ)⊢P(q,e,γβ)
- ⇒(q,xy,S)⊢P∗(q,y,γβ)\Rightarrow (q,xy,S)\vdash_P^*(q,y,\gamma\beta)⇒(q,xy,S)⊢P∗(q,y,γβ)
- ⇒(q,w,S)⊢P∗(q,y,yα)⊢P∗(q,e,α)\Rightarrow (q,w,S)\vdash_P^*(q,y,y\alpha)\vdash_P^*(q,e,\alpha)⇒(q,w,S)⊢P∗(q,y,yα)⊢P∗(q,e,α)
- Base case: # steps =0=0=0, S⇒L∗wαS\xRightarrow{L}^*w\alphaSL∗wα
- Prove necessity by induction on # type-2 transition
- Base case: # steps of type-2 =0=0=0, (q,w,S)⊢P∗(q,e,α)(q,w,S)\vdash_P^*(q,e,\alpha)(q,w,S)⊢P∗(q,e,α)
- ⇒w=e,α=S\Rightarrow w=e,\alpha=S⇒w=e,α=S
- ⇒S⇒L∗wα\Rightarrow S\xRightarrow{L}^*w\alpha⇒SL∗wα
- Inductive case: holds for # steps of type-2 =k=k=k, then for # steps =k+1=k+1=k+1
- Let ((q,e,A),(q,γ))((q,e,A),(q,\gamma))((q,e,A),(q,γ)) be the last type-2 transition
- ∃y∈Σ∗,∃β∈V∗,(q,w,S)⊢P∗(q,y,Aβ)⊢P(q,y,γβ)⊢P∗(q,e,α)\exists y\in\Sigma^*,\exists\beta\in V^*,(q,w,S)\vdash_P^*(q,y,A\beta)\vdash_P(q,y,\gamma\beta)\vdash_P^*(q,e,\alpha)∃y∈Σ∗,∃β∈V∗,(q,w,S)⊢P∗(q,y,Aβ)⊢P(q,y,γβ)⊢P∗(q,e,α)
- (q,w,S)⊢P∗(q,y,Aβ)(q,w,S)\vdash_P^*(q,y,A\beta)(q,w,S)⊢P∗(q,y,Aβ)
- ⇒∃x∈Σ∗,w=xy,(q,xy,S)⊢P∗(q,y,Aβ)\Rightarrow\exists x\in\Sigma^*,w=xy,(q,xy,S)\vdash_P^*(q,y,A\beta)⇒∃x∈Σ∗,w=xy,(q,xy,S)⊢P∗(q,y,Aβ)
- ⇒(q,x,S)⊢P∗(q,e,Aβ)\Rightarrow(q,x,S)\vdash_P^*(q,e,A\beta)⇒(q,x,S)⊢P∗(q,e,Aβ)
- ⇒S⇒L∗xAβ\Rightarrow S\xRightarrow{L}^*xA\beta⇒SL∗xAβ
- (q,y,Aβ)⊢P(q,y,γβ)(q,y,A\beta)\vdash_P(q,y,\gamma\beta)(q,y,Aβ)⊢P(q,y,γβ)
- ⇒(A,γ)∈R\Rightarrow(A,\gamma)\in R⇒(A,γ)∈R
- (q,y,γβ)⊢P∗(q,e,α)(q,y,\gamma\beta)\vdash_P^*(q,e,\alpha)(q,y,γβ)⊢P∗(q,e,α)
- ⇒∃α,yα=γβ\Rightarrow\exists\alpha,y\alpha=\gamma\beta⇒∃α,yα=γβ
- Therefore, S⇒L∗xAβ⇒Lxγβ⇒L∗xyα(=wα)S\xRightarrow{L}^*xA\beta\xRightarrow{L}x\gamma\beta\xRightarrow{L}^*xy\alpha(=w\alpha)SL∗xAβLxγβL∗xyα(=wα)
- Base case: # steps of type-2 =0=0=0, (q,w,S)⊢P∗(q,e,α)(q,w,S)\vdash_P^*(q,e,\alpha)(q,w,S)⊢P∗(q,e,α)
- P→GP\to GP→G, via simple PDA
- A PDA P=(K,Σ,Γ,Δ,s,F)P=(K,\Sigma,\Gamma,\Delta,s,F)P=(K,Σ,Γ,Δ,s,F) is simple if:
- ∣F∣=1|F|=1∣F∣=1
- ∀((q,a,α),(q,β))∈Δ\forall((q,a,\alpha),(q,\beta))\in\Delta∀((q,a,α),(q,β))∈Δ:
- either α=e,∣β∣=1\alpha=e,|\beta|=1α=e,∣β∣=1 (push)
- or ∣α∣=1,β=e|\alpha|=1,\beta=e∣α∣=1,β=e (pop)
- Lemma: Every PDA has a equivalent simple PDA
- Proof:
- Let P=(K,Σ,Γ,Δ,s,F)P=(K,\Sigma,\Gamma,\Delta,s,F)P=(K,Σ,Γ,Δ,s,F) be a PDA
- If ∣F∣>1|F|>1∣F∣>1:
- create a new state fff
- for ∀q∈F\forall q\in F∀q∈F, create a new transition ((q,e,e),(f,e))((q,e,e),(f,e))((q,e,e),(f,e))
- replace FFF with {f}\{f\}{f}
- Violations:
- For each ((q,a,α),(q,β))((q,a,\alpha),(q,\beta))((q,a,α),(q,β)) with ∣α∣≥1|\alpha|\ge1∣α∣≥1 and ∣β∣≥1|\beta|\ge1∣β∣≥1:
- create a new state rrr
- replace with ((p,a,α),(r,e))((p,a,\alpha),(r,e))((p,a,α),(r,e)) and ((r,e,e),(q,β))((r,e,e),(q,\beta))((r,e,e),(q,β)), respectively
- For each ((q,a,α),(q,e))((q,a,\alpha),(q,e))((q,a,α),(q,e)) with α=c1c2…ck\alpha=c_1c_2\dots c_kα=c1c2…ck for some k≥2k\ge2k≥2:
- create k−1k-1k−1 new states r1,r2,…,rk−1r_1,r_2,\dots,r_{k-1}r1,r2,…,rk−1
- replace with ((p,a,c1),(r1,e))((p,a,c_1),(r_1,e))((p,a,c1),(r1,e)) and ((ri,e,c2),(ri+1,e)),i∈[1,k−1)((r_i,e,c_2),(r_{i+1},e)),i\in[1,k-1)((ri,e,c2),(ri+1,e)),i∈[1,k−1) and ((rk−1,e,ck),(q,e))((r_{k-1},e,c_k),(q,e))((rk−1,e,ck),(q,e)), respectively
- For each ((q,a,e),(q,β))((q,a,e),(q,\beta))((q,a,e),(q,β)) with β=c1c2…ck\beta=c_1c_2\dots c_kβ=c1c2…ck for some k≥2k\ge2k≥2:
- create k−1k-1k−1 new states r1,r2,…,rk−1r_1,r_2,\dots,r_{k-1}r1,r2,…,rk−1
- replace with ((p,a,e),(r1,ck))((p,a,e),(r_1,c_k))((p,a,e),(r1,ck)) and ((ri,e,e),(ri+1,ck−i)),i∈[1,k−1)((r_i,e,e),(r_{i+1},c_{k-i})),i\in[1,k-1)((ri,e,e),(ri+1,ck−i)),i∈[1,k−1) and ((rk−1,e,e),(q,c1))((r_{k-1},e,e),(q,c_1))((rk−1,e,e),(q,c1)), respectively
- For each ((p,a,e),(q,e))∈Δ((p,a,e),(q,e))\in\Delta((p,a,e),(q,e))∈Δ
- create a new symbol @@@
- replace with ((p,a,e),(r,@))((p,a,e),(r,@))((p,a,e),(r,@)) and ((r,e,@),(q,e))((r,e,@),(q,e))((r,e,@),(q,e))
- Lemma: Every simple PDA has a equivalent CFG
- Proof:
- Let P=(K,Σ,Γ,Δ,s,F)P=(K,\Sigma,\Gamma,\Delta,s,F)P=(K,Σ,Γ,Δ,s,F) be a simple PDA
- Construct G=(V,Σ,R,S)G=(V,\Sigma,R,S)G=(V,Σ,R,S) s.t. L(G)=L(P)L(G)=L(P)L(G)=L(P)
- Non-terminals: {Apq:p,q∈K}\{A_{pq}:p,q\in K\}{Apq:p,q∈K}
- ApqA_{pq}Apq represents {w∈Σ∗:(p,w,e)⊢P∗(q,e,e)}\{w\in\Sigma^*:(p,w,e)\vdash_P^*(q,e,e)\}{w∈Σ∗:(p,w,e)⊢P∗(q,e,e)}
- S=AsfS=A_{sf}S=Asf
- R={Apq→aArtb:((p,a,e),(r,u)),((t,b,u),(q,e))∈Δ}∪{Apq→AprArq:r∈K}∪{App→e:p∈K}R=\{A_{pq}\to aA_{rt}b:((p,a,e),(r,u)),((t,b,u),(q,e))\in\Delta\}\cup\{A_{pq}\to A_{pr}A_{rq}:r\in K\}\cup\{A_{pp}\to e:p\in K\}R={Apq→aArtb:((p,a,e),(r,u)),((t,b,u),(q,e))∈Δ}∪{Apq→AprArq:r∈K}∪{App→e:p∈K}
- w=avbw=avbw=avb for some v∈Σ∗v\in\Sigma^*v∈Σ∗ with (r,v,e)⊢P∗(t,e,e)(r,v,e)\vdash^*_P(t,e,e)(r,v,e)⊢P∗(t,e,e)
- Non-terminals: {Apq:p,q∈K}\{A_{pq}:p,q\in K\}{Apq:p,q∈K}
- Claim: Apq⇒∗w∈Σ∗A_{pq}\xRightarrow{}^*w\in\Sigma^*Apq∗w∈Σ∗ iff (p,w,e)⊢P∗(q,e,e)(p,w,e)\vdash^*_P(q,e,e)(p,w,e)⊢P∗(q,e,e) (proof omitted)
- Collary: A language is context-free iff it is accepted by some PDA