1 / 27

Understanding Context-Free Grammars in Computation

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.

jwhitworth
Download Presentation

Understanding Context-Free Grammars in Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 14Grammars CSCE 355 Foundations of Computation Topics: • Context Free Grammars • Parses, derivations, parse trees • Language generated by a grammar October 15, 2008

  2. 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

  3. 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.

  4. 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

  5. Regular or Not? • {w in {0,1}* | w has equal number of zeroes and ones} • {w in {0,1}* | w has even length}

  6. 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”.

  7. 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

  8. 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

  9. Further Notational Assumptions • G • a, b, c,… • A,B, … X, Y, Z • α,β,µ,γ,δ,ζ,θ • ε and sometimes λ • x

  10. 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 

  11. Sentential forms • E  E+E | E*E | (E) | id • α is a sentential form if

  12. Parse Trees

  13. Language Generated by a Grammar

  14. Grammar for Expressions

More Related