PDAs Accept ContextFree Languages Prof Busch LSU 1
PDAs Accept Context-Free Languages Prof. Busch - LSU 1
Theorem: Context-Free Languages (Grammars) Languages Accepted by PDAs Prof. Busch - LSU 2
Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with: Prof. Busch - LSU 3
Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA grammar with: to a context-free Prof. Busch - LSU 4
Proof - step 1 Convert Context-Free Grammars to PDAs Prof. Busch - LSU 5
Take an arbitrary context-free grammar We will convert to a PDA Prof. Busch - LSU such that: 6
Conversion Procedure: For each production in For each terminal in Add transitions Prof. Busch - LSU 7
Grammar Example PDA Prof. Busch - LSU 8
Example: Input Time 0 Stack Prof. Busch - LSU 9
Derivation: Input Time 1 Stack Prof. Busch - LSU 10
Derivation: Input Time 2 Stack Prof. Busch - LSU 11
Derivation: Input Time 3 Stack Prof. Busch - LSU 12
Derivation: Input Time 4 Stack Prof. Busch - LSU 13
Derivation: Input Time 5 Stack Prof. Busch - LSU 14
Derivation: Input Time 6 Stack Prof. Busch - LSU 15
Derivation: Input Time 7 Stack Prof. Busch - LSU 16
Derivation: Input Time 8 Stack Prof. Busch - LSU 17
Derivation: Input Time 9 Stack Prof. Busch - LSU 18
Derivation: Input Time 10 Stack accept Prof. Busch - LSU 19
Proof - step 2 Convert PDAs to Context-Free Grammars Prof. Busch - LSU 20
For any NPDA we will construct a context-free grammar Courtesy Costas Busch - RPI with 21
Intuition: The grammar simulates the machine A derivation in Grammar terminals Input processed : variables Stack contents Current configuration in NPDA Courtesy Costas Busch - RPI 22
From NPDA to CFG • Lets look at how a PDA can consume • and empty the stack. • We shall define a grammar with variables of the • form [pi-1 Yi pi] that would represent going from pi-1 to pi with the net effect of popping Yi. Courtesy Costas Busch - RPI 23
To generate all those strings w that cause P to pop Z 0 from its stack while going from q 0 to p. 24
Courtesy Costas Busch - RPI 25
26
27
28
Some Necessary Modifications Modify (if necessary) the NPDA (accepting by reaching final state) so that: 1) The stack is never empty 2) It has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form Courtesy Costas Busch - RPI 29
1) Modify the NPDA so that the stack is never empty Stack OK OK Courtesy Costas Busch - RPI NOT OK 30
Introduce the new symbol the bottom of the stack Courtesy Costas Busch - RPI to denote 31
At the beginning push into the stack Original NPDA new initial state original initial state Courtesy Costas Busch - RPI 32
In transitions: replace every instance of with Example: Courtesy Costas Busch - RPI 33
Convert all transitions so that: if the automaton attempts to pop or replace it will halt Courtesy Costas Busch - RPI 34
Convert transitions as follows: l, $ ® $ halting state Courtesy Costas Busch - RPI 35
2) Modify the NPDA so that it empties the stack and has a unique final state Empty the stack NPDA l, l ® l , l Old final states Courtesy Costas Busch - RPI 36
3) modify the NPDA so that transitions have the following forms: OR Courtesy Costas Busch - RPI 37
Convert: Courtesy Costas Busch - RPI 38
Convert: symbols Courtesy Costas Busch - RPI 39
Convert: symbols Convert recursively Courtesy Costas Busch - RPI 40
Example of a NPDA in correct form: Courtesy Costas Busch - RPI 41
The Grammar Construction In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Courtesy Costas Busch - RPI 42
For each transition We add production Courtesy Costas Busch - RPI 43
For each transition We add productions For all possible states in the automaton Courtesy Costas Busch - RPI 44
Stack bottom symbol Start Variable: Start state Courtesy Costas Busch - RPI final state 45
Example: Grammar production: Courtesy Costas Busch - RPI 46
Example: Grammar productions: Courtesy Costas Busch - RPI 47
Example: Grammar production: Courtesy Costas Busch - RPI 48
Resulting Grammar: Courtesy Costas Busch - RPI 49
Courtesy Costas Busch - RPI 50
Derivation of string Courtesy Costas Busch - RPI 51
In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack Courtesy Costas Busch - RPI 52
Therefore: if and only if is accepted by the NPDA Courtesy Costas Busch - RPI 53
Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs Courtesy Costas Busch - RPI 54
- Slides: 54