Context-Free Grammar
|
|
- Douglas Copeland
- 6 years ago
- Views:
Transcription
1 Context-Free Grammar CFGs are more powerful than regular expressions. They are more powerful in the sense that whatever can be expressed using regular expressions can be expressed using context-free grammars, but they can also express languages that do not have regular expressions.
2 Context-Free Grammar
3 Example: Context-Free Grammar
4 Example Context-Free Grammar
5 Context-Free Grammar Construct a context free grammar for palindromes containing 0s and 1s.
6 Context-Free Grammar Construct a context free grammar for all integers (with sign) G ={V, Σ, R, S} V = {S, G, D, I}, Σ = {0, 1, 2, 3,., 9, +, -}
7 Derivation Trees
8 Derivation Trees
9 Derivation Trees
10 Derivation Trees
11 Derivation Tree
12 Ambiguity Consider the grammar for arithmetic expressions involving addition and multiplication operators: Consider the sentence ID+ID ID. This can be parsed in two different ways.
13 Ambiguity In the figure, the parse tree to the left gives the addition operator precedence over multiplication. In other words, an expression such as is evaluated as (3+5) 9 with a result of 72. Whereas, the tree to the right, does what is considered the standard practice in programming languages, i.e. giving precedence over +. The previous example would be evaluated as 3+(5 9) resulting in 48. A context free grammar G is ambiguous if there exists some w L(G), which is ambiguous. If G is the grammar Show that G is ambiguous.
14 Ambiguity To prove that G is ambiguous, we need to find a w L(G), which is ambiguous. Consider the word abababa.
15 Ambiguity
16 What about a + a a? Removing Ambiguity
17 Removing Ambiguity
18 Simplification of CFG If G is a CFG, then we can construct a simplified equivalent CFG G with the help of following steps: 1. Eliminate all null productions to get G Eliminate all unit productions in G 1 to get G Construct a reduced Grammar G from G 2.
19 Simplification of CFG 1.Elimination of null productions Let G 1 =(V, Σ,P,S) be the GFG having NO null productions. Consider the Grammar G whose productions are given below. Construct a Grammar G 1 without null productions generating L(G)-{ε}
20 Simplification of CFG Step 1: Construction of the set W of all nullable variables W 1 ={A 1 V A 1 ε is a production in P}={A,B} W i+1 = W i {K V there exists a production K α with α W i * } W 2 ={A,B} {S} as S AB is a production with AB W 1 * = { S,A,B} W 3 = W 2 = W 2 Erasing from RHS Construction of P : D b, S as, S AB, S a, S A, S B.
21 Simplification of CFG 2.Elimination of unit productions A unit production in a context free grammar G is a production of the form A B where A and B are variables(non terminals) in G. For such a variable A the following steps have to be applied: Step1: Construction of the set of variables derivable from A. W 0 (A)={A} W i+1 (A)=W i (A) {B V C B is in P with C W i (A) }
22 Simplification of CFG Step2: Construction of A productions The A-productions in G 2 are either (a) The non unit production in G 1 or (b) A α whenever B α is in G 1 with B W(A) and α V. Now we can define G 2, where P 2 is constructed using step2 for every A V
23 Simplification of CFG Example: Let the productions in G 1 be S AB, A a, B C b, C D, D E and E a W(B)={B,C,D,E}, W(C)={C,D,E}, W(D)={D,E} The productions P 2 in G 2 are: S AB, A a, B a b, C a, D a and E a
24 Simplification of CFG 3.Construction of reduced Grammars: Many productions in P may not be useful for the purpose of derivation. It would be better to eliminate (1) variables that do not derive any terminal string and (2) symbols that are not reachable from the start symbol. If G is a CFG, then we can find an equivalent grammar G such that each variable in G derives some terminal string. Let G2=(V, Σ,P,S). We can define G =(V, Σ,P,S) as follows.
25 a) Construction of V : We define W i V by recursion. Simplification of CFG W 1 ={A V there exists a production A ω where ω Σ*} W i+1 =W i {A V there exists some production A α with α (Σ W i )*} At some point W k =W k+1. Then we get V =W k. b) Construction of P. P ={A α A, α (V Σ)*}
26 Example: Let G be Simplification of CFG S AB, A a, B b, B C, and E c Find G such that every variable in G derives some terminal string. Here we get V ={S,A,B,E}. So P = S AB, A a, B b and E c
27 Simplification of CFG If G=(V, Σ,P,S), we can construct an equivalent grammar G = (V, Σ,P,S) such that every symbol in V Σ is derivable from S. a) Construction of Wi W 1 ={S}. W i+1 =W i {X (V Σ) there exists a production A α with A W i and α containing the symbol X } At some point W k =W k+1. b) Construction of V, Σ, P. V =V W k, Σ = Σ W k, P ={A α A W k }
28 Simplification of CFG Example: Consider G=({S,A,B,E}, {a,b,c},p,s), where P consists of S AB, A a, B b and E c. W 3 ={S,A,B} {a,b} V = {S,A,B}, Σ ={a,b} P = S AB, A a, B b
29 Simplification of CFG Find reduced grammars equivalent to the following 1) S AB CA, B BC AB, A a, C ab b. 2) S aaa, A Sb bcc DaA, C abb DD, E ac, D ada. Answers: 1) S CA, A a, C b 2) S aaa, A Sb bcc, C abb
30 Normal Forms for CFG In a context free grammar, the R.H.S of a production can be any string of variables and terminals. When the production in G satisfy certain restrictions, then G is said to be in a normal form. 1. Chomsky Normal Form(CNF) In CNF we have restrictions on the length of R.H.S and the nature of symbols in the R.H.S A CFG G is said to be in CNF, if every production is of the form A a, or A BC, and S ε. When ε is in L(G) we assume that S does not appear on the R.H.S of any production.
31 Normal Forms for CFG Example: Consider a CFG whose productions are S AB ε, A a, B b Is it in CNF? YES Reduction to CNF Consider an example. Let G be S ABC ac, A a, B b, C c. Except S ABC ac, all other productions are in the form required for CNF. The terminal a in ac can be replaced by a new variable D. By adding a new production D a. So S ac becomes S DC.
32 Normal Forms for CFG S ABC is not in the required form. So it can be replaced by two productions: S AE and E BC. It is important to note that unit productions and null productions are to be removed before substitutions. Elimination of terminals on R.H.S: If there is a terminal a i on the R.H.S of a production, then add a new variable (non terminal) C ai a i Restricting the number of variables on R.H.S: Consider productions of the form A A 1 A 2.A m. We introduce new productions A A 1 C 1, C 1 A 2 C 2,, C m-2 A m-1 A m
33 Example1: Reduce the following grammar G to CNF: S aad, A ab bab, B b, D d. Example2: Reduce the following grammar G to CNF: S aabb, A aa a, B bb b. Normal Forms for CFG Answer: S C a C 1, A C a B C b C 2, C 1 AD, C 2 AB, B b, D d, C a a, C b b. Answer: S C a C 1, C 1 AC 2, C 2 C b B, A C a A, B C b B, C a a, C b b, A a, B b.
34 Normal Forms for CFG Greibach Normal Form(GNF): A grammar is in GNF if every production is of the form A aα, where α V*. And a Σ. S ε is in G, when ε is in L(G) and we assume that S does not appear on the R.H.S of any production. Example: S aab ε, A bc, B b, C c is in GNF.
35 Normal Forms for CFG Lemma1: Let G be a CFG, and A Bλ be a production in P. Assume that P also has the following productions: B β 1 β 2. β s We can define P 1 =(P - {A Bλ}) {A β i λ 1 i s } Then G 1 having P 1 is also a CFG equivalent to G. Example: Consider G with the following productions: A Bab, B aa bb aa AB G 1 which is equivalent to G can be constructed with the following productions. A aaab bbab aaab ABab, B aa bb aa AB
36 Normal Forms for CFG Lemma2: Let G contains productions of the form A Aα 1 Aα 2. Aα r β 1 β 2. β s (β i s do not start with A) Let Z be a new variable in G 1, where P 1 is defined as follows: A β 1 β 2. β s A β 1 Z β 2 Z. β s Z. Z α 1 α 2. α r Z α 1 Z α 2 Z. α r Z Example: Consider G with the following productions: A abd bdb c AB AD
37 Normal Forms for CFG Then G 1, equivalent to G contains the following productions: A abd bdb c A abdz bdbz cz Z B D Z BZ DZ
38 Reduction to GNF Normal Forms for CFG Step1: Check whether the given grammar is in CNF. If not in CNF, make it in CNF. Rename the variables as A 1,A 2,.A n. With S=A 1. Step2: A i productions should be of the form A i A j λ such that i < j. If there are productions of the form A i A i λ, apply Lemma2 to get rid of such productions. Otherwise apply Lemma1. Step3: Modify Z i productions. Apply Lemma1 to eliminate productions of the form Z i A k λ.
39 Normal Forms for CFG Example1: Construct a grammar in GNF equivalent to the grammar: S AA a, A SS b Answer: The given grammar is in CNF. Let S be A 1 and A be A 2. A 1 A 2 A 2 A 1 a A 2 A 1 A 1 A 2 b A 1 productions are in the required form. A 2 b is also in the required form.
40 Apply Lemma1 to A 2 A 1 A 1. Normal Forms for CFG We need to apply Lemma2 to A 2 A 2 A 2 A 1. Let Z 2 be the new variable. Now we can eliminate A 1 A 2 A 2 using Lemma1.
41 We apply Lemma1 to get Normal Forms for CFG
42 Normal Forms for CFG
43 Normal Forms for CFG Example2: Convert the following grammar into GNF. Rename The productions are :
44 Normal Forms for CFG
45 Normal Forms for CFG
46 Normal Forms for CFG
Theory of Computation - Module 3
Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of
More informationLecture 12 Simplification of Context-Free Grammars and Normal Forms
Lecture 12 Simplification of Context-Free Grammars and Normal Forms COT 4420 Theory of Computation Chapter 6 Normal Forms for CFGs 1. Chomsky Normal Form CNF Productions of form A BC A, B, C V A a a T
More informationSimplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University
Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form
More informationSimplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University
Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form
More informationCFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions
CFG Simplification (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions 1 Eliminating useless symbols 1. A symbol X is generating if there exists: X * w, for
More informationContext-Free Grammars: Normal Forms
Context-Free Grammars: Normal Forms Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr
More informationPlan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form
Plan for 2 nd half Pumping Lemma for CFLs The Return of the Pumping Lemma Just when you thought it was safe Return of the Pumping Lemma Recall: With Regular Languages The Pumping Lemma showed that if a
More informationParsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26
Parsing Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Winter 2017/18 1 / 26 Table of contents 1 Context-Free Grammars 2 Simplifying CFGs Removing useless symbols Eliminating
More informationTheory Of Computation UNIT-II
Regular Expressions and Context Free Grammars: Regular expression formalism- equivalence with finite automata-regular sets and closure properties- pumping lemma for regular languages- decision algorithms
More informationHomework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,
Introduction to Formal Language, Fall 2016 Due: 21-Apr-2016 (Thursday) Instructor: Prof. Wen-Guey Tzeng Homework 4 Solutions Scribe: Yi-Ruei Chen 1. Find context-free grammars for the language L = {a n
More informationCS375: Logic and Theory of Computing
CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1 Table of Contents: Week 1: Preliminaries (set algebra, relations, functions) (read Chapters
More informationProperties of Context-free Languages. Reading: Chapter 7
Properties of Context-free Languages Reading: Chapter 7 1 Topics 1) Simplifying CFGs, Normal forms 2) Pumping lemma for CFLs 3) Closure and decision properties of CFLs 2 How to simplify CFGs? 3 Three ways
More informationTAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar
TAFL 1 (ECS-403) Unit- III 3.1 Definition of CFG (Context Free Grammar) and problems 3.2 Derivation 3.3 Ambiguity in Grammar 3.3.1 Inherent Ambiguity 3.3.2 Ambiguous to Unambiguous CFG 3.4 Simplification
More informationContext Free Grammars: Introduction. Context Free Grammars: Simplifying CFGs
Context Free Grammars: Introduction CFGs are more powerful than RGs because of the following 2 properties: 1. Recursion Rule is recursive if it is of the form X w 1 Y w 2, where Y w 3 Xw 4 and w 1, w 2,
More informationAutomata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008
Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008 Name: ID #: This is a Close Book examination. Only an A4 cheating sheet belonging to you is acceptable. You can write your answers
More informationDefinition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where
Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the
More informationFinite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols
Finite Automata and Formal Languages TMV026/DIT321 LP4 2012 Lecture 13 Ana Bove May 7th 2012 Overview of today s lecture: Normal Forms for Context-Free Languages Pumping Lemma for Context-Free Languages
More informationCS 373: Theory of Computation. Fall 2010
CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1 1 Normal Forms for CFG Normal Forms for Grammars It is typically easier to work with a context free language if given a CFG in a normal
More informationSolution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.
Section 12.4 Context-Free Language Topics Algorithm. Remove Λ-productions from grammars for langauges without Λ. 1. Find nonterminals that derive Λ. 2. For each production A w construct all productions
More informationAutomata Theory CS F-08 Context-Free Grammars
Automata Theory CS411-2015F-08 Context-Free Grammars David Galles Department of Computer Science University of San Francisco 08-0: Context-Free Grammars Set of Terminals (Σ) Set of Non-Terminals Set of
More informationSt.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad
St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-500 014 Subject: FORMAL LANGUAGES AND AUTOMATA THEORY Class : CSE II PART A (SHORT ANSWER QUESTIONS) UNIT- I 1 Explain transition diagram, transition
More information5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where:
Grammar Automata and Languages Grammar Prof. Mohamed Hamada oftware Engineering Lab. The University of Aizu Japan Regular Grammar Context-free Grammar Context-sensitive Grammar Left-linear Grammar right-linear
More informationContext-Free Grammars. 2IT70 Finite Automata and Process Theory
Context-Free Grammars 2IT70 Finite Automata and Process Theory Technische Universiteit Eindhoven May 18, 2016 Generating strings language L 1 = {a n b n n > 0} ab L 1 if w L 1 then awb L 1 production rules
More informationContext-Free Grammars and Languages
Context-Free Grammars and Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr
More informationProperties of context-free Languages
Properties of context-free Languages We simplify CFL s. Greibach Normal Form Chomsky Normal Form We prove pumping lemma for CFL s. We study closure properties and decision properties. Some of them remain,
More informationPushdown Automata. Reading: Chapter 6
Pushdown Automata Reading: Chapter 6 1 Pushdown Automata (PDA) Informally: A PDA is an NFA-ε with a infinite stack. Transitions are modified to accommodate stack operations. Questions: What is a stack?
More information60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor
60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is
More informationSFWR ENG 2FA3. Solution to the Assignment #4
SFWR ENG 2FA3. Solution to the Assignment #4 Total = 131, 100%= 115 The solutions below are often very detailed on purpose. Such level of details is not required from students solutions. Some questions
More informationTheory of Computation Turing Machine and Pushdown Automata
Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type
More informationEXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully
EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write
More informationMTH401A Theory of Computation. Lecture 17
MTH401A Theory of Computation Lecture 17 Chomsky Normal Form for CFG s Chomsky Normal Form for CFG s For every context free language, L, the language L {ε} has a grammar in which every production looks
More informationCPSC 313 Introduction to Computability
CPSC 313 Introduction to Computability Grammars in Chomsky Normal Form (Cont d) (Sipser, pages 109-111 (3 rd ed) and 107-109 (2 nd ed)) Renate Scheidler Fall 2018 Chomsky Normal Form A context-free grammar
More informationConcordia University Department of Computer Science & Software Engineering
Concordia University Department of Computer Science & Software Engineering COMP 335/4 Theoretical Computer Science Winter 2015 Assignment 3 1. In each case, what language is generated by CFG s below. Justify
More informationAC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013
Q.2 a. Prove by mathematical induction n 4 4n 2 is divisible by 3 for n 0. Basic step: For n = 0, n 3 n = 0 which is divisible by 3. Induction hypothesis: Let p(n) = n 3 n is divisible by 3. Induction
More informationContext Free Grammars: Introduction
Context Free Grammars: Introduction Context free grammar (CFG) G = (V, Σ, R, S), where V is a set of grammar symbols Σ V is a set of terminal symbols R is a set of rules, where R (V Σ) V S is a distinguished
More informationLecture 11 Context-Free Languages
Lecture 11 Context-Free Languages COT 4420 Theory of Computation Chapter 5 Context-Free Languages n { a b : n n { ww } 0} R Regular Languages a *b* ( a + b) * Example 1 G = ({S}, {a, b}, S, P) Derivations:
More informationCS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz.
CS3133 - A Term 2009: Foundations of Computer Science Prof. Carolina Ruiz Homework 2 WPI By Li Feng, Shweta Srivastava, and Carolina Ruiz Chapter 4 Problem 1: (10 Points) Exercise 4.3 Solution 1: S is
More informationCSE 355 Test 2, Fall 2016
CSE 355 Test 2, Fall 2016 28 October 2016, 8:35-9:25 a.m., LSA 191 Last Name SAMPLE ASU ID 1357924680 First Name(s) Ima Regrading of Midterms If you believe that your grade has not been added up correctly,
More information1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.
Code No: R09220504 R09 Set No. 2 II B.Tech II Semester Examinations,December-January, 2011-2012 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 75 Answer
More informationContext Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.
Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Language Generator: Context free grammars are language generators,
More informationSection 1 (closed-book) Total points 30
CS 454 Theory of Computation Fall 2011 Section 1 (closed-book) Total points 30 1. Which of the following are true? (a) a PDA can always be converted to an equivalent PDA that at each step pops or pushes
More informationChomsky Normal Form and TURING MACHINES. TUESDAY Feb 4
Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form: A BC A a S ε B and C aren t start variables a is
More informationCS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)
CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour
More informationChapter 4: Context-Free Grammars
Chapter 4: Context-Free Grammars 4.1 Basics of Context-Free Grammars Definition A context-free grammars, or CFG, G is specified by a quadruple (N, Σ, P, S), where N is the nonterminal or variable alphabet;
More informationAC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014
Q.2 a. Show by using Mathematical Induction that n i= 1 i 2 n = ( n + 1) ( 2 n + 1) 6 b. Define language. Let = {0; 1} denote an alphabet. Enumerate five elements of the following languages: (i) Even binary
More informationContext-Free Grammars and Languages. Reading: Chapter 5
Context-Free Grammars and Languages Reading: Chapter 5 1 Context-Free Languages The class of context-free languages generalizes the class of regular languages, i.e., every regular language is a context-free
More informationThe Pumping Lemma for Context Free Grammars
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 is in the form A BC A a Where a is any terminal
More informationQuestion Bank UNIT I
Siddhivinayak Technical Campus School of Engineering & Research Technology Department of computer science and Engineering Session 2016-2017 Subject Name- Theory of Computation Subject Code-4KS05 Sr No.
More informationNotes for Comp 497 (Comp 454) Week 10 4/5/05
Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : FORMAL LANGUAGES AND AUTOMATA THEORY Course Code : A40509 Class :
More informationContext Free Grammars
Automata and Formal Languages Context Free Grammars Sipser pages 101-111 Lecture 11 Tim Sheard 1 Formal Languages 1. Context free languages provide a convenient notation for recursive description of languages.
More informationCPS 220 Theory of Computation
CPS 22 Theory of Computation Review - Regular Languages RL - a simple class of languages that can be represented in two ways: 1 Machine description: Finite Automata are machines with a finite number of
More informationSheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed
Sheet -8 Dr. Mostafa Aref Format By : Mostafa Sayed 09 Introduction Assignment. For = {a, } a) Write 0 strings of the following languages i) All strings with no more than one a,,, a, a, a, a, a, a, a ii)
More informationFinite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018
Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 14 Ana Bove May 14th 2018 Recap: Context-free Grammars Simplification of grammars: Elimination of ǫ-productions; Elimination of
More informationFORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form:
More informationContext-Free Grammars (and Languages) Lecture 7
Context-Free Grammars (and Languages) Lecture 7 1 Today Beyond regular expressions: Context-Free Grammars (CFGs) What is a CFG? What is the language associated with a CFG? Creating CFGs. Reasoning about
More informationFinite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove
Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove Tuesday 28 of May 2013 Total: 60 points TMV027/DIT321 registration VT13 TMV026/DIT321 registration before VT13 Exam
More informationNotes for Comp 497 (454) Week 10
Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free
More informationFoundations of Informatics: a Bridging Course
Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html
More informationSolutions to Problem Set 3
V22.0453-001 Theory of Computation October 8, 2003 TA: Nelly Fazio Solutions to Problem Set 3 Problem 1 We have seen that a grammar where all productions are of the form: A ab, A c (where A, B non-terminals,
More informationComputability and Complexity
Computability and Complexity Rewriting Systems and Chomsky Grammars CAS 705 Ryszard Janicki Department of Computing and Software McMaster University Hamilton, Ontario, Canada janicki@mcmaster.ca Ryszard
More informationThis lecture covers Chapter 7 of HMU: Properties of CFLs
This lecture covers Chapter 7 of HMU: Properties of CFLs Chomsky Normal Form Pumping Lemma for CFs Closure Properties of CFLs Decision Properties of CFLs Additional Reading: Chapter 7 of HMU. Chomsky Normal
More informationEinführung in die Computerlinguistik
Einführung in die Computerlinguistik Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2016 1 / 22 CFG (1) Example: Grammar G telescope : Productions: S NP VP NP
More informationLanguages. Languages. An Example Grammar. Grammars. Suppose we have an alphabet V. Then we can write:
Languages A language is a set (usually infinite) of strings, also known as sentences Each string consists of a sequence of symbols taken from some alphabet An alphabet, V, is a finite set of symbols, e.g.
More informationVTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.
VTU QUESTION BANK Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a s and b s having exactly one a.(5m )( Dec-2014) 2. Obtain a DFA to accept strings of a s and b s having even
More informationChomsky and Greibach Normal Forms
Chomsky and Greibach Normal Forms Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Computation Theory p.1/25 Simplifying a CFG It is often convenient to simplify CFG One
More informationContext Free Languages and Grammars
Algorithms & Models of Computation CS/ECE 374, Fall 2017 Context Free Languages and Grammars Lecture 7 Tuesday, September 19, 2017 Sariel Har-Peled (UIUC) CS374 1 Fall 2017 1 / 36 What stack got to do
More informationMA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online
More informationSimplification and Normalization of Context-Free Grammars
implification and Normalization, of Context-Free Grammars 20100927 Slide 1 of 23 Simplification and Normalization of Context-Free Grammars 5DV037 Fundamentals of Computer Science Umeå University Department
More informationChapter 5: Context-Free Languages
Chapter 5: Context-Free Languages Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu Please read the corresponding chapter
More informationAn automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).
Automata The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled computing device which follows a predetermined
More informationwhere A, B, C N, a Σ, S ϵ is in P iff ϵ L(G), and S does not occur on the right-hand side of any production. 3.6 The Greibach Normal Form
262 CHAPTER 3. CONTEXT-FREE LANGUAGES AND PDA S 3.6 The Greibach Normal Form Every CFG G can also be converted to an equivalent grammar in Greibach Normal Form (for short, GNF). Acontext-freegrammarG =(V,Σ,P,S)
More informationNote: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).
Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates
More informationComputational Models - Lecture 4 1
Computational Models - Lecture 4 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. April 3/8, 2013 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationComputational Models - Lecture 3
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p. 1 Computational Models - Lecture 3 Equivalence of regular expressions and regular languages (lukewarm leftover
More informationHomework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz
CS3133 - A Term 2009: Foundations of Computer Science Prof. Carolina Ruiz Homework 4 WPI By Li Feng, Shweta Srivastava, and Carolina Ruiz Chapter 7 Problem: Chap 7.1 part a This PDA accepts the language
More informationComputational Models - Lecture 4 1
Computational Models - Lecture 4 1 Handout Mode Iftach Haitner. Tel Aviv University. November 21, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.
More informationdownload instant at Assume that (w R ) R = w for all strings w Σ of length n or less.
Chapter 2 Languages 3. We prove, by induction on the length of the string, that w = (w R ) R for every string w Σ. Basis: The basis consists of the null string. In this case, (λ R ) R = (λ) R = λ as desired.
More informationFLAC Context-Free Grammars
FLAC Context-Free Grammars Klaus Sutner Carnegie Mellon Universality Fall 2017 1 Generating Languages Properties of CFLs Generation vs. Recognition 3 Turing machines can be used to check membership in
More informationBefore We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?
Before We Start The Pumping Lemma Any questions? The Lemma & Decision/ Languages Future Exam Question What is a language? What is a class of languages? Context Free Languages Context Free Languages(CFL)
More informationEinführung in die Computerlinguistik
Einführung in die Computerlinguistik Context-Free Grammars formal properties Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2018 1 / 20 Normal forms (1) Hopcroft and Ullman (1979) A normal
More informationCOMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars
COMP-330 Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lec. 10 : Context-Free Grammars COMP 330 Fall 2017: Lectures Schedule 1-2. Introduction 1.5. Some basic mathematics 2-3. Deterministic finite
More informationGrammars and Context Free Languages
Grammars and Context Free Languages H. Geuvers and A. Kissinger Institute for Computing and Information Sciences Version: fall 2015 H. Geuvers & A. Kissinger Version: fall 2015 Talen en Automaten 1 / 23
More informationCISC 4090 Theory of Computation
CISC 4090 Theory of Computation Context-Free Languages and Push Down Automata Professor Daniel Leeds dleeds@fordham.edu JMH 332 Languages: Regular and Beyond Regular: Captured by Regular Operations a b
More information(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},
Code No: 07A50501 R07 Set No. 2 III B.Tech I Semester Examinations,MAY 2011 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 80 Answer any FIVE Questions All
More informationIntroduction to Formal Languages, Automata and Computability p.1/42
Introduction to Formal Languages, Automata and Computability Pushdown Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/42 Introduction We have considered
More informationComputational Models - Lecture 5 1
Computational Models - Lecture 5 1 Handout Mode Iftach Haitner. Tel Aviv University. November 28, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.
More informationThe View Over The Horizon
The View Over The Horizon enumerable decidable context free regular Context-Free Grammars An example of a context free grammar, G 1 : A 0A1 A B B # Terminology: Each line is a substitution rule or production.
More informationProperties of Context-Free Languages
Properties of Context-Free Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr
More informationCISC4090: Theory of Computation
CISC4090: Theory of Computation Chapter 2 Context-Free Languages Courtesy of Prof. Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 Overview In Chapter
More informationRecitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings
Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings 11-711: Algorithms for NLP October 10, 2014 Conversion to CNF Example grammar
More informationChap. 7 Properties of Context-free Languages
Chap. 7 Properties of Context-free Languages 7.1 Normal Forms for Context-free Grammars Context-free grammars A where A N, (N T). 0. Chomsky Normal Form A BC or A a except S where A, B, C N, a T. 1. Eliminating
More informationContext-free Grammars and Languages
Context-free Grammars and Languages COMP 455 002, Spring 2019 Jim Anderson (modified by Nathan Otterness) 1 Context-free Grammars Context-free grammars provide another way to specify languages. Example:
More informationChomsky Normal Form for Context-Free Gramars
Chomsky Normal Form for Context-Free Gramars Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 17 September 2014 Outline 1 CNF 2 Converting to CNF 3 Correctness
More informationCS481F01 Prelim 2 Solutions
CS481F01 Prelim 2 Solutions A. Demers 7 Nov 2001 1 (30 pts = 4 pts each part + 2 free points). For this question we use the following notation: x y means x is a prefix of y m k n means m n k For each of
More informationMiscellaneous. Closure Properties Decision Properties
Miscellaneous Closure Properties Decision Properties 1 Closure Properties of CFL s CFL s are closed under union, concatenation, and Kleene closure. Also, under reversal, homomorphisms and inverse homomorphisms.
More informationHarvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition
Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition Salil Vadhan October 11, 2012 Reading: Sipser, Section 2.3 and Section 2.1 (material on Chomsky Normal Form). Pumping Lemma for
More informationGrammars and Context-free Languages; Chomsky Hierarchy
Regular and Context-free Languages; Chomsky Hierarchy H. Geuvers Institute for Computing and Information Sciences Version: fall 2015 H. Geuvers Version: fall 2015 Huygens College 1 / 23 Outline Regular
More informationEinführung in die Computerlinguistik Kontextfreie Grammatiken - Formale Eigenschaften
Normal forms (1) Einführung in die Computerlinguistik Kontextfreie Grammatiken - Formale Eigenschaften Laura Heinrich-Heine-Universität Düsseldorf Sommersemester 2013 normal form of a grammar formalism
More informationGrammars and Context Free Languages
Grammars and Context Free Languages H. Geuvers and J. Rot Institute for Computing and Information Sciences Version: fall 2016 H. Geuvers & J. Rot Version: fall 2016 Talen en Automaten 1 / 24 Outline Grammars
More information