270 likes | 276 Views
Explore context-free grammars, parse trees, and languages generated by grammars. Learn about pumping lemma, regularity, and proofs of language regularity. Derive insights into adversarial games and pumping lemma applications.
E N D
Lecture 14Grammars CSCE 355 Foundations of Computation Topics: • Context Free Grammars • Parses, derivations, parse trees • Language generated by a grammar October 15, 2008
Last Time: • Examples of Sets of indistinguishable prefixes • Pumping Lemma • If L is regular is the Reversal LR regular? • Review: Proofs Languages are not Regular • Sets of distinguishable prefixes • Pumping Lemma • Languages Regular or Not • {0n1m | n > 100, m < 100}, {0m | m = k2 }, {ww | w in {a,b}* }, {w in {a,b}* | w viewed as binary is divisible by 7} New: • Adversarial game revisited • Regular or not • Grammars: definitions, derivations, parse trees, languages generated by grammars, L(G) Homework • Sets of indistinguishable • Pumping lemma • Derivations
Pumping Lemma as Adversarial Game • You pick the language L to be proved nonregular. • Opponent picks n, but does not reveal it. • You carefully pick w, which may depend on n and |w| ≥ n • Opponent divides w into x, y and z, with |y| > 0, |xy| ≤ n • You “win’ by picking k, which may be a function of n, x, y and z such that xykz is not in L.
Pumping Lemma Examples from the Web • http://www.seas.upenn.edu/~cit596/notes/dave/pumping0.html • {anbn: n 0}, {anbk: n > k and n 0}, {an: n is a prime number} • xxx
Regular or Not? • {w in {0,1}* | w has equal number of zeroes and ones} • {w in {0,1}* | w has even length}
Chapter 5 Grammars Grammar for Palindromes P ε P 0 P 1 P 0 P 0 P 1 P 1 is interpreted as “may be rewritten as”.
Definitions G = (N, T, P, S) • G = (N, T, P, S) • N = set of nonterminal symbols (text call these variables) • T = set of terminals (or sometime tokens) • S = start symbol (a nonterminal) • P = a set of Productions, rewrite rules of the form • X α1 α2 …αn-1 αn • Where X εN and each αi is from N U T
Notational Shorthand • Typically just list productions • For all productions with same LHS use ‘|’ to separate RHS’s • Nonterminals? • Terminals? • Start Symbol? P ε | 0 | 1 | 0 P 0 | 1 P 1
Further Notational Assumptions • G • a, b, c,… • A,B, … X, Y, Z • α,β,µ,γ,δ,ζ,θ • ε and sometimes λ • x
Derives Relation • Given a Grammar G. If α and βare strings of grammar symbols then we can define the “derives” relation as • α β, if α = α1Xα2 and β = α1ξα2 where X ξ is a production in G • α * β derives in zero or more steps • This is the transitive reflexive closure of
Sentential forms • E E+E | E*E | (E) | id • α is a sentential form if