110 likes | 280 Views
Pushdown Automata and Context-Free Grammars. Reading: 7.2 & 7.3. CFG(L) = PDA(L). Any context-free language has a pushdown automata that accepts the language. Any context-free language can be written in Greibach Normal Form. (All productions of the form
E N D
Pushdown Automata and Context-Free Grammars Reading: 7.2 & 7.3
CFG(L) = PDA(L) • Any context-free language has a pushdown automata that accepts the language. • Any context-free language can be written in Greibach Normal Form. (All productions of the form A -> aX where X is a string of variables.)
PDA from Greibach • First, push the start symbol onto the stack. δ(q0,λ,Z) = {(q1,SZ)} • Any productions of the form A->a: δ(q1,a,A) = (q1, λ) • Any productions of the form A->aX: δ(q1,a,A) = {(q1,X)} • Finally, recognize the accept state: δ(q1,λ,Z) = {(q2, λ)}
Example S -> aSA | a A -> bB B -> b Yields: δ(q0,λ,Z) = {(q1,SZ)} δ(q1,a,S) = {(q1, λ), (q1, SA)} δ(q1,b,A) = {(q1, B)} δ(q1,b,B) = {(q1, λ)} δ(q1, λ,Z) = (q2, λ)
Deterministic PDA • At each step, there is no choice for the move: • Every δ(q,a,b) contains at most one element • If δ(q,λ,b) is not empty, then δ(q,c,b) must be empty for every c in the alphabet • Note: Lambda transitions are allowed, but it is always clear when to take them.
Theoretical Results • Every CFG can be written in Greibach • There is an algorithm (in book) to turn PDA into a CFG. • A language accepted by a deterministic pushdown automata is called a deterministic context-free language. • NPDA’s are more powerful than DPDA’s. • Not every context-free language is a deterministic context-free language!