Title: NPDAs continued
1 NPDAs continued
2Pushing Strings
Pop symbol
Input symbol
Push string
3Example
input
pushed string
stack
top
Push
4Another NPDA example
NPDA
5Execution Example
Time 0
Input
Stack
current state
6Time 1
Input
Stack
7Time 3
Input
Stack
8Time 4
Input
Stack
9Time 5
Input
Stack
10Time 6
Input
Stack
11Time 7
Input
Stack
12Time 8
Input
Stack
accept
13Formalities for NPDAs
14Transition function
15Transition function
16Formal Definition
Non-Deterministic Pushdown Automaton
NPDA
Final states
States
Input alphabet
Stack start symbol
Transition function
Initial state
Stack alphabet
17Instantaneous Description
Current state
Current stack contents
Remaining input
18Example
Instantaneous Description
Input
Time 4
Stack
19Example
Instantaneous Description
Input
Time 5
Stack
20We write
Time 4
Time 5
21A computation
22For convenience we write
23Formal Definition
Language of NPDA
Initial state
Final state
24Example
NPDA
25NPDA
26Therefore
NPDA
27NPDAs Accept Context-Free Languages
28Theorem
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
29Proof - Step 1
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any context-free grammar to a NPDA
with
30Proof - Step 2
Context-Free Languages (Grammars)
Languages Accepted by NPDAs
Convert any NPDA to a context-free
grammar with
31Converting Context-Free Grammarsto NPDAs
32An example grammar
What is the equivalent NPDA?
33Grammar
NPDA
34The NPDA simulates leftmost derivations of the
grammar
L(Grammar) L(NPDA)
35Grammar
A leftmost derivation
36NPDA execution
Time 0
Input
Stack
current state
37Time 1
Input
Stack
38Time 2
Input
Stack
39Time 3
Input
Stack
40Time 4
Input
Stack
41Time 5
Input
Stack
42Time 6
Input
Stack
43Time 7
Input
Stack
44Time 8
Input
Stack
45Time 9
Input
Stack
46Time 10
Input
Stack
accept
47In general
Given any grammar
We can construct a NPDA
With
48Constructing NPDA from grammar
For any production
For any terminal
49Grammar generates string
if and only if
NPDA accepts
50Therefore
For any context-free language there is an
NPDA that accepts the same language
51Converting NPDAstoContext-Free Grammars
52For any NPDA
we will construct a context-free grammar
with
53Intuition
The grammar simulates the machine
A derivation in Grammar
Current configuration in NPDA
54A derivation in Grammar
terminals
variables
Input processed
Stack contents
in NPDA
55Some 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
56Second, we modify the NPDA transitions all
transitions will have form
or
57Example of a NPDA in correct form
58The Grammar Construction
In grammar
Stack symbol
Variables
states
Terminals Input symbols of NPDA
59For each transition
We add production
60For each transition
We add production
For all states
61Stack bottom symbol
Start Variable
Start state
final state
62Example
Grammar production
63Example
Grammar productions
64Example
Grammar production
65Resulting Grammar
66(No Transcript)
67Derivation of string
68In general, in Grammar
if and only if
is accepted by the NPDA
69Explanation
By construction of Grammar
if and only if
in the NPDA going from to the stack
doesnt change below and is removed from
stack