以下是一个上下文有关的文法例子,用于生成正规的非上下文无关语言:
S → aRc
R → aRT | b
bTc → bbcc
bTT → bbUT
UT → UU
UUc → VUc → Vcc
UV → VV
bVc → bbcc
bVV → bbWV
WV → WW
WWc → TWc → Tcc
WT → TT
例如,产生序列 aaa bbb ccc 的链如下:
S
aRc
aaRTc
aaaRTTc
aaabTTc
aaabbUTc
aaabbUUc
aaabbVUc
aaabbVcc
aaabbbccc
而对于序列 aaaa bbbb cccc,产生链如下:
S
aRc
aaRTc
aaaRTTc
aaaaRTTTc
aaaabTTTTc
aaaabbUTTTc
aaaabbUUTTc
aaaabbUUUTc
aaaabbUVUTc
aaaabbUVVcc
aaaabbVVCcc
aaaabbVVWVcc
aaaabbVVWWcc
aaaabbVVTWcc
aaaabbVTccc
aaaabbbbcccc
扩展资料上下文有关文法(CSG)是其中任何产生规则的左手端和右手端都可以被终结符和非终结符的上下文所围绕的形式文法。上下文有关文法比上下文无关文法更一般性但仍足够有秩序得可以被线性有界自动机所解析。