Yet More CFLs; Turing Machines. CS154 Chris Pollett Mar 8, 2006.

Similar documents
Normal Forms and Parsing. CS154 Chris Pollett Mar 14, 2007.

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

Decision Properties for Context-free Languages

Context Free Grammars. CS154 Chris Pollett Mar 1, 2006.

CS525 Winter 2012 \ Class Assignment #2 Preparation

Limits of Computation p.1/?? Limits of Computation p.2/??

JNTUWORLD. Code No: R

Normal Forms for CFG s. Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form

1. Provide two valid strings in the languages described by each of the following regular expressions, with alphabet Σ = {0,1,2}.

From Theorem 8.5, page 223, we have that the intersection of a context-free language with a regular language is context-free. Therefore, the language

Theory of Computation, Homework 3 Sample Solution

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

Multiple Choice Questions

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

Final Course Review. Reading: Chapters 1-9

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CS 44 Exam #2 February 14, 2001

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

The CYK Parsing Algorithm

Ambiguous Grammars and Compactification

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Context Free Grammars, Parsing, and Amibuity. CS154 Chris Pollett Feb 28, 2007.

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

COMP 330 Autumn 2018 McGill University

Decidable Problems. We examine the problems for which there is an algorithm.

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.


Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

PDA s. and Formal Languages. Automata Theory CS 573. Outline of equivalence of PDA s and CFG s. (see Theorem 5.3)

UNIT I PART A PART B

CS402 - Theory of Automata Glossary By

A Note on the Succinctness of Descriptions of Deterministic Languages

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Complementing Non-CFLs If A and B are context free languages then: AR is a context-free language TRUE

Chapter 2 :: Programming Language Syntax

Menu. Problem 5: PRIMES. Problem 5: PRIMES. Please read the PS2 Comments thoroughly! cs3102: Theory of Computation

Actually talking about Turing machines this time

The CYK Algorithm. We present now an algorithm to decide if w L(G), assuming G to be in Chomsky Normal Form.

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

1. Provide two valid strings in the languages described by each of the following regular expressions, with alphabet Σ = {0,1,2}.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Reflection in the Chomsky Hierarchy

CpSc 421 Final Solutions

CT32 COMPUTER NETWORKS DEC 2015

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

Syntax Analysis Part I

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

QUESTION BANK. Unit 1. Introduction to Finite Automata

1. [5 points each] True or False. If the question is currently open, write O or Open.

Parsing III. (Top-down parsing: recursive descent & LL(1) )

Computation Engineering Applied Automata Theory and Logic. Ganesh Gopalakrishnan University of Utah. ^J Springer

AUBER (Models of Computation, Languages and Automata) EXERCISES

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University

A Characterization of the Chomsky Hierarchy by String Turing Machines

programming languages need to be precise a regular expression is one of the following: tokens are the building blocks of programs

To illustrate what is intended the following are three write ups by students. Diagonalization

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

CYK parsing. I love automata theory I love love automata automata theory I love automata love automata theory I love automata theory

More Closure Properties, Algorithms, and the Pumping Lemma. CS154 Chris Pollett Feb 21, 2007.

CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY

CSCI 340: Computational Models. Turing Machines. Department of Computer Science

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

CSC-461 Exam #2 April 16, 2014

CS2210: Compiler Construction Syntax Analysis Syntax Analysis

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

More Simulations. CS154 Chris Pollett Apr 25, 2007.

Lecture Notes on Shift-Reduce Parsing

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

Non-context-Free Languages. CS215, Lecture 5 c

The CKY Parsing Algorithm and PCFGs. COMP-599 Oct 12, 2016

Context-Free Languages and Parse Trees

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

ECS 120 Lesson 16 Turing Machines, Pt. 2

Non-deterministic Finite Automata (NFA)

Computer Science 236 Fall Nov. 11, 2010

Context-Free Grammars

Theory Bridge Exam Example Questions Version of June 6, 2008

Qualifying Exam Theory

Bottom-Up Parsing. Lecture 11-12

Computer Sciences Department

Recursively Enumerable Languages, Turing Machines, and Decidability

Parsing. Cocke Younger Kasami (CYK) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 35

Outline. Language Hierarchy

Theory of Computations Spring 2016 Practice Final Exam Solutions

CMPT 755 Compilers. Anoop Sarkar.

Syntax Analysis. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Bottom-Up Parsing. Lecture 11-12

Syntax Analysis. The Big Picture. The Big Picture. COMP 524: Programming Languages Srinivas Krishnan January 25, 2011

Theory of Computation

CS 314 Principles of Programming Languages. Lecture 3

CS 320 Week 8 Homework Due W 3/27 11:59pm. incm 5 >>= (\x -> incm x >>= (\y -> incm y) )

3. Parsing. Oscar Nierstrasz

Problems, Languages, Machines, Computability, Complexity

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Transcription:

Yet More CFLs; Turing Machines CS154 Chris Pollett Mar 8, 2006.

Outline Algorithms for CFGs Pumping Lemma for CFLs Turing Machines

Introduction to Cocke-Younger- Kasami (CYK) algorithm (1960) This is an O(n 3 ) algorithm to check if a string w is can be generated by a CFG in Chomsky Normal Form. As cubic algorithms tend to be slow, in practice people use algorithms based on restricted types of CFGs with a fixed amount of lookahead. Either top down LL parsing or bottom-up LR parsing. These algorithms are based on the PDA model. There have been improvements to CYK algorithm which reduce the run-time slightly below cubic (n 2.8 ) and to quadratic in the case of an unambiguous grammar.

The CYK algorithm On input w= w 1 w 2 w n : 1. If w = ε and S--> ε is a rule accept. 2. For i = 1 to n: [set up the subtring of length 1 case] 3. For each variable A: 4. Test whether A--> b is a rule, where b=w i 5. If so, place A in table(i,i). 6. For l = 2 to n: [Here l is a length of a substring] 7. For i = 1 to n - l + 1: [i is the start of the substring] 8. Let j = i + l - 1, [j is the end of the substring] 9. For k = i to j-1: [k is a place to split substring] 10. For each rule A-->BC 11. If table(i,k) contains B and table(k+1, j) contains C put A in table(i,j). 12. If S is in table(1,n) accept. Otherwise, reject.

Languages that are not Context Free We can prove languages are not context free by using the Pumping Lemma for context-free languages: Pumping Lemma for Context Free Languages: If A is a context free language, then there is a number p (the pumping length) where, if s is any string A of length at least p, then s maybe divided into five pieces s= uvxyz satisfying the conditions: 1. for each i>=0, uv i xy i z is in A. 2. vy > 0, and 3. vxy <= p.

Example use of the CFL Pumping Lemma Let C = {a i b j c k 0 <= i <=j <= k} Argue by contradiction. Let p be the pumping length of C and consider the string s=a p b p c p. Then s can be written as uvxyz. There are two cases: 1. Both v and y contain only one type of alphabet symbol. So one of a, b, or c does not appear in v or y. So there are three subcases a) The a s do not appear. By the pumping lemma, uv 0 xy 0 z= uxz must be in the language. This string has the same number of a s but fewer b s or c s so cannot be in C giving a contradiction. b) The b s do not appear. Then either a s or c s must appear in v and y. If a s appear, then uv 2 xy 2 z will have more a s then b s giving a contradiction. If c s appear, then uv 0 xy 0 z will have more b s then c s giving a contradiction. c) The c s do not appear. Then uv 2 xy 2 z will have more a s or b s then c s giving a contradiction. 2. When either v or y contain more than one symbol uv 2 xy 2 z will not contain the symbols in the right order giving a contradiction.

Proof of the Pumping Lemma for CFGs. Let G be a CFG for our context free language A. Let V be the number of variables in G. Let b be the maximum number of symbols on the right hand side of a rule. So the maximum number of leaves a parse tree of height d can have is b d. We set the pumping length to p = b V +1. So if s is in A of length bigger than p, its smallest parse tree must be of height greater than V +1. So some variable R must be repeated. So we can do the following kind of surgeries on the parse tree to show condition 1 of the pumping lemma: S RR u v x y z u S R x S z RR R u v x y z Condition 2 of the pumping lemma will hold since if v and y were the empty string then the pumped down tree would be a smaller derivations of s contradicting our choice of parse tree. Condition 3 can be guarenteed by choosing R among the laset V +1 of the longest path in the tree.

General Models of Computation So far we have looked at machines that either have bounded memory or access to memory limited to stack operations. We would like to consider models of computation which correspond to general purpose computers. In 1936, Alan Turing presented such a general model of a computer now called a Turing Machine. In this model, the machine has a finite control and a arbitrarily long tape of data consisting of squares able to hold one symbol. The machine also has a read head which can read one square at a time. Initially, this tape is black except for the n first squares which have the input. The machine in one step is allowed to read what s under its tape head, write a new symbol, move left or right one square and change its state. The machine has special states for accepting or rejecting. The first actual computer developed for code-breaking during World War II was actually based on his model. It turns out this model is actually equivalent to what can be done on modern computers.

Example Let B be the language {w#w w is a string over 0,1} A Turing Machine M that could accept this language might operate as follows: On input w: 1. Zig-zag across the tape to the corresponding positions on either side of the # symbol to check whether these positions contain the same symbol. If they do not, or if no # is found do into the reject state. If they have the same symbol change the symbol to a new symbol X. 2. When all the symbols on the left side of the # have been X d out, check if there are any more symbols to the right of the #. If yes reject; if not accept.