1 Chapter 11 - 3 Constructing Efficient Finite Automata.

Slides:



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

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Transparency No. 2-1 Formal Language and Automata Theory Homework 3.
Finite Automata CPSC 388 Ellen Walker Hiram College.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
YES-NO machines Finite State Automata as language recognizers.
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
©2004 Brooks/Cole FIGURES FOR CHAPTER 2 SCANNING Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter in the book.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Fall 2006Costas Busch - RPI1 Regular Expressions.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
Homework #2 Solutions.
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.
CS 310 – Fall 2006 Pacific University CS310 Decidability Section 4.1/4.2 November 10, 2006.
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.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Non-Deterministic Automata Regular Expressions.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
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.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
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.
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)
CSCI 2670 Introduction to Theory of Computing August 24, 2005.
CS-5800 Theory of Computation II PROJECT PRESENTATION By Quincy Campbell & Sandeep Ravikanti.
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.
1 Chapter Regular Language Topics. 2 Section 11.4 Regular Language Topics Regular languages are also characterized by special grammars called regular.
Lexical Analysis Constructing a Scanner from Regular Expressions.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
CS412/413 Introduction to Compilers Radu Rugina Lecture 4: Lexical Analyzers 28 Jan 02.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Regular Expressions Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
 Regular Grammar and Regular Language [Def 3.1] Regular Grammar(use to in lexical analysis) Type 3 grammar(regular grammar, RG) Type 3 grammar(regular.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
Section 11.4 Regular Language Topics
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Finite Automata Chapter 1. Automatic Door Example Top View.
Regular Language Algorithms. Algorithms We have seen many algorithms for manipulating computational systems for the regular languages. Each treats these.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Recap: Transformation NFA  DFA  s s1s1... snsn p1p1 p2p2... pmpm >...  p1p1  p2p2  pipi s e s1s1 e s2s2 e sisi >
1 Chapter Regular Languages. 2 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet.
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.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
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.
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:
1 Section 11.3 Constructing Efficient Finite Automata First we’ll see how to transform an NFA into a DFA. Then we’ll see how to transform a DFA into a.
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-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
Foundations of Computing Science
PROPERTIES OF REGULAR LANGUAGES
Copyright © Cengage Learning. All rights reserved.
Two issues in lexical analysis
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Jaya Krishna, M.Tech, Assistant Professor
REGULAR LANGUAGES AND REGULAR GRAMMARS
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
Nondeterministic Finite Automata
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
Finite Automata.
Chapter 1 Regular Language - 02
Chapter 1 Regular Language
Presentation transcript:

1 Chapter Constructing Efficient Finite Automata

2 Section 11.3 Constructing Efficient Finite Automata First we’ll see how to transform an NFA into a DFA. Then we’ll see how to transform a DFA into a minimum-state DFA. Transforming an NFA into a DFA The λ -closure of a state s, denoted λ (s), is the set consisting of s together with all states that can be reached from s by traversing λ -edges. The λ -closure of a set S of states, denoted λ (S), is the union of the λ -closures of the states in S.

3 Example Given the following NFA as a graph and as a transition table. Some sample λ -closures for the NFA are as follows: λ (0) = {0, 1, 2} λ (1) = {1, 2} λ (2) = {2} λ ( Ф ) = Ф λ ({1, 2}) = {1, 2} λ ({0, 1, 2}) = {0, 1, 2}.

4 Algorithm: Transform an NFA into a DFA Construct a DFA table TD from an NFA table TN as follows: 1. The start state of the DFA is λ (s), where s is the start state of the NFA. 2. If {s 1, …, s n } is a DFA state and a ∈ A, then T D ({s 1, …, s n }, a) = λ (T N (s 1, a) ⋃ … ⋃ T N (s n, a)). 3. A DFA state is final if one of its elements is an NFA final state.

5 Example Given the following NFA

6 Solution The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states

7 Quiz Use the algorithm to transform the following NFA into a DFA

8 Solution The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states.

9 Transforming an DFA into a minimum-state DFA Let S be the set of states that can be reached from the start state of a DFA over A. For states s, t ∈ S let s ~ t mean that for all strings w ∈ A* either T(s, w) and T(t, w) are both final or both nonfinal. Observe that ~ is an equivalence relation on S. So it partitions S into equivalence classes. Observe also that the number of equivalence classes is the minimum number of states needed by a DFA to recognize the language of the given DFA.

10 Algorithm Transform a DFA to a minimum-state DFA 1. Construct the following sequence of sets of possible equivalent pairs of distinct states: E 0 ⊃ E 1 ⊃ … ⊃ E k = E k+1, where E 0 = {{s, t} | s and t are either both final or both nonfinal} and E i+1 = {{s, t} ∈ E i | {T(s, a), T(t, a)} ∈ E i or T(s, a) = T(t, a)} for every a ∈ A}. E k represents the distinct pairs of equivalent states from which ~ can be generated. 2. The equivalence classes form the states of the minimum state DFA with transition table T min defined by T min ([s], a) = [T(s, a)]. 3. The start state is the class containing the start state of the given DFA. 4. A final state is any class containing a final state of the given DFA.

11 Example Use the algorithm to transform the following DFA into a minimum-state DFA.

12 Solution The set of states is S = {0, 1, 2, 3, 4}. To find the equivalent states calculate: E 0 = {{0, 4}, {1, 2}, {1, 3}, {2, 3}} E 1 = {{1, 2}, {1, 3}, {2, 3}} E 2 = {{1, 2}, {1, 3}, {2, 3}} = E 1. So 1 ~ 2, 1 ~ 3, 2 ~ 3. This tells us that S is partitioned by {0}, {1, 2, 3}, {4}, which we name [0], [1], [4], respectively. So the minimum-state DFA has three states.

13 Quiz What regular expression equality arises from the two DFAs? Answer: a + aa + (aaa + aab + ab)(a + b)* = a(a + b)*

14 Quiz Is the following DFA a minimum-state DFA? Answer. No. Use the minimum-state algorithm

15 The partition So 0 ~ 1, which tells us that the partition is the whole set of states {0, 1} = [0]. Therefore, we obtain the following minimum-state DFA

16 Quiz Is the following DFA a minimum-state DFA? Answer: No. E 0 = {{0, 1}, {0, 5}, {1, 5}, {2, 3}, {2, 4}, {3, 4}} E 1 = {{1, 5}, {2, 4}} E 2 = {{1, 5}, {2, 4}} = E 1.

17 The DFA So 1 ~ 5 and 2 ~ 4. This gives us {0}, {1, 5}, {2, 4}, {3}, with names [0], [1], [2], [3], respectively with the following minimum- state DFA.

18 The End of Chapter