Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.

Slides:



Advertisements
Similar presentations
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Advertisements

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
1 Regular Expressions Highlights: –A regular expression is used to specify a language, and it does so precisely. –Regular expressions are very intuitive.
Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Fall 2006Costas Busch - RPI1 Regular Expressions.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
1 Non-Deterministic Automata Regular Expressions.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
1 Regular Expressions Definitions Equivalence to Finite Automata.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Lesson No.6 Naveen Z Quazilbash. Overview Attendance and lesson plan sharing Assignments Quiz (10 mins.). Some basic ideas about this course Regular Expressions.
CHAPTER 1 Regular Languages
January 9, 2015CS21 Lecture 31 CS21 Decidability and Tractability Lecture 3 January 9, 2015.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Finite Automata Chapter 1. Automatic Door Example Top View.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Scribing K SAMPATH KUMAR 11CS10022 scribing. Definition of a Regular Expression R is a regular expression if it is: 1.a for some a in the alphabet ,
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
1 Introduction to the Theory of Computation Regular Expressions.
Deterministic Finite Automata Nondeterministic Finite Automata.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
CSE 105 theory of computation
Nondeterministic Finite Automata
Single Final State for NFA
REGULAR LANGUAGES AND REGULAR GRAMMARS
COSC 3340: Introduction to Theory of Computation
Definitions Equivalence to Finite Automata
Finite Automata Reading: Chapter 2.
Definitions Equivalence to Finite Automata
Chapter Five: Nondeterministic Finite Automata
CSCI 2670 Introduction to Theory of Computing
CS21 Decidability and Tractability
Instructor: Aaron Roth
Definitions Equivalence to Finite Automata
Chapter 1 Regular Language
CHAPTER 1 Regular Languages
Presentation transcript:

Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3

Machines versus expressions Finite automata are machine-like descriptions of languages Alternative: declarative description Specifying a language using expressions and operations Example: 01* + 10* defines the language containing strings such as 01111, 100, 0, ; * and + are operators in this “algebra”

Regular expressions defined The simplest regular expressions are The empty set Φ The empty string  A symbol a from an alphabet Given that R 1 and R 2 are regular expressions, regular expressions are built from the following operations Union: R 1 +R 2 Concatenation: R 1 R 2 Closure: R 1 * Parentheses (to enforce precedence): (R 1 ) Nothing else is a regular expression unless it is built from the above rules

Examples 1 +  (ab)* + (ba)* ( )*(0+5) (x+y)*x(x+y)* (01)* 0(1*) 01* equivalent to 0(1*)

Equivalence between regular expressions and finite automata Strategy: Convert regular expression to an  -NFA Convert a DFA to a regular expression

Regular Expression to  -NFA Recursive construction Base cases follow base case definitions of regular expressions  :  -NFA that accepts the empty string – a single state that is the start and end state a:  -NFA that accepts {a} – two-state machine (start and final state) with an a-transition Note: technically, we also need an  -NFA for the empty language {} – easy

Regular Expression to  -NFA Recursive step: build  -NFA from smaller  - NFAs that correspond to the operand regular expressions To simplify construction, we may ensure the following characteristics for the automata we build Only one final state, with no outgoing transitions No transitions into the start state Note: the base cases satisfy these characteristics

Regular Expression to  -NFA Suppose  -NFA 1 and  -NFA 2 are the automata for R 1 and R 2 Three operations to worry about: union R 1 + R 2, concatenation R 1 R2), closure R 1 * With  -transitions, construction is straightforward Union: create a new start state, with  -transitions into the start states of  -NFA 1 and  -NFA 2 ; create a new final state, with  -transitions from the two final states of  -NFA 1 and  - NFA 2 Concatenation:  -transition from final state of  -NFA 1 to the start state of  -NFA 2 Closure: closure can be supported by an  -transition from final to start state; need a few more  -transitions (why?)

DFA to Regular Expression More difficult construction Build the regular expression “bottom up” starting with simpler strings that are acceptable using a subset of states in the DFA Define R k i,j as the expression for strings that have an admissible state sequence from state i to state j with no intermediate states greater than k Assume no states are numbered 0, but k can be 0

R 0 i,j Observe that R 0 i,j describes strings of length 1 or 0: {a 1, a 2, a 3, … }, where, for each a x,  (i,a x ) = j Add  to the set if i = j R 0 i,j is the union (+) of applicable symbols in Σ (and perhaps  ) The 0 in R 0 i,j means no intermediate states are allowed, so either no transition is made (just stay in state i to accept  if i = j) or make a single transition from state i to state j These are the base cases in our construction

R k i,j Recursive step: for each k, we can build R k i,j as follows: R k i,j = R k-1 i,j + R k-1 i,k (R k-1 k,k )* R k-1 k,j Intuition: since the accepting sequence contains one or more visits to state k, break the path into pieces that first goes from i to its first k-visit (R k-1 i,k ) followed by zero or more revisits to k (R k-1 k,k ) followed by a path from k to j (R k-1 k,j )

And finally… We get the regular expression(s) that represent all strings with admissible sequences that start with the initial state (state 1) and end with a final state Resulting regular expression built from the DFA: the union of all R n 1,f where f is a final state Note: n is the number of states in the DFA meaning there are no more restrictions for intermediate states in the accepting sequence

Example 3 12 a a a,b b b Describes strings with at least 2 b’s

3 12 a a a,b b b i \ j123 1  + a bΦ 2Φ b 3ΦΦ  + a + b R 0 i,j

3 12 a a a,b b b i \ j123 1a*a*bΦ 2Φ  + a b 3ΦΦ  + a + b R 1 i,j

3 12 a a a,b b b i \ j123 1a*a*ba*a*ba*b 2Φa*a*b 3ΦΦ  + a + b R 2 i,j

3 12 a a a,b b b i \ j123 1a*a*ba*a*ba*b(a+b)* 2Φa*a*b(a+b)* 3ΦΦ(a+b)* R 3 i,j

3 12 a a a,b b b i \ j123 1a*a*ba*a*ba*b(a+b)* 2Φa*a*b(a+b)* 3ΦΦ(a+b)* Final answer: R 3 1,3