Costas Busch - RPI1 NPDAs Accept Context-Free Languages
Costas Busch - RPI2 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:
Costas Busch - RPI3 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:
Costas Busch - RPI4 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:
Costas Busch - RPI5 Converting Context-Free Grammars to NPDAs Proof - step 1
Costas Busch - RPI6 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of
Costas Busch - RPI7 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation
Costas Busch - RPI8 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached
Costas Busch - RPI9 An example grammar: What is the equivalent NPDA?
Costas Busch - RPI10 Grammar: NPDA:
Costas Busch - RPI11 Grammar: A leftmost derivation:
Costas Busch - RPI12 Input Stack Time 0 Derivation:
Costas Busch - RPI13 Input Stack Time 0 Derivation:
Costas Busch - RPI14 Input Stack Time 1 Derivation:
Costas Busch - RPI15 Input Stack Time 2 Derivation:
Costas Busch - RPI16 Input Stack Time 3 Derivation:
Costas Busch - RPI17 Input Stack Time 4 Derivation:
Costas Busch - RPI18 Input Stack Time 5 Derivation:
Costas Busch - RPI19 Input Stack Time 6 Derivation:
Costas Busch - RPI20 Input Stack Time 7 Derivation:
Costas Busch - RPI21 Input Stack Time 8 Derivation:
Costas Busch - RPI22 Input Stack accept Time 9 Derivation:
Costas Busch - RPI23 In general: Given any grammar We can construct a NPDA With
Costas Busch - RPI24 Constructing NPDA from grammar : For any production For any terminal
Costas Busch - RPI25 Grammar generates string if and only if NPDA accepts
Costas Busch - RPI26 Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs
Costas Busch - RPI27 Converting NPDAs to Context-Free Grammars Proof - step 2
Costas Busch - RPI28 For any NPDA we will construct a context-free grammar with
Costas Busch - RPI29 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables
Costas Busch - RPI30 Some Necessary Modifications Modify (if necessary) the NPDA so that: 1) The stack is never empty 2) It has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form
Costas Busch - RPI31 1)Modify the NPDA so that the stack is never empty Stack OK NOT OK
Costas Busch - RPI32 Introduce the new symbol to denote the bottom of the stack
Costas Busch - RPI33 Original NPDA At the beginning push into the stack original initial state new initial state
Costas Busch - RPI34 In transitions: replace every instance of with Example:
Costas Busch - RPI35 if the automaton attempts to pop or replace it will halt Convert all transitions so that:
Costas Busch - RPI36 $$ , Convert transitions as follows: halting state
Costas Busch - RPI37 NPDA , Empty the stack 2) Modify the NPDA so that it empties the stack and has a unique final state , , Old final states
Costas Busch - RPI38 3) modify the NPDA so that transitions have the following forms: OR
Costas Busch - RPI39 Convert:
Costas Busch - RPI40 Convert: symbols
Costas Busch - RPI41 Convert: symbols Convert recursively
Costas Busch - RPI42 Example of a NPDA in correct form:
Costas Busch - RPI43 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:
Costas Busch - RPI44 For each transition We add production
Costas Busch - RPI45 For each transition We add productions For all possible states in the automaton
Costas Busch - RPI46 Start Variable: Stack bottom symbol Start state final state
Costas Busch - RPI47 Example: Grammar production:
Costas Busch - RPI48 Example: Grammar productions:
Costas Busch - RPI49 Example: Grammar production:
Costas Busch - RPI50 Resulting Grammar:
Costas Busch - RPI51
Costas Busch - RPI52 Derivation of string
Costas Busch - RPI53 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
Costas Busch - RPI54 Therefore: if and only if is accepted by the NPDA
Costas Busch - RPI55 Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs
Costas Busch - RPI56 Deterministic PDA DPDA
Costas Busch - RPI57 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)
Costas Busch - RPI58 Allowed transitions: (deterministic choices)
Costas Busch - RPI59 Not allowed: (non deterministic choices)
Costas Busch - RPI60 DPDA example
Costas Busch - RPI61 The language is deterministic context-free
Costas Busch - RPI62 Definition: A language is deterministic context-free if there exists some DPDA that accepts it
Costas Busch - RPI63 Example of Non-DPDA (NPDA)
Costas Busch - RPI64 Not allowed in DPDAs
Costas Busch - RPI65 NPDAs Have More Power than DPDAs
Costas Busch - RPI66 Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA It holds that:
Costas Busch - RPI67 We will actually show: We will show that there exists a context-free language which is not accepted by any DPDA Deterministic Context-Free Languages (DPDA) Context-Free Languages (NPDA)
Costas Busch - RPI68 The language is: We will show: is context-free is not deterministic context-free
Costas Busch - RPI69 Language is context-free Context-free grammar for :
Costas Busch - RPI70 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )
Costas Busch - RPI71 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts
Costas Busch - RPI72 DPDA with accepts
Costas Busch - RPI73 DPDA with Such a path exists because of the determinism
Costas Busch - RPI74 The language is not context-free (we will prove this at a later class using pumping lemma for context-free languages) Fact 1: Regular languages Context-free languages
Costas Busch - RPI75 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)
Costas Busch - RPI76 We will construct a NPDA that accepts: which is a contradiction!
Costas Busch - RPI77 Modify Replace with
Costas Busch - RPI78 The NPDA that accepts Connect final states of with final states of
Costas Busch - RPI79 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free)
Costas Busch - RPI80 Therefore: There is no DPDA that accepts End of Proof Not deterministic context free