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