Costas Busch - LSU1 PDAs Accept Context-Free Languages
Costas Busch - LSU2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
Costas Busch - LSU3 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 1: Convert any context-free grammar to a PDA with:
Costas Busch - LSU4 Context-Free Languages (Grammars) Languages Accepted by PDAs Proof - Step 2: Convert any PDA to a context-free grammar with:
Costas Busch - LSU5 Convert Context-Free Grammars to PDAs Proof - step 1
Costas Busch - LSU6 We will convert to a PDA such that: Take an arbitrary context-free grammar
Costas Busch - LSU7 production in terminal in Conversion Procedure: For each Add transitions
Costas Busch - LSU8 Grammar PDA Example
Costas Busch - LSU9 PDA simulates leftmost derivations Grammar Leftmost Derivation PDA Computation Scanned symbols Stack contents
Costas Busch - LSU10 Grammar Leftmost Derivation Production applied Terminals Leftmost variable Variables or terminals Terminals Variable Variables or terminals
Costas Busch - LSU11 Grammar Leftmost Derivation PDA Computation Production appliedTransition applied
Costas Busch - LSU12 Grammar Leftmost Derivation PDA Computation Transition applied Read from input and remove it from stack
Costas Busch - LSU13 Grammar Leftmost Derivation PDA Computation Last Transition applied All symbols have been removed from top of stack
Costas Busch - LSU14 Production applied The process repeats with the next leftmost variable And so on……
Costas Busch - LSU15 Input Stack Time 0 Example:
Costas Busch - LSU16 Input Stack Time 1 Derivation:
Costas Busch - LSU17 Input Stack Time 2 Derivation:
Costas Busch - LSU18 Input Stack Time 3 Derivation:
Costas Busch - LSU19 Input Stack Time 4 Derivation:
Costas Busch - LSU20 Input Stack Time 5 Derivation:
Costas Busch - LSU21 Input Stack Time 6 Derivation:
Costas Busch - LSU22 Input Stack Time 7 Derivation:
Costas Busch - LSU23 Input Stack Time 8 Derivation:
Costas Busch - LSU24 Input Stack Time 9 Derivation:
Costas Busch - LSU25 Input Stack accept Time 10 Derivation:
Costas Busch - LSU26 Grammar Leftmost Derivation PDA Computation
Costas Busch - LSU27 Grammar generates string PDA accepts In general, it can be shown that: If and Only if Therefore
Costas Busch - LSU28 Convert PDAs to Context-Free Grammars Proof - step 2
Costas Busch - LSU29 We will convert to a context-free grammar such that: Take an arbitrary PDA
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 #
Costas Busch - LSU31 PDA , , , Old accept states New accept state 1. The PDA has a single accept state PDA
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
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)
Costas Busch - LSU34 4. Each transition either pushes a symbol or pops a symbol but not both together PDA
Costas Busch - LSU35 PDA Where is a symbol of the stack alphabet
Costas Busch - LSU36 PDA is the final modified PDA Note that the new initial stack symbol # is never used in any transition
Costas Busch - LSU37 Example:
Costas Busch - LSU38 Grammar Construction Variables: States of PDA
Costas Busch - LSU39 PDA Grammar Kind 1: for each state
Costas Busch - LSU40 PDA Grammar Kind 2: for every three states
Costas Busch - LSU41 PDA Grammar Kind 3: for every pair of such transitions
Costas Busch - LSU42 PDA Grammar Initial stateAccept state Start variable
Costas Busch - LSU43 Example: PDA
Costas Busch - LSU44 Grammar Kind 1: from single states
Costas Busch - LSU45 Start variable Kind 2: from triplets of states
Costas Busch - LSU46 Kind 3: from pairs of transitions
Costas Busch - LSU47 We need to prove that Suppose that a PDA is converted to a context-free grammar or equivalently
Costas Busch - LSU48 We need to show that if has derivation: Then there is an accepting computation in : (string of terminals) with input string
Costas Busch - LSU49 We will actually show that if has derivation: Then there is a computation in :
Costas Busch - LSU50 Therefore: Since there is no transition with the # symbol
Costas Busch - LSU51 Lemma: If (string of terminals) then there is a computation from state to state on string which leaves the stack empty:
Costas Busch - LSU52 Proof Intuition: Case 1: Case 2: Type 2 Type 3
Costas Busch - LSU53 Case 1: Type 2 Stack height Input string Generated by
Costas Busch - LSU54 Stack height Input string Generated by Case 2: Type 3
Costas Busch - LSU55 We formally prove this claim by induction on the number of steps in derivation: Formal Proof: number of steps
Costas Busch - LSU56 Induction Basis: (one derivation step) A Kind 1 production must have been used: Therefore, and This computation of PDA trivially exists:
Costas Busch - LSU57 Induction Hypothesis: derivation steps suppose it holds:
Costas Busch - LSU58 Induction Step: derivation steps We have to show:
Costas Busch - LSU59 derivation steps Case 1: Case 2: Type 2 Type 3
Costas Busch - LSU60 Case 1: Type 2 We can write At most steps steps
Costas Busch - LSU61 At most steps From induction hypothesis, in PDA: From induction hypothesis, in PDA:
Costas Busch - LSU62 since
Costas Busch - LSU63 Case 2: Type 3 We can write At most steps steps
Costas Busch - LSU64 At most steps From induction hypothesis, the PDA has computation:
Costas Busch - LSU65 And PDA Contains transitions Type 3 Grammar contains production
Costas Busch - LSU66
Costas Busch - LSU67 We know We also know Therefore:
Costas Busch - LSU68 since END OF PROOF
Costas Busch - LSU69 So far we have shown: With a similar proof we can show Therefore: