Compiler Design Optimization of DFA- Based Pattern Matchers 06/17/22 1 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
Compiler Design
Optimization of DFA-Based Pattern Matchers
05/01/23 1ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
Optimization of DFA-Based Pattern Matchers
• It refers to detecting those states of a DFA whose presence or absence in a DFA does not affect the language accepted by the automata.
• These states can be eliminated from the automata without affecting the language accepted by the automata.
• SUCH STATES ARE:-• Unreachable States:• Dead States:• Nondistinguishable States:
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 2
Contd…….
• Unreachable States: Unreachable states of a DFA are not reachable from the initial state of DFA on any possible input sequence.
• Dead States: A dead state is a nonfinal state of a DFA whose transitions on every input symbol terminates on itself. For example, q is a dead state if q is in Q F, and δ(q, a) = q for every a in Σ.
• Nondistinguishable States: Nondistinguishable states are those states of a DFA for which there exist no distinguishing strings; hence, they cannot be distinguished from one another.
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 3
Contd……..
• Optimization entails:
• Detection of unreachable states and eliminating them from DFA;
• Identification of nondistinguishable states, and merging them together; and
• Detecting dead states and eliminating them from the DFA.
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 4
Consider The Transition Diagram
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 5
Fig: Partitioning down to a single state.
Contd……
• Initially, we have two groups, as shown below:
Group I Group IISince
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 6
A, B, C, E, F D
Contd…..• Partitioning of Group I is not possible, because the
transitions from all the members of Group I go only to Group I. But since
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 7
state F is distinguishable from the rest of the members of Group I. Hence, we divide Group I into two groups: one containing A, B, C, E, and the other containing F, as shown below:
Contd……
Group I Group II Group IIISince
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 8
A, B, C, E F D
partitioning of Group I is not possible, because the transitions from all the members of Group I go only to Group I. But since
Contd…..
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 9
states A and E are distinguishable from states B and C. Hence, we further divide Group I into two groups: one containing A and E, and the other containing B and C, as shown below:
Contd……
Group I Group II Group III Group IV Since
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 10
A, E B, C F D
state A is distinguishable from state E. Hence, we divide Group I into two groups: one containing A and the other containing E, as shown below:
Contd……
Group I Group II Group III Group IV Group VSince
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 11
A E B, C D
partitioning of Group III is not possible, because the transitions from all the members of Group III on a go to group III only. Similarly,
F
Contd…..
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 12
partitioning of Group III is not possible, because the transitions from all the members of Group III on b also only go to Group III.
Hence, B and C are nondistinguishable states; therefore, we merge B and C to form a single state, B1, as shown in next Figure…
Contd……..
05/01/23 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 13
Fig. Merging nondistinguishable states B&C into a single state B1.
THANKS
05/01/23 14ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI