Compiler Design and Construction - Old Questions

2.  Convert the following RE to DFA directly.

                (a+b)*ab

6 marks | Asked in 2073

Given RE;

(a+b)*ab

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}

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 'a'

    2 represents 'b'

followpos({1, 3}) = {1, 2, 3, 4} = S1

    δ(s0, a) = S1

followpos({2}) = {1, 2, 3} = S0

    δ(S0, b) = S0

3) From S1 = {1, 2, 3, 4}

    1, 3 → a

    2, 4 → b

followpos({1, 3}) = {1, 2, 3, 4} = S1

     δ(S1, a) = S1

followpos({2, 4}) = {1, 2, 3, 5} = S2

     δ(S1, b) = S2

4) From S2 = {1, 2, 3, 5}

    1, 3 → a

    2 → b

    5 → #

followpos({1, 3}) = {1, 2, 3, 4}= S1

    δ(S2, a) = S1

followpos({2}) = {1, 2, 3} = S0

     δ(S2, b) = S0

Now there was no new states occur.

Therefore, Final state = {S2}

Now the resulting DFA of given regular expression is: