12 - 12: PA CFG Theorem 1 If a language is context-free,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
12: PA CFG Theorem 1 If a language is context-free, then it is accepted by a PA. The proof is a constructive proof. We Frst sketch the idea. We construct a PA from the given C±G as follows: 1. Push the start nonterminal of the C±G onto the stack 2. Repeat the following steps: (a) If the top of the stack is a nonterminal, say A , nonde- terministically select one of the rules for A , and replace A in the stack by the string on the right hand side of the rule (recall: leftmost symbol in the string ends up topmost in the stack). (b) If the top of the stack is a terminal symbol, say a ,read the next symbol from the input and compare it with a . If they match, repeat step (2). If not, reject this branch of non-determinism. Recall: a string is accepted by a PA i² there exists a compu- tation sequence such that when the entire input string is read, the PA is in a Fnal state and the stack is empty. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PA CFG Proof : Given a CFG G =( V, Σ ,R,S ). Construct the following PA M that accepts L ( G ). M =( { p,q } , Σ ,V, Δ ,p, { q } ) where Δ contains the follow- ing transitions: 1. (( p,e,e ) , ( q,S )) 2. (( q,e,A ) , ( q,x )) for each rule A x in R 3. (( q,a,a ) , ( q,e )) for each a Σ p q e, e -> S e, A -> x a, a -> e 2
Background image of page 2
The transitions of M are designed such that what is stored in the stack in fact mimics a leftmost derivation of the in-
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/22/2011 for the course COMP 272 taught by Professor Prof.tai during the Spring '10 term at HKUST.

Page1 / 11

12 - 12: PA CFG Theorem 1 If a language is context-free,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online