Download presentation
Presentation is loading. Please wait.
Published byFerdinand Hunter Modified over 8 years ago
1
Costas Busch - LSU1 PDAs Accept Context-Free Languages
2
Costas Busch - LSU2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
3
Costas Busch - LSU3 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 1: Convert any context-free grammar to a PDA with:
4
Costas Busch - LSU4 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 2: Convert any PDA to a context-free grammar with:
5
Costas Busch - LSU5 Convert Context-Free Grammars to PDAs Proof - step 1
6
Costas Busch - LSU6 We will convert to a PDA such that: Take an arbitrary context-free grammar
7
Costas Busch - LSU7 production in terminal in Conversion Procedure: For each Add transitions
8
Costas Busch - LSU8 Grammar PDA Example
9
Costas Busch - LSU9 PDA simulates leftmost derivations Grammar Leftmost Derivation PDA Computation Scanned symbols Stack contents
10
Costas Busch - LSU10 Grammar Leftmost Derivation Production applied Terminals Leftmost variable Variables or terminals Terminals Variable Variables or terminals
11
Costas Busch - LSU11 Grammar Leftmost Derivation PDA Computation Production appliedTransition applied
12
Costas Busch - LSU12 Grammar Leftmost Derivation PDA Computation Transition applied Read from input and remove it from stack
13
Costas Busch - LSU13 Grammar Leftmost Derivation PDA Computation Last Transition applied All symbols have been removed from top of stack
14
Costas Busch - LSU14 Production applied The process repeats with the next leftmost variable And so on……
15
Costas Busch - LSU15 Input Stack Time 0 Example:
16
Costas Busch - LSU16 Input Stack Time 1 Derivation:
17
Costas Busch - LSU17 Input Stack Time 2 Derivation:
18
Costas Busch - LSU18 Input Stack Time 3 Derivation:
19
Costas Busch - LSU19 Input Stack Time 4 Derivation:
20
Costas Busch - LSU20 Input Stack Time 5 Derivation:
21
Costas Busch - LSU21 Input Stack Time 6 Derivation:
22
Costas Busch - LSU22 Input Stack Time 7 Derivation:
23
Costas Busch - LSU23 Input Stack Time 8 Derivation:
24
Costas Busch - LSU24 Input Stack Time 9 Derivation:
25
Costas Busch - LSU25 Input Stack accept Time 10 Derivation:
26
Costas Busch - LSU26 Grammar Leftmost Derivation PDA Computation
27
Costas Busch - LSU27 Grammar generates string PDA accepts In general, it can be shown that: If and Only if Therefore
28
Costas Busch - LSU28 Convert PDAs to Context-Free Grammars Proof - step 2
29
Costas Busch - LSU29 We will convert to a context-free grammar such that: Take an arbitrary PDA
30
Costas Busch - LSU30 First modify PDA so that: 1. The PDA has a single accept state 4. Each transition either pushes a symbol or pops a symbol but not both together 3. On acceptance the stack contains only stack symbol # (this symbol is not used in any transition) 2. Use new initial stack symbol #
31
Costas Busch - LSU31 PDA , , , Old accept states New accept state 1. The PDA has a single accept state PDA
32
Costas Busch - LSU32 PDA 2. Use new initial stack symbol # new initial stack symbol initial stack symbol of M Top of stack still thinks that Z is the initial stack PDA auxiliary stack symbol
33
Costas Busch - LSU33 Empty stack New accept state PDA Old accept state PDA 3. On acceptance the stack contains only stack symbol # (this symbol is not used in any transition)
34
Costas Busch - LSU34 4. Each transition either pushes a symbol or pops a symbol but not both together PDA
35
Costas Busch - LSU35 PDA Where is a symbol of the stack alphabet
36
Costas Busch - LSU36 PDA is the final modified PDA Note that the new initial stack symbol # is never used in any transition
37
Costas Busch - LSU37 Example:
38
Costas Busch - LSU38 Grammar Construction Variables: States of PDA
39
Costas Busch - LSU39 PDA Grammar Kind 1: for each state
40
Costas Busch - LSU40 PDA Grammar Kind 2: for every three states
41
Costas Busch - LSU41 PDA Grammar Kind 3: for every pair of such transitions
42
Costas Busch - LSU42 PDA Grammar Initial stateAccept state Start variable
43
Costas Busch - LSU43 Example: PDA
44
Costas Busch - LSU44 Grammar Kind 1: from single states
45
Costas Busch - LSU45 Start variable Kind 2: from triplets of states
46
Costas Busch - LSU46 Kind 3: from pairs of transitions
47
Costas Busch - LSU47 We need to prove that Suppose that a PDA is converted to a context-free grammar or equivalently
48
Costas Busch - LSU48 We need to show that if has derivation: Then there is an accepting computation in : (string of terminals) with input string
49
Costas Busch - LSU49 We will actually show that if has derivation: Then there is a computation in :
50
Costas Busch - LSU50 Therefore: Since there is no transition with the # symbol
51
Costas Busch - LSU51 Lemma: If (string of terminals) then there is a computation from state to state on string which leaves the stack empty:
52
Costas Busch - LSU52 Proof Intuition: Case 1: Case 2: Type 2 Type 3
53
Costas Busch - LSU53 Case 1: Type 2 Stack height Input string Generated by
54
Costas Busch - LSU54 Stack height Input string Generated by Case 2: Type 3
55
Costas Busch - LSU55 We formally prove this claim by induction on the number of steps in derivation: Formal Proof: number of steps
56
Costas Busch - LSU56 Induction Basis: (one derivation step) A Kind 1 production must have been used: Therefore, and This computation of PDA trivially exists:
57
Costas Busch - LSU57 Induction Hypothesis: derivation steps suppose it holds:
58
Costas Busch - LSU58 Induction Step: derivation steps We have to show:
59
Costas Busch - LSU59 derivation steps Case 1: Case 2: Type 2 Type 3
60
Costas Busch - LSU60 Case 1: Type 2 We can write At most steps steps
61
Costas Busch - LSU61 At most steps From induction hypothesis, in PDA: From induction hypothesis, in PDA:
62
Costas Busch - LSU62 since
63
Costas Busch - LSU63 Case 2: Type 3 We can write At most steps steps
64
Costas Busch - LSU64 At most steps From induction hypothesis, the PDA has computation:
65
Costas Busch - LSU65 And PDA Contains transitions Type 3 Grammar contains production
66
Costas Busch - LSU66
67
Costas Busch - LSU67 We know We also know Therefore:
68
Costas Busch - LSU68 since END OF PROOF
69
Costas Busch - LSU69 So far we have shown: With a similar proof we can show Therefore:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.