1 PDAs Accept Context-Free Languages
2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
3 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 1: Convert any context-free grammar to a PDA with:
4 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 2: Convert any PDA to a context-free grammar with:
5 Converting Context-Free Grammars to PDAs Proof - step 1
6 Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with:
7 to a PDA such that: We will convert grammar simulates leftmost derivations of
8 Production in Terminal in Convert grammar to PDA
9 Grammar leftmost derivation PDA computation Simulates grammar leftmost derivations Leftmost variable
10 Grammar PDA Example
11 Grammar derivation PDA computation
12 Input Stack Time 0 Derivation:
13 Input Stack Time 0 Derivation:
14 Input Stack Time 1 Derivation:
15 Input Stack Time 2 Derivation:
16 Input Stack Time 3 Derivation:
17 Input Stack Time 4 Derivation:
18 Input Stack Time 5 Derivation:
19 Input Stack Time 6 Derivation:
20 Input Stack Time 7 Derivation:
21 Input Stack Time 8 Derivation:
22 Input Stack accept Time 9 Derivation:
23 Grammar generates string PDA accepts In general, it can be shown that: If and Only if Therefore
24 Therefore: For any context-free language there is a PDA that accepts Context-Free Languages (Grammars) Languages Accepted by PDAs
25 Converting PDAs to Context-Free Grammars Proof - step 2
26 Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with:
27 We will convert PDA to a context-free grammar such that: simulates computations of with leftmost derivations
28 Some Necessary Modifications If necessary, modify the PDA so that: 1. The stack is never empty during computation 2. It has a single accept state and empties the stack when it accepts a string 3. Has transitions without popping
29 1. Modify the PDA so that the stack is never empty during computation Stack OK NOT OK
30 Introduce the new symbol to mark the bottom of the stack
31 Original PDA At the beginning insert into the stack original initial state new initial state
32 # # , halting state Convert all transitions so that after popping the automaton halts pop
33 PDA , Empty stack 2. Modify the PDA so that at end it empties stack and has a unique accept state , , Old accept states New accept state
34 3. Modify the PDA so that it has no transitions popping :
35 Example of a PDA in correct form: (modifications are not necessary)
36 Grammar Construction In grammar : Terminals: PDA stack symbolsVariables: PDA input symbols Start Variable:Stack bottom symbol
37 PDA transition Grammar production
38 PDA transition Grammar production
39 Grammar leftmost derivation PDA computation Leftmost variable
40 Example PDA: Grammar:
41 Grammar Leftmost derivation: PDA Computation:
42 Derivation: Time 0
43 Derivation: Time 1 Stack
44 Derivation: Time 2 Stack
45 Derivation: Time 3 Stack
46 Derivation: Time 4 Stack
47 Derivation: Time 5 Stack empty
48 However, this grammar conversion does not work for all PDAs:
49 Grammar:
50 Grammar: Bad Derivation:
51 The Correct Grammar Construction In grammar : Terminals: Input symbols of PDA PDA states PDA stack symbol Variables:
52 PDA transition Grammar production
53 PDA transition Grammar production For all possible states in PDA
54 Start Variable: Stack bottom symbol Start state accept state
55 Example: Grammar production:
56 Example: Grammar productions:
57 Example: Grammar production:
58 Resulting Grammar:
59
60 Grammar Leftmost derivation PDA computation
61 Derivation: Time 0
62 Derivation: Time 1 Stack
63 Derivation: Time 2 Stack
64 Derivation: Time 3 Stack
65 Derivation: Time 4 Stack
66 Derivation: Time 5 Stack empty
67 In general: If and Only if Grammar PDA
68 Thus: If and Only if Grammar generates PDA accepts
69 Therefore: For any PDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by PDAs