Download presentation
Presentation is loading. Please wait.
1
Costas Busch - RPI1 NPDAs Accept Context-Free Languages
2
Costas Busch - RPI2 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:
3
Costas Busch - RPI3 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:
4
Costas Busch - RPI4 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:
5
Costas Busch - RPI5 Converting Context-Free Grammars to NPDAs Proof - step 1
6
Costas Busch - RPI6 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of
7
Costas Busch - RPI7 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation
8
Costas Busch - RPI8 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached
9
Costas Busch - RPI9 An example grammar: What is the equivalent NPDA?
10
Costas Busch - RPI10 Grammar: NPDA:
11
Costas Busch - RPI11 Grammar: A leftmost derivation:
12
Costas Busch - RPI12 Input Stack Time 0 Derivation:
13
Costas Busch - RPI13 Input Stack Time 0 Derivation:
14
Costas Busch - RPI14 Input Stack Time 1 Derivation:
15
Costas Busch - RPI15 Input Stack Time 2 Derivation:
16
Costas Busch - RPI16 Input Stack Time 3 Derivation:
17
Costas Busch - RPI17 Input Stack Time 4 Derivation:
18
Costas Busch - RPI18 Input Stack Time 5 Derivation:
19
Costas Busch - RPI19 Input Stack Time 6 Derivation:
20
Costas Busch - RPI20 Input Stack Time 7 Derivation:
21
Costas Busch - RPI21 Input Stack Time 8 Derivation:
22
Costas Busch - RPI22 Input Stack accept Time 9 Derivation:
23
Costas Busch - RPI23 In general: Given any grammar We can construct a NPDA With
24
Costas Busch - RPI24 Constructing NPDA from grammar : For any production For any terminal
25
Costas Busch - RPI25 Grammar generates string if and only if NPDA accepts
26
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
27
Costas Busch - RPI27 Converting NPDAs to Context-Free Grammars Proof - step 2
28
Costas Busch - RPI28 For any NPDA we will construct a context-free grammar with
29
Costas Busch - RPI29 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables
30
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
31
Costas Busch - RPI31 1)Modify the NPDA so that the stack is never empty Stack OK NOT OK
32
Costas Busch - RPI32 Introduce the new symbol to denote the bottom of the stack
33
Costas Busch - RPI33 Original NPDA At the beginning push into the stack original initial state new initial state
34
Costas Busch - RPI34 In transitions: replace every instance of with Example:
35
Costas Busch - RPI35 if the automaton attempts to pop or replace it will halt Convert all transitions so that:
36
Costas Busch - RPI36 $$ , Convert transitions as follows: halting state
37
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
38
Costas Busch - RPI38 3) modify the NPDA so that transitions have the following forms: OR
39
Costas Busch - RPI39 Convert:
40
Costas Busch - RPI40 Convert: symbols
41
Costas Busch - RPI41 Convert: symbols Convert recursively
42
Costas Busch - RPI42 Example of a NPDA in correct form:
43
Costas Busch - RPI43 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:
44
Costas Busch - RPI44 For each transition We add production
45
Costas Busch - RPI45 For each transition We add productions For all possible states in the automaton
46
Costas Busch - RPI46 Start Variable: Stack bottom symbol Start state final state
47
Costas Busch - RPI47 Example: Grammar production:
48
Costas Busch - RPI48 Example: Grammar productions:
49
Costas Busch - RPI49 Example: Grammar production:
50
Costas Busch - RPI50 Resulting Grammar:
51
Costas Busch - RPI51
52
Costas Busch - RPI52 Derivation of string
53
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
54
Costas Busch - RPI54 Therefore: if and only if is accepted by the NPDA
55
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
56
Costas Busch - RPI56 Deterministic PDA DPDA
57
Costas Busch - RPI57 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)
58
Costas Busch - RPI58 Allowed transitions: (deterministic choices)
59
Costas Busch - RPI59 Not allowed: (non deterministic choices)
60
Costas Busch - RPI60 DPDA example
61
Costas Busch - RPI61 The language is deterministic context-free
62
Costas Busch - RPI62 Definition: A language is deterministic context-free if there exists some DPDA that accepts it
63
Costas Busch - RPI63 Example of Non-DPDA (NPDA)
64
Costas Busch - RPI64 Not allowed in DPDAs
65
Costas Busch - RPI65 NPDAs Have More Power than DPDAs
66
Costas Busch - RPI66 Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA It holds that:
67
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)
68
Costas Busch - RPI68 The language is: We will show: is context-free is not deterministic context-free
69
Costas Busch - RPI69 Language is context-free Context-free grammar for :
70
Costas Busch - RPI70 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )
71
Costas Busch - RPI71 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts
72
Costas Busch - RPI72 DPDA with accepts
73
Costas Busch - RPI73 DPDA with Such a path exists because of the determinism
74
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
75
Costas Busch - RPI75 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)
76
Costas Busch - RPI76 We will construct a NPDA that accepts: which is a contradiction!
77
Costas Busch - RPI77 Modify Replace with
78
Costas Busch - RPI78 The NPDA that accepts Connect final states of with final states of
79
Costas Busch - RPI79 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free)
80
Costas Busch - RPI80 Therefore: There is no DPDA that accepts End of Proof Not deterministic context free
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.