Compiler Design and Construction - Old Questions

4.  Given a regular expression (a+) bc*. Construct the DFA recognizing the pattern described by the regular expression using syntax tree based reduction.

6 marks | Asked in 2072

Given RE;

(a+bc*

The augmented RE of the given RE is:

(a+bc* #

Syntax tree for augmented R.E. is

Calculating followpos:

followpos(1) = {2}

followpos(2) = {3, 4}

followpos(3) = {3, 4}

Now,

1) Start state of DFA = firstpos(root) = {1, 2} = S0

Use followpos of symbol representing position in RE to obtain the next state of DFA.

2) From S0 = {1, 2}

    1  represents 'a'

    2 represents 'b'

followpos(1) = {2} = S1

     δ(s0, a) = S1

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

    δ(S0, b) = S2

3) From S1 = {2}

    Here 2 represents 'b'

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

     δ(S1, b) = S2

4) From S2 = {3, 4}

    Here 3 represents 'c'

    4 represents '#'

followpos(3) = {3, 4} = S2

    δ(S2, c) =  S2

Now there was no new states occur.

Therefore, Final state = {S2}

Now the resulting DFA of given regular expression is: