CS 3240 – Chapter 3.  How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the.

Slides:



Advertisements
Similar presentations
Theory Of Automata By Dr. MM Alam
Advertisements

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Lecture 9,10 Theory of AUTOMATA
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Regular Grammars Formal definition of a regular expression.
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.
Cohen, Chapter 61 Introduction to Computational Theory Chapter 6.
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.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
1 NFAs accept the Regular Languages. 2 Equivalence of Machines Definition: Machine is equivalent to machine if.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
1 Reverse of a Regular Language. 2 Theorem: The reverse of a regular language is a regular language Proof idea: Construct NFA that accepts : invert the.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
CS 3240 – Chuck Allison.  A model of computation  A very simple, manual computer (we draw pictures!)  Our machines: automata  1) Finite automata (“finite-state.
Lecture 5UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Regular Expressions and Finite State Automata  Themes  Finite State Automata (FSA)  Describing patterns with graphs  Programs that keep track of state.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Grammars CPSC 5135.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
Regular Expressions Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators.
CS 3240 – Chapter 11.  They may not halt on every possible input!  And not just because the creator of a specific TM was a doofus  This is related.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
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.
Kleene’s Theorem Group No. 3 Presented To Mam Amina Presented By Roll No Roll No Roll No Roll No Group No. 3 Presented To Mam.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
CS 3240 – Chapter 5. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
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.
Brian Mitchell - Drexel University MCS680-FCS 1 Patterns, Automata & Regular Expressions int MSTWeight(int graph[][], int size)
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 3813: Introduction to Formal Languages and Automata
CS 203: Introduction to Formal Languages and Automata
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
Finite Automata & Regular Languages Sipser, Chapter 1.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Conversions Regular Expression to FA FA to Regular Expression.
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:
 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.
1 Introduction to the Theory of Computation Regular Expressions.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Deterministic Finite Automata Nondeterministic Finite Automata.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
Lecture # 8 (Transition Graphs). Example Consider the language L of strings, defined over Σ={a, b}, having (containing) triple a or triple b. Consider.
CS314 – Section 5 Recitation 2
Kleene’s Theorem and NFA
Theory of Computation Lecture #
Complexity and Computability Theory I
REGULAR LANGUAGES AND REGULAR GRAMMARS
NFAs and Transition Graphs
NFAs and Transition Graphs
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
COSC 3340: Introduction to Theory of Computation
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

CS 3240 – Chapter 3

 How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the letter a?  PowerPoint file names that contain the string 3240? 2CS Regular Languages and Grammars

 *.cpp  a*.ppt  *3240*.ppt  These are wildcard expressions  Not bona fide regular expressions 3CS Regular Languages and Grammars

LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar Recursively Enumerable Turing MachineUnrestricted Phrase- Structure Grammar 4CS Introduction

 Text patterns that represent regular languages  We’ll show shortly that for every regular expression there is a finite automaton that accepts that language  And vice-versa  The operators are:  ( ) (Grouping)  * (Kleene Star)  + (Union)  xy(Concatenation) 5CS Regular Languages and Grammars

 1) Specify base case(s)  2) Show how to generate other elements  Rules that use what’s in the set already  Example: Non-negative multiples of 5, F  1) 0, 5 is in F  2) For x, y in F, then x + y is in F  Alternate definition:  1) 0 is in F  2) For x in F, so is x + 5 CS Regular Languages and Grammars6

 Base cases:  The empty set: ∅ or ( )  The empty string: λ  Any letter in Σ  Recursive rules: Given regular expressions r, r 1, r 2 :  (r)(Grouping)  r * (Kleene Star)  r 1 + r 2 (Union)  r 1 r 2 (Concatenation) 7CS Regular Languages and Grammars

 All strings beginning with a:  a(a + b) *  All strings containing aba:  (a + b) * aba(a + b) *  All strings of even length:  ((a + b)(a + b)) * = (aa + ba + ab + bb) * = ((a + b) 2 ) *  All strings of odd length:  (a+b)((a + b) 2 ) *  Valid decimal integers in C:  ( )( ) * 8CS Regular Languages and Grammars

 Put anything you want on an edge  Use an “else” branch as well  [0-9] (if-branch)  ~[0-9] or [^(0-9)] or else CS Regular Languages and Grammars9 (Decimal integers)

 (b * ab * ab * ab * + b) *  = b * (ab * ab * ab * ) *  = b * + (b * ab * ab * ab * ) *  (a(a+bb) * ) *  ((a + b)a) * 10CS Regular Languages and Grammars

 L( ∅ ) = ∅  L(λ) = λ  L(c) = c, for c ∊ Σ  L((r)) = L(r)  L(r * ) = L(r) *  L(r 1 + r 2 ) = L(r 1 ) ∪ L(r 2 )  L(r 1 r 2 ) = L(r 1 )L(r 2 ) 11CS Regular Languages and Grammars

12  r+s = s+r  (r+s)+t = r+(s+t)  r+r = r  r + ∅ = r  (rs)t = r(st)  rλ = λr = r  r ∅ = ∅ r = ∅  r(s+t) = rs+rt  (r+s)t = rt+st

1. For every regular expression there is an associated NFA that accepts the same language  And therefore a DFA, by conversion 2. For every FA (either NFA or DFA) there is a regular expression that represents the same language 13CS Regular Languages and Grammars

 We will show how to convert each element of the definition of regular expressions to an NFA  This is sufficient!  And shows the convenience of recursive definitions (review slide 7 now)  because if we can give a machine for every case in the definition of REs, we are done! 14CS Regular Languages and Grammars

Empty Language Empty String Single Character 15CS Regular Languages and Grammars

16CS Regular Languages and Grammars

 Just draw the lambdas from a new start state to the start states of each machine  Remove the start notation from the original start states  (No need to have a new final state) CS Regular Languages and Grammars17

18CS Regular Languages and Grammars

 1) Just draw a lambda from each final state of the first machine to the start state of the second machine  2) remove the acceptability of those final states of the first machine CS Regular Languages and Grammars19

20CS Regular Languages and Grammars

 We need to do two things:  1) Add the empty string, if needed  2) Loop from each final state back to the start state  Procedure:  1) If the empty string is not accepted, create a new start state which accepts, and connect to the original start state with λ  2) Add a λ-edge from each final state to the original (or the new) start state CS Regular Languages and Grammars21

 Draw NFAs for the REs on slides 8 and 9 CS Regular Languages and Grammars22

 First remove all jails  Then, if needed, convert the DFA to an equivalent NFA with  A start state with no incoming edges  A single final state with no outgoing edges  Will need lambda transitions for this  Then “eliminate” all but the start and final states  Without changing the language accepted  Using GTGs… 23CS Regular Languages and Grammars

 Allow regular expressions on the edges Accepts a * + a * (a+b)c * [Note: (c * ) * = c * ] 24CS Regular Languages and Grammars

 If the start state has an incoming edge (even if it’s a loop), create a new start state with a lambda transition to the old start state: CS Regular Languages and Grammars25

 If there is more than one final state, or if the single final state has an outgoing edge (even if it’s a loop), create a new final state and link to it with a lambda transition from each final state: CS Regular Languages and Grammars26

 “Remove” each intermediate state, one at a time: 1. Combine each incoming path with each outgoing path (only “through” paths; not loops) 2. Determine the regular expression equivalent to the combined path through the current state 3. Add an edge with that RE between the incoming state and the outgoing state 4. Repeat until all intermediate states vanish CS Regular Languages and Grammars27

CS Regular Languages and Grammars28

CS Regular Languages and Grammars29 To eliminate 2: 1-2-1: af * b 1-2-3: af * c 3-2-1: df * b 3-2-3: df * c

CS Regular Languages and Grammars30 To eliminate 1: 0-1-3: (e+af * b) * (h+af * c) 3-1-3: (i+df * b)(e+af * b) * (h+af * c)

CS Regular Languages and Grammars31 Eliminate 3 (Final Result): (e+af * b) * (h+af * c)(g+df * c+(i+df * b)(e+af * b) * (h+af * c)) *

CS Regular Languages and Grammars32

 Find a regular expression for the language containing all strings that do not contain the substring aa CS Regular Languages and Grammars33

 See bypass.docbypass.doc  Shows different possibilities by eliminating states in different orders  But the REs obtained are equivalent ▪ Meaning they represent the same language CS Regular Languages and Grammars34

LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar Recursively Enumerable Turing MachineUnrestricted Phrase- Structure Grammar 35CS Introduction

 There is a natural correspondence between FAs and grammars  Right-linear Grammars  “Linear” means there is at most one variable on the right-hand side of the rule  “Right-linear” means the variable occurs as the last entry in the rule: ▪ A → abC CS Regular Languages and Grammars36

 The variables represent states  The right-hand side contains the character(s) on the edge, optionally followed by the target state  The accepting states have a lambda rule CS Regular Languages and Grammars37 A → aB | bC | λ B → aA | bD C → aD | bA D → aC | bB

 Go to an accepting state with no out-edges CS Regular Languages and Grammars38 A → b

 S → aaS | bbS | abA | baA | λ  A → aaA | bbA | abS | baS CS Regular Languages and Grammars39 a GTG

 Construct a regular grammar for the language denoted by aab * a 1. First build a GTG 2. Then map to a right-linear grammar CS Regular Languages and Grammars40

 S → Xa  X → Xb | aa  How did I come up with this? CS Regular Languages and Grammars41

 If you have the single variable only at the left ends, you have a left-linear grammar  This is also a regular grammar  We will show how to convert between right- linear and left-linear grammars  We will use two facts to establish the process:  If L is regular, so is L R (Section 2.3, exercise 12)  L(G R ) = L(G) R (obvious, but on next slide…) CS Regular Languages and Grammars42

 G R means you reverse the right-hand sides of each rule in a grammar, G  The language generated is L(G) R (the reverse of L(G)) CS Regular Languages and Grammars43 S → abS | X X → bX | λ (ab) * b * S → Sba | X X → Xb | λ b * (ba) *

1. Convert the right-linear grammar to a GTG 2. “Reverse” the GTG (a la Section 2.3, #12)  Ensure a single final state (use λ if needed)  Interchange the role of the start and final states  Reverse all arrows 3. Convert the reversed GTG to a right-linear grammar 4. Reverse the right-hand sides of each rule to obtain the left-linear grammar CS Regular Languages and Grammars44

CS Regular Languages and Grammars45 A → aB B → abA | b C → bB B → aA A → baB | λ ba(baa) * C → Bb B → Aa A → Bab | λ (aab) * ab (rev)

 Reverse the grammar, G, obtaining right- linear grammar, G R, for L(G) R  Convert to GTG  Reverse the GTG  Convert to Right-linear CS Regular Languages and Grammars46

CS Regular Languages and Grammars47