Enter Chomsky Grammars. 2 What has Chomsky* to do with computing? Linguistics and computing intersect at various places: Things that are used to create.

Slides:



Advertisements
Similar presentations
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
YES-NO machines Finite State Automata as language recognizers.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
ISBN Chapter 3 Describing Syntax and Semantics.
CS5371 Theory of Computation
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
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.
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.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Normal forms for Context-Free Grammars
Topics Automata Theory Grammars and Languages Complexities
How to Convert a Context-Free Grammar to Greibach Normal Form
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.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Theory Of Automata By Dr. MM Alam
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
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.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
CS/IT 138 THEORY OF COMPUTATION Chapter 1 Introduction to the Theory of Computation.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Grammars CPSC 5135.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
ISBN Chapter 3 Describing Syntax and Semantics.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Lecture 11 Theory of AUTOMATA
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.
ISBN Chapter 3 Describing Syntax and Semantics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
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.
Recursive Definations Regular Expressions Ch # 4 by Cohen
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.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
Lecture 16: Modeling Computation Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output.
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
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.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Theory of Languages and Automata By: Mojtaba Khezrian.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Recap lecture 31 Context Free Grammar, Terminals, non- terminals, productions, CFG, context Free language, examples.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
20 G M aaba acba aaba.. What is it about? Models of Language Generation Models of Language Recognition.
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
Context-Free Grammars: an overview
Lecture 1 Theory of Automata
Formal Language.
CHAPTER 2 Context-Free Languages
Presentation transcript:

Enter Chomsky Grammars

2 What has Chomsky* to do with computing? Linguistics and computing intersect at various places: Things that are used to create computer software—programming languages, compilers, text editors, etc.—all of these have elements of linguistics. More importantly, any computing problem can be seen as a “language recognition” problem! Even problems that seem remotely connected to language recognition such as adding two numbers, for instance, can be seen as language recognition problems: Consider L = { a m b n c x | there is a c for each and every occurrence of an a and a b }. In fact, recognizing L amounts to adding two numbers: a ’s represent the first number, b ’s denote the second number and c ’s, the sum of the two (in unary form). Thus, the theoretician rightly views the whole business of computing simply as “language recognition”. And, describing languages in precise ways is definitely an issue … * Noam Chomsky is, for linguists, what Einstein is for physicists. Chomsky, a Professor of Linguistics at MIT, is also a political analyst well-known for his criticisms of the US foreign policy.

3 What has Chomsky to do with computing? What Chomsky set out to do: “Assuming the set of grammatical sentences of English to be given, we now ask what sort of device can produce this set …..” (N. Chomsky, Syntactic Structures, 1957, proposition 3.1.) Chomsky “invented” a powerful theoretical tool for generating strings/patterns of a given type (a language) known as grammars and launched the new field, Formal Languages.

4 Grammars are “string generators” 0123 a abb Language recognizers (e.g. finite state automata) a abb Language generators (e.g. grammars)

5 God loves chicken and even numbers. He decides to create a world with just chicken---even number of them, and allow them to “multiply”. (At no point of time, he’d allow odd number of chicken in the world.) God is intelligent (!) and he does the following trick: A fairy tale Creates the first egg. Creates the following rule: From each egg can come out two little eggs or two chicken. (Once again, from each little egg can come out two tiny eggs or two chicken and so on.)

6 Each egg (shell) can break and let out either two chicken or two little shells that can in turn let out two chicken or two tiny little shells that can … One possible “chicken world” or The Rule Using this rule, one generates any even number of chicken. Shell  Shell Shell | a a Grammar Rule that mimics bursting shells: Generates language L = {strings of a ’s of even length (greater than 0) } A fairy tale Grammar rules operate in a way similar to the way “God’s rule” works in the fairy tale.

7 The Two Commandments 1. Thou shalt not produce any string that is “outside the set” (strings that don’t belong to L). 2. Thou shalt produce ALL strings that are “inside the set” (strings that belong to L). Anyone who wishes to write grammar rules to generate a language L has to follow these “commandments”:

8 An example S  S S Let Σ = { a, b } L = { w є Σ* | w is of even length } Did you notice? … that Finite State Automata use loops/cycles to generate patterns repetitively and grammars use recursion for the same purpose. production rules (substitution rules) Example: Let’s see how the string abbaba (which is of even length) can be generated / derived from this grammar. S  S S  S S S  ab S S  abbaS  abbaba Derivation: 1 S  S S  ab S  ab S S  abbaS  abbaba Derivation: 2 A grammar that allows two different (left-most*) derivations for the same string (as above) is not considered “good” in general. But, this example is used just to show how grammar works. Also, one can easily modify this grammar to avoid such multiple derivations. *Left-most capital-letter-symbol is expanded first always. S  aa | ab | ba | bb S  ε

9 Grammar: Definition A grammar G is a 4-tuple ( V, Σ, R, S ) finite set of non_terminals (capital letters) finite set of terminals (small letters) finite set of rules start symbol a special non-terminal V and Σ are disjoint All grammar rules that we develop (in this course) will have only one non-terminal symbol on the left side of “  ”. A grammar with such a restriction is known as “context-free grammar”.

10 Exercises (see next page for answers to some of the questions) (one or more a ’s) (one or more a ’s OR one or more b ’s) (zero or more a ’s followed by one or more b ’s) (any combination of a ’s and b ’s) (zero or more a ’s and b ’s followed by abb ) ( a ’s and b ’s of length = 2) ( a ’s and b ’s of length ≠ 2) L 8 = { w є { a,b } * : | w | is even } ( a ’s and b ’s of even length) L 1 = { a n | n >= 1} L 2 = { a n | n >= 1} U { b n | n >= 1} L 3 = { a m b n | m >= 0, n >= 1} L 4 = { a,b }* - { ε } L 5 = { x abb | x є { a,b }*} L 6 = { w є { a,b } * : | w | = 2 } L 7 = { w є { a,b } * : | w | ≠ 2 } L 9 = { w є { a,b } * : | w | is odd } ( a ’s and b ’s of odd length) L 10 = { w є { a,b } * : w doesn’t have two consecutive b ’s} L 11 = { ww R | w є { a,b } * } (any string followed by its reverse) L 12 = { w є { a,b } * | w is a palindrome} L 13 = { w є { [, ] } * | w has balanced parentheses} L 15 = { a n b n | n > 0 } L 14 = { w є { a,b } * | w contains bbb } L 16 = { a n b m c m d n | n, m > 0 } L 17 = { a m b n | m, n > 0, m < n } L 18 = { a m b n | m, n > 0, m ≠ n }

11 Examples (one or more a ’s) S  aS | a (one or more a ’s OR one or more b ’s) (zero or more a ’s followed by one or more b ’s) S  A B A  aA | ε B  bB | b (any combination of a ’s and b ’s) S  aS | bS | a | b S  A | B A  aA | a B  bB | b (zero or more a ’s and b ’s followed by abb ) Please work it out yourself! ( a ’s and b ’s of length = 3) S  A A A A  a | b ( a ’s and b ’s of length ≠ 2) S  ε | a | b | aa A | ab A | bb A | bb A A  aA | bA | a | b L 8 = { w є { a,b } * : | w | is even } ( a ’s and b ’s of even length) S  aaS | bbS | abS | baS | ε L 1 = { a n | n >= 1} L 2 = { a n | n >= 1} U { b n | n >= 1} L 3 = { a m b n | m >= 0, n >= 1} L 4 = { a,b }* - { ε } L 5 = { x abb | x є { a,b }*} L 6 = { w є { a,b } * : | w | = 3 } L 7 = { w є { a,b } * : | w | ≠ 2 }

12 L 9 = { w є { a,b } * : | w | is odd } ( a ’s and b ’s of odd length) More examples L 10 = { w є { a,b } * : w doesn’t have two consecutive b ’s} S  baS ……. (Work out the remaining rules for this language yourself!) Please work it out yourself! L 14 = { w є { a,b } * | w contains bbb } S  L bbb L L  aL | bL | ε Some of the remaining (harder) problems will be solved in class.