kleene s theorem
play

Kleenes theorem 1) For any regular expression r that represents - PDF document

Kleenes theorem 1) For any regular expression r that represents language L(r), there is a finite automaton that accepts that same CS 3813: Introduction to Formal Languages language. and Automata 2) For any finite automaton M that accepts


  1. Kleene’s theorem 1) For any regular expression r that represents language L(r), there is a finite automaton that accepts that same CS 3813: Introduction to Formal Languages language. and Automata 2) For any finite automaton M that accepts language L(M), there is a regular expression that represents the same language. Regular expressions and regular languages Sec 3.2 Therefore, the class of languages that can be represented by regular expressions is equivalent to the class of languages accepted by finite automata -- the regular languages . Proof of 1st half of Kleene’s theorem Kleene’s theorem part 1 Proof strategy: for any regular expression, we show how to construct an equivalent NFA. NFA regular expression Because regular expressions are defined recursively, obvious the proof is by induction. subset Kleene’s construction DFA Theorem part 2 Base step: Give a NFA that accepts each of the simple Inductive step: For each of the operations -- union, or “base” languages, ∅ , { λ }, and {a} for each a ∈ Σ . concatenation and Kleene star -- show how to construct an accepting NFA. Closure under union: M 1 λ λ λ M 2 λ a 1

  2. Exercise Closure under concatenation: Use the construction of the first half of Kleene’s M 1 M 2 λ theorem to construct a NFA that accepts the language L(ab*aa + bba*ab). Closure under Kleene Star: λ λ M 1 λ λ Exercise Kleene’s theorem part 2 Construct a NFA that accepts the language Any language accepted by a finite automaton can corresponding to the regular expression: be represented by a regular expression. ((b(a+b)*a) + a) The proof strategy: For any DFA, we show how create an equivalent regular expression. In other words, we describe an algorithm for converting any DFA to a regular expression. Algorithm for converting a DFA into an Generalized transition graph equivalent regular expression • A labeled directed graph (similar to a finite state Initial step: Change every transition labeled a,b to (a+b). diagram) in which transitions are labeled by regular Add single start state with outgoing λ -transition to current expressions start state, and add single final state with incoming • Has a single start state with no incoming transitions λ -transitions from every previous final state. • Has a single accepting state with no outgoing transitions Main step: Until expression diagram has only two states • Example: ab (initial state and final state), repeat the following: -- pick some non-start, non-final state (a+b) a* -- remove it from diagram and re-label transitions with regular expressions so that the same language is accepted 2

  3. The key step is removing states and re-labeling transitions with regular expressions. Here are Exercise some examples of how to do this. b a,b a a (a+b) a a ab*a λ λ b b b ab*a a b ab*b Continue ... a b ab*b b a ab*a a Exercise Exercise Find a regular expression that corresponds to the Find a regular expression that corresponds to the language accepted by the following DFA. language accepted by the following DFA. 0 q 0 q 1 a b 0 a 1 1 q 2 b 1 0 Applications of regular expressions Alternative definition of regular languages • Validation – checking that an input string is in valid format The simplest possible regular languages are the empty set – example 1: checking format of email address on and languages consisting of a single string that is either WWW entry form the empty string or has length one. For example; if – example 2: UNIX regex command Σ = {a,b}, the simplest languages are ∅ , {e}, {a}, and {b}. • Search and selection – looking for strings that match a certain pattern A regular language is a language that can be built from – example: UNIX grep command these simple languages, by using the three operations • Tokenization of union, concatenation, and Kleene star. – converting sequence of characters (a string) into sequence of tokens (e..g, keywords, identifiers) – used in lexical analysis phase of compiler 3

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend