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

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

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

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Automata Theory CS F-08 Context-Free Grammars

Context Free Languages and Grammars

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Context-Free Grammars and Languages

Context Free Grammars

Miscellaneous. Closure Properties Decision Properties

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Chapter 5: Context-Free Languages

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

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

Computational Models - Lecture 4 1

Lecture 11 Context-Free Languages

6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions

Concordia University Department of Computer Science & Software Engineering

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

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

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

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.

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Context-free Grammars and Languages

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Grammars and Context Free Languages

Properties of Context-Free Languages. Closure Properties Decision Properties

Intro to Theory of Computation

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

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

FLAC Context-Free Grammars

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

Grammars and Context Free Languages

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

Formal Languages, Grammars and Automata Lecture 5

Introduction to Theory of Computing

5 Context-Free Languages

Computational Models - Lecture 4 1

Context-Free Grammars and Languages. We have seen that many languages cannot be regular. Thus we need to consider larger classes of langs.

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

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

NPDA, CFG equivalence

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Pushdown Automata (PDA) The structure and the content of the lecture is based on

Computational Models - Lecture 3

CPSC 421: Tutorial #1

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp )

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

CPS 220 Theory of Computation Pushdown Automata (PDA)

Grammars (part II) Prof. Dan A. Simovici UMB

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Einführung in die Computerlinguistik

CISC4090: Theory of Computation

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

Foundations of Informatics: a Bridging Course

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.

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.

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

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

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

Section 1 (closed-book) Total points 30

The Pumping Lemma for Context Free Grammars

Theory of Computation (VI) Yijia Chen Fudan University

Theory of Computation (IX) Yijia Chen Fudan University

INSTITUTE OF AERONAUTICAL ENGINEERING

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

3515ICT: Theory of Computation. Regular languages

PUSHDOWN AUTOMATA (PDA)

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

CS375: Logic and Theory of Computing

Intro to Theory of Computation

CMSC 330: Organization of Programming Languages

Properties of Context Free Languages

Einführung in die Computerlinguistik

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

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

Computability Theory

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Context-free grammars and languages

CS375: Logic and Theory of Computing

CS21 Decidability and Tractability

(pp ) PDAs and CFGs (Sec. 2.2)

Computational Models - Lecture 4

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

CSE 105 THEORY OF COMPUTATION

Ogden s Lemma for CFLs

Theory of Languages and Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

How do regular expressions work? CMSC 330: Organization of Programming Languages

Theory of Computation (IV) Yijia Chen Fudan University

Transcription:

Context-Free Grammars 2IT70 Finite Automata and Process Theory Technische Universiteit Eindhoven Quartile2, 2014-2015

Generating strings language L 1 èa n b n Ë n 0 í ab L 1 if w L 1 then awb L 1 2 IT70 (2014) Context-Free Grammars 2/ 13

Generating strings language L 1 èa n b n Ë n 0 í ab L 1 if w L 1 then awb L 1 production rules S ab and S asb 2 IT70 (2014) Context-Free Grammars 2/ 13

Generating strings language L 1 èa n b n Ë n 0 í language L 2 01 ab L 1 ε L 2 if w L 1 then awb L 1 if w L 2 then 01w L 2 production rules S ab and S asb 2 IT70 (2014) Context-Free Grammars 2/ 13

Generating strings language L 1 èa n b n Ë n 0 í language L 2 01 ab L 1 ε L 2 if w L 1 then awb L 1 if w L 2 then 01w L 2 production rules S ab and S asb production rules S ε and S 01S 2 IT70 (2014) Context-Free Grammars 2/ 13

Variables, terminals, production rules, start symbol palindromes over èa, bí S ε S a S b S asa S bsb binary integer expressions E I E N E E E E E E E E I a I I0 I I1 N 1 N N0 N N1 2 IT70 (2014) Context-Free Grammars 3/ 13

Variables, terminals, production rules, start symbol palindromes over èa, bí S ε S a S b S asa S bsb alternative notation S ε Ë a Ë b ËaSa ËbSb binary integer expressions E I E N E E E E E E E E I a I I0 I I1 N 1 N N0 N N1 alternative notation E I Ë N Ë E E Ë E E Ë E I aëi0 Ë I1 N 1ËN0 Ë N1 2 IT70 (2014) Context-Free Grammars 3/ 13

Question Consider again the grammar given by E I Ë N Ë E E Ë E E Ë E I aëi0 Ë I1 N 1ËN0 Ë N1 How many of the strings aa1, a01, 011, 11a, a01 a01, a11 a10, 101, 110 cannot be generated by the grammar, you expect? A. Two strings B. Three strings C. Four strings D. Six strings E. Can t tell 2 IT70 (2014) Context-Free Grammars 4/ 13

Language of a CFG context-free grammar G V, T, R, S V variables and T terminals R V V T production rules A α S V start symbol productions G V T V T γ G γ ì if γ β 1 Aβ 2, A α rule of G, γ ì β 1 αβ 2 production sequences γ 0 G γ 1 G G γ n 2 IT70 (2014) Context-Free Grammars 5/ 13

Language of a CFG context-free grammar G V, T, R, S V variables and T terminals R V V T production rules A α S V start symbol productions G V T V T γ G γ ì if γ β 1 Aβ 2, A α rule of G, γ ì β 1 αβ 2 production sequences γ 0 G γ 1 G G γ n language of a variable Ä G A èw T Ë A G w í language of the grammar Ä G Ä G S 2 IT70 (2014) Context-Free Grammars 5/ 13

More examples expression term Ë expression + term term factor Ë term factor factor identifier Ë expression identifier a Ë b Ëc Ë... 2 IT70 (2014) Context-Free Grammars 6/ 13

More examples expression term Ë expression + term term factor Ë term factor factor identifier Ë expression identifier a Ë b Ëc Ë... char a Ë... Ë z ËAË... Ë Z Ë... text ε Ë char text doc ε Ë element doc element text Ë <EM> doc </EM> Ë <P> doc Ë <OL> list </OL> listitem <LI> doc list ε Ë listitem doc 2 IT70 (2014) Context-Free Grammars 6/ 13

Combining and splitting productions lemma CFG G V, T, R, S if X 1 n1 G γ 1,...,X k nk G γ k then X 1 X k ng γ 1 γ k where n n 1 n k if X 1 X k ng γ then X 1 n1 G γ 1,...,X k nk G γ k where n n 1 n k and γ γ 1...γ k X 1,...,X k V T 2 IT70 (2014) Context-Free Grammars 7/ 13

The parentheses language L CFG S εëss Ë S several production sequences for string S G SS G S S G S S G S G S G S G SS G S S G S G S G S G S G SS G S S G S S G S G S G leftmost, rightmost, mixed production sequence 2 IT70 (2014) Context-Free Grammars 8/ 13

Clicker question L82 Given the CFG S Ë S Ë SS. How many production sequences are there for the string? A. has 5 possible production sequences B. has 6 possible production sequences C. has 10 possible production sequences D. has 12 possible production sequences E. Can t tell 2 IT70 (2014) Context-Free Grammars 9/ 13

Proving a grammar correct CFG G with production rules S ab and S asb for L èa n b n Ë n 1 í it holds that Ä G L proof induction on n: if S ng w then w L, thus Ä G L induction on n: if w a n b n then w Ä G, thus L Ä G Ù 2 IT70 (2014) Context-Free Grammars 10/ 13

Avoiding the inductive proofs lemma CFGs G 1 V 1, T 1, R 1, S 1 and G 2 V 2, T 2, R 2, S 2 moreover V 1 and V 2 disjoint define CFG G èsí V 1 V 2, T 1 T 2, R, S if R ès S 1 ËS 2 í R 1 R 2 then Ä G Ä G 1 Ä G 2 if R ès S 1 S 2 í R 1 R 2 then Ä G Ä G 1 Ä G 2 if R ès εës 1 Sí R 1 then Ä G Ä G 1 2 IT70 (2014) Context-Free Grammars 11/ 13

Avoiding the inductive proofs (cont.) CFG G with production rules S S 1 Ë S 2 S 1 ab B εëbb S 2 ba A εëaa then Ä G èab n, ba m Ë n,m 0 í proof use the lemma Ä G A èa m Ëm 0 í and Ä G B èb n Ën 0 í Ä G S 1 èaí èb n Ën 0 í and Ä G S 2 èbí èa m Ëm 0 í Ä G èab n Ë n 0 í èba m Ë m 0 í Ù 2 IT70 (2014) Context-Free Grammars 12/ 13

Context-free languages language L is context-free if L Ä G for CFG G èa n b n Ën 0 í and èww R Ë w è0,1í í are context-free theorem if L is regular then L is context-free proof for DFA D Q, Σ, δ, q 0, F put G Q, Σ, R, q 0 where R èq aq ì Ë δ q,a q ì í èq εëq F í then L Ä G Ù 2 IT70 (2014) Context-Free Grammars 13/ 13