Download presentation
Presentation is loading. Please wait.
Published byBrett Stevenson Modified over 9 years ago
1
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages
2
Fall 2006Costas Busch - RPI2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
3
Fall 2006Costas Busch - RPI3 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 1: Convert any context-free grammar to a PDA with:
4
Fall 2006Costas Busch - RPI4 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 2: Convert any PDA to a context-free grammar with:
5
Fall 2006Costas Busch - RPI5 Convert Context-Free Grammars to PDAs Proof - step 1
6
Fall 2006Costas Busch - RPI6 We will convert to a PDA such that: Take an arbitrary context-free grammar
7
Fall 2006Costas Busch - RPI7 production in terminal in Conversion Procedure: For each Add transitions
8
Fall 2006Costas Busch - RPI8 Grammar PDA Example
9
Fall 2006Costas Busch - RPI9 PDA simulates leftmost derivations Grammar Leftmost Derivation PDA Computation Scanned symbols Stack contents
10
Fall 2006Costas Busch - RPI10 Grammar Leftmost Derivation Production applied Terminals Leftmost variable Variables or terminals Terminals Variable Variables or terminals
11
Fall 2006Costas Busch - RPI11 Grammar Leftmost Derivation PDA Computation Production appliedTransition applied
12
Fall 2006Costas Busch - RPI12 Grammar Leftmost Derivation PDA Computation Transition applied Read from input and remove it from stack
13
Fall 2006Costas Busch - RPI13 Grammar Leftmost Derivation PDA Computation Last Transition applied All symbols have been removed from top of stack
14
Fall 2006Costas Busch - RPI14 Production applied The process repeats with the next leftmost variable And so on……
15
Fall 2006Costas Busch - RPI15 Input Stack Time 0 Example:
16
Fall 2006Costas Busch - RPI16 Input Stack Time 1 Derivation:
17
Fall 2006Costas Busch - RPI17 Input Stack Time 2 Derivation:
18
Fall 2006Costas Busch - RPI18 Input Stack Time 3 Derivation:
19
Fall 2006Costas Busch - RPI19 Input Stack Time 4 Derivation:
20
Fall 2006Costas Busch - RPI20 Input Stack Time 5 Derivation:
21
Fall 2006Costas Busch - RPI21 Input Stack Time 6 Derivation:
22
Fall 2006Costas Busch - RPI22 Input Stack Time 7 Derivation:
23
Fall 2006Costas Busch - RPI23 Input Stack Time 8 Derivation:
24
Fall 2006Costas Busch - RPI24 Input Stack Time 9 Derivation:
25
Fall 2006Costas Busch - RPI25 Input Stack accept Time 10 Derivation:
26
Fall 2006Costas Busch - RPI26 Grammar Leftmost Derivation PDA Computation
27
Fall 2006Costas Busch - RPI27 Grammar generates string PDA accepts In general, it can be shown that: If and Only if Therefore
28
Fall 2006Costas Busch - RPI28 Convert PDAs to Context-Free Grammars Proof - step 2
29
Fall 2006Costas Busch - RPI29 We will convert to a context-free grammar such that: Take an arbitrary PDA
30
Fall 2006Costas Busch - RPI30 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 # 2. Use new initial stack symbol #
31
Fall 2006Costas Busch - RPI31 PDA , , , Old accept states New accept state 1. The PDA has a single accept state PDA
32
Fall 2006Costas Busch - RPI32 PDA 2. Use new initial stack symbol # new initial stack symbol old initial stack symbol Top of stack still thinks that Z is the initial stack PDA auxiliary stack symbol
33
Fall 2006Costas Busch - RPI33 Empty stack New accept state PDA Old accept state PDA 3. On acceptance the stack contains only stack symbol #
34
Fall 2006Costas Busch - RPI34 4. Each transition either pushes a symbol or pops a symbol but not both together PDA
35
Fall 2006Costas Busch - RPI35 PDA Where is a symbol of the stack alphabet
36
Fall 2006Costas Busch - RPI36 PDA is the final modified PDA Note that the new initial stack symbol # is never used in any transition
37
Fall 2006Costas Busch - RPI37 Example:
38
Fall 2006Costas Busch - RPI38 Grammar Construction Variables: States of PDA
39
Fall 2006Costas Busch - RPI39 PDA Grammar Kind 1: for each state
40
Fall 2006Costas Busch - RPI40 PDA Grammar Kind 2: for every three states
41
Fall 2006Costas Busch - RPI41 PDA Grammar Kind 3: for every pair of such transitions
42
Fall 2006Costas Busch - RPI42 PDA Grammar Initial stateAccept state Start variable
43
Fall 2006Costas Busch - RPI43 Example: PDA
44
Fall 2006Costas Busch - RPI44 Grammar Kind 1: from single states
45
Fall 2006Costas Busch - RPI45 Start variable Kind 2: from triplets of states
46
Fall 2006Costas Busch - RPI46 Kind 3: from pairs of transitions
47
Fall 2006Costas Busch - RPI47 We need to prove that Suppose that a PDA is converted to a context-free grammar or equivalently
48
Fall 2006Costas Busch - RPI48 We need to show that if has derivation: Then there is an accepting computation in : (string of terminals) with input string
49
Fall 2006Costas Busch - RPI49 We will actually show that if has derivation: Then there is a computation in :
50
Fall 2006Costas Busch - RPI50 Therefore: Since there is no transition with the # symbol
51
Fall 2006Costas Busch - RPI51 Lemma: If (string of terminals) then there is a computation from state to state on string which leaves the stack empty:
52
Fall 2006Costas Busch - RPI52 Proof Intuition: Case 1: Case 2: Type 2 Type 3
53
Fall 2006Costas Busch - RPI53 Case 1: Type 2 Stack height Input string Generated by
54
Fall 2006Costas Busch - RPI54 Stack height Input string Generated by Case 2: Type 3
55
Fall 2006Costas Busch - RPI55 We formally prove this claim by induction on the number of steps in derivation: Formal Proof: number of steps
56
Fall 2006Costas Busch - RPI56 Induction Basis: (one derivation step) A Kind 1 production must have been used: Therefore, and This computation of PDA trivially exists:
57
Fall 2006Costas Busch - RPI57 Induction Hypothesis: derivation steps suppose it holds:
58
Fall 2006Costas Busch - RPI58 Induction Step: derivation steps We have to show:
59
Fall 2006Costas Busch - RPI59 derivation steps Case 1: Case 2: Type 2 Type 3
60
Fall 2006Costas Busch - RPI60 Case 1: Type 2 We can write At most steps steps
61
Fall 2006Costas Busch - RPI61 At most steps From induction hypothesis, in PDA: From induction hypothesis, in PDA:
62
Fall 2006Costas Busch - RPI62 since
63
Fall 2006Costas Busch - RPI63 Case 2: Type 3 We can write At most steps steps
64
Fall 2006Costas Busch - RPI64 At most steps From induction hypothesis, the PDA has computation:
65
Fall 2006Costas Busch - RPI65 And PDA Contains transitions Type 3 Grammar contains production
66
Fall 2006Costas Busch - RPI66
67
Fall 2006Costas Busch - RPI67 We know We also know Therefore:
68
Fall 2006Costas Busch - RPI68 since END OF PROOF
69
Fall 2006Costas Busch - RPI69 So far we have shown: With a similar proof we can show Therefore:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.