Convert from NFA to DFA using Thompson’s rule for (a+b)*abb
Compiler Design

Convert from NFA to DFA using Thompson’s rule for (a+b)*abb

Oct 1, 2024

To convert the regular expression (a + b)*abb from an NFA to a DFA using Thompson’s construction, we will follow these steps:

  1. Create an NFA for (a + b)*abb using Thompson’s construction.
  2. Convert the NFA into a DFA using the subset construction method.
  3. Provide the transition table for the DFA.
  4. Draw the DFA diagram.

Step 1: NFA for (a + b)*abb

Breakdown of the Regular Expression:

  • (a + b)*: Any number of a or b (including zero occurrences).
  • abb: A fixed sequence of a followed by two bs.

NFA State Diagram:

States:
q0 -> initial state
q1 -> state for (a + b)*
q2 -> for the first 'a' of `abb`
q3 -> for the first 'b' of `abb`
q4 -> for the second 'b' of `abb` (final state)

Transitions:
- q0 --ε--> q1 (ε transition to begin the (a + b)*)
- q1 --a--> q1 (loop on `a` for (a + b)*)
- q1 --b--> q1 (loop on `b` for (a + b)*)
- q1 --a--> q2 (transition for the first 'a' in `abb`)
- q2 --b--> q3 (transition for the first 'b' in `abb`)
- q3 --b--> q4 (transition for the second 'b' in `abb`)

Final State: q4

The NFA accepts strings of any length from (a + b)* and ends with the substring abb.

Step 2: Convert NFA to DFA Using Subset Construction

We convert the NFA to DFA by determining the epsilon closures and forming new DFA states as combinations of NFA states.

Steps:

  1. Start with the epsilon closure of the start state (q0), which includes {q0, q1}.
  2. Calculate transitions for each input (a and b) from this new DFA state by taking the union of all possible NFA states that can be reached from any state in the set.
  3. Repeat this process for every new DFA state until all possible transitions are covered.
  4. Mark final states: A DFA state is a final state if it contains the NFA final state q4.

Subset Construction Table (DFA Creation)

DFA States NFA States On ‘a’ On ‘b’ Final?
A {q0, q1} {q1, q2} {q1} No
B {q1, q2} {q1, q2} {q3} No
C {q1} {q1, q2} {q1} No
D {q3} {q4} No
E {q4} Yes

Step 3: DFA Transition Table

Here’s the transition table for the DFA created through subset construction:

State On ‘a’ On ‘b’ Is Final
A B C No
B B D No
C B C No
D E No
E Yes
  • A: Start state representing the NFA’s {q0, q1}.
  • B: Represents NFA’s {q1, q2}, which corresponds to reading an a from (a + b)* or reaching the first a in abb.
  • C: Represents NFA’s {q1}, looping through (a + b)* without matching abb.
  • D: Represents reaching the first and second b of abb.
  • E: The final state where abb is fully matched.

Step 4: DFA State Diagram

Now, we can draw the DFA state diagram:

Convert from NFA to DFA using Thompson’s rule for (a+b)*abb

Leave a Reply

Your email address will not be published. Required fields are marked *