Job SEVEN - formal style to the regular grammar and Automata

Job SEVEN - formal style to the regular grammar and Automata

 

to sum up

1, the regular cast as a regular grammar

Same three rules 1. Rules of the form A → ab converted into A → aB, B → b

2. the form A → a | b rules, be converted into A → a, A → b (A → a | b)

3. The form A → a * b rules, be converted into A → aA, A → b

   The form A → ba * As a rule, be converted into A → Aa, A → b

 

2、DFA

Quintuple

There is a unique initial state

3, the three ways described DFA

Five-tuple, the state diagram (the most intuitive), matrix

4、NFA

Quintuple

Encounters the same state can be converted into a plurality of status symbol

In addition to non-empty set of states

 

 

Regular Expression to regular grammar

For any regular formula R selecting a nonterminal Z → Z generation rule R

1. rules of the form A → ab converted into A → aB, B → b

2. the form A → a | b rules, be converted into A → a, A → b (A → a | b)

3. The form A → a * b rules, be converted into A → aA, A → b

   The form A → ba * As a rule, be converted into A → Aa, A → b

Continue using the conversion rules, each rule comprising at most until a terminator far.

1(0|1)*101

(a|b)*(aa|bb)(a|b)*

((0|1)*|(11))*

(0|11*0)*

Z->A1

A->B0

B->C1

C->1(0|1)*

C->C(0|1)|1

C->C0|C1|1

The idea is for each rule contains up to a terminator, the type 1 (0 | 1) * can be used to convert the third rule, there are 101 regular style is not consistent with the form, you can split it step by step.

S->(a|b)S

S->(aa|bb)(a|b)*

S->S(a|b)

S->(aa|bb)

S-> ThE | P | In | SB | AA | BB

A->a

B->b

The idea is if the regular type too long, you first select the most familiar split into formal style form

S->((0|1)*|(11))S|ε

S->(0|1)*S|11S|ε

S->(0|1)*S

S->(0|1)S|S

S->0S|1S|S

S->11S

S->1A

A->1S

In summary:

S->0S|1S|S|1A

A->1S

(0|11*0)*

S->(0|11*0)S|ε

S->0S|(11*0)S|ε

S->(11*0)S

S->A0

A->11*

A->A1|1

S->0S|A0|ε

A->A1|1

自动机M=({q0,q1,q2,q3},{0,1},f,q0,{q3})

其中f:

(q0,0)=q1

(q1,0)=q2

(q2,0)=q3

(q0,1)=q0

(q1,1)=q0

(q2,1)=q0

(q3,0)=q3

(q3,1)=q3

画现状态转换矩阵和状态转换图。

根据五元组可知,q0,q1,q2,q3是状态,{0,1}是有穷字母表,当状态遇见0或1时会转换到下一个状态,f是映像,q0是唯一的一个初态,{q3}是一个终态集

 

 

0

1

q0

q1

q0

q1

q2

q0

q2

q3

q0

q3

q3

q3

 

 

 

 

3.由正规式R 构造 自动机NFA 

(a|b)*abb

 

 

 

(a|b)*(aa|bb)(a|b)*

 

 

 

1(1010*|1(010)*1)*0

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/cyxxixi/p/11729863.html