作业六----正规文法与正规式
1.分别写出描述以下语言的正规文法和正规式:
L1={abna|n≥0}。
L2={ambn|n≥1,m ≥1}
L2={(ab)n|n≥1}
答:(1) S → aA
A → bA | a
L1 = ab*a
(2)S → aA
A → aA | bB | b
B → bB | b
L2 = a*b*
(3)S → aA
A → bB
B → aA | ε
L3 = (ab)*
2.将以下正规文法转换到正规式
Z→0A
A→0A|0B
B→1A|ε
答:Z = 0A
A = 0A + 0B
B = 1A + ε
A = 0A + 0(1A + ε) = 0A + 01A + 0
A = aA | b
Z = 0(0 | 01)*0
Z→U0|V1
U→Z1|1
V→Z0|0
答:Z = U0 + V1
U = Z1 + 1
V = Z0 + 0
Z = (Z1+1)0 + V1
Z = (Z1+1)0 +(Z0+0)1
Z = Z10 + 10 +Z01 + 01
Z = Z(10+01)+10+01
Z = (10+01)*1001
Z = (10 | 01)*1001
S→aA
A→bA|aB|b
B→aA
答:S = aA
A = bA + aB + b
B = aA
A = bA + a(aA) +b = (b + aa)A +b
S = (b | aa)*b
I→l|Il|Id
答: I = l + Il + Id
I = l + I(l +d)
I = l(l | d)*