Module 34 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Module 34

Description:

The reverse is true as well, but we do not prove that here ... (q1, aab, UZ) (other branch not shown) (q1, aab, aaUbZ) (other branch not shown) (q1, ab, aUbZ) ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 20
Provided by: erict9
Learn more at: http://www.cse.msu.edu
Category:
Tags: class | module

less

Transcript and Presenter's Notes

Title: Module 34


1
Module 34
  • CFG --gt PDA construction
  • Shows that for any CFL L, there exists a PDA M
    such that L(M) L
  • The reverse is true as well, but we do not prove
    that here

2
CFL subset LPDA
  • Let L be an arbitrary CFL
  • Let G be the CFG such that L(G) L
  • G exists by definition of L is CF
  • Construct a PDA M such that L(M) L
  • M is constructed from CFG G
  • Argue L(M) L
  • There exists a PDA M such that L(M) L
  • L is in LPDA
  • By definition of L in LPDA

3
Visualization
  • Let L be an arbitrary CFL
  • Let G be the CFG such that L(G) L
  • G exists by definition of L is CF
  • Construct a PDA M such that L(M) L
  • M is constructed from CFG G
  • Argue L(M) L
  • There exists a PDA M such that L(M) L
  • L is in LPDA
  • By definition of L in LPDA

CFL
LPDA
4
Algorithm Specification
  • Input
  • CFG G
  • Output
  • PDA M such that L(M) L(G)

CFG G
PDA M
5
Construction Idea
  • The basic idea is to have a 2-phase PDA
  • Phase 1
  • Derive all strings in L(G) on the stack
    nondeterministically
  • Do not process any input while we are deriving
    the string on the stack
  • Phase 2
  • Match the input string against the derived string
    on the stack
  • This is a deterministic process
  • Move to an accepting state only when the stack is
    empty

6
Illustration
1. Derive all strings in L(G) on the stack2.
Match the derived string against input
  • Input Grammar G
  • V S
  • S a,b
  • S S
  • P
  • S --gt aSb l
  • What is L(G)?

Illustration of how the PDA might work, though
not completely accurate.
(q0, aabb, Z) / put S on stack / (q1, aabb,
SZ) / derive aabb on stack / (q1, aabb,
aSbZ) (q1, aabb, aaSbbZ) (q1, aabb, aabbZ) /
match stack vs input / (q2, aabb, aabbZ) (q2,
abb, abbZ) (q2, bb, bbZ) (q2, b, bZ) (q2,l,
Z) (q3, l, Z)
7
Difficulty
1. Derive all strings in L(G) on the stack2.
Match the derived string against input
(q0, aabb, Z) / put S on stack / (q1, aabb,
SZ) / derive aabb on stack / (q1, aabb,
aSbZ) (q1, aabb, aaSbbZ) (q1, aabb, aabbZ) /
match stack vs input / (q2, aabb, aabbZ) (q2,
abb, abbZ) (q2, bb, bbZ) (q2, b, bZ) (q2,l,
Z) (q3, l, Z)
What is illegal with the computation graph on the
left?
8
Construction
  • Input Grammar
  • G(V,S, S, P)
  • Output PDA
  • M(Q, S, G, q0, Z, F, d)
  • Q q0, q1, q2
  • S S
  • G V union S union Z
  • Z Z
  • q0 q0
  • F q2
  • d
  • d(q0, l, Z) (q1, SZ)
  • d(q1, l, Z) (q2, Z)
  • For all productions A --gt a
  • d(q1, l, A) (q1, a)
  • For all a in S
  • d(q1, a, a) (q1, l)

9
Examples
10
Palindromes
  • d(q0, l, Z) (q1, SZ)
  • d(q1, l, Z) (q2, Z)
  • Production Transitions
  • d(q1, l, S) (q1, aSa)
  • d(q1, l, S) (q1, bSb)
  • d(q1, l, S) (q1, a)
  • d(q1, l, S) (q1, b)
  • d(q1, l, S) (q1, l)
  • Matching transitions
  • d(q1, a, a) (q1, l)
  • d(q1, b, b) (q1, l)
  • PALG
  • V S
  • S a,b
  • S S
  • P
  • S --gt aSa bSb a b l
  • Output PDA M(Q,S,G,q0,Z,F,d)
  • Q q0, q1, q2
  • G a,b,S,Z
  • q0 q0
  • Z Z
  • F q2
  • d

11
Palindrome Transition Table
  • Transition Current Input Top of
    Next Stack
  • Number State Symbol Stack
    State Update
  • --------------------------------------------------
    -------------------------------
  • 1 q0 l
    Z q1 SZ
  • 2 q1 l
    Z q2 Z
  • 3 q1 l
    S q1 aSa
  • 4 q1 l
    S q1 bSb
  • 5 q1 l
    S q1 a
  • 6 q1 l
    S q1 b
  • 7 q1 l
    S q1 l
  • 8 q1 a
    a q1 l
  • 9 q1 b
    b q1 l

12
Partial Computation Graph
(q0, aba, Z) (q1, aba, SZ) (q1, aba, aSaZ)
(other branches not shown) (q1, ba, SaZ) (q1, ba,
baZ) (other branches not shown) (q1, a,
aZ) (q1, l, Z) (q2, l, Z) On your own, draw
computation trees for other strings not in the
language and see that they are not accepted.
13
anbn n gt 0
  • d(q0, l, Z) (q1, SZ)
  • d(q1, l, Z) (q2, Z)
  • Production Transitions
  • Matching transitions
  • Grammar G
  • V S
  • S a,b
  • S S
  • P
  • S --gt aSb l
  • Output PDA M(Q,S,G,q0,Z,F,d)
  • Q q0, q1, q2
  • G a,b,S,Z
  • q0 q0
  • Z Z
  • F q2
  • d

14
anbn n gt 0 Transition Table
  • Transition Current Input Top of
    Next Stack
  • Number State Symbol Stack
    State Update
  • --------------------------------------------------
    -------------------------------
  • 1 q0 l
    Z
  • 2 q1 l
    Z
  • 3 q1 l
    S
  • 4 q1 l
    S
  • 5 q1 a
    a
  • 6 q1 b
    b

15
Partial Computation Graph
(q0, aabb, Z) (q1, aabb, SZ) (q1, aabb, aSbZ)
(other branch not shown) (q1, abb, SbZ) (q1, abb,
aSbbZ) (other branch not shown) (q1, bb,
SbbZ) (q1, bb, bbZ) (other branch not
shown) (q1, b, bZ) (q1, l, Z) (q2, l, Z)
16
aibj i j or i 2j
  • d
  • d(q0, l, Z) (q1, SZ)
  • d(q1, l, Z) (q2, Z)
  • Production Transitions
  • d(q1, l, S) (q1, T)
  • d(q1, l, S) (q1, U)
  • d(q1, l, T) (q1, aTb)
  • d(q1, l, T) (q1, l)
  • d(q1, l, U) (q1, aaUb)
  • d(q1, l, U) (q1, l)
  • Matching transitions
  • d(q1, a, a) (q1, l)
  • d(q1, b, b) (q1, l)
  • Grammar G
  • V S,T,U
  • S a,b
  • S S
  • P
  • S --gt T U
  • T --gt aTb l
  • U --gt aaUb l
  • Output PDA M(Q,S,G,q0,Z,F,d)
  • Q q0, q1, q2
  • G a,b,S,T,U,Z
  • q0 q0
  • Z Z
  • F q2

17
aibj i j or i 2j Transition Table
  • Transition Current Input Top of
    Next Stack
  • Number State Symbol Stack
    State Update
  • --------------------------------------------------
    -------------------------------
  • 1 q0 l
    Z q1 SZ
  • 2 q1 l
    Z q2 Z
  • 3 q1 l
    S q1 T
  • 4 q1 l
    S q1 U
  • 5 q1 l
    T q1 aTb
  • 6 q1 l
    T q1 l
  • 7 q1 l
    U q1 aaUb
  • 8 q1 l
    U q1 l
  • 9 q1 a
    a q1 l
  • 10 q1 b
    b q1 l

18
Partial Computation Graph
(q0, aab, Z) (q1, aab, SZ) (q1, aab, UZ)
(other branch not shown) (q1, aab, aaUbZ) (other
branch not shown) (q1, ab, aUbZ) (q1, b,
UbZ) (q1, b, bZ) (other branch not
shown) (q1, l, Z) (q2, l, Z)
19
Things you should be able to do
  • You should be able to execute this algorithm
  • Given any CFG, construct an equivalent PDA
  • You should understand the idea behind this
    algorithm
  • Derive string on stack and then match it against
    input
  • You should understand how this construction can
    help you design PDAs
  • You should understand that it can be used in
    answer-preserving input transformations between
    decision problems about CFLs.
Write a Comment
User Comments (0)
About PowerShow.com