You are on page 1of 10

NSHM KNOWLEDGE CAMPUS, DURGAPUR-

GOI (College Code: 273)


CA1 Assessment

CONVERSION OF REGULAR EXPRESSIONS TO DFA

Presented By

Student Name: DEBASIS GARAI


University Roll No.: 27300121013
University Registration 212730100110040(2021-22)
No.:
Branch: Computer Science Engineering
Year: 3rd
Semester: 5th
Paper Name: Compiler Design
Paper Code: PCC-CS-501
TABLE OF CONTENTS

 What are Regular expressions ?


 Operations on regular expressions
 Examples
 What is deterministic finite automata
 relationship between regular expression and
finite automata
 Steps of conversion
 Example
WHAT ARE REGULAR EXPRESSIONS ?

 Regular Expressions are the expressions that describe the language


accepted by Finite Automata. It is the most efficient way to
represent any language.
 The languages accepted by some regular expressions are referred
to as Regular languages.
 Regular expressions are used to check and match character
combinations in strings. The string searching algorithm uses this
pattern to find the operations on a string.
Operations on regular expressions :

1.) Union :
If R and S are two regular languages, their union R U S is also a Regular Language.
R U S = {a | a is in R or a is in S}

2.) Intersection :
If R and S are two regular languages, their intersection is also a Regular Language.
L ⋂ M = {ab | a is in R and b is in S}

3.) Kleene closure :


If R is a regular language, its Kleene closure R1* will also be a Regular Language.
R* = Zero or more occurrences of language R.
Examples on regular expressions :

Example 1 Example 2
Consider the languages L1 = ∅ and L2 = Which one of the following languages over the alphabet
{x}. Which one of the following {a,b} is described by the regular expression:
represents (a+b)*a(a+b)*a(a+b)*?
L1 L2* U L1*. a.) Set of all strings containing the substring aa.
a.) {ε} b.) Set of all strings containing at least two a’s.
b.) x* c.) Set of all strings that begin and end with either a or b.
c.) ∅ d.) Set of all strings containing at most two a’s
d.) {ε,x} Ans. b.) Set of all strings containing at least two a’s.
Ans. a.) {ε} Explanation: The regular expression has two a′s
Explanation: L1 L2* U L1* Result of L1 surrounded by (a+b)*, which means accepted strings must
L2* is ∅, {∅} indicates an empty language. have at least two a′s. The least possible string is ε a ε a ε =
Concatenation of ∅ with any other language aa The set of strings accepted is = { aa, aaa, baa, aaba, bbbb,
is ∅. aabaa, baabaab,.....}. Thus, we can see from the set of
L1* = ∅* which is {ε}. Union of ∅ and {ε} accepted strings that all have at least two a’s, the least
is {ε}. possible string.
What is Deterministic Finite Automata(DFA) :

 A Deterministic Finite Automaton (DFA) is Components of a DFA:


a mathematical model used to recognize 1.States: The DFA has a finite set of states, each
and accept regular languages. representing a particular condition or
 It is a finite state machine that processes configuration of the machine.
input symbols sequentially and moves 2.Alphabet: The set of input symbols that the
from one state to another based on the DFA recognizes.
current state and the input symbol. 3.Transition Function: A function that maps
 DFAs are "deterministic" because for any each state and input symbol to a unique next
given input symbol and current state, there state. For each state 'q' and input symbol 'a,' the
is only one possible transition to a new transition function δ(q, a) gives the state to which
state. the DFA transitions.
 A DFA consists of a finite set of states, a 4.Start State: The initial state of the DFA from
set of input symbols (the alphabet), a which the machine begins processing the input.
transition function that defines the state 5.Accepting States: A subset of states from the
transitions, a start state, and a set of DFA that represents the final or accepting states.
accepting states.
Relationship between Finite Automata and
Regular Expression:

The relationship between Finite Automata (FA) and Regular Expressions


(RE) can be described in several steps:
1. Using epsilon moves, regular expressions can be transformed into Non-
deterministic Finite Automata (NFA). Without an input symbol, epsilon moves
let you jump from one state to another.
2. The NFA with epsilon moves can be transformed into an equivalent NFA
without epsilon moves. This process involves eliminating the epsilon transitions
by performing the epsilon closure operation and creating new transitions.
3. The NFA can be further transformed into a Deterministic Finite Automata
(DFA) without epsilon stages.
4. Additionally, a DFA can be converted back into a Regular Expression. This
kind of data conversion is possible using methods like state elimination, in
which unnecessary states are gradually eliminated until a regular expression
representation is produced.
Steps to convert RE to
DFA :

Step 1: Design a transition diagram


for given regular expression, using
NFA with ε moves.
Step 2: Convert this NFA with ε to
NFA without ε.
Step 3: Convert the obtained NFA to
equivalent DFA.
Example :
Design a FA from given regular expression 10 + (0 + 11)0* 1.
Solution: First we will construct the transition diagram for a given regular
expression.

Step 1: Step 5:

Step 2 :

Now we have got NFA without ε. Now we will convert it into required DFA for
that, we will first write a transition table for this NFA.

The equivalent DFA will be:

Step 3:
State 0 1
→[q0] [q3] [q1, q2]
[q1] [qf] ϕ
Step 4:
[q2] ϕ [q3]
[q3] [q3] [qf]
[q1, q2] [qf] [qf]
*[qf] ϕ ϕ
THANK
YOU

You might also like