Transition Diagrams Lecture 3 Fri, Jan 21, 2005.

Slides:



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

Lecture 8 From NFA to Regular Language. Induction on k= # of states other than initial and final states K=0 a a* b a c d c*a(d+bc*a)*
Transparency No. 2-1 Formal Language and Automata Theory Homework 3.
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.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
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.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
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.
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.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
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.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
CS412/413 Introduction to Compilers Radu Rugina Lecture 4: Lexical Analyzers 28 Jan 02.
Converting NFAs to DFAs How a Syntax Analyser is constructed.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
 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.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
Regular Expressions Costas Busch - LSU.
Finite Automata Chapter 1. Automatic Door Example Top View.
Chapter 2 Scanning. Dr.Manal AbdulazizCS463 Ch22 The Scanning Process Lexical analysis or scanning has the task of reading the source program as a file.
1 Chapter Constructing Efficient Finite Automata.
Jianguo Lu : Lab 3 Jan 30, Winter 2004.
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.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
Non Deterministic Automata
Chapter 2 Finite Automata
Theory of Computation Lecture # 9-10.
The time complexity for e-closure(T).
Lecture 9 Theory of AUTOMATA
Recognizer for a Language
Finite Automata & Regular Languages
Review: NFA Definition NFA is non-deterministic in what sense?
Single Final State for NFA
Jaya Krishna, M.Tech, Assistant Professor
Decision Properties of Regular Languages
Regular Expressions Prof. Busch - LSU.
Properties of Regular Languages
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Non-Deterministic Finite Automata
Lexical Analysis Lecture 2 Mon, Jan 17, 2005.
Nondeterministic Finite Automata
Lecture 4: Lexical Analysis II: From REs to DFAs
Animated Conversion of Regular Expressions to C Code
Theory of Computation Lecture #
Finite Automata Reading: Chapter 2.
Converting NFAs to DFAs How Lex is constructed
Finite Automata.
4b Lexical analysis Finite Automata
CSCI 2670 Introduction to Theory of Computing
4b Lexical analysis Finite Automata
Chapter 1 Regular Language
Regular Language Equivalence and DFA Minimization
CSCI 2670 Introduction to Theory of Computing
Part Two : Nondeterministic Finite Automata
Presentation transcript:

Transition Diagrams Lecture 3 Fri, Jan 21, 2005

Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b, c, …, operators, parentheses, and . We describe a recursive method of building a transition diagram from a regular expression.

Building Transition Diagrams The basic cases. For , build :  For each symbol a  , build a: a

Building Transition Diagrams The recursive cases. For the expression r | s, build r | s:  r s

Building Transition Diagrams For the expression rs, build rs: r s  For the expression r*, build r*:  r

Building Transition Diagrams Applying these rules builds an NFA representing the regular expression. Note that each diagram has unique start and accepting states. Note also that generous use was made of -moves. This facilitates joining them together without any complications.

Example: Building a Transition Diagram Build a transition diagram from the regular expression ab*(a | ). Applying the rules rigorously produces the following. a  b

Converting an NFA to a DFA Let Q be the states of the NFA. The -closure of a state q in the NFA is the set of all states that are reachable from q through sequences of -moves (including q itself). Define the states of the DFA to be (Q), i.e., sets of states in the NFA.

Converting an NFA to a DFA For every state A  (Q) and every symbol x  , the transition (A, x) is the -closure of all states in the NFA that are reached from states in A by reading x. That is, First find all states reached from A by following x-moves. Then find the -closure of that set of states.

Example: A DFA from an NFA Consider the NFA of the regular expression ab*(a | ). Number the states 1 through 12. 1 3 4 5 6 8 9 12 10 11 a  b 2 7

Example: A DFA from an NFA Find the -closure of each state. -cl(1) = {1}. -cl(2) = {2, 3, 4, 6, 7, 8, 10, 11, 12}. -cl(3) = {3, 4, 6, 7, 8, 10, 11, 12}. -cl(4) = {4}. -cl(5) = {4, 5, 6, 7, 8, 10, 11, 12}. -cl(6) = {6, 7, 8, 10, 11, 12}. -cl(7) = {7, 8, 10, 11, 12}.

Example: A DFA from an NFA -cl(8) = {8}. -cl(9) = {9, 12}. -cl(10) = {10, 11, 12}. -cl(11) = {11, 12}. -cl(12) = {12}. The start state of the DFA is -cl(1). From there, follow the rule for the transitions of the DFA.

Example: A DFA from an NFA The result is a b 4, 5, 6, 7, 8, 10, 11, 12 2, 3, 6, 7, 8, 10, 11, 12 9, 12 1

Minimizing a DFA To minimize a DFA is to reduce the number of states to a minimum without changing the language accepted by the DFA. Two states p and q are equivalent if for every string w  *, (p, w) and (q, w) are either both accepting states or both rejecting states.

Example: Minimizing a DFA Minimize the DFA of regular expression ab*(a | ). First, add a dead state to make the DFA fully defined. 1 5 2 3 4 a a | b b

Example: Minimizing a DFA The initial partition is {1, 5}, {2, 3, 4}. Apply the transitions by a and b: 1 5 2 3 4 a b a distinguishes 1 from 5, and 2 and 4 from 3. b distinguishes 2 and 4 from 3.

Example: Minimizing a DFA The second partition is {1}, {2, 4}, {3}, {5}. a and b do not distinguish 2 and 4. Therefore, this is the final partition. States 2 and 4 are equivalent and should be merged. Also, remove the dead state.

Example: Minimizing a DFA The minimized DFA is 1 2 3 a b

Programming a DFA There are two basic methods of programming a DFA. Use switch statements. Use a transition table.

Using Switch Statements The main function contains a switch statement whose cases are the different states, including the dead state. Each case contains a switch statement whose cases are the different symbols.

Using a Transition Table The program uses a 2-dimensional array to store the transitions. Rows represent states. Columns represent symbols. The programs lex, flex, and JLex all use the tables.