Converting a DFA to a Regular Expression JP

Similar documents
CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

lec3:nondeterministic finite state automata

CSE 105 THEORY OF COMPUTATION

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

6 NFA and Regular Expressions

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Regular Languages and Regular Expressions

Midterm I review. Reading: Chapters 1-4

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

Lexical Analysis. Prof. James L. Frankel Harvard University

Lexical Analysis - 2

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions


CS52 - Assignment 10

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CSE 105 THEORY OF COMPUTATION

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Non-deterministic Finite Automata (NFA)

G52LAC Languages and Computation Lecture 6

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Lexical Analysis. Implementation: Finite Automata

Formal Languages and Automata

CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles

Theory Bridge Exam Example Questions Version of June 6, 2008

(Refer Slide Time: 0:19)

Automating Construction of Lexers

Implementation of Lexical Analysis

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

CS402 - Theory of Automata Glossary By

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

Theory of Computations Spring 2016 Practice Final Exam Solutions

Chapter Seven: Regular Expressions

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

CSE 105 THEORY OF COMPUTATION

Dr. D.M. Akbar Hussain

Ambiguous Grammars and Compactification

COMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Implementation of Lexical Analysis

Lecture 3: Lexical Analysis

Implementation of Lexical Analysis

Computer Sciences Department

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

CS 310: State Transition Diagrams

David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain)

Lexical Analysis. Introduction

Multiple Choice Questions

CSE 105 THEORY OF COMPUTATION

Module 6 Lexical Phase - RE to DFA

CS402 - Theory of Automata FAQs By

CS308 Compiler Principles Lexical Analyzer Li Jiang

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Lexical Analysis. Chapter 2

CS2 Language Processing note 3

Introduction to Lexical Analysis

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.

CIT3130: Theory of Computation. Regular languages

FAdo: Interactive Tools for Learning Formal Computational Models

Implementation of Lexical Analysis. Lecture 4

Figure 2.1: Role of Lexical Analyzer

Learn Smart and Grow with world

8 ε. Figure 1: An NFA-ǫ

Decision Properties of RLs & Automaton Minimization

1 Finite Representations of Languages

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Languages and Compilers

Lecture 4: Syntax Specification

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Finite Automata Part Three

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

CMSC 350: COMPILER DESIGN

LECTURE NOTES THEORY OF COMPUTATION

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Languages and Finite Automata

LECTURE NOTES THEORY OF COMPUTATION

Finite Automata Part Three

LR Parsing. The first L means the input string is processed from left to right.

JNTUWORLD. Code No: R

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Lexical Analysis. Lecture 2-4

Question Bank. 10CS63:Compiler Design

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Theory of Computation, Homework 3 Sample Solution

Regular Languages. Regular Language. Regular Expression. Finite State Machine. Accepts

COMP Logic for Computer Scientists. Lecture 25

A Typed Lambda Calculus for Input Sanitation

CT32 COMPUTER NETWORKS DEC 2015


Transcription:

Converting a DFA to a Regular Expression JP Prerequisite knowledge: Regular Languages Deterministic Finite Automata Nondeterministic Finite Automata Regular Expressions Conversion of Regular Expression to Deterministic Finite Automata Set Theory JFLAP Tutorial In this unit, we will look at the process of converting a DFA into an equivalent RE. Description of DFA RE Conversion Process One approach to converting a DFA into an equivalent RE is to successively replace states and transitions in the DFA graph with transitions labeled with the equivalent regular expressions. Note that initially, every transition in the DFA is de facto labeled with a regular expression. If there are multiple final states, a new final state should be created with an ε-transition from each of the previous final states. For example, consider the following FA with three states. The state q1 can be replaced by a transition labeled with the regular expression ab representing the concatenation of a and b. Next, consider the following FA with two states and two parallel transitions. The two transitions can be replaced with a single transition labeled with the regular expression a+b representing the union of a and b. Now, consider the following FA containing a transition to and from the same state.

That transition indicates the Kleene star over a, which can be represented by regular expression a*. Thus the two transitions can be replaced with a single transition labeled with the regular expression a*b indicating the concatenation of a* with b. Once the FA graph has been reduced to two states (an initial state and a final state) and a single transition, the label on that transition is the regular expression equivalent to the original DFA. Example Consider the following DFA (see: DFA_ab_or_c.jff). Note that because there are multiple final states, this needs to be converted to an NFA by creating a single final state with ε-transition connections from each of the previous final states. Then we can proceed with state removal and transition combination. The following sequence of images depicts the path through the conversion process as provided by JFLAP. 1. First, create the DFA in JFLAP.

2. The conversion process begins by choosing Convert > Convert FA to RE.

Although in general when the Do It button is selected JFLAP performs the indicated operation, here JFLAP instead provides a message that indicates its assumption that you already know how to accomplish the specified task.

3. Manually create the new state.

4. Add each required λ-transition.

5. The next step is to collapse parallel transitions, labeling the resulting transitions with the equivalent regular expressions. Here is the result.

6. The next activity is adding empty transitions between every pair of states that lack an explicit existing transition, including states paired with themselves. As stated in the JFLAP tutorial, this is a necessary step because before the conversion algorithm can work, every state must have a transition to every state in the graph, including itself. 1 Here is the result of having let JFLAP simply Do It. 1 http://www.jflap.org/tutorial/fa/fa2re/index.html

7. Finally, the collapse state tool provides a convenient means to eliminate states by replacing them with transitions labeled with the equivalent regular expression. The end result is shown here.

The resultant regular expression is a(a+b)*+c which is a specification of the language recognized by the original DFA. Questions to Think About 1. How can you convince yourself that this regular expression is equivalent to the original DFA? Answer: The steps of conversion actually constitute a proof. 2. What is another regular expression that is equivalent to a(a+b)*+c? Answer: c+a(a+b)* 3. How might that RE be derived from the same DFA starting point? Answer: Because union is commutative, when collapsing multiple transitions the order of operands is not significant. Thus, the two operands c and a(a+b)* could be combined either as c+a(a+b)* or a(a+b)*+c. References Wikipedia, Regular Expression http://en.wikipedia.org/wiki/regular_expression [13 June 2014; Accessed 17 June 2014]

JFLAP Tutorial, FA to Regular Expression http://www.jflap.org/tutorial/fa/fa2re/index.html [Accessed 1 July 2014]