1 Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday) 2. Covert the following context-free.

Slides:



Advertisements
Similar presentations
4.5 Inherently Ambiguous Context-free Language For some context-free languages, such as arithmetic expressions, may have many different CFG’s to generate.
Advertisements

1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
Simplifying CFGs There are several ways in which context-free grammars can be simplified. One natural way is to eliminate useless symbols those that cannot.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 1. Show the result of each of the following set operations in terms of set property. Write your sets as simple as possible. (a) L 0  L 4 (b) L 0  L.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
Slide 1 Chapter 2-b Syntax, Semantics. Slide 2 Syntax, Semantics - Definition The syntax of a programming language is the form of its expressions, statements.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.
Key to Homework #2 1. What is the language of L-system G = ({a, b, c}, h, acb ), where the rewriting rule h is defined as follows: h (a) = aa h (b) = cb.
Normal forms for Context-Free Grammars
How to Convert a Context-Free Grammar to Greibach Normal Form
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Finite State Machines Data Structures and Algorithms for Information Processing 1.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
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.
Normal Forms for Context-Free Grammars Definition: A symbol X in V  T is useless in a CFG G=(V, T, P, S) if there does not exist a derivation of the form.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
Grammars CPSC 5135.
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Complexity and Computability Theory I Lecture #9 Instructor: Rina Zviel-Girshin Lea Epstein.
Section 12.4 Context-Free Language Topics
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
LESSON 04.
1 1. Let A ={r, p, i } and B = { w, o, r, l, d }. What does each of the following (a), (b) and (c) denote? Briefly explain in plain English. (a) A * B.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
Re-enter Chomsky More about grammars. 2 Parse trees S  A B A  aA | a B  bB | b Consider L = { a m b n | m, n > 0 } (one/more a ’s followed by one/more.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
1 Chapter 6 Simplification of CFGs and Normal Forms.
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.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Syntax Analyzer (Parser)
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
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.
Exercises on Chomsky Normal Form and CYK parsing
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Key to Homework #3 (Models of Computation, Spring, 2001) Finite state control with a 4-way read/write head Figure (a)Figure (b) (over)
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
20 G M aaba acba aaba.. What is it about? Models of Language Generation Models of Language Recognition.
Closed book, closed notes
Regular Grammar.
CHAPTER 2 Context-Free Languages
Midterm (Models of Computation, Fall, 2000)
Homework #5 (Models of Computation, Spring, 2001) Due: Section 1; February 27 Section 2; February 28 ** Please put your homework in the collection.
Key Answers for Homework #7
Presentation transcript:

1 Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday) 2. Covert the following context-free grammar into a Chomsky Normal Form. S  abABCde A  aAa B  ba C  cab G: S  BA | CDg B  aEA A  DEd C  Ce D  Df |  E  Eg | g F  hF | h G  cGCc I  cDEFab 1. This problem is to clean up context-free grammar G shown below. Using the two algorithms presented in the class, we are going to eliminate all useless symbols from the following context-free grammar G. Answer the following two questions. (a) Using the algorithm in Lemma 1 for grammar G construct a context-free grammar G’ such that L(G) = L(G’) and every nonterminal symbol in G’ derives a string x  (V T ) *, where V T is set of terminal symbols of G. (b) Using the algorithm in Lemma 2 for grammar G’, the result of part (a), and construct a context-free grammar G’’ such that L(G) = L(G’’), and for each symbol X (which is either terminal or nonterminal symbol) in G’’, starting with the start symbol, it is possible to derive a string containing X. Your answer should include detailed procedure (steps of the algorithm) that you took to collect the information needed to get your answer. No grade will be given to an answer that only shows the final result. ** Notice that this homework has 7 problems.

2 3. (a) Show that the following grammar is ambiguous. S  S + S | S * S | T T  a | b (b) Let + be the addition and * be the multiplication. Then the above grammar generates mathematical expressions with the two operators on two variable a and b. Convert the above grammar to an unambiguous context-free grammar such that it generates the same language and * has higher precedence than +. (c) Convert the above grammar to an unambiguous context-free grammar such that - it generates the same language, - the two operators * and + have the same precedence, and - the evaluation is done right to left. 4. The following syntax flow graph is a simplified definition of the Pascal’s syntax flow graph for. Assume that all the strings in a circle are terminal symbols. (a) Convert this syntax flow graph for to a context-free grammar that generate the same language, and show that the grammar is ambiguous. (b) Convert your grammar to an unambiguous grammar that generates the same if statements. You should briefly describe your idea. IF( ) then else c d a + b a - b

3 5. Using the pumping lemma we want to prove that language L = {xx R | x  {a, b, c} * } is not regular as follows. Complete the proof by answering the questions. Proof. Suppose that L is regular. Then L should satisfy the pumping lemma. Let n be the constant of the lemma. Clearly, all the following strings belong to L. (a) abccba (b) a 100 b 100 b 100 a 100 (c ) a n/2 b n/2 b n/2 a n/2 (d) a n b n b n a n Question 1: Which string will you choose for z of the lemma? Why the other strings cannot be a candidate for z? If none of the above strings can be a candidate for z, what is your choice from L? Question 2: Let u, v, w  {a, b, c} * be the strings of the lemma such that z = uvw. What will be in v? Shortly describe all possible contents of string v. Question 3: The pumping lemma says “For all i  0, string uv i w  L.” How do you deal with this statement for your proof? Justify what you do. 6. Which of the following language are regular. Prove your answer. Your answer will be graded according to the logical completeness. L 1 = {a i b j a k | i, j, k > 0 } L 2 = {a i b j a i | i, j > 0 } 7. For a string x, let #a(x), #b(x), and #c(x) denote, respectively, the number of a’s, number of b’s and number of c’s in string x. Which of the following languages are context-free? Prove your answer. Your answer will be graded according to the logical completeness. L 3 = { x | x  {a,b,c} +, and #a(x) > #c(x) } L 4 = { x | x  {a,b,c} +, and #a(x) = #b(x) = #c(x) } L 5 = {x | x  {a,b,c} +, and #a(x) > #b(x) > #c(x) }