Processing math: 100%

5.Equivalence of NPDA and CFG§

Now we want to show that NPDA’s and CFG both represent CFL’s.
We will show that we can take any CFG and construct a NPDA, and vice versa.

Any CFG has a NPDA

Theorem: For any CFG L not containing λ, a NPDA M such that L=L(M).

Proof (sketch)
Assume (to simplify) that the CFG is in Griebach Normal Form
Grammar G=(V,T,S,P) is in GNF if all productions in P are of the form:
Aax
AV,aT,xV
We will construct a NPDA that performs a leftmost-derivation of the string.
Given (λ -free) CFL L.
CFG G such that L=L(G).
 G in GNF, such that L(G)=L(G).

Proof Idea

At any point in the derivation, we have terminals on the left, and variables on the right.
Terminals on the left are inputs seen.
Variables on the right are kept on the PDA’s stack.
Simply replace the first variable with the derivation that gives us the next input characters, and maybe some variables to stick on the stack.
Big problem: Which production to do next?
No, this is not a problem! Because… non-determinism!!

Proof Example (1)

SaSbba

Transform to GNF:
SaSAa
AbB
Bb

Proof Example (2)

Construct NPDA M=(Q,Σ,Γ,δ,q0,z,F)
Q={q0,q1,qf},Σ=T,Γ=V{z},F={qf}
1. M starts by putting S on the stack
2. For each production
AaX1X2Xn
put (q1,X1X2Xn) in δ(q1,a,A)
(Pop A from the stack, read “a” from tape, and push X1X2Xn onto the stack)
3. Accept if SwΣ (all variables on the stack are replaced by terminals or λ)

Proof Example (3)

Another Example

Let G=(V,T,S,P),P= | SaSA | aAA | b | AbBBB | Bb

QUESTION: Is this grammar in GNF?

lt7pf3

Trace abbbbb in grammar and pda.

Any NPDA has a CFG (1)

Want to show that each NPDA represents a CFG, so we will take a NPDA M and convert it to a CFG.
It will be an easier construction if we take the NPDA and put all the transitions in a simpler form.
So, there are some side proofs (here and in book) to justify the simplifying assumptions.

Simplifying Assumptions (1)

1. NPDA has a single final state qf that is entered if and only if the stack is empty.
2. Can limit the PDA transitions to increase or decrease the stack by one symbol
Theorem: Given a NPDA M, a NPDA M such that all transitions have the form δ(qi,a,A)={c1,c2,cn} where
ci=(qj,λ) or
ci=(qj,BC)
Each move either increases or decreases stack contents by a single symbol.

Simplifying Assumptions (2)

lt7pf4

Any NPDA has a CFG (2)

Theorem: If L=L(M) for some NPDA M, then L is a CFG.

Proof Sketch:
Given NPDA M, first, construct an equivalent NPDA M that meets the simplifying assumptions.
Reverse the process used to generate a PDA from a grammar to simulate the PDA in the grammar
The content of the stack should be reflected in the variable part of the sentential form
The processed input is the terminal prefix of the sentential form