courtesy costas busch - rpi1 npdas accept context-free languages

Post on 20-Dec-2015

213 views

Category:

Documents

Tags:

• stack proof

Embed Size (px)

TRANSCRIPT

• Slide 1
• Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages
• Slide 2
• Courtesy Costas Busch - RPI2 Instantaneous Description Current state Remaining input Current stack contents
• Slide 3
• 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.
• Slide 4
• 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.
• Slide 5
• 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.
• Slide 6
• 6 Languages of PDA Acceptance by Final State Language of NPDA : Initial state Final state
• Slide 7
• 7 Languages of PDA Acceptance by Empty Stack Language of NPDA : Initial state Any state
• Slide 8
• 8 From Empty Stack to Final State If of some PDA Then there is a PDA such that
• Slide 9
• 9 From Empty Stack to Final State Proof: Let
• Slide 10
• 10 Property # 2
• Slide 11
• 11 Then there is a PDA such that From Final State to Empty Stack If for some PDA
• Slide 12
• 12 From Final State to Empty Stack Proof: Let
• Slide 13
• 13 from Property # 2 of ID
• Slide 14
• Courtesy Costas Busch - RPI14 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:
• Slide 15
• Courtesy Costas Busch - RPI15 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:
• Slide 16
• Courtesy Costas Busch - RPI16 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:
• Slide 17
• Courtesy Costas Busch - RPI17 Converting Context-Free Grammars to NPDAs Proof - step 1
• Slide 18
• Courtesy Costas Busch - RPI18 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of
• Slide 19
• Courtesy Costas Busch - RPI19 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation
• Slide 20
• Courtesy Costas Busch - RPI20 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached
• Slide 21
• Courtesy Costas Busch - RPI21 An example grammar: What is the equivalent NPDA?
• Slide 22
• Courtesy Costas Busch - RPI22 Grammar: NPDA:
• Slide 23
• Courtesy Costas Busch - RPI23 Grammar: A leftmost derivation:
• Slide 24
• Courtesy Costas Busch - RPI24 Input Stack Time 0 Derivation:
• Slide 25
• Courtesy Costas Busch - RPI25 Input Stack Time 0 Derivation:
• Slide 26
• Courtesy Costas Busch - RPI26 Input Stack Time 1 Derivation:
• Slide 27
• Courtesy Costas Busch - RPI27 Input Stack Time 2 Derivation:
• Slide 28
• Courtesy Costas Busch - RPI28 Input Stack Time 3 Derivation:
• Slide 29
• Courtesy Costas Busch - RPI29 Input Stack Time 4 Derivation:
• Slide 30
• Courtesy Costas Busch - RPI30 Input Stack Time 5 Derivation:
• Slide 31
• Courtesy Costas Busch - RPI31 Input Stack Time 6 Derivation:
• Slide 32
• Courtesy Costas Busch - RPI32 Input Stack Time 7 Derivation:
• Slide 33
• Courtesy Costas Busch - RPI33 Input Stack Time 8 Derivation:
• Slide 34
• Courtesy Costas Busch - RPI34 Input Stack accept Time 9 Derivation:
• Slide 35
• Courtesy Costas Busch - RPI35 In general: Given any grammar We can construct a NPDA With
• Slide 36
• Courtesy Costas Busch - RPI36 Constructing NPDA from grammar : For any production For any terminal
• Slide 37
• Courtesy Costas Busch - RPI37 Grammar generates string if and only if NPDA accepts
• Slide 38
• 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
• Slide 39
• Courtesy Costas Busch - RPI39 Note: From CFG to PDA accepting by emptying stack Given any grammar We can construct a NPDA With
• Slide 40
• Courtesy Costas Busch - RPI40 Constructing NPDA from grammar : For any production For any terminal
• Slide 41
• Courtesy Costas Busch - RPI41 Converting NPDAs to Context-Free Grammars Proof - step 2
• Slide 42
• Courtesy Costas Busch - RPI42 For any NPDA we will construct a context-free grammar with
• Slide 43
• Courtesy Costas Busch - RPI43 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables
• Slide 44
• 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.
• Slide 45
• 45 To generate all those strings w that cause P to pop Z 0 from its stack while going from q 0 to p.
• Slide 46
• Courtesy Costas Busch - RPI46
• Slide 47
• 47
• Slide 48
• 48
• Slide 49
• 49
• Slide 50
• 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
• Slide 51
• Courtesy Costas Busch - RPI51 1)Modify the NPDA so that the stack is never empty Stack OK NOT OK
• Slide 52
• Courtesy Costas Busch - RPI52 Introduce the new symbol to denote the bottom of the stack
• Slide 53
• Courtesy Costas Busch - RPI53 Original NPDA At the beginning push into the stack original initial state new initial state
• Slide 54
• Courtesy Costas Busch - RPI54 In transitions: replace every instance of with Example:
• Slide 55
• Courtesy Costas Busch - RPI55 if the automaton attempts to pop or replace it will halt Convert all transitions so that:
• Slide 56
• Courtesy Costas Busch - RPI56 \$\$ , Convert transitions as follows: halting state
• Slide 57
• 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
• Slide 58
• Courtesy Costas Busch - RPI58 3) modify the NPDA so that transitions have the following forms: OR
• Slide 59
• Courtesy Costas Busch - RPI59 Convert:
• Slide 60
• Courtesy Costas Busch - RPI60 Convert: symbols
• Slide 61
• Courtesy Costas Busch - RPI61 Convert: symbols Convert recursively
• Slide 62
• Courtesy Costas Busch - RPI62 Example of a NPDA in correct form:
• Slide 63
• Courtesy Costas Busch - RPI63 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:
• Slide 64
• Courtesy Costas Busch - RPI64 For each transition We add production
• Slide 65
• Courtesy Costas Busch - RPI65 For each transition We add productions For all possible states in the automaton
• Slide 66
• Courtesy Costas Busch - RPI66 Start Variable: Stack bottom symbol Start state final state
• Slide 67
• Courtesy Costas Busch - RPI67 Example: Grammar production:
• Slide 68
• Courtesy Costas Busch - RPI68 Example: Grammar productions:
• Slide 69
• Courtesy Costas Busch - RPI69 Example: Grammar production:
• Slide 70
• Courtesy Costas Busch - RPI70 Resulting Grammar:
• Slide 71
• Courtesy Costas Busch - RPI71
• Slide 72
• Courtesy Costas Busch - RPI72 Derivation of string
• Slide 73
• Courtesy Costas Busch - RPI73 In general: if and only if the NPDA goes from to by reading string and the stack doesnt change below and then is removed from stack
• Slide 74
• Courtesy Costas Busch - RPI74 Therefore: if and only if is accepted by the NPDA
• Sli

Recommended