Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages
Courtesy Costas Busch - RPI2 Instantaneous Description Current state Remaining input Current stack contents
3 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, then so is the sequence obtained by adding an additional string at the end of component number two.
4 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, then so is the sequence obtained by adding an additional string at the bottom of component number three.
5 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, and some tail of the input is not consumed, then removing this tail from all ID's result in a legal computation sequence.
6 Languages of PDA Acceptance by Final State Language of NPDA : Initial state Final state
7 Languages of PDA Acceptance by Empty Stack Language of NPDA : Initial state Any state
8 From Empty Stack to Final State If of some PDA Then there is a PDA such that
9 From Empty Stack to Final State Proof: Let
10 Property # 2
11 Then there is a PDA such that From Final State to Empty Stack If for some PDA
12 From Final State to Empty Stack Proof: Let
13 from Property # 2 of ID
Courtesy Costas Busch - RPI14 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:
Courtesy Costas Busch - RPI15 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:
Courtesy Costas Busch - RPI16 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:
Courtesy Costas Busch - RPI17 Converting Context-Free Grammars to NPDAs Proof - step 1
Courtesy Costas Busch - RPI18 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of
Courtesy Costas Busch - RPI19 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation
Courtesy Costas Busch - RPI20 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached
Courtesy Costas Busch - RPI21 An example grammar: What is the equivalent NPDA?
Courtesy Costas Busch - RPI22 Grammar: NPDA:
Courtesy Costas Busch - RPI23 Grammar: A leftmost derivation:
Courtesy Costas Busch - RPI24 Input Stack Time 0 Derivation:
Courtesy Costas Busch - RPI25 Input Stack Time 0 Derivation:
Courtesy Costas Busch - RPI26 Input Stack Time 1 Derivation:
Courtesy Costas Busch - RPI27 Input Stack Time 2 Derivation:
Courtesy Costas Busch - RPI28 Input Stack Time 3 Derivation:
Courtesy Costas Busch - RPI29 Input Stack Time 4 Derivation:
Courtesy Costas Busch - RPI30 Input Stack Time 5 Derivation:
Courtesy Costas Busch - RPI31 Input Stack Time 6 Derivation:
Courtesy Costas Busch - RPI32 Input Stack Time 7 Derivation:
Courtesy Costas Busch - RPI33 Input Stack Time 8 Derivation:
Courtesy Costas Busch - RPI34 Input Stack accept Time 9 Derivation:
Courtesy Costas Busch - RPI35 In general: Given any grammar We can construct a NPDA With
Courtesy Costas Busch - RPI36 Constructing NPDA from grammar : For any production For any terminal
Courtesy Costas Busch - RPI37 Grammar generates string if and only if NPDA accepts
Courtesy Costas Busch - RPI38 Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs
Courtesy Costas Busch - RPI39 Note: From CFG to PDA accepting by emptying stack Given any grammar We can construct a NPDA With
Courtesy Costas Busch - RPI40 Constructing NPDA from grammar : For any production For any terminal
Courtesy Costas Busch - RPI41 Converting NPDAs to Context-Free Grammars Proof - step 2
Courtesy Costas Busch - RPI42 For any NPDA we will construct a context-free grammar with
Courtesy Costas Busch - RPI43 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables
Courtesy Costas Busch - RPI44 From NPDA to CFG Lets look at how a PDA can consume and empty the stack. We shall define a grammar with variables of the form [p i-1 Y i p i ] that would represent going from p i-1 to p i with the net effect of popping Y i.
45 To generate all those strings w that cause P to pop Z 0 from its stack while going from q 0 to p.
Courtesy Costas Busch - RPI46
47
48
49
Courtesy Costas Busch - RPI50 Some Necessary Modifications Modify (if necessary) the NPDA (accepting by reaching final state) 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
Courtesy Costas Busch - RPI51 1)Modify the NPDA so that the stack is never empty Stack OK NOT OK
Courtesy Costas Busch - RPI52 Introduce the new symbol to denote the bottom of the stack
Courtesy Costas Busch - RPI53 Original NPDA At the beginning push into the stack original initial state new initial state
Courtesy Costas Busch - RPI54 In transitions: replace every instance of with Example:
Courtesy Costas Busch - RPI55 if the automaton attempts to pop or replace it will halt Convert all transitions so that:
Courtesy Costas Busch - RPI56 $$ , Convert transitions as follows: halting state
Courtesy Costas Busch - RPI57 NPDA , Empty the stack 2) Modify the NPDA so that it empties the stack and has a unique final state , , Old final states
Courtesy Costas Busch - RPI58 3) modify the NPDA so that transitions have the following forms: OR
Courtesy Costas Busch - RPI59 Convert:
Courtesy Costas Busch - RPI60 Convert: symbols
Courtesy Costas Busch - RPI61 Convert: symbols Convert recursively
Courtesy Costas Busch - RPI62 Example of a NPDA in correct form:
Courtesy Costas Busch - RPI63 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:
Courtesy Costas Busch - RPI64 For each transition We add production
Courtesy Costas Busch - RPI65 For each transition We add productions For all possible states in the automaton
Courtesy Costas Busch - RPI66 Start Variable: Stack bottom symbol Start state final state
Courtesy Costas Busch - RPI67 Example: Grammar production:
Courtesy Costas Busch - RPI68 Example: Grammar productions:
Courtesy Costas Busch - RPI69 Example: Grammar production:
Courtesy Costas Busch - RPI70 Resulting Grammar:
Courtesy Costas Busch - RPI71
Courtesy Costas Busch - RPI72 Derivation of string
Courtesy Costas Busch - RPI73 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
Courtesy Costas Busch - RPI74 Therefore: if and only if is accepted by the NPDA
Courtesy Costas Busch - RPI75 Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs
Courtesy Costas Busch - RPI76 Deterministic PDA DPDA
Courtesy Costas Busch - RPI77 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)
Courtesy Costas Busch - RPI78 Allowed transitions: (deterministic choices)
Courtesy Costas Busch - RPI79 Not allowed: (non deterministic choices)
Courtesy Costas Busch - RPI80 DPDA example
Courtesy Costas Busch - RPI81 The language is deterministic context-free
Courtesy Costas Busch - RPI82 Definition: A language is deterministic context-free if there exists some DPDA that accepts it
Courtesy Costas Busch - RPI83 Example of Non-DPDA (NPDA)
Courtesy Costas Busch - RPI84 Not allowed in DPDAs
Courtesy Costas Busch - RPI85 NPDAs Have More Power than DPDAs
Courtesy Costas Busch - RPI86 Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA It holds that:
Courtesy Costas Busch - RPI87 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)
Courtesy Costas Busch - RPI88 The language is: We will show: is context-free is not deterministic context-free
Courtesy Costas Busch - RPI89 Language is context-free Context-free grammar for :
Courtesy Costas Busch - RPI90 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )
Courtesy Costas Busch - RPI91 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts
Courtesy Costas Busch - RPI92 DPDA with accepts
Courtesy Costas Busch - RPI93 DPDA with Such a path exists because of the determinism
Courtesy Costas Busch - RPI94 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
Courtesy Costas Busch - RPI95 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)
Courtesy Costas Busch - RPI96 We will construct a NPDA that accepts: which is a contradiction!
Courtesy Costas Busch - RPI97 Modify Replace with
Courtesy Costas Busch - RPI98 The NPDA that accepts Connect final states of with final states of
Courtesy Costas Busch - RPI99 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free)
Courtesy Costas Busch - RPI100 Therefore: There is no DPDA that accepts End of Proof Not deterministic context free