NPDAs Accept ContextFree Languages - PowerPoint PPT Presentation

About This Presentation
Title:

NPDAs Accept ContextFree Languages

Description:

... convert any context-free grammar. Such that: Simulates leftmost ... Example of a NPDA in correct form: Fall 2004. COMP 335. 32. The Grammar Construction ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 70
Provided by: cost80
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: NPDAs Accept ContextFree Languages


1
NPDAs Accept Context-Free Languages
2
Theorem
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
3
Proof - Step 1
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any context-free grammar to a NPDA
with
4
Proof - Step 2
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any NPDA to a context-free
grammar with
5
Converting Context-Free Grammarsto NPDAs
Proof - step 1

6
We will convert any context-free grammar
to an NPDA automaton
Such that
Simulates leftmost derivations of
7
Leftmost derivation
Input processed
Stack contents
leftmost variable
Stack
Simulation of derivation
Input
8
Leftmost derivation
string of terminals
Stack
Simulation of derivation
Input
end of input is reached
9
An example grammar
What is an equivalent NPDA?
10
Grammar
NPDA
11
Grammar
A leftmost derivation
12
Derivation
Input
Time 0
Stack
13
Derivation
Input
Time 0
Stack
14
Derivation
Input
Time 1
Stack
15
Derivation
Input
Time 2
Stack
16
Derivation
Input
Time 3
Stack
17
Derivation
Input
Time 4
Stack
18
Derivation
Input
Time 5
Stack
19
Derivation
Input
Time 6
Stack
20
Derivation
Input
Time 7
Stack
21
Derivation
Input
Time 8
Stack
22
Derivation
Input
Time 9
Stack
accept
23
In general
Given any grammar
We can construct a NPDA
With
24
Constructing NPDA from grammar
For any terminal
For any production
25
Grammar generates string
if and only if
NPDA accepts
26
Therefore
For any context-free language there is a
NPDA that accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
27
Converting NPDAstoContext-Free Grammars
Proof - step 2

28
For any NPDA
we will construct a context-free grammar
with
29
Intuition
The grammar simulates the computation of the
machine
A derivation in Grammar
terminals
variables
Input processed
Stack contents
Current configuration in NPDA
30
Some 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)

31
Example of a NPDA in correct form
32
The Grammar Construction
In grammar
Stack symbol
Variables
states
Terminals Input symbols of NPDA
33
For each transition
We add production
34
For each transition
We add productions
For all possible states in the automaton
35
Stack bottom symbol
Start Variable
Start state
final state
36
Example
Grammar production
37
Example
Grammar productions
38
Example
Grammar production
39
Resulting Grammar
40
(No Transcript)
41
Derivation of string
42
In 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
43
Therefore
if and only if
is accepted by the NPDA
44
Therefore
For any NPDA there is a context-free grammar that
accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
45
Deterministic PDADPDA

46
Deterministic PDA DPDA
Allowed transitions
(deterministic choices)
47
Allowed transitions
(deterministic choices)
48
Not allowed
(non deterministic choices)
49
DPDA example
50
The language
is deterministic context-free
51
Definition
A language is deterministic context-free if
there exists some DPDA that accepts it
52
Example of Non-DPDA (NPDA)
53
Not allowed in DPDAs
54
NPDAs Have More Power thanDPDAs

55
It holds that
Deterministic Context-Free Languages (DPDA)
Context-Free Languages NPDAs
Since every DPDA is also a NPDA
56
We will actually show
Deterministic Context-Free Languages (DPDA)
Context-Free Languages (NPDA)
57
The language is
We will show
  • is context-free
  • is not deterministic context-free

58
Language is context-free
59
Theorem
The language
is not deterministic context-free
(there is no DPDA that accepts )
60
Proof
Assume for contradiction that
is deterministic context free
Therefore
there is a DPDA that accepts
61
DPDA with
accepts
accepts
62
DPDA with
Such a path exists because of the determinism
63
Fact 1
The language is not
context-free
(we will prove this at a later class
using pumping lemma for context-free languages)
64
Fact 2
The language is not
context-free
(we can prove this using pumping lemma for
context-free languages)
65
We will construct a NPDA that accepts
which is a contradiction!
66
Replace with
Modify
67
The NPDA that accepts
Connect final states of with final states
of
68
Since is accepted by a
NPDA
it is context-free
Contradiction!
(since is not
context-free)
69
Therefore
Not deterministic context free
There is no DPDA that accepts
End of Proof
Write a Comment
User Comments (0)
About PowerShow.com