Regular Expression
Regular Expression
L={baaa,babaa,bababab,ababab,…..}
R=(b*.a.b*.a.b*.a.b*)*
• Write r.e to denote a language L which accepts
all the strings which begin or end with either
00 or 11.
Solution:
The r.e can be categorized into two subparts.
R=L1+L2
L1= The strings which begin with 00 or 11.
L2= The strings which end with 00 or 11.
Let us find out L1 and L2:
L1=(00+11)(any number of 0’s and 1’s)
L1=(00+11)(0+1)*
• Similarly,
L2=(any number of 0’s and 1’s)(00+11)
L2=(0+1)*(00+11)
Hence
R=[(00+11)(0+1)*]+[(0+1)*(00+11)]
EQUIVALENCE
• L can be represented by a regexp
• ⇔
• L is a regular language
R=ε ε
(matches the empty string)
R=∅
(matches nothing)
THOMPSON’S CONSTRUCTION
Inductive Step:
Assume R has length k > 1 and that any regular
expression of length < k represents a language
that can be recognized by an NFA
ε R ε
ε S ε
THOMPSON’S CONSTRUCTION
ε
R S
THOMPSON’S CONSTRUCTION
CLOSURE OPERATION OF R- R*
R
ε ε
ε
THOMPSON’S CONSTRUCTION
PARENTHESIZED R- ( R)
R
Have Shown
1
ε ε
ε 0 ε
ε 1 5 6
ε ε
1 2 3 4 9 10
1
ε 7 8 ε
ε
THOMPSON’S CONSTRUCTION METHOD
RE to ε-NFA Example
• Convert R= (ab+a)* to an NFA
– We proceed in stages, starting from simple
elements and working our way up
a
a
b
b
a ε b
ab
THOMPSON’S CONSTRUCTION
a
ε ε
(ab+a)* a ε b
ε ε
ε ε
a
ε ε