You are on page 1of 10

School of Engineering & Computer Science

Independent University, Bangladesh (IUB)

Lecture 04
Regular Expressions to NFA

M Ashraful Amin, PhD


Three ways of doing it

L = {x *: x ends in 01}  = {0, 1}

q
q
0, 1

0
1
0

q
q

q (0+1)*01

0
0

1
1

1
0

q

q
q

q

1
0

q
0
1

regular
0

NFA DFA expression


They are all the same

regular
DFA NFA
expression

regular languages
Road map

NFA NFA
without 
regular DFA
expression
Examples: regular expression → NFA

q0 0 q1
R1 = 0

0 1
R2 = 01 q0 q1 q2
Examples: regular expression → NFA

0 NFA3
q1 q2
 
R3 = 0 + 01 q0 q6
 q3 0 q4 1 q5 



R4 = (0 + 01)* q0’  NFA3  q1’
Regular expressions

In general, how do we convert a regular


expression to an NFA?

• A regular expression over  is an expression formed


using the following rules:
– The symbols  and  are regular expressions
– Every a in  is a regular expression
– If R and S are regular expressions, so are R+S, RS and R*.
General method
regular expr NFA

 q0

 q0

a q0 a q1

RS q0  NFAR  NFAS  q1
General method continued
regular expr NFA

NFAR 

R+S q0 q1
 
NFAS



R* q0  NFAR  q1
Road map


regular NFA
expression

You might also like