Regular Expressions and DFAs COP 3402 (Summer 2014)

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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 Lecture12: Decidable Languages 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.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
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 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.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
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.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
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.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
REGULAR LANGUAGES.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
By: Er. Sukhwinder kaur.  What is Automata Theory? What is Automata Theory?  Alphabet and Strings Alphabet and Strings  Empty String Empty String 
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
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
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 203: Introduction to Formal Languages and Automata
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
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.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Theory of Computation Automata Theory Dr. Ayman Srour.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Kleene’s Theorem and NFA
Finite automate.
CSE 105 theory of computation
Lexical analysis Finite Automata
Non Deterministic Automata
Regular Expressions.
CSE 105 theory of computation
Chapter 2 FINITE AUTOMATA.
Non-deterministic Finite Automata (NFA)
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
Non Deterministic Automata
NFAs and Transition Graphs
Regular Expressions.
Finite Automata.
4b Lexical analysis Finite Automata
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
4b Lexical analysis Finite Automata
Language Recognition (12.4)
CSE 105 theory of computation
Chapter 1 Regular Language
Lecture 5 Scanning.
Lexical Analysis Uses formalism of Regular Languages
CSE 105 theory of computation
Presentation transcript:

Regular Expressions and DFAs COP 3402 (Summer 2014)

Regular Expression Notation to specify a set of strings

Examples

Exercise 1 Let ∑ be a finite set of symbols ∑ = {10, 11}, ∑* = ?

Answer Answer: ∑* = {є, 10, 11, 1010, 1011, 1110, 1111, …}

Exercises 2 Let ∑={0,1} be a finite set of symbols and let L1 and L2 be sets of strings from ∑*. L1L2 is the set {xy | x is in L1, and y is in L2} L1 = {10, 1}, L2 = {011, 11}, L1L2 = ?

Answer L1L2 = {10011, 1011, 111}

Exercises 3 Write RE for 1. All strings of 0’s and 1’s 2. All strings of 0’s and 1’s with at least 2 consecutive 0’s 3. All strings of 0’s and 1’s beginning with 1 and not having two consecutive 0’s

Answer 1. (0|1)* All strings of 0’s and 1’s 2. (0|1)*00(0|1)* All strings of 0’s and 1’s with at least 2 consecutive 0’s 3. (1|10)+ All strings of 0’s and 1’s beginning with 1 and not having two consecutive 0’s

More Exercises 1) (0|1)*011 2) 0*1*2* 3) 00*11*22*

More Exercises (Answers) 1) (0|1)*011 Answer: all strings of 0’s and 1’s ending in 011 2) 0*1*2* Answer: any number of 0’s followed by any number of 1’s followed by any number of 2’s 3) 00*11*22* Answer: strings in 0*1*2 with at least one of each symbol

Using Regular Expressions Regular expressions are a standard programmer's tool. Built in to Java, Perl, Unix, Python,....

Deterministic Finite Automata (DFA) Simple machine with N states. Begin in start state. Read first input symbol. Move to new state, depending on current state and input symbol. Repeat until last input symbol read. Accept or reject string depending on label of last state.

DFA

Theory of DFAs and REs RE. Concise way to describe a set of strings. DFA. Machine to recognize whether a given string is in a given set. Duality: for any DFA, there exists a regular expression to describe the same set of strings; for any regular expression, there exists a DFA that recognizes the same set.

Duality Example DFA for multiple of 3 b’s: RE for multiple of 3 b’s:

Duality… Practical consequence of duality proof: to match regular expression patterns, (i) build DFA and (ii) simulate DFA on input string.

Fundamental Questions Which languages CANNOT be described by any RE? Set of all bit strings with equal number of 0s and 1s. Set of all decimal strings that represent prime numbers. Many more....

Problem 1 Make a DFA that accepts the strings in the language denoted by regular expression ab*a

Solution ab*a:

Problem 2 Write the RE for the following automata:

Solution a(a|b)*aa*

DFA to RE: State Elimination Eliminates states of the automaton and replaces the edges with regular expressions that includes the behavior of the eliminated states. Eventually we get down to the situation with just a start and final node, and this is easy to express as a RE

State Elimination Consider the figure below, which shows a generic state s about to be eliminated. The labels on all edges are regular expressions. To remove s, we must make labels from each qi to p1 up to pm that include the paths we could have made through s.

DFA to RE via State Elimination (1) Starting with intermediate states and then moving to accepting states, apply the state elimination process to produce an equivalent automaton with regular expression labels on the edges. The result will be a one or two state automaton with a start state and accepting state.

DFA to RE State Elimination (2) If the start state is not an accepting state, we will have an automaton that looks like the following: We can describe this automaton as: (R | SU*T)*SU*

DFA to RE State Elimination (3) If the start state is also an accepting state, then we must also perform a state elimination from the original automaton that gets rid of every state but the start state. This leaves the following: We can describe this automaton as simply R*

DFA to RE State Elimination (4) If there are n accepting states, we must repeat the above steps for each accepting states to get n different regular expressions, R1, R2, … Rn. For each repeat we turn any other accepting state to non-accepting. The desired regular expression for the automaton is then the union of each of the n regular expressions: R1 U R2… U RN

DFA->RE Example Convert the following to a RE: First convert the edges to RE’s:

DFA -> RE Example (2) Eliminate State 1: Note edge from 3->3 Answer: (0|10)*11(0|1)*

Second Example Automata that accepts even number of 1’s Eliminate state 2:

Second Example (2) Two accepting states, turn off state 3 first This is just 0*; we can ignore going to state 3 since we would “die” (can’t come back to an accepting state).

Second Example (3) Turn off state 1 second: This is just 0*10*1(0|10*1)* Combine from previous slide to get 0* | 0*10*1(0|10*1)*

RE -> Automata We can do this easiest by converting a RE to an NFA (Non-deterministic Finite Automata). Beyond the scope of this course…

Questions