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 the 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 production
For any terminal
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 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) It has a single final state
- and empties the stack when it accepts a
string - 3) Has transitions in a special form
31- Modify the NPDA so that
- the stack is never empty
Stack
OK
OK
NOT OK
32Introduce the new symbol to denote the
bottom of the stack
33At the beginning push into the stack
Original NPDA
new initial state
original initial state
34In transitions replace every instance of
with
Example
35Convert all transitions so that
if the automaton attempts to pop or replace
it will halt
36Convert transitions as follows
halting state
372) Modify the NPDA so that it empties the
stack and has a unique final state
Empty the stack
NPDA
Old final states
383) modify the NPDA so that transitions have
the following forms
OR
39Convert
40Convert
symbols
41Convert
symbols
Convert recursively
42Example of a NPDA in correct form
43The Grammar Construction
In grammar
Stack symbol
Variables
states
Terminals Input symbols of NPDA
44For each transition
We add production
45For each transition
We add productions
For all possible states in the automaton
46Stack bottom symbol
Start Variable
Start state
final state
47Example
Grammar production
48Example
Grammar productions
49Example
Grammar production
50Resulting Grammar
51(No Transcript)
52Derivation of string
53In 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
54Therefore
if and only if
is accepted by the NPDA
55Therefore
For any NPDA there is a context-free grammar that
accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
56Deterministic PDADPDA
57Deterministic PDA DPDA
Allowed transitions
(deterministic choices)
58Allowed transitions
(deterministic choices)
59Not allowed
(non deterministic choices)
60DPDA example
61The language
is deterministic context-free
62Definition
A language is deterministic context-free if
there exists some DPDA that accepts it
63Example of Non-DPDA (NPDA)
64Not allowed in DPDAs
65NPDAs Have More Power thanDPDAs
66It holds that
Deterministic Context-Free Languages (DPDA)
Context-Free Languages NPDAs
Since every DPDA is also a NPDA
67We will actually show
Deterministic Context-Free Languages (DPDA)
Context-Free Languages (NPDA)
68The language is
We will show
- is not deterministic context-free
69Language is context-free
70Theorem
The language
is not deterministic context-free
(there is no DPDA that accepts )
71Proof
Assume for contradiction that
is deterministic context free
Therefore
there is a DPDA that accepts
72DPDA with
accepts
accepts
73DPDA with
Such a path exists because of the determinism
74Fact 1
The language is not
context-free
(we will prove this at a later class
using pumping lemma for context-free languages)
75Fact 2
The language is not
context-free
(we can prove this using pumping lemma for
context-free languages)
76We will construct a NPDA that accepts
which is a contradiction!
77Replace with
Modify
78The NPDA that accepts
Connect final states of with final states
of
79Since is accepted by a
NPDA
it is context-free
Contradiction!
(since is not
context-free)
80Therefore
Not deterministic context free
There is no DPDA that accepts
End of Proof