1 Section 12.1 Context-Free Languages We know that the language {a n b n | n  N} is not regular, but it certainly has a non-regular grammar, such as S.

Slides:



Advertisements
Similar presentations
Natural Language Processing - Formal Language - (formal) Language (formal) Grammar.
Advertisements

1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
Regular operations Sipser 1.1 (pages 44 – 47). CS 311 Mount Holyoke College 2 Building languages If L is a language, then its complement is L’ = {w |
Context-Free Grammars Sipser 2.1 (pages 99 – 109).
Context-Free Grammars Sipser 2.1 (pages 99 – 109).
1 Lecture 31 EQUAL language –Designing a CFG –Proving the CFG is correct.
1 Module 28 Context Free Grammars –Definition of a grammar G –Deriving strings and defining L(G) Context-Free Language definition.
1 Lecture 29 Context Free Grammars –Examples of “real-life” grammars –Definition of a grammar G –Deriving strings and defining L(G) Context-Free Language.
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.
1 Module 30 EQUAL language –Designing a CFG –Proving the CFG is correct.
1 Module 34 CFG --> PDA construction –Shows that for any CFL L, there exists a PDA M such that L(M) = L –The reverse is true as well, but we do not prove.
1 、 Alphabet Non-empty set of symbols , usually expressed in  、 V or Other Upper-case Greece Letter 2 、 Symbol(Character) Elements in alphabet, finest.
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.
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Chapter 12: Context-Free Languages and Pushdown Automata
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
Formal Grammars Denning, Sections 3.3 to 3.6. Formal Grammar, Defined A formal grammar G is a four-tuple G = (N,T,P,  ), where N is a finite nonempty.
1 Section 3.3 Grammars A grammar is a finite set of rules, called productions, that are used to describe the strings of a language. Notational Example.
1 Chapter Construction Techniques. 2 Section 3.3 Grammars A grammar is a finite set of rules, called productions, that are used to describe the.
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.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
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.
1 Chapter Regular Language Topics. 2 Section 11.4 Regular Language Topics Regular languages are also characterized by special grammars called regular.
1 Context-Free Languages Not all languages are regular. L 1 = {a n b n | n  0} is not regular. L 2 = {(), (()), ((())),...} is not regular.  some properties.
Lecture # 19. Example Consider the following CFG ∑ = {a, b} Consider the following CFG ∑ = {a, b} 1. S  aSa | bSb | a | b | Λ The above CFG generates.
Chapter 5 Context-Free Grammars
Context-Free Grammars – Derivations Lecture 15 Section 2.1 Mon, Sep 24, 2007.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Grammar G = (V N, V T, P, S) –V N : Nonterminal symbols –V T : Terminal symbols V N  V T = , V N ∪ V T = V – P : a finite set of production rules α 
Midterm 1 Breakdown >79 3 >29 7 >69 5 >19 5 >59 7 >49 9 >39 7.
Regular Grammars Chapter 7 1. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.
Section 12.4 Context-Free Language Topics
1 Section 12.3 Context-Free Parsing We know (via a theorem) that the context-free languages are exactly those languages that are accepted by PDAs. When.
Enter Chomsky Grammars. 2 What has Chomsky* to do with computing? Linguistics and computing intersect at various places: Things that are used to create.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
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.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
Section 11.4 Regular Language Topics
Non-Context-Free Languages Section 2.3 CSC 4170 Theory of Computation.
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.
Context-Free Languages
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 10 Automata, Grammars and Languages.
Context Free Grammars and Regular Grammars Needs for CFG Grammars and Production Rules Context Free Grammars (CFG) Regular Grammars (RG)
1 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring.
1 Chapter Regular Languages. 2 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Chomsky Normal Form.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Recap lecture 31 Context Free Grammar, Terminals, non- terminals, productions, CFG, context Free language, examples.
Context Free Grammars & Parsing CPSC 388 Fall 2001 Ellen Walker Hiram College.
Lecture 17: Theory of Automata:2014 Context Free Grammars.
1 Chapter Context-Free Languages. 2 Section 12.1 Context-Free Languages We know that the language {a n b n | n ∈ N} is not regular, but it certainly.
1 Section 4.4 Inductive Proof What do we believe about nonempty subsets of N? Since  N, <  is well-founded, and in fact it is linear, it follows that.
20 G M aaba acba aaba.. What is it about? Models of Language Generation Models of Language Recognition.
Grammars.
Formal Language & Automata Theory
Chapter Thirteen: Stack Machines
Chapter 7 Regular Grammars
Presentation transcript:

1 Section 12.1 Context-Free Languages We know that the language {a n b n | n  N} is not regular, but it certainly has a non-regular grammar, such as S  aSb | . A context-free grammar has productions of the form N  w N  w Where N is a nonterminal and w is any string containing terminals and/or nonterminals. A context-free language is the set of strings derived from a context-free grammar. Example. {a n b n | n  N} is a C-F language derived from the C-F grammar S  aSb | . Example. Any regular grammar is context-free. So regular languages are C-F languages. Quiz. Find a grammar for {a n b n + 2 | n  N}. Answer. S  aSb | bb. Quiz. Find a grammar for{ww R | w  {a, b}*}, where w R is the reverse of w. Answer. S  aSa | bSb | . Techniques for Constucting Grammars: Let L and M be two C-F grammars with disjoint sets of nonterminals and with start symbols A and B, respectively. Then L  M has grammar S  A | B. LM has grammar S  AB. L* has grammar S  AS | .

2 Example. Let L be the language of strings over {a, b} with the same number of a’s and b’s. Does L have the following grammar? S  aSbS | bSaS | . It’s easy to see that the language of the grammar is a subset of L. What about the other way? Assume that w  L and show w is derived by the grammar. If w = , then S  . Let w ≠  and assume that if s  L and | s | < | w |, then S  + s. Show that S  + w. Consider the four cases: 1.w = asb for some string s. In this case, s  L and | s | < | w |. So by induction we have S  + s. Therefore, we have S  aSbS  aSb  + asb = w. 2. w = bsa for some string s. Similar to case 1. 3.w = axa for some string x. In this case, x has two more b’s than a’s. So x  L. What do we do now? Notice, for example, if | w | = 4, then w = abba. If | w | = 6, then w has one of the forms aabbba, ababba, abbaba abbbaa. We claim that x can be written in the form x = ubbv where u, v  L. (Can you prove it?) So by induction we have derivations S  + u and S  + v. Therefore, we have S  aSbS  + aubS  aubbSaS  + aubbvaS  aubbva = axa = w. 4. w = bxb for some string x. Similar to case 3. QED.

3 Examples/Quizzes. For a string x and letter a let n a (x) be the number of a’s in x. Let L = {x  {a, b}* | n a (x) = n b (x)}. A grammar for L with start symbol E can be written as: E  aEbE | bEaE | . Use this information to find grammars for the following languages. 1. {x  {a, b}* | n a (x) = 1 + n b (x)}. Solution: S  EaE. 2. {x  {a, b}* | n a (x) = 2 + n b (x)}. Solution: S  EaEaE. 3. {x  {a, b}* | n a (x) > n b (x)}. Solution: S  EaET T  aET | . 4. {x  {a, b}* | n a (x) < n b (x)}. Solution: S  EbET T  bET | . 5. {x  {a, b}* | n a (x) ≠ n b (x)}. Solution: This language is the union of the languages in (3) and (4). Rename the nonterminals in the grammars for (3) and (4) as follows: (3)A  EaET T  aET | . (4)B  EbEU U  bEU | . Then S  A | B is the desired grammar.