Title: NPDAs Accept ContextFree Languages
1NPDAs Accept Context-Free Languages
2Theorem
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
3Proof - Step 1
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any context-free grammar to a NPDA
with
4Proof - Step 2
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any NPDA to a context-free
grammar with
5Converting Context-Free Grammarsto NPDAs
Proof - step 1
6We will convert any context-free grammar
to an NPDA automaton
Such that
Simulates leftmost derivations of
7Leftmost derivation
Input processed
Stack contents
leftmost variable
Stack
Simulation of derivation
Input
8Leftmost derivation
string of terminals
Stack
Simulation of derivation
Input
end of input is reached
9An example grammar
What is an equivalent NPDA?
10Grammar
NPDA
11Grammar
A leftmost derivation
12Derivation
Input
Time 0
Stack
13Derivation
Input
Time 0
Stack
14Derivation
Input
Time 1
Stack
15Derivation
Input
Time 2
Stack
16Derivation
Input
Time 3
Stack
17Derivation
Input
Time 4
Stack
18Derivation
Input
Time 5
Stack
19Derivation
Input
Time 6
Stack
20Derivation
Input
Time 7
Stack
21Derivation
Input
Time 8
Stack
22Derivation
Input
Time 9
Stack
accept
23In general
Given any grammar
We can construct a NPDA
With
24Constructing NPDA from grammar
For any terminal
For any production
25Grammar generates string
if and only if
NPDA accepts
26Therefore
For any context-free language there is a
NPDA that accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
27Converting NPDAstoContext-Free Grammars
Proof - step 2
28For any NPDA
we will construct a context-free grammar
with
29Intuition
The grammar simulates the computation of the
machine
A derivation in Grammar
terminals
variables
Input processed
Stack contents
Current configuration in NPDA
30Some Necessary Modifications
- Modify (if necessary) the NPDA so that
- 1) The stack is never empty
- 2) has a single final state and empties
- the stack when it accepts a string
- 3) Has transitions in a special form
- ?(qi,a,A)c1,c2,,cn, where ci(qj,?) or
ci(qj,BC)
31Example of a NPDA in correct form
32The Grammar Construction
In grammar
Stack symbol
Variables
states
Terminals Input symbols of NPDA
33For each transition
We add production
34For each transition
We add productions
For all possible states in the automaton
35Stack bottom symbol
Start Variable
Start state
final state
36Example
Grammar production
37Example
Grammar productions
38Example
Grammar production
39Resulting Grammar
40(No Transcript)
41Derivation of string
42In 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
43Therefore
if and only if
is accepted by the NPDA
44Therefore
For any NPDA there is a context-free grammar that
accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
45Deterministic PDADPDA
46Deterministic PDA DPDA
Allowed transitions
(deterministic choices)
47Allowed transitions
(deterministic choices)
48Not allowed
(non deterministic choices)
49DPDA example
50The language
is deterministic context-free
51Definition
A language is deterministic context-free if
there exists some DPDA that accepts it
52Example of Non-DPDA (NPDA)
53Not allowed in DPDAs
54NPDAs Have More Power thanDPDAs
55It holds that
Deterministic Context-Free Languages (DPDA)
Context-Free Languages NPDAs
Since every DPDA is also a NPDA
56We will actually show
Deterministic Context-Free Languages (DPDA)
Context-Free Languages (NPDA)
57The language is
We will show
- is not deterministic context-free
58Language is context-free
59Theorem
The language
is not deterministic context-free
(there is no DPDA that accepts )
60Proof
Assume for contradiction that
is deterministic context free
Therefore
there is a DPDA that accepts
61DPDA with
accepts
accepts
62DPDA with
Such a path exists because of the determinism
63Fact 1
The language is not
context-free
(we will prove this at a later class
using pumping lemma for context-free languages)
64Fact 2
The language is not
context-free
(we can prove this using pumping lemma for
context-free languages)
65We will construct a NPDA that accepts
which is a contradiction!
66Replace with
Modify
67The NPDA that accepts
Connect final states of with final states
of
68Since is accepted by a
NPDA
it is context-free
Contradiction!
(since is not
context-free)
69Therefore
Not deterministic context free
There is no DPDA that accepts
End of Proof