Download presentation
Presentation is loading. Please wait.
1
NPDAs Accept Context-Free Languages
Costas Busch - RPI
2
Theorem: Context-Free Languages Languages Accepted by (Grammars) NPDAs
Costas Busch - RPI
3
Convert any context-free grammar to a NPDA with:
Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any context-free grammar to a NPDA with: Costas Busch - RPI
4
Convert any NPDA to a context-free grammar with:
Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by NPDAs Convert any NPDA to a context-free grammar with: Costas Busch - RPI
5
Converting Context-Free Grammars to NPDAs
Proof - step 1 Converting Context-Free Grammars to NPDAs Costas Busch - RPI
6
We will convert any context-free grammar
to an NPDA automaton Such that: Simulates leftmost derivations of Costas Busch - RPI
7
Simulation of derivation
Leftmost derivation Input processed Stack contents leftmost variable Stack Simulation of derivation Input Costas Busch - RPI
8
Simulation of derivation
Leftmost derivation string of terminals Stack Simulation of derivation Input end of input is reached Costas Busch - RPI
9
What is the equivalent NPDA?
An example grammar: What is the equivalent NPDA? Costas Busch - RPI
10
Grammar: NPDA: Costas Busch - RPI
11
A leftmost derivation:
Grammar: A leftmost derivation: Costas Busch - RPI
12
Derivation: Input Time 0 Stack Costas Busch - RPI
13
Derivation: Input Time 0 Stack Costas Busch - RPI
14
Derivation: Input Time 1 Stack Costas Busch - RPI
15
Derivation: Input Time 2 Stack Costas Busch - RPI
16
Derivation: Input Time 3 Stack Costas Busch - RPI
17
Derivation: Input Time 4 Stack Costas Busch - RPI
18
Derivation: Input Time 5 Stack Costas Busch - RPI
19
Derivation: Input Time 6 Stack Costas Busch - RPI
20
Derivation: Input Time 7 Stack Costas Busch - RPI
21
Derivation: Input Time 8 Stack Costas Busch - RPI
22
Derivation: Input Time 9 Stack accept Costas Busch - RPI
23
In general: Given any grammar We can construct a NPDA With
Costas Busch - RPI
24
Constructing NPDA from grammar :
For any production For any terminal Costas Busch - RPI
25
Grammar generates string
if and only if NPDA accepts Costas Busch - RPI
26
For any context-free language there is a NPDA
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 - RPI
27
Converting NPDAs to Context-Free Grammars
Proof - step 2 Converting NPDAs to Context-Free Grammars Costas Busch - RPI
28
a context-free grammar with
For any NPDA we will construct a context-free grammar with Costas Busch - RPI
29
The grammar simulates the machine
Intuition: The grammar simulates the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA Costas Busch - RPI
30
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 - RPI
31
the stack is never empty
Modify the NPDA so that the stack is never empty Stack OK OK NOT OK Costas Busch - RPI
32
Introduce the new symbol to denote the bottom of the stack
Costas Busch - RPI
33
At the beginning push into the stack
Original NPDA new initial state original initial state Costas Busch - RPI
34
replace every instance of with
In transitions: replace every instance of with Example: Costas Busch - RPI
35
Convert all transitions so that:
if the automaton attempts to pop or replace it will halt Costas Busch - RPI
36
l , ® $ Convert transitions as follows: halting state
Costas Busch - RPI
37
2) Modify the NPDA so that it empties the stack
and has a unique final state Empty the stack NPDA l , l , l , Old final states Costas Busch - RPI
38
3) modify the NPDA so that transitions have the following forms:
Costas Busch - RPI
39
Convert: Costas Busch - RPI
40
Convert: symbols Costas Busch - RPI
41
Convert: symbols Convert recursively Costas Busch - RPI
42
Example of a NPDA in correct form:
Costas Busch - RPI
43
The Grammar Construction
In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Costas Busch - RPI
44
For each transition We add production Costas Busch - RPI
45
For all possible states in the automaton
For each transition We add productions For all possible states in the automaton Costas Busch - RPI
46
Stack bottom symbol Start Variable: Start state final state
Costas Busch - RPI
47
Example: Grammar production: Costas Busch - RPI
48
Example: Grammar productions: Costas Busch - RPI
49
Example: Grammar production: Costas Busch - RPI
50
Resulting Grammar: Costas Busch - RPI
51
Costas Busch - RPI
52
Derivation of string Costas Busch - RPI
53
the stack doesn’t change below and then is removed from stack
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 - RPI
54
Therefore: if and only if is accepted by the NPDA Costas Busch - RPI
55
there is a context-free grammar that accepts the same language
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 - RPI
56
Deterministic PDA DPDA
Costas Busch - RPI
57
Deterministic PDA: DPDA
Allowed transitions: (deterministic choices) Costas Busch - RPI
58
(deterministic choices)
Allowed transitions: (deterministic choices) Costas Busch - RPI
59
(non deterministic choices)
Not allowed: (non deterministic choices) Costas Busch - RPI
60
DPDA example Costas Busch - RPI
61
is deterministic context-free
The language is deterministic context-free Costas Busch - RPI
62
A language is deterministic context-free
Definition: A language is deterministic context-free if there exists some DPDA that accepts it Costas Busch - RPI
63
Example of Non-DPDA (NPDA)
Costas Busch - RPI
64
Not allowed in DPDAs Costas Busch - RPI
65
NPDAs Have More Power than DPDAs
Costas Busch - RPI
66
Since every DPDA is also a NPDA
It holds that: Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA Costas Busch - RPI
67
We will show that there exists a context-free language which is not
We will actually show: Deterministic Context-Free Languages (DPDA) Context-Free Languages (NPDA) We will show that there exists a context-free language which is not accepted by any DPDA Costas Busch - RPI
68
is not deterministic context-free
The language is: We will show: is context-free is not deterministic context-free Costas Busch - RPI
69
Language is context-free
Context-free grammar for : Costas Busch - RPI
70
Theorem: The language is not deterministic context-free
(there is no DPDA that accepts ) Costas Busch - RPI
71
Proof: Assume for contradiction that is deterministic context free
Therefore: there is a DPDA that accepts Costas Busch - RPI
72
DPDA with accepts accepts Costas Busch - RPI
73
Such a path exists because of the determinism
DPDA with Such a path exists because of the determinism Costas Busch - RPI
74
Context-free languages
Fact 1: The language is not context-free Regular languages Context-free languages (we will prove this at a later class using pumping lemma for context-free languages) Costas Busch - RPI
75
Fact 2: The language is not context-free
(we can prove this using pumping lemma for context-free languages) Costas Busch - RPI
76
We will construct a NPDA that accepts:
which is a contradiction! Costas Busch - RPI
77
Replace with Modify Costas Busch - RPI
78
Connect final states of with final states of
The NPDA that accepts Connect final states of with final states of Costas Busch - RPI
79
Since is accepted by a NPDA
it is context-free Contradiction! (since is not context-free) Costas Busch - RPI
80
Not deterministic context free
Therefore: Not deterministic context free There is no DPDA that accepts End of Proof Costas Busch - RPI
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.