Download presentation
Presentation is loading. Please wait.
1
1 Converting NPDAs to Context-Free Grammars
2
2 For any NPDA we will construct a context-free grammar with
3
3 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA
4
4 in NPDA A derivation in Grammar : Input processedStack contents terminalsvariables
5
5 Some Necessary Modifications First, we modify the NPDA: It has a single final state It empties the stack when it accepts the input Original NPDA Empty Stack
6
6 Second, we modify the NPDA transitions: all transitions will have form or
7
7 Example of a NPDA in correct form:
8
8 The Grammar Construction In grammar variables have form Terminals are input symbols states stack symbol
9
9 For each transition We add production For all states
10
10 For each transition We add production For all states in the NPDA
11
11 Start Variable: Stack bottom symbol Start state final state
12
12 Example: Grammar production:
13
13 Example: Grammar productions:
14
14 Example: Grammar production:
15
15 Resulting Grammar:
16
16
17
17 Derivation of string
18
18 In general, in grammar if and only if is accepted by the NPDA
19
19 Explanation: By construction of grammar: If and only if in the NPDA going from to the stack doesn’t change below and is removed from stack
20
20 Deterministic PDAs (DPDAs)
21
21 DPDAs Allowed Transitions:
22
22 Not allowed: Not allowed even when is
23
23 Allowed:
24
24 Not allowed: Not allowed even when is
25
25 DPDA example
26
26 The language is deterministic context-free
27
27 In general: A language is deterministic context-free if there is some NPDA that accepts it
28
28 Example of Non-DPDA
29
29 Not allowed transitions for DPDAs
30
30 NPDAs have more power than DPDAs
31
31 We will show: There is which is not a context-free language deterministic context-free (accepted by a NPDA) (not accepted by a DPDA)
32
32 The language is:
33
33 The language is context-free Context-free grammar for : (there is an NPDA that accepts )
34
34 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )
35
35 Proof: Assume for contradiction that is deterministic context free Therefore: There exists a DPDA that accepts
36
36 The DPDA with accepts
37
37 The language is not context-free (we will prove it at the next class) A fact:
38
38 Another fact: The language is not context-free
39
39 We will construct a NPDA that accepts
40
40 First, we modify : Modified Replace with
41
41 The NPDA that accepts Modified Original
42
42 is accepted by a NPDA Therefore: is context-free Contradiction! ( is not context-free)
43
43 Therefore: There is no DPDA that accepts End of Proof
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.