当前位置:网站首页>Lecture on Compilation Principles

Lecture on Compilation Principles

2022-06-13 01:09:00 includeSteven

DFA To minimize

Why minimize

DFA To minimize the number of States is to seek the minimum number of states , And with the original DFA equivalent DFA

significance : Minimization can reduce the complexity of compiler construction , Improve the running efficiency of the compiler

Minimize whether there is

P56 Theorem 3.2: To any one DFA N There is an equivalent DFA M bring M Contains the minimum number of States , And M only ( Except for isomorphism with different state names )

The minimization algorithm

Pre knowledge

1. Equivalence and distinguishability between states :

hypothesis s and t by M Two states of

  • If from the State s And status t You can read a word when you start α And stop in the final state , said s and t Equivalent

  • There is a word α, bring s and t One readout α Stop in the final state , The other reads α Stop in a non final state , said s and t Distinguishable

So through the empty string , All non final states and final states are distinguishable

2. Useless state and unreachable state

Useless state : There is no path from this state to the final state
Inaccessible state : There is no path from the initial state to this state

eg: Insert picture description here

The detailed steps

1. Preprocessing : Delete N All useless and unreachable states in

2. Yes N The state set of

  • Initial division :Π={F,S-F [,{error}] }

  • Yes Π Each subset of P division , until Π The states of any two different subsets of are distinguishable , And any two states of the same subset are equivalent ( Basis of division )

Basis of division :

For any subset of States
I j = { q 1 , q 2 , q 3 . . . q k } I_j = \bigr\{ {q_1,q_2,q_3...q_k}\bigr\} Ij={ q1,q2,q3...qk}
If there is an input in the alphabet a, bring
T ( q i , a ) = s , T ( q j , a ) = t , s and t No stay When front draw branch Π Of ren What One individual shape state Son Set in T ( q i , a ) and T ( q j , a ) Of ren What One individual nothing set The righteous T(q_i,a)=s,T(q_j,a)=t,s and t Not in current partition Π Any state subset of \\ T(q_i,a) and T(q_j,a) There is no definition of any of the T(qi,a)=s,T(qj,a)=t,s and t No stay When front draw branch Π Of ren What One individual shape state Son Set in T(qi,a) and T(qj,a) Of ren What One individual nothing set The righteous
Then you can put I j I_j Ij Split in two

3. Let each subset choose a representative , At the same time, other states of the subset are eliminated

example

P55 chart 3-13

 Insert picture description here

原网站

版权声明
本文为[includeSteven]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280555542673.html