Download presentation
Presentation is loading. Please wait.
Published byUtami Cahyadi Modified over 6 years ago
1
Animated Conversion of Regular Expressions to C Code
On the regular expression: ((a⋅ b)|c)*
2
Thompson’s construction
Convert the regular expression to an NFA.
3
Step 1: construct a parse tree for the expression ((a⋅ b)|c)
Step 1: construct a parse tree for the expression ((a⋅ b)|c)* giving each nested expression a unique name. r6 r5 * r3 | r4 r1 ⋅ r2 c a b
4
Step 2: construct NFA for r1.
* r3 | r4 r1 ⋅ r2 c a b
5
Step 3: construct NFA for r2.
1 2 r6 r5 * b 3 4 r3 | r4 r1 ⋅ r2 c a b
6
Step 4: construct NFA for r3.
b 1 2 4 r6 r5 * r3 | r4 r1 ⋅ r2 c a b
7
Step 5: construct NFA for r4.
b 1 2 4 r6 r5 * c 5 6 r3 | r4 r1 ⋅ r2 c a b
8
Step 6: construct NFA for r5.
b r5 * 1 2 4 𝜀 𝜀 r3 | r4 7 8 𝜀 𝜀 5 6 r1 ⋅ r2 c c a b
9
Step 7: construct NFA for r6.
𝜀 a b 1 2 4 𝜀 𝜀 𝜀 𝜀 10 9 7 8 𝜀 𝜀 5 6 c 𝜀
10
Subset construction Convert the NFA to a DFA.
11
Draw transition table for DFA
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c
12
Add 𝜀-closure(9) as DFA start state
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c {9, 7, 1, 5, 10} A
13
Mark state A 2 4 1 5 6 7 8 9 b a c 𝜀 10 NFA States DFA State
Next State a b c {9, 7, 1, 5, 10} A
14
Compute 𝜀-closure(move(A, a))
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c {9, 7, 1, 5, 10} A B {2}
15
Compute 𝜀-closure(move(A, b))
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c {9, 7, 1, 5, 10} A B - {2}
16
Compute 𝜀-closure(move(A, c))
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c {9, 7, 1, 5, 10} A B - C {2} {6, 10, 7, 1, 5}
17
Mark state B 2 4 1 5 6 7 8 9 b a c 𝜀 10 NFA States DFA State
Next State a b c {9, 7, 1, 5, 10} A B - C {2} B {6, 10, 7, 1, 5}
18
Compute 𝜀-closure(move(A, c))
2 4 b 1 a 5 6 c 7 𝜀 8 9 10 NFA States DFA State Next State a b c {9, 7, 1, 5, 10} A B - C {2} B {6, 10, 7, 1, 5}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.