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.

Slides:



Advertisements
Similar presentations
Reducing DFA’s Section 2.4. Reduction of DFA For any language, there are many DFA’s that accept the language Why would we want to find the smallest? Algorithm:
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.
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.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
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.
CS5371 Theory of Computation
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.
Regular Expression to NFA-  (a+ba) * a. First Parsing Step concatenate (a+ba) * a.
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)
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?”
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.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
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)
Review for final pm. 2 Review for Midterm Induction – On integer: HW1, Ex 2.2.9b p54 – On length of string: Ex p53, HW2, HW3.
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 ::=
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 Constructing Efficient 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.
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.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Compilers Lexical Analysis 1. while (y < z) { int x = a + b; y += x; } 2.
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
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
Presentation transcript:

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 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. Example. Given the following NFA as a graph and as a transition table. S b b  a  a 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}.

2 Algorithm: Transform an NFA into a DFA Construct a DFA table T D from an NFA table T N 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. Example. Given the following NFA. The algorithm constructs the following DFA transition table T D, where it is also written in simplified form after a renumbering of the states. S b b a  a 2 b

3 Quiz. Use the algorithm to transform the following NFA into a DFA. S 0 1 a a  b 2 3 a 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.

4 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. 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.

5 Example. Use the algorithm to transform the following DFA into a minimum-state DFA. S 0 a b a 2 a, b b 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. Min-state TableRenamed Table S 0 a b a, b 2 1 Min-state DFA graph Quiz: What regular expression equality arises from the two DFAs? Answer: a + aa + (aaa + aab + ab)(a + b)* = a(a + b)*.

6 Quiz. Is the following DFA a minimum-state DFA? S b 0 1 a a b S a, b 0 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. 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. E 0 = {{0, 1}} E 1 = {{0, 1}} = E 0. 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. Answer. No. Use the minimum-state algorithm. Quiz. Is the following DFA a minimum-state DFA?