Compiler Design and Construction - Old Questions
3. Given the regular expression (0 + 1)* 011 , construct a DFA equivalent to this regular expression computing follow pos ().
Given RE;
(0 + 1)* 011
The augmented RE of the given RE is:
Syntax tree for augmented R.E. is
Calculating followpos:
followpos(1) = {1, 2, 3}
followpos(2) = {1, 2, 3}
followpos(3) = {4}
followpos(4) = {5}
followpos(5) = {6}
Now,
1) Start state of DFA = firstpos(root) = {1, 2, 3} = S0
Use followpos of symbol representing position in RE to obtain the next state of DFA.
2) From S0 = {1, 2, 3}
1 and 3 represents '0'
2 represents '1'
followpos({1, 3}) = {1, 2, 3, 4} = S1
δ(s0, 0) = S1
followpos({2}) = {1, 2, 3} = S0
δ(S0, 1) = S0
3) From S1 = {1, 2, 3, 4}
1, 3 → 0
2, 4 → 1
followpos({1, 3}) = {1, 2, 3, 4} = S1
δ(S1, 0) = S1
followpos({2, 4}) = {1, 2, 3, 5} = S2
δ(S1, 1) = S2
4) From S2 = {1, 2, 3, 5}
1, 3 → 0
2, 5 → 1
followpos({1, 3}) = {1, 2, 3, 4}= S1
δ(S2, 0) = S1
followpos({2, 5}) = {1, 2, 3, 6} = S3
δ(S2, 1) = S3
5) From S3 = {1, 2, 3, 6}
1, 3 → 0
2 → 1
6 → #
followpos({1, 3}) = {1, 2, 3, 4}= S1
δ(S3, 0) = S1
followpos({2}) = {1, 2, 3} = S0
δ(S3, 1) = S0
Now there was no new states occur.
Therefore, Final state = {S3}
Now the resulting DFA of given regular expression is: