Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Similar documents
Minimal Spanning Trees

The Critical-Path Algorithm

Recursive Descent Parsers

Formal Languages and Automata

Rotations and Translations

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Sampling Distribution Examples Sections 15.4, 15.5

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

LR Parsing - Conflicts

Regular Languages. Regular Language. Regular Expression. Finite State Machine. Accepts

The Decreasing-Time Algorithm

The Pairwise-Comparison Method

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Density Curves Sections

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Chapter 4: Regular Expressions

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Solving Recursive Sequences by Iteration

The CYK Parsing Algorithm

LR Parsing - The Items

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Street-Routing Problems

Scheduling and Digraphs

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Chapter Seven: Regular Expressions

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

The Traveling Salesman Problem Brute Force Method

The Normal Distribution

CMPSCI 250: Introduction to Computation. Lecture #36: State Elimination David Mix Barrington 23 April 2014

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Building the Abstract Syntax Trees

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

The Plurality-with-Elimination Method

JNTUWORLD. Code No: R

Scope and Parameter Passing

The Graphics Pipeline

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

The Class Construct Part 1

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Nondeterministic Programming in C++

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Binary Tree Applications

Glynda, the good witch of the North

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Magnification and Minification

Scope and Parameter Passing

Implementing Linked Lists

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Programming Languages

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Finite Automata Part Three

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

The Coefficient of Determination

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Displaying Distributions - Quantitative Variables

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

Recursive Linked Lists

Function Definition Syntax Tree

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Regular Expressions. Regular Expressions. Regular Languages. Specifying Languages. Regular Expressions. Kleene Star Operation

XQuery FLOWR Expressions Lecture 35

Notes for Comp 454 Week 2

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

PHP Queries and HTML Forms Lecture 23

Recognition of Tokens

The Graphics Pipeline

8 ε. Figure 1: An NFA-ǫ

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

Friends and Unary Operators

Dr. D.M. Akbar Hussain

JFlex Regular Expressions

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

The Traveling Salesman Problem Cheapest-Link Algorithm

Introduction to Compiler Design

Regular Languages and Regular Expressions

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

Programming Languages

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

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

Introduction to Databases

The Projection Matrix

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

Welcome! CSC445 Models Of Computation Dr. Lutz Hamel Tyler 251

UNIT I PART A PART B

Compiler Construction

Inheritance: The Fundamental Functions

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

ECS 120 Lesson 7 Regular Expressions, Pt. 1

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Languages and Strings. Chapter 2

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

List Iterator Implementation

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Transcription:

Regular Expressions Lecture 10 Sections 3.1-3.2 Robb T. Koether Hampden-Sydney College Wed, Sep 14, 2016 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 1 / 23

Outline 1 Regular Expressions 2 Equivalence of Regular Expressions and DFAs 3 Assignment Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 2 / 23

Outline 1 Regular Expressions 2 Equivalence of Regular Expressions and DFAs 3 Assignment Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 3 / 23

Regular Expressions Regular expressions are like algebraic expressions except that they describe regular languages. Examples: a a (a (a + b)) (b + a b a) Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 4 / 23

Regular Expressions Definition (Basic regular expressions) The basic regular expressions are The symbols of the alphabet Σ λ Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 5 / 23

Regular Operators Definition (Regular operators) Definition (Regular expression) A regular expression is one of the basic regular expressions or r 1 + r 2 r 1 r 2 (or r 1 r 2 ) r 1 (r 1 ) where r 1 and r 2 are regular expressions. The regular operators are union, concatenation, and star. Regular expressions are defined recursively. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 6 / 23

Language of a Regular Expression Definition (Language of a regular expression) The language of a regular expression is defined as follows. L(a) = {a} for every a Σ. L(λ) = {λ} L( ) = L(r 1 + r 2 ) = L(r 1 ) L(r 2 ) L(r 1 r 2 ) = L(r 1 )L(r 2 ) L(r1 ) = (L(r 1)) L((r 1 )) = L(r 1 ) where r 1 and r 2 are regular expressions. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 7 / 23

Language of a Regular Expression Examples Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 8 / 23

Language of a Regular Expression Examples L(a + b) = L(a) L(b) = {a} {b} = {ab}. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 8 / 23

Language of a Regular Expression Examples L(a + b) = L(a) L(b) = {a} {b} = {ab}. L(a b ) = L(a)L(b ) = {a}{b} = {a}{λ, b, bb, bbb,...} = {a, ab, abb, abbb,...}. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 8 / 23

Examples Example (Regular expressions) Write regular expressions for the following regular languages. All strings ending with a. All strings containing aba. All strings containing aba or bab. All strings containing aba and bab. All strings not containing aaa. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 9 / 23

Outline 1 Regular Expressions 2 Equivalence of Regular Expressions and DFAs 3 Assignment Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 10 / 23

Regular Languages and Regular Expressions Theorem A language is regular if and only if it is the language of some regular expression. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 11 / 23

Regular Languages and Regular Expressions Proof ( ). The basic languages L(a), L(λ), and L( ) are regular. Union, concatenation, and Kleene star of regular languages are regular. Therefore, the language of a regular expression is regular. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 12 / 23

Regular Languages and Regular Expressions Proof ( ), beginning. Let L be a regular language. We need to construct a regular expression r such that L(r) = L. We will use a generalized transition graph (GTG). Definition A generalized transition graph is like a regular transition graph except that the labels are regular expressions. To make a transition from one state to another, we must read a string that matches the regular expression labeling that transition. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 13 / 23

Converting a DFA to a Regular Expression Proof, continued. Begin with a transition diagram for L. Replace each label (symbol) with the equivalent regular expression. Add a new start state that has no transitions into it, but has one λ-move from it to the original start state. Add a new accept state that has no transitions out of it, but has λ-moves into it from all of the original accept states. Remove all states from which the accept state is inaccessible. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 14 / 23

Converting a DFA to a Regular Expression Proof, continued. Note that the number of states in the GTG is at least 3. The proof will reduce the number of states down to 2, at which point we will have the regular expression. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 15 / 23

Converting a DFA to a Regular Expression Proof, continued. Choose a non-initial, non-final state q to be removed. For every state p with a transition into q and for every state r with a transition from q, create a transition from p to r, as follows. Let r 1 be the label on the transition p q. r 2 be the label on a loop q q, if there is one. r 3 be the label on the transition from q r. Apply the label r 1 r 2 r 3 to the new transition. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 16 / 23

Converting a DFA to a Regular Expression Proof, concluded. After doing this for every combination of transitions into q and out of q, remove state q and all of its transitions. Repeat this process until only the initial and final states remain. The label on that single remaining transition is the regular expression. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 17 / 23

Example Example (Converting a DFA to a regular expression) Find a regular expression for the language L = {w w has an even number of a s}. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 18 / 23

Example Example (Converting a DFA to a regular expression) b 1 a a b 2 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 19 / 23

Example Example (Converting a DFA to a regular expression) b b 0 λ 1 a a 2 λ 3 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 19 / 23

Example Example (Converting a DFA to a regular expression) b 0 λ 1 ab * a λ 3 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 19 / 23

Example Example (Converting a DFA to a regular expression) b + ab * a 0 λ 1 λ 3 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 19 / 23

Example Example (Converting a DFA to a regular expression) 0 λ(b + ab * a) * λ 3 Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 19 / 23

Example Example (Converting a DFA to a regular expression) Therefore, L((b + ab a) ) = {w w has an even number of a s}. This regular expression parses the string babbaababbbaab as b abba aba b b b aa b. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 20 / 23

Example Example (Converting a DFA to a regular expression) Find regular expressions for the following languages All strings containing an odd number of a s. All strings containing an even number of a s and an even number of b s. All strings that do not contain aaa. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 21 / 23

Outline 1 Regular Expressions 2 Equivalence of Regular Expressions and DFAs 3 Assignment Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 22 / 23

Assignment Assignment p. 78: 3, 5, 11, 21, 22, 26, 27. p. 90: 1, 7, 10, 12b, 15ac. Write a regular expression that will match <b>any text</b>, where any text does not include the string </b>. Robb T. Koether (Hampden-Sydney College) Regular Expressions Wed, Sep 14, 2016 23 / 23