我如何构建生成这种语言的语法?
我正在研究有限自动机和 语法测试,我被这个问题困住了:
Construct a grammar that generates L:
L = {a^n b^m c^m+n|n>=0, m>=0}
我相信我的产生式应该遵循这样的思路:
S->aA | aB
B->bB | bC
C->cC | c Here's where I have doubts
我的 C 产生式如何记住 m 和 n 的数字? 我猜这一定是上下文无关语法,如果是这样,它应该怎么样?
I'm studying for a finite automata & grammars test and I'm stuck with this question:
Construct a grammar that generates L:
L = {a^n b^m c^m+n|n>=0, m>=0}
I believe my productions should go along this lines:
S->aA | aB
B->bB | bC
C->cC | c Here's where I have doubts
How can my production for C remember the numbers of m and n? I'm guessing this must rather be a context-free grammar, if so, how should it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
看起来应该是这样的:
您需要在构建过程中强制对 C'c 进行计数。 为了表明它是上下文无关的,我会考虑使用 Pump Lemma。
Seems like it should be like:
You need to force C'c to be counted during construction process. In order to show it's context-free, I would consider to use Pump Lemma.
其中
e == epsilon
和X
是不必要的,但是为了清楚起见添加了
where
e == epsilon
andX
is unnecessary butadded for clarity
是的,这听起来确实像家庭作业,但有一个提示:
每次匹配“a”时,都必须匹配“c”。 与匹配“b”相同。
Yes, this does sound like homework, but a hint:
Every time you match an 'a', you must match a 'c'. Same for matching a 'b'.
S->aSc|A
A->bAc|λ
这意味着当你得到 a 时,你至少有 1 个 c,或者如果你得到 a 和 b,你必须有 2 个 c。
我希望这对你有帮助
S->aSc|A
A->bAc|λ
This means when ever you get a at least you have 1 c or if you get a and b you must have 2 c.
i hope it has been helpful
好吧,伙计们,我将这样做:
Well guys, this is how I'll do it:
我的答案:
S-> 丙烯酰胺| aSc
A-> 公元前 | bAc
其中 S 是起始符号。
My answer:
S -> aAc | aSc
A -> bc | bAc
where S is the start symbol.
L = {epsilon, ac, bc, abcc, abbccc, aabbcccc,.....}
每次 a 或 b 增加时,我们可以尝试增加 c。
S-> aSc|bSc|epsilon
L = {epsilon, ac, bc, abcc, abbccc, aabbcccc,.....}
We can try to increase c every time either a or b is increased.
S -> aSc|bSc|epsilon
表示
其中 'e' 是 epsilon
,就像现在生成 aabbbccccc,
aSc 将生成 aacc(平衡 a 和 c)
那么A将取代S并生成aabbbccccc(平衡b和c)
means
where 'e' is epsilon
like to generate aabbbccccc now,
aSc will make aacc (balance a and c)
then A will replace S and generate aabbbccccc (balance b and c)
S-> aBC/ε
B-> bBC/S/ε
这也考虑了字母的顺序
S-> aBc/epsilon
B-> bBc/S/epsilon
This takes care of the order of the alphabets as well