1.分别写出描述以下语言的正规文法和正规式:
(1)L1={abna|n≥0}。
(2)L2={ambn|n≥1,m ≥1}
(3)L3={(ab)n|n≥1}
答:
(1) 正规文法:
S->aA
A->bA|a
正规式:
S = a (b)* a
(2) 正规文法:
S->aS
S->bs | b
正规式:
S = a (a)* b (b)*
(3) 正规文法:
S->(ab)S |(ab)
正规式:
S=(ab)(ab)*
2.将以下正规文法转换到正规式
(1) Z→0A
A→0A|0B
B→1A|ε
答:Z = 0A, A = 0A+0B,B = 1A+ε
A = 0A + OB = 0A + 0(1A+ε) = 0A + 01A +
0=(0+01)A+0 = (0|01)*0
即Z = 0A = 0 (0|01)*0
(2) 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
即Z = (10|01)*(10|01)
(3)S→aA
A→bA|aB|b
B→aA
答:S = aA , A = bA + aB + b , B = aA
A = bA + aB + b = bA + aaA + b = (b+aa)A
+ b = (b|aa)*b
即S = aA = a(b|aa)*b
(4)I→l|Il|Id
答:I = l + Il + Id = I(l+d) + l
即I=(l|d)*l
原文地址:https://www.cnblogs.com/Azan1999/p/11684788.html
时间: 2024-10-09 09:49:20