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