Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.

Slides:



Advertisements
Similar presentations
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Advertisements

Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CFGs and PDAs Sipser 2 (pages ). Last time…
CS5371 Theory of Computation
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Normal forms for Context-Free Grammars
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Specifying Languages CS 480/680 – Comparative Languages.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
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.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CONVERTING TO CHOMSKY NORMAL FORM
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
Classification of grammars Definition: A grammar G is said to be 1)Right-linear if each production in P is of the form A  xB or A  x where A and B are.
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Grammars CPSC 5135.
Context-free Languages
Lecture # 9 Chap 4: Ambiguous Grammar. 2 Chomsky Hierarchy: Language Classification A grammar G is said to be – Regular if it is right linear where each.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
CS 3240: Languages and Computation Context-Free Languages.
Complexity and Computability Theory I Lecture #9 Instructor: Rina Zviel-Girshin Lea Epstein.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
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.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
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.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Chomsky Normal Form.
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.
1 Context Free Grammars Xiaoyin Wang CS 5363 Spring 2016.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
Context-Free Grammars: an overview
Formal Language & Automata Theory
Context-free Languages
CHAPTER 2 Context-Free Languages
Context-Free Languages
Chapter 2 Context-Free Language - 01
Theory of Computation Lecture #
Context-Free Grammars
Presentation transcript:

Introduction to the Theory of Computation John Paxton Montana State University Summer 2003

Humor A foreign visitor was being given a tour of Washington, D.C. one day by an American friend of hers. She was amazed at the size of the Monuments, the Congressional Buildings, and so forth. Finally she gazed upon the White House itself. "My, that's an incredibly large building!" she remarked. "Yes, it's pretty big, alright." said her friend. "Big? It's huge!! About how many people work in there?" she asked. "Oh... about half."

Chapter 2: Context-Free Languages Applications: Capture most human language syntax, programming language syntax, the parser in a compiler More powerful model of computation

2.1 Context-Free Grammars A grammar consists of –production rules –variables –terminals –a starting variable A => 0A1 | #

Derivation A => 0A1 => 00A11 => 00#11

Parse Tree A 0 A 1 #

Natural Language => => | => => a | the => boy | girl => runs | plays

Context Free Grammar Definition A CFG is a 4-tuple (V, , R, S) where 1.V is a finite set called the variables 2.  is a finite set, disjoint from V, called the terminals 3.R is a finite set of rules, with each rule being a variable and a string of variables and terminals 4.S is the start symbol

Exercise Identify (V, , R, S) for A => 0A1 | # Describe the language

More Definitions uAv yields uwv if A => w is a rule uAv =>* uwv if a sequence of 1 or more steps exist such that A => w The language of the grammer is { w   * | S =>* w }

Another Grammar => + | => x | => ( ) | a Exercise: Parse tree for a + a x a Exercise: Parse tree for (a + a) x a

Exercises Design a context free grammar for the language {0 n 1 n | n >= 0} U {1 n 0 n | n >= 0} Design a context free grammar for the below NFA 1 0 

Exercises Give a CFG that generates the language {w | w contains at least three 1s} over the alphabet {0,1}. Repeat the above question for {w | w contains more 1s than 0s} Repeat the above question for {w | w contains twice as many a’s as b’s} over the alphabet {a, b}

Ambiguity => + | x | a A string w is derived ambiguously in a CFG if it has two or more different leftmost derivations. A CFG is ambiguous if it generates some string ambiguously. Exercise: Show a + a x a is ambiguous.

Chomsky Normal Form All rules are in one of the following forms: 1.S =>  is allowed (S is the start symbol) 2.A => B C (B and C aren’t S) 3.A => a

Theorem Any context-free language is generated by a context-free grammar in Chomsky normal form.

Proof Add new start symbol S 0 Add S 0 => S Eliminate an  rule, adjust other rules. Repeat above step until all  rules eliminated except for possible S 0 =>  Example: A => , B => aAaAa becomes B => aAaAa | aaAa | aAaa

Proof Remove a unit rule A => B. Example: A => B, C => AA becomes C => BB Repeat until all unit rules removed.

Proof Convert all remaining rules into proper form. Example: A => aBcD becomes A => U 1 U 2 U 1 => a U 2 => BU 3 U 3 => U 4 D U 4 => c

Example S => ASA | b |  A => a S 0 => S (add new start rule) S => ASA | b |  A => a

Example S 0 => S |  S => AA | ASA | b (eliminate S =>  ) A => a S 0 => AA | ASA | b |  (eliminate S 0 => S) S => AA | ASA | b A => a

Example S 0 => AA | AU 1 | b |  (change S 0 => ASA) S => AA | AU 1 | b (change S => ASA) A => a U1 => SA

Exercise Convert the following grammar to Chomsky Normal Form: A => BAB | B |  B -> 00 | 