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