简体   繁体   English

构造一个生成L = {a ^ pb ^ mc ^ n | n> = 0,m> = 0,p = m + n}的语法

[英]Construct a grammar that generates L = {a^p b^m c^n|n>=0, m>=0, p=m+n}

Construct a grammar that generates L: 构造一个生成L的语法:

L = {a^pb^mc^n|n>=0, m>=0, p=m+n} L = {a ^ pb ^ mc ^ n | n> = 0,m> = 0,p = m + n}

Till now I have attempted this much: 直到现在我已经尝试了这么多:

S->A
A->aAb|B
B->aBc|epsilon

Is my grammar right? 我的语法是对的吗?

I can't give the mathematical proof, but let's try to enumerate the strings your grammar can produce: 我不能给出数学证明,但让我们尝试枚举你的语法可以产生的字符串:

ε, ac, aacc, aaaccc, ... (more same # of a and c), ab, aabb, aaabbb, ... (more same # of a and b), aacb, aaaccb, aaacbb, aaaaccbb, ... (more # a which is the same as # b + c) ε,ac,aacc,aaaccc,...(更多相同的a和c),ab,aabb,aaabbb,......(更多相同的a和b),aacb,aaaccb,aaacbb,aaaaccbb,.. 。(更多#a与#b + c相同)

Now does: 现在做:

a^p b^m c^n

indicate that the order must be strictly fulfilled? 表明必须严格履行订单? ie a first then b then c. 即第一个然后是b然后是c。 if yes, you can see yourself that b and c are actually swapped in your grammar. 如果是的话,你可以看到自己b和c实际上是在你的语法中交换的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM