1.分別寫出描述如下語言的正規文法和正規式:class
L1={abna|n≥0}。語言
L2={ambn|n≥1,m ≥1}di
L2={(ab)n|n≥1}co
答:L1正規文法:S → aA A → bnaab
A → Ba B → bn
B → bB | ε
L1正規式:S = ab*a
L2正規文法:S -> aA
A -> aA | bB | b
B -> bB | b
L2正規式:a(ab)*b
L3正規文法:S → aA
A → bB
B → aA | ε
L3正規式:S = (ab)(ab)*
2.將如下正規文法轉換到正規式
Z→0A
A→0A|0B
B→1A|ε
答:Z = 0A
A = 0A + 0B
B = 1A + ε
A = 0A + 0(1A + ε) = 0A + 01A + 0 = (0 + 01) A + 0
A : (0 | 1)*0
Z = 0A
= 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 + (Z0 + 0)1
= Z10 + 10 + Z01 + 01
= Z(10 + 01) + 10 + 01
= (10 + 01)(10 + 01)*
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 = I + Il + Id
= l + I(l + d)
= l(l + d)*