MC 306 Theory of Computation Tuesday, 102803 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

MC 306 Theory of Computation Tuesday, 102803

Description:

Given a CFG, we show how to construct an equivalent PDA. Given a PDA, we show how to construct an equivalent CFG. Tuesday, 10/28/03, Slide #7 ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 9
Provided by: skid
Category:

less

Transcript and Presenter's Notes

Title: MC 306 Theory of Computation Tuesday, 102803


1
MC 306 Theory of ComputationTuesday, 10/28/03
  • Last time
  • Normal forms
  • Backus-Naur form
  • Chomsky normal forms
  • See handout for completed example
  • Today
  • Pushdown Automata
  • Reading
  • 3.3, 3.4
  • Exercises
  • 3.3 3.18, 3.20, 3.22-3.24
  • 3.4 3.29, Also Construct a pda equivalent to
    grammar in 3.3, and show its accepting
    computation of the string in part a.
  • Hand-in
  • No new hand-in

2
A machine to accept context-free languages
  • One of our archetypical context-free languages is
    anbn n ? 0
  • We can soup up an NFA to accept this language
    by adding a stack
  • a, ? 1 on arrow means do the following in
    order (1) Read a from input string (2) Pop ?
    from stack (3) Push 1 onto stack.
  • Must be able to both read and pop to use arrow.

3
Definition of PDA
  • A (nondeterministic) pushdown automaton is a
    6-tuple
  • Q is a finite set of states
  • ? is the input alphabet
  • ? is the stack alphabet
  • s0 ? Q is the start state
  • F ?? Q is the set of final (favorable) states
  • ? , the transition relation, which is a set of
    ordered pairs of the form ( (q1, w1, v1), (q2,
    v2) ),
  • where q1 and q2 are states
  • where w1 ? ? ? ? (we read the input symbol w1)
  • and where v1 and v2 ? ? (we pop v1, then push
    v2)
  • Hence ? is a subset of (Q x (? ? ?) x ?) x (Q
    x ?)
  • What is 6-tuple for preceding example?

4
Computations and acceptance
  • A configuraton of a pda is a triple (q, w, v),
    where q is a state, w ? ? (current input
    string), and v ? ?? (current stack)
  • We say that a pda accepts a string w if there is
    some computation of the machine beginning with
    the starting configuration (s0, w, ?) and
    yielding an accepting configuration (f, ?, ?),
    where f is a final state
  • I.e., you must be able to read the whole string
    and empty out the stack, ending in a final state
  • Note JFLAP does not require emptying the stack
    to accept.
  • Look at our example in JFLAP (anbn.jfl)
  • Modify to make it do right thing!

5
Exercises
  • 1) Design a PDA to accept the language
  • ai bj ck i, j, k 0, and i j or j k
  • 2) Design a PDA to accept the language
  • w ? a, b Na(w) Nb(w), where Nx(w) means
    the number of xs in w.
  • 3) Prove If L is any regular language, there is
    some PDA that accepts L.
  • 4) Is the converse of (3) true? Why?

6
Equivalence of CFGs and PDAs
  • Just as NFAs and regular expressions describe the
    same class of languages, namely the regular
    languages
  • So do CFGs and PDAs describe the same class of
    languages, namely the context-free languages
  • Given a CFG, we show how to construct an
    equivalent PDA
  • Given a PDA, we show how to construct an
    equivalent CFG.

7
From CFG to PDA
  • Given a CFG G, we construct a PDA M that
    simulates a derivation of a string
  • Q s, f s start state, f only final state
  • ?M ?Q ?M ?Q ? NTQ
  • Transitions
  • Transition from s to f Read nothing, pop
    nothing push starting nonterminal S onto stack
  • Transitions from f to f, corresponding to rules
  • For each rule A ? ?, read nothing, pop A, push ?
  • Transitions from f to f, corresponding to ?
    symbols
  • For each x ??, read x, pop x, push nothing.

8
Example Convert CFG to PDA
  • A CFG that accepts w wR over alphabet ? a, b
  • S ? a S a b S b ?
  • A derivation of aabbaa
  • S ? aSa ? aaSaa ? aabSbaa ? aabbaa
  • Construct the PDA as defined by algorithm.
  • What does computation of PDA look like on string
    aabbaa?
Write a Comment
User Comments (0)
About PowerShow.com