0% found this document useful (0 votes)
25 views6 pages

Chapter1541 Dvi

csi3104

Uploaded by

Lucy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Chapter1541 Dvi

csi3104

Uploaded by

Lucy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSI3104 - Dr. Thomas Tran 1 CSI3104 - Dr.

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.

CSI3104 - Dr. Thomas Tran 2 CSI3104 - Dr. Thomas Tran 4

Example (inside the proof)

• Consider the following CFG in CNF:


Theorems 30 and 31
S → SB|AB
• Theorem 30: A → CC
Given a CFG that generates the language L, there is a PDA that B→b
accepts exactly L. C→a
• Theorem 31: • We now propose the following nondeterministic PDA where the
Given a PDA that accepts the language L, there exists a CFG that STACK alphabet is
generates exactly L. Γ = {S, A, B, C}
and the TAPE alphabet is only

Σ = {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:

C ∆ Working string Production used


B
∆ S ⇒ AB S → AB
PUSH S POP READ 3
⇒ CCB A → CC
S A
S ⇒ aCB C→a

PUSH B PUSH B PUSH C


⇒ aaB C→a
⇒ aab B→b

PUSH S PUSH A PUSH C

CSI3104 - Dr. Thomas Tran 6 CSI3104 - Dr. Thomas Tran 8

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 pop the top of the STACK: a READ 1 READ 2 ACCEPT

– We either replace the removed nonterminal with two other


C ∆
nonterminals, thereby simulating a production, B

– Or we go to a READ state, which insists that we must read a PUSH S POP READ 3
specific terminal from the TAPE, or else it crashes. S A
S
• To get to ACCEPT, we must have encountered the READ states that
wanted to read exactly the letters on the INPUT TAPE. PUSH B PUSH B PUSH C

• We now show that doing this is equivalent to simulating a leftmost


PUSH S PUSH A PUSH C
derivation of the input string in the given CFG.
CSI3104 - Dr. Thomas Tran 9 CSI3104 - Dr. Thomas Tran 11

• 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∆

CSI3104 - Dr. Thomas Tran 10 CSI3104 - Dr. Thomas Tran 12

• We go back to POP. We now simulate A → CC by popping A and do


PUSH C and PUSH C:

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

Algorithm Algorithm (cont.)

• Given a CFG in CNF as follows: • For each production of the form


X1 → X2 X3 Xi → Xj Xk
X1 → X3 X4
X2 → X2 X2 • We include this circuit from the POP state back to itself:

...
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 , ...

CSI3104 - Dr. Thomas Tran 14 CSI3104 - Dr. Thomas Tran 16

Algorithm (cont.)
Algorithm (cont.)
• For each production of the form

• We build the corresponding PDA as follows: Xi → b

• 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

• This kills the nonterminal S without replacing it with anything. So,


the next time we enter the POP, we get a blank and can proceed to
accept the word.

CSI3104 - Dr. Thomas Tran 18 CSI3104 - Dr. Thomas Tran 20

Example

Algorithm (cont.) • The language PALINDROME (including Λ) can be generated by the


following CFG in CNF (plus one Λ-production):

• 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

READ 1 READ 2 READ 3

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

PUSH A PUSH S PUSH B PUSH S PUSH A PUSH B

CSI3104 - Dr. Thomas Tran 22

Notes

• The proof of Theorem 31 is not included in the syllabus; however,


you are encouraged to read it from the text.
• Theorems 30 and 31 together prove that the set of all languages
accepted by PDAs is the same as the set of all languages
generated by CFGs.

You might also like