Introduction and Motivation. Introduction and Motivation. Introduction to Computability. Introduction and Motivation. Theory. Lecture5: Context Free

Similar documents
CISC4090: Theory of Computation

Lecture 11 Context-Free Languages

Theory of Computation (IV) Yijia Chen Fudan University

Introduction to Theory of Computing

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Theory of Computation (II) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Properties of Context-Free Languages. Closure Properties Decision Properties

This lecture covers Chapter 5 of HMU: Context-free Grammars

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CSE 105 THEORY OF COMPUTATION

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Computational Models - Lecture 5 1

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Context-free Grammars and Languages

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

CISC 4090 Theory of Computation

Grammars and Context Free Languages

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

Computational Models - Lecture 4 1

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Foundations of Informatics: a Bridging Course

Context-Free Grammars and Languages. Reading: Chapter 5

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

CSE 105 THEORY OF COMPUTATION

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

CPS 220 Theory of Computation

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Part 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages

Harvard CS 121 and CSCI E-207 Lecture 9: Regular Languages Wrap-Up, Context-Free Grammars

This lecture covers Chapter 6 of HMU: Pushdown Automata

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

5 Context-Free Languages

Grammars and Context Free Languages

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Computational Models - Lecture 4

Formal Languages, Grammars and Automata Lecture 5

Computational Models - Lecture 4 1

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

(pp ) PDAs and CFGs (Sec. 2.2)

Context-Free Grammars. 2IT70 Finite Automata and Process Theory

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

CISC 4090 Theory of Computation

MA/CSSE 474 Theory of Computation

Pushdown Automata (2015/11/23)

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Theory of Computation (IX) Yijia Chen Fudan University

Finite Automata. Finite Automata

CPS 220 Theory of Computation Pushdown Automata (PDA)

Context-Free Languages (Pre Lecture)

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

Syntactical analysis. Syntactical analysis. Syntactical analysis. Syntactical analysis

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

FLAC Context-Free Grammars

Einführung in die Computerlinguistik

Theory of Computation

Talen en Compilers. Johan Jeuring , period 2. October 29, Department of Information and Computing Sciences Utrecht University

Pushdown Automata: Introduction (2)

Pumping Lemma for CFLs

Computational Models - Lecture 3

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

(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},

CPSC 421: Tutorial #1

Theory of Languages and Automata

PUSHDOWN AUTOMATA (PDA)

Context Free Languages and Grammars

CSE 105 THEORY OF COMPUTATION

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Decidability (intro.)

Automata and Computability. Solutions to Exercises

Theory Bridge Exam Example Questions

Ogden s Lemma for CFLs

5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where:

Computational Models: Class 3

Final exam study sheet for CS3719 Turing machines and decidability.

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CSC236 Week 11. Larry Zhang

Automata and Computability. Solutions to Exercises

Context Free Grammars

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)

Cliff s notes for equivalence of CFLs and L(PDAs) LisaCFL L = L(M) for some PDA M L=L(M)forsomePDAM L = L(G) for some CFG G

Context-Free Grammars and Languages

Lecture 17: Language Recognition

Computability Theory

Decidable and undecidable languages

Einführung in die Computerlinguistik

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Transcription:

ntroduction to Computability Theory Lecture5: Context Free Languages Prof. Amos sraeli 1 ntroduction and Motivation n our study of RL-s we Covered: 1. Motivation and definition of regular languages. 2. DFA-s, NFA-s, RE-s and their equivalence. 3. Non Regular Languages and the Pumping Lemma. 3 ntroduction and Motivation On the last lecture we completed our study of regular languages. (There is still a lot to learn but our time is limited ). 2 ntroduction and Motivation n this lecture, we turn to Context Free Grammars and Context Free Languages. The class of Context Free Languages is an intermediate class between the class of regular languages and the class of Decidable Languages(To be defined). 4

ntroduction and Motivation A Context Free Grammar is a machine that creates a language. A language created by a CF grammar is called A Context Free Language. (We will show that) The class of Context Free Languages Properly Contains the class of Regular Languages. 5 Context Free Grammar - Example Consider grammar G 1 : ab ε The grammar generates the language B 1 G 1 { } n n = a b n 0 called the language of, denoted by L. G ( ) G 1 7 Context Free Grammar - Example Consider grammar G 1 : ab ε A CFL consists of substitution s called Productions. The capital letters are the Variables. The other symbols are the Terminals. 6 Context Free Grammar - Example Consider grammar G 1 : ab ε This is a Derivation of the word aaabbb by : ab aabb aaabbb aaabbb G 1 On each step, a single is activated. This mechanism is nondeterministic. 8

Context Free Grammar - Example This is A Parse Treeof the word aaabbbb by : G 1 9 a a a ε b b b CF Grammar A Formal Definition A Context Free Grammar is a 4-tupple V,Σ, R, S where: ( ) 1. V is a finite set called the variables. 2. Σ is a finite set, disjoint from Vcalled the terminals. 3. R is a set of s, where a is a variable, and a string of variables and terminals, and 4. S V is the start variable. 11 Context Free Grammar - Example ab ε a a a ε b b b Each internal node of the tree is associated with a single production. 10 A Derivation A Formal Definition A word is a string of terminals. A derivation of a word wfrom a context Free Grammar G = ( V,Σ, R, S ) is a sequence of strings S = s 0 s 2... s l = w, over V Σ, where: 1. s 0 = S is the start variable of G. 2. For each 1 i l, is obtained by s i activating a single production () of Gon one of the variables of. s i 1 12

CF Grammar A Formal Definition A word wis in the Language of grammar G, denoted by w L, if there exists a ( G ) derivation whose rightmost string is w. Thus, L ( G ) = { w w can be derived from G } 13 < EXPR 15 Grammar : V = { < EXP, < TERM, < FACTOR } Σ = a b Rules: 1. 2. 3. {,, +,,(,) } < EXPR < EXPR +< TERM < TERM < TERM < TERM < FACTOR < FACTOR < ( EXPR ) a b FACTOR < S =< EXPR 14 < EXPR < EXPR < TERM 16

< EXPR < TERM output < EXPR < TERM 17 < EXPR < TERM < TERM < TERM < FACTOR 19 < EXPR < TERM 18 < EXPR < TERM < TERM < FACTOR output < TERM < TERM < FACTOR 20

< EXPR < TERM < TERM < FACTOR 21 < EXPR < TERM < TERM < FACTOR < TERM a output < FACTORa 23 < EXPR < TERM < TERM < FACTOR < FACTORa 22 < EXPR < TERM < TERM < FACTOR < TERM a 24

< EXPR < TERM < TERM < FACTOR < TERM a < TERM < FACTOR 25 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a 27 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR output < TERM < FACTOR a 26 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a ( < ) < FACTOR EXPR 28

< EXPR < TERM < TERM < FACTOR < TERM a < FACTOR < EXPR output a ( < ) < FACTOR EXPR 29 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR < EXPR a < EXPR < EXPR +< TERM 31 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR < EXPR a 30 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) output < EXPR < EXPR +< TERM 32

< EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) 33 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a output < EXPR < TERM 35 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) < EXPR < TERM 34 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a 36

< EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a < TERM < FACTOR 37 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a 39 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a output < TERM < FACTOR 38 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a < FACTOR a 40

< EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a ( a +< FACTOR ) a output < FACTOR a 41 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a ( a +< FACTOR ) a < FACTOR b 43 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a ( a +< FACTOR ) a 42 < EXPR < TERM < TERM < FACTOR < TERM a < FACTOR a < EXPR a < EXPR +< TERM ( ) ( < TERM +< TERM ) a ( < FACTOR +< FACTOR ) a ( a +< FACTOR ) a ( a + b) a 44

Derivation of a + b a by Grammar : < EXPR < EXPR +< TERM < TERM +< TERM < FACTOR +< TERM a +< TERM a +< TERM < FACTOR a +< FACTOR < FACTOR a + b < FACTOR a + b a Note:There is more than one derivation. 45 Ambiguity We already saw that a word may have more then a single derivation from the same grammar. A Leftmost Derivation is a derivation in which s are applied in order left to right. A grammar is ambiguous if it has Two parse trees. 47 Example3: The Language of WF ( ) To be Demonstrated on the blackboard 46 Ambiguity Reminder:Two parse trees are equal if they are equal as trees and if all productions corresponding to inner nodes are also equal. 48

Example4: Similar to Arith. EXPS Grammar : { < EXP, < TERM < } {,, +,,(,) } V =, FACTOR Σ = a b G 4 Rules: < EXPR < EXPR +< EXPR < EXPR < EXPR < EXPR < EXPRa, S =< EXPR, 49 Example4: 2 nd Parse Tree for a + b a < EXPR < EXPR +< EXPR < EXPR < EXPR < EXPR < EXPR < EXPR a + b a 51 Example4: 1 st Parse Tree for a + b a < EXPR < EXPR < EXPR < EXPR < EXPR < EXPR < EXPR < EXPR a + b 50 Ambiguity Note: Some ambiguous grammars may have an unambiguous equivalent grammar. But: There exist nherently Ambiguous Grammars, i.e. an ambiguous grammar that does not have an equivalent unambiguous one. 52 a

Discussion Q: From a computational point of view, how strong are context free languages? { } n n A:Since the language B = a b n 0 is not regular and it is CF, we conclude that CFL RL. Q: Can one prove CFL RL? A: Yes. 53 Discussion Q:A language is regular if it is recognized by a DFA (or NFA). Does there exist a type of machine that characterizes CFL? A: Yes, those are the Push-Down Automata (Next Lecture).. Q: Can one prove a language not to be CFL? A:Yes, by the Pumping Lemma for CFL-s. For n n n example: L = a b c n 0 is not CFL. { } 54