PDAs Accept Context-Free Languages Prof. Busch - LSU
Theorem: Context-Free Languages Languages Accepted by (Grammars) PDAs Prof. Busch - LSU
Convert any context-free grammar to a PDA with: Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with: Prof. Busch - LSU
Convert any PDA to a context-free grammar with: Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with: Prof. Busch - LSU
Convert Context-Free Grammars to PDAs Proof - step 1 Convert Context-Free Grammars to PDAs Prof. Busch - LSU
Take an arbitrary context-free grammar We will convert to a PDA such that: Prof. Busch - LSU
Conversion Procedure: For each For each production in terminal in Add transitions Prof. Busch - LSU
Example Grammar PDA Prof. Busch - LSU
Example: Input Time 0 Stack Prof. Busch - LSU
Derivation: Input Time 1 Stack Prof. Busch - LSU
Derivation: Input Time 2 Stack Prof. Busch - LSU
Derivation: Input Time 3 Stack Prof. Busch - LSU
Derivation: Input Time 4 Stack Prof. Busch - LSU
Derivation: Input Time 5 Stack Prof. Busch - LSU
Derivation: Input Time 6 Stack Prof. Busch - LSU
Derivation: Input Time 7 Stack Prof. Busch - LSU
Derivation: Input Time 8 Stack Prof. Busch - LSU
Derivation: Input Time 9 Stack Prof. Busch - LSU
Derivation: Input Time 10 Stack accept Prof. Busch - LSU
Convert PDAs to Context-Free Grammars Proof - step 2 Convert PDAs to Context-Free Grammars Prof. Busch - LSU
Courtesy Costas Busch - RPI For any NPDA we will construct a context-free grammar with Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Intuition: The grammar simulates the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI 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
To generate all those strings w that cause P to pop Z0 from its stack while going from q0 to p.
Courtesy Costas Busch - RPI
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
Courtesy Costas Busch - RPI Modify the NPDA so that the stack is never empty Stack OK OK NOT OK Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Introduce the new symbol to denote the bottom of the stack Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI At the beginning push into the stack Original NPDA new initial state original initial state Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI In transitions: replace every instance of with Example: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Convert all transitions so that: if the automaton attempts to pop or replace it will halt Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Convert transitions as follows: $ ® , l halting state Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI 2) Modify the NPDA so that it empties the stack and has a unique final state Empty the stack NPDA l ® , l ® , l ® , Old final states Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI 3) modify the NPDA so that transitions have the following forms: OR Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Convert: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Convert: symbols Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Convert: symbols Convert recursively Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Example of a NPDA in correct form: Courtesy Costas Busch - RPI
The Grammar Construction In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI For each transition We add production Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI For each transition We add productions For all possible states in the automaton Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Stack bottom symbol Start Variable: Start state final state Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Example: Grammar production: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Example: Grammar productions: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Example: Grammar production: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Resulting Grammar: Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI Derivation of string Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI 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
Courtesy Costas Busch - RPI Therefore: if and only if is accepted by the NPDA Courtesy Costas Busch - RPI
Courtesy Costas Busch - RPI 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