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