CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.

Slides:



Advertisements
Similar presentations
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Advertisements

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
1 Parsing The scanner recognizes words The parser recognizes syntactic units Parser operations: Check and verify syntax based on specified syntax rules.
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Syntax Lecture 2 - Syntax, Spring CSE3302 Programming Languages, UT-Arlington ©Chengkai.
CS5371 Theory of Computation
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
Grammars This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit.
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Computer Science 112 Fundamentals of Programming II Recursive Processing of Languages.
ITEC 380 Organization of programming languages Lecture 2 – Grammar / Language capabilities.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Parsing arithmetic expressions Reading material: These notes and an implementation (see course web page). The best way to prepare [to be a programmer]
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
Syntax and Backus Naur Form
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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)
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Context-free Languages
PART I: overview material
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Notes on Pinker ch.7 Grammar, parsing, meaning. What is a grammar? A grammar is a code or function that is a database specifying what kind of sounds correspond.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
The man bites the dog man bites the dog bites the dog the dog dog Parse Tree NP A N the man bites the dog V N NP S VP A 1. Sentence  noun-phrase verb-phrase.
1 Context Free Grammars October Syntactic Grammaticality Doesn’t depend on Having heard the sentence before The sentence being true –I saw a unicorn.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
1 Using Yacc. 2 Introduction Grammar –CFG –Recursive Rules Shift/Reduce Parsing –See Figure 3-2. –LALR(1) –What Yacc Cannot Parse It cannot deal with.
Syntax The Structure of a Language. Lexical Structure The structure of the tokens of a programming language The scanner takes a sequence of characters.
GRAMMARS & PARSING Lecture 8 CS2110 – Spring If you are going to form a group for A2, please do it before tomorrow (Friday) noon.
Review for final pm. 2 Review for Midterm Induction – On integer: HW1, Ex 2.2.9b p54 – On length of string: Ex p53, HW2, HW3.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Syntax Analysis - Parsing Compiler Design Lecture (01/28/98) Computer Science Rensselaer Polytechnic.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
ADTS, GRAMMARS, PARSING, TREE TRAVERSALS Lecture 13 CS2110 – Spring
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions: Context-Free Grammars and Languages Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Context Free Grammars. Slide 1 Syntax Syntax = rules describing how words can connect to each other * that and after year last I saw you yesterday colorless.
CSE 105 Theory of Computation
ADTs, Grammars, Parsing, Tree traversals
Teori Bahasa dan Automata Lecture 9: Contex-Free Grammars
Context-Free Grammars
Presentation transcript:

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at Permissions beyond the scope of this license may be available at

From Preliminary Exam 1 Regular languages are closed under union. If L1 and L2 are regular, then is L1 U L2 regular? – a) true – b) false

From Preliminary Exam 1 Regular languages are closed under union. If L1 U L2 is regular, are L1 and L2 both regular? – a) true – b) false

From Preliminary Exam 1 Direction Matters. “If P, then Q” does NOT mean “if Q, then P”. – It does mean “If not Q, then not P”, which is how we use the pumping lemma to prove that languages are not regular. Direction Matters even more, later in the course.

CONTEXT-FREE GRAMMARS CFG S Back to your [English/Spanish/French/…] class

Context-free Grammars (CFG) Context-free grammars are one way that scholars have tried to model how language, and our brain’s models of language, might be structured – Key concept: representing and generating infinite complexity, with just a few simple rules

What is the language of this CFG? S → 0S S → 0 a){0} b){0, 00, 000, …} c){ε, 0, 00, 000, …} d)None of the above

The LANGUAGE of a CFG The set of strings that can be generated following the given production rules. Every string generated is in the language, and every string that cannot be generated is not in the language.

What is the language of this CFG? S → 0S S → 1S S → ε a)Same as the regular expression 0*1* b)Same as the regular expression 0* U 1* c)Same as the regular expression (0 U 1)* d)None of the above

What is the language of this CFG? S → T0T T → TT T → 0T1 T → 1T0 T → 0 T → ε a)All strings of 0’s and 1’s b)All strings of 0’s and 1’s with at least one 0 in it c)All strings of 0’s and 1’s with at least two 0’s in it d)All strings of 0’s and 1’s that have the same number of 0’s and 1’s e)All strings of 0’s and 1’s that have more 0’s than 1’s

Are CFG’s more powerful than DFA’s? In other words: is there a CFG G such that the language of G is not regular? a)Yes b)No

Demonstrating the power of CFG’s The language L = {0 n 1 n | n ≥ 0} is NOT regular. (Why not?) Which of these grammars describes the language L? a) S → AB A → 0A | ε B → 1B | ε d) S → 01S01 | ε b) S → AB A → 0A1 | ε B → 0B1 | ε c) S → 0S1 | ε e) There is no CFG that describes L.

Why do we care about CFG’s? You write a Java program but forget a semicolon. How does the compiler catch it? You type (5+81(*24) in your fancy TI-89 calculator. How does it not blow up? You want to recursively define a tree datatype in O’Caml. How do you do this? You pull out your iPhone and ask Siri “When is the Sungod festival this year?” How does Siri have any hope of figuring out what you’re asking?

Why do we care about CFG’s? All of those situations (and more!) can be handled using CFG’s and parsing a string to see if it can be generated by a CFG. Programming languages are often specified as a grammar. There are programs (yacc) that can build parsers out of grammars. Doesn’t tell you anything about the meaning of the string. This is why they are “context-free” languages.

Sometimes a string can be parsed two different ways. S → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A → a | the N → boy | girl | flower V → touches | likes | sees P → with S = Sentence NP = Noun-Phrase VP = Verb-Phrase PP = Prep-Phrase CN = Complex-Noun CV = Complex-Verb A = Article N = Noun V = Verb P = Preposition

Parse Tree “The girl touches the boy with the flower.” (a) (b) S → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A → a | the N → boy | girl | flower V → touches | likes | sees P → with

Parse Tree 2 “The girl touches the boy with the flower.” (a) (b) S → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A → a | the N → boy | girl | flower V → touches | likes | sees P → with

Ambiguity