Document Sample

NPDA’s Accept Context-Free Languages Fall 2004 COMP 335 1 Theorem: Context-Free Languages Languages Accepted by (Grammars) NPDAs Fall 2004 COMP 335 2 Proof - Step 1: Context-Free Languages Languages Accepted by (Grammars) NPDAs Convert any context-free grammar to a NPDA with: Fall 2004 COMP 335 3 Proof - Step 2: Context-Free Languages Languages Accepted by (Grammars) NPDAs Convert any NPDA to a context-free grammar with: Fall 2004 COMP 335 4 Proof - step 1 Converting Context-Free Grammars to NPDAs Fall 2004 COMP 335 5 We will convert any context-free grammar to an NPDA automaton Such that: Simulates leftmost derivations of Fall 2004 COMP 335 6 Leftmost derivation Input Stack processed contents leftmost variable Simulation of derivation Stack Input Fall 2004 COMP 335 7 Leftmost derivation string of terminals Simulation of derivation Stack Input end of input is reached Fall 2004 COMP 335 8 An example grammar: What is an equivalent NPDA? Fall 2004 COMP 335 9 Grammar: NPDA: Fall 2004 COMP 335 10 Grammar: A leftmost derivation: Fall 2004 COMP 335 11 Derivation: Input Time 0 Stack Fall 2004 COMP 335 12 Derivation: Input Time 0 Stack Fall 2004 COMP 335 13 Derivation: Input Time 1 Stack Fall 2004 COMP 335 14 Derivation: Input Time 2 Stack Fall 2004 COMP 335 15 Derivation: Input Time 3 Stack Fall 2004 COMP 335 16 Derivation: Input Time 4 Stack Fall 2004 COMP 335 17 Derivation: Input Time 5 Stack Fall 2004 COMP 335 18 Derivation: Input Time 6 Stack Fall 2004 COMP 335 19 Derivation: Input Time 7 Stack Fall 2004 COMP 335 20 Derivation: Input Time 8 Stack Fall 2004 COMP 335 21 Derivation: Input Time 9 Stack accept Fall 2004 COMP 335 22 In general: Given any grammar We can construct a NPDA With Fall 2004 COMP 335 23 Constructing NPDA from grammar : For any terminal For any production Fall 2004 COMP 335 24 Grammar generates string if and only if NPDA accepts Fall 2004 COMP 335 25 Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages Languages Accepted by (Grammars) NPDAs Fall 2004 COMP 335 26 Proof - step 2 Converting NPDAs to Context-Free Grammars Fall 2004 COMP 335 27 For any NPDA we will construct a context-free grammar with Fall 2004 COMP 335 28 Intuition: The grammar simulates the computation of the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA Fall 2004 COMP 335 29 Some Necessary Modifications Modify (if necessary) the NPDA so that: 1) The stack is never empty 2) has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form: d(qi,a,A)={c1,c2,…,cn}, where ci=(qj,l) or ci=(qj,BC) Fall 2004 COMP 335 30 Example of a NPDA in correct form: Fall 2004 COMP 335 31 The Grammar Construction In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Fall 2004 COMP 335 32 For each transition We add production Fall 2004 COMP 335 33 For each transition We add productions For all possible states in the automaton Fall 2004 COMP 335 34 Stack bottom symbol Start Variable: Start state final state Fall 2004 COMP 335 35 Example: Grammar production: Fall 2004 COMP 335 36 Example: Grammar productions: Fall 2004 COMP 335 37 Example: Grammar production: Fall 2004 COMP 335 38 Resulting Grammar: Fall 2004 COMP 335 39 Fall 2004 COMP 335 40 Derivation of string Fall 2004 COMP 335 41 In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack Fall 2004 COMP 335 42 Therefore: if and only if is accepted by the NPDA Fall 2004 COMP 335 43 Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages Languages Accepted by (Grammars) NPDAs Fall 2004 COMP 335 44 Deterministic PDA DPDA Fall 2004 COMP 335 45 Deterministic PDA: DPDA Allowed transitions: (deterministic choices) Fall 2004 COMP 335 46 Allowed transitions: (deterministic choices) Fall 2004 COMP 335 47 Not allowed: (non deterministic choices) Fall 2004 COMP 335 48 DPDA example Fall 2004 COMP 335 49 The language is deterministic context-free Fall 2004 COMP 335 50 Definition: A language is deterministic context-free if there exists some DPDA that accepts it Fall 2004 COMP 335 51 Example of Non-DPDA (NPDA) Fall 2004 COMP 335 52 Not allowed in DPDAs Fall 2004 COMP 335 53 NPDAs Have More Power than DPDAs Fall 2004 COMP 335 54 It holds that: Deterministic Context-Free Context-Free Languages Languages NPDAs (DPDA) Since every DPDA is also a NPDA Fall 2004 COMP 335 55 We will actually show: Deterministic Context-Free Context-Free Languages Languages (NPDA) (DPDA) We will show that there exists a context-free language which is not accepted by any DPDA Fall 2004 COMP 335 56 The language is: We will show: • is context-free • is not deterministic context-free Fall 2004 COMP 335 57 Language is context-free Context-free grammar for : Fall 2004 COMP 335 58 Theorem: The language is not deterministic context-free (there is no DPDA that accepts ) Fall 2004 COMP 335 59 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts Fall 2004 COMP 335 60 DPDA with accepts accepts Fall 2004 COMP 335 61 DPDA with Such a path exists because of the determinism Fall 2004 COMP 335 62 Fact 1: The language is not context-free Context-free languages Regular languages (we will prove this at a later class using pumping lemma for context-free languages) Fall 2004 COMP 335 63 Fact 2: The language is not context-free (we can prove this using pumping lemma for context-free languages) Fall 2004 COMP 335 64 We will construct a NPDA that accepts: which is a contradiction! Fall 2004 COMP 335 65 Modify Replace with Fall 2004 COMP 335 66 The NPDA that accepts Connect final states of with final states of Fall 2004 COMP 335 67 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free) Fall 2004 COMP 335 68 Therefore: Not deterministic context free There is no DPDA that accepts End of Proof Fall 2004 COMP 335 69

DOCUMENT INFO

Shared By:

Categories:

Tags:

Stats:

views: | 1 |

posted: | 8/14/2013 |

language: | |

pages: | 69 |

OTHER DOCS BY pptfiles

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.