标签:psi 文法 class content 描述 ilo nbsp div aaa
1.分别写出描述以下语言的正规文法和正规式:
L1={abna|n≥0}
正规文法:S -> aA
A -> bA | a
正规式:ab*a
L2={ambn|n≥1,m ≥1}
正规文法:S -> aS
S -> bS | b
正规式:aa*bb*
L3={(ab)n|n≥1}
正规文法:S -> ( ab )S | ( ab )
正规式: S = ( ab )( ab )*
2.将以下正规文法转换到正规式
Z→0A
A→0A|0B
B→1A|ε
B = 1A + ε
A = 0A + 0 (1A + ε )
= 0A + 01A +0
= ( 0 + 01 ) A + 0
= ( 0 | 01 ) A | 0
= ( 0 | 01 )* 0
Z = 0A = 0 ( 0 | 01 )* 0
Z→U0|V1
U→Z1|1
V→Z0|0
V = Z0 + 0
U = Z1 + 1
Z = ( Z1 + 1 )0 + ( Z0 + 0 )1
= Z10 +10 + Z01 +01
= Z( 10 + 01 ) + 10 + 01
= Z ( 10 | 01) | (10 | 01)
= ( 10 | 01 )* ( 10 | 01 )
S→aA
A→bA|aB|b
B→aA
B = aA
A = bA + aB + b
= bA + aaA + b
S = a ( bA + aaA + b )
= abA +aaaA + ab
= aA ( b + aa ) + ab
= S ( b | aa ) | ab
= ( b | aa )* ab
I→l|Il|Id
I = L + IL + Id
= L + I ( L + d )
= L | I ( L | d )
= L ( L | d )*
标签:psi 文法 class content 描述 ilo nbsp div aaa
原文地址:https://www.cnblogs.com/jwwzone/p/11684536.html