Professional Documents
Culture Documents
Regular Expressions
s Vrabel,
1 / 23
Outline
Introduction
Basic terms
Why?
Methods
Transitive Closure Method
State Removal Method
Brzozowski Algebraic Method
Comparison
2 / 23
Basic Terms
3 / 23
Why?
X
Finite automaton Regular expression
Uhm. . . Why?
4 / 23
ab
q1
q2
b
c
q3
5 / 23
r
r +
Rij0 =
6 / 23
Example (1/5)
q1
q2
0, 1
7 / 23
Example (2/5)
1) Initialize Rij0 :
1
0
q1
0
R11
0
R12
0
R21
0
R22
q2
0, 1
+1
0
+0+1
8 / 23
Example (3/5)
2) Compute Rij1 :
1
q1
1
R11
1
R12
1
R21
1
R22
q2
0, 1
By direct substitution
Simplified
+ 1 + ( + 1)( + 1) ( + 1)
0 + ( + 1)( + 1) 0
+ ( + 1) ( + 1)
+ 0 + 1 + ( + 1) 0
1
1 0
+0+1
9 / 23
Example (4/5)
3) Compute Rij2 :
1
0
q1
q2
0, 1
By direct substitution
2
R11
2
R12
2
R21
2
R22
Simplified
1 + 1 0( + 0 + 1)
1 0 + 1 0( + 0 + 1) ( + 0 + 1)
+ ( + 0 + 1)( + 0 + 1)
+ 0 + 1 + ( + 0 + 1)( + 0 + 1) ( + 0 + 1)
1
1 0(0 + 1)
(0 + 1)
10 / 23
Example (5/5)
q1
q2
0, 1
2
= R12 = 1 0(0 + 1) is the REGEXP corresponding to the
R12
NFA.
11 / 23
12 / 23
Example (1/3)
Transform the following NFA to the corresponding REGEXP using
State Removal Method:
e
b
a
q1
q2
d
q3
c
13 / 23
Example (2/3)
1) Remove the middle state:
e
b
a
q1
q2
q3
c
ae d
ce b
ae b
q1
q3
ce d
14 / 23
Example (3/3)
ae d
ce b
ae b
q1
q3
ce d
15 / 23
solve it.
16 / 23
Example (1/5)
q2
17 / 23
Example (2/5)
q2
b
X1
aX1
bX2
18 / 23
Example (3/5)
q2
b
X2
bX1
cX2
19 / 23
Example (4/5)
X1
X2
=
=
aX1
bX1
+
+
bX2
cX2
20 / 23
Example (5/5)
Solution:
X1 = (a + bc b) bc
X2 = c [ + b(a + bc b) bc ]
a
b
q1
q2
b
X1 is the REGEXP corresponding to the NFA.
21 / 23
22 / 23
References
J. Brzozowski.
Derivatives of regular expressions.
Journal of the ACM, 11(4):481494, 1964.
J. E. Hopcroft and J. D. Ullman.
Introduction to Automata Theory, Languages, and Computation.
Addison-Wesley, 1979.
P. Linz.
An introduction to Formal Languages and Automata.
Jones and Bartlett Publishers, 3rd edition, 1979.
C. Neumann.
Converting deterministic finite automata to regular expressions.
Available on URL:
http://neumannhaus.com/christoph/papers/2005-03-16.DFA to RegEx.pdf.
ska, T. Vojnar, and A. Smr
M. Ce
cka.
informatika.
Studijn opora do predm
etu teoreticka
Available on URL:
https://www.fit.vutbr.cz/study/courses/TIN/public/Texty/oporaTIN.pdf.
23 / 23
Discussion