简体   繁体   English

给定的语言是有效的 CFG 吗?

[英]Is the given language a valid CFG?

Language, L = { a^nb^na^n;语言,L = { a^nb^na^n; n=1,2,3,.. } n=1,2,3,..}

I want to check whether the given language L is context free or not.我想检查给定的语言 L 是否是上下文无关的。

CFG make use of PDA which uses stacks. CFG 利用使用堆栈的 PDA。 So, first store each 'a' to the stack.因此,首先将每个“a”存储到堆栈中。 Then pop twice for each occurrence of 'b'.然后每次出现“b”时弹出两次。 Is this logic correct?这个逻辑正确吗?

This language can be shown not to be context-free using the pumping lemma for context-free languages.使用上下文无关语言的泵引理可以证明这种语言不是上下文无关的。 The proof is by contradiction.证明是反证法。 Suppose the language is context-free.假设语言是上下文无关的。 Then words of length at least p in the language can be written as uvxyz with |vxy|那么语言中长度至少为 p 的词可以写成 uvxyz 和 |vxy| <= p, |vy| <= p, |维| > 0 and where u(v^n)x(y^n)z is in the language for all integers n. > 0 并且其中 u(v^n)x(y^n)z 在所有整数 n 的语言中。 Choose the string a^pb^pa^p in the language.选择语言中的字符串 a^pb^pa^p。 There are five cases to consider:有五种情况需要考虑:

  1. vxy consists only of a's from the first part. vxy 仅由第一部分的 a 组成。 Pumping up or down breaks the requirement that the number of a's in the first part equal the number of b's in the second part.向上或向下抽水打破了第一部分中 a 的数量等于第二部分中 b 的数量的要求。

  2. vxy consists only of a's and b's from the first two parts. vxy 仅由前两部分的 a 和 b 组成。 Pumping might keep the requirement that the number of a's in the first part equal the number of b's in the second, but it will certainly break the requirement that the numbers of a's in the first and third sections be the same.泵送可能会保持第一部分中 a 的数量等于第二部分中 b 的数量的要求,但它肯定会打破第一部分和第三部分中 a 的数量相同的要求。

  3. vxy consists only of b's from the second section. vxy 仅包含来自第二部分的 b。 Pumping fails for the same reason as in case 1.泵送失败的原因与案例 1 相同。

  4. vxy consists of a's and b's from the second and third parts. vxy 由第二部分和第三部分的 a 和 b 组成。 Pumping fails for a reason similar to that given in the second case.泵送失败的原因与第二种情况类似。

  5. vxy consists only of a's from the third section. vxy 仅包含来自第三部分的 a。 Pumping fails for a similar reason to that given in the first case.泵送失败的原因与第一种情况类似。

So, there is no way to rewrite our string a^nb^na^n so that it can be written uvxyz and satisfy the pumping lemma's requirements.所以,没有办法重写我们的字符串 a^nb^na^n 使其可以写成 uvxyz 并满足泵引理的要求。 This is a contradiction, so the language cannot have been regular.这是矛盾的,所以语言不可能是正则的。

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

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