CSCI 2670 Introduction to Theory of Computing September 16, 2004.

Slides:



Advertisements
Similar presentations
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
Advertisements

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CSCI 2670 Introduction to Theory of Computing September 15, 2004.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
CS5371 Theory of Computation
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
CONVERTING TO CHOMSKY NORMAL FORM
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
CSCI 2670 Introduction to Theory of Computing August 24, 2005.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Grammars CPSC 5135.
Context-free Languages
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
CS 3240: Languages and Computation Context-Free Languages.
CS 461 – Sept. 19 Last word on finite automata… –Scanning tokens in a compiler –How do we implement a “state” ? Chapter 2 introduces the 2 nd model of.
Complexity and Computability Theory I Lecture #9 Instructor: Rina Zviel-Girshin Lea Epstein.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
Context-Free Grammars: an overview
CSE 105 theory of computation
Context-free Languages
CHAPTER 2 Context-Free Languages
Context-Free Grammars
Context-Free Languages
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Context-Free Grammars
CSE 105 theory of computation
Presentation transcript:

CSCI 2670 Introduction to Theory of Computing September 16, 2004

Agenda Yesterday –Prove the pumping lemma –Introduce context-free grammars Today –Quiz –Formally define CFG’s –Build CFG’s

Announcement The solution to 1.16a on the website is incorrect. I will fix it today.

Example S  (S) | SS | () (()())(()) S  SS  (S)(S)  (SS)(())  (()())(()) This sequence of substitutions is called a derivation

Parse tree S  (S) | SS | () S SS SS () S )( S ()

Context-free grammar definition A context-free grammar is a 4-tuple (V, ,R,S), where 1.V is a finite set called the variables, 2.  is a finite set, disjoint from V, called the terminals, 3.R is a finite set of rules, with each rule being a variable and a string of variables and terminals, and 4.S  V is the start variable.

More definitions If u, v, and w are strings of variables and terminals, and A  w is a rule of the grammar, we say uAv yields uwv –Denoted uAv  uwv

More definitions If a sequence of rules leads from u to v – i.e., u  u 1  u 2  …  v, we denote this u  * v (I can’t do the actual notation in powerpoint – the * should be over the double bars) The language of the grammar is {w   * | s  * w}

Example A  Ab | Bb B  aBb | ab V = {A,B}  = {a,b} R is the set of rules listed above S = A The language of this grammar is {w  {a,b} * | w = a n b m, m > n > 0}

Designing CFG’s Requires creativity Write a CFG to accept the language {0 n 1 n | n = 0, 1, 2, …} Write a CFG for operators +, -, and () over the symbols x, y, and z

Construction 1 {w = 0 n 1 n | n = 0, 1, 2, … } S  0S1 | ε

Construction 2 CFG for operators +, -, and () over the symbols x, y, and z S  S + S | S – S | (S) | x | y | z

Designing the union of two CFG’s Design each CFG separately with starting variables S 1, S 2, …, S k and combine using the rule S  S 1 | S 2 | … | S k What is the CFG for the following language { w|w = a n b m, m > n > 0}  {w|w = b n a m, m > n > 0}

Example First design {a n b m, m > n > 0} S 1  S 1 b | Ab A  aAb | ab Then design {b n a m, m > n > 0} –(use different variables) S 2  S 2 a | Ba B  bBa | ba Finally, add the “unifying” rule S  S 1 | S 2

Converting DFA’s into CFG’s For each state q i in the DFA, make a variable R i for your CFG. For each transition rule  (q i,a)=q k in your DFA, add the rule R i  aR k to your CFG For each accept state q a in your DFA, add the rule R a  ε If q 0 is the start state in your DFA, then R 0 is the starting variable in your CFG

Linked terminals Terminals may be “linked” to one another in that they have the same number of occurrences (or a related number) –{0 n 1 n }, {a n b m |m>n>0}, {x n y 2n } Add terminals simultaneously –S  0S1 | ε –S  xSyy | ε

Recursive behavior Some languages may be built of pieces that are within the language –(()())(()) For these languages, you will want a recursive rule –S  SS Not all recursive rules will be that easy!

Example Construct a CFG accepting all strings in {0,1} * that have equal numbers of 0’s and 1’s S  S0S1S | S1S0S | ε

Ambiguity Consider the CFG ({S},{0,1},R,S), where the rules of R are S  0 | 1 | S + S | S * S Derive the string 0 * 1 + 1

Ambiguity S  0 | 1 | S + S | S * S 0 * S SS* S+S 0 11 S SS+ S*S 1 01 Different parse trees!

Next week Chomsky normal form for CFG’s Pushdown automata Non-context-free languages –Pumping lemma for CFG’s