Chapter1541 Dvi
Chapter1541 Dvi
Thomas Tran 3
Proof of Theorem 30
Chapter 15: CFG = PDA
• The proof will be by constructive algorithm.
• We are now able to prove that the set of all languages accepted by • From Theorem 26 in Chapter 13 (page 278), we can assume that the
PDAs is the same as the set of all languages generated by CFGs. CFG is in CNF. (We shall handle the problem of Λ later.)
• We can prove this in two steps. • Before we describe our algorithm, let us illustrate it on a particular
example.
Σ = {a, b}
CSI3104 - Dr. Thomas Tran 5 CSI3104 - Dr. Thomas Tran 7
START
b
• Let’s consider a specific example. Let’s generate the word aab using
a READ 1 READ 2 ACCEPT leftmost derivation in the given CFG:
Let us run this word (aab) on the proposed PDA, following the same sequence of
productions in the leftmost derivation above.
• We begin by pushing S onto the top of the STACK.
START
• We then enter the central POP state. Two things are possible when b
• We begin at START
STACK TAPE • We now re-enter the POP state and simulate the last production,
B → b. We POP B and READ b from the TAPE
∆ aab∆
STACK TAPE
• We push the symbol S on the STACK ∆ aab∆
STACK TAPE
• At this point the STACK is empty, and the blank ∆ is the only thing
S aab∆
we can read next from the TAPE.
• We then go to POP state. The first production we must simulate is • Hence, we follow the path
S → AB. So, we POP S and then PUSH B and PUSH A:
P OP ∆ → READ3 ∆ → ACCEP T
STACK TAPE So, the word aab is accepted by the PDA.
AB aab∆
STACK TAPE • It should also be clear that if any input string reaches the ACCEPT
CCB aab∆ state in the PDA, that string must have got there by having each of its
letters read via simulating the Chomsky production of the form
• Again, we go back to POP. This time, we must simulate C → a by Nonterminal → terminal
poping C and reading a from the TAPE: • This means that we have necessarily formed a complete leftmost
STACK TAPE derivation of this word through CFG productions with no
nonterminals left over in the STACK. Therefore, every word accepted
CB aab∆
by this PDA is in the language generated by the CFG.
• We simulate another C → a: • We are now ready to present the algorithm to construct a PDA from a
given CFG.
STACK TAPE
B aab∆
CSI3104 - Dr. Thomas Tran 13 CSI3104 - Dr. Thomas Tran 15
...
POP
X3 → a
X4 → a Xi
X5 → b
PUSH Xk
...
where the start symbol S = X1 and the other nonterminals are X2 , PUSH Xj
X3 , ...
Algorithm (cont.)
Algorithm (cont.)
• For each production of the form
• We begin with
• We include this circuit:
START
b
READ
Xi
PUSH X1 POP
POP
CSI3104 - Dr. Thomas Tran 17 CSI3104 - Dr. Thomas Tran 19
Algorithm (cont.)
Algorithm (cont.) • In this case, we can convert all productions into CNF and construct
the PDA as described above. In addition, we must also include Λ.
This can be done by adding a simple circuit at the POP:
• When the STACK is empty, which means that we have converted our
last nonterminal to a terminal and the terminals have matched the
INPUT TAPE, we add this path:
S
POP
POP
∆ READ
∆
ACCEPT
Example
• From the reasons and example above, we know that all words
generated by the given CFG will be accepted by the PDA, and all S → AR1 |BR2 |AA|BB|a|b|Λ
words accepted by this PDA will have leftmost derivations in the R1 → SA
given CFG.
R2 → SB
• At the beginning we assumed that the CFG was in CNF. But there are A→a
some CFLs that cannot be put into CNF. These are the languages that
B→b
include the word Λ.
• Using the algorithm above, we build the following PDA that accepts
exactly the same language:
CSI3104 - Dr. Thomas Tran 21
START a ACCEPT
a, b b
S B A
∆
S ∆
PUSH S POP READ 4
S S R2 S S
R1
PUSH R1 PUSH A PUSH R2 PUSH B PUSH A PUSH B
Notes