简体   繁体   English

这是语法 {a^2n b^n | n >= 0} 是否上下文无关?

[英]Is this grammar {a^2n b^n | n >= 0} context free or not?

这个语法上下文是否免费?

{a^2n b^n | n >= 0}

The object you're asking about is not a grammar but a language: a set of strings.你问的对象不是语法而是一种语言:一组字符串。 A set of strings can be potentially described by a context-free grammar, in the sense that a some grammar exists whose rules generate exactly that set of strings.一组字符串可以潜在地由上下文无关文法描述,从某种意义上说,存在某种语法,其规则正好生成那组字符串。

In this case, the expansion of your set looks like this:在这种情况下,您的集合的扩展如下所示:

{ "", "aab", "aaaabb", "aaaaaabbb", ... }

It's the set of all strings consisting of an even number of a -s, followed by half as many b -s.它是由偶数个a -s 和一半的b -s 组成的所有字符串的集合。

This set can be generated by repetitions of the following rules:这个集合可以通过重复以下规则来生成:

  1. The empty string is in the set.空字符串在集合中。
  2. If a string s is in the set, then the string "aa" + s + "b" is in the set.如果字符串s在集合中,则字符串"aa" + s + "b"在集合中。

That is, from any string which is in the set, we can form a new string which is also in the set, simply by adding two a -s on the left and a b on the right.也就是说,从集合中的任何字符串,我们可以形成一个也在集合中的新字符串,只需在左侧添加两个a -s,在右侧添加一个b Together with the base case rule that the empty string is in the set, these rules describe the entire set.连同空字符串在集合中的基本情况规则,这些规则描述了整个集合。

And these rules are equivalent to, and can be written in the form of, a context-free grammar:这些规则等价于,可以写成上下文无关文法的形式:

s -> ""
  -> "aa" s "b"

The grammar is context free because it only has rules of the form "a -> symbols ...": the left hand side only has a single non-terminal symbol.语法是上下文无关的,因为它只有“a -> 符号 ...”形式的规则:左侧只有一个非终结符。 So none of the generations depend on context: a single symbol is taken, and replaced in isolation according to some available rule.因此,所有代都不依赖于上下文:采用单个符号,并根据某些可用规则单独替换。

暂无
暂无

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

相关问题 这是语法{a ^ nb ^ 2n | n&gt; = 0}是否正常? - Is this grammar {a^n b^2n | n >= 0} regular or not? 语言A = {0 ^ n 1 ^ n 0 ^ n}是否上下文无关? - Is the language A = {0^n 1^n 0^n} context free? 是语言{0 ^ n 1 ^ n 0 ^ k | k!= n}上下文免费? - Is the language {0^n 1^n 0^k | k != n} context free? 证明形式为0 ^ n(其中n为素数)的语言既不是常规语言也不是上下文无关语言 - prooving that a language of form 0^n where n is prime is neither regular nor context free L = {a^na^nb^m |m, n ≥ 0} 是规则语言还是不规则语言? - Is L = {a^n a^n b^m |m, n ≥ 0} a regular or irregular language? L1 = {a ^ n b ^ n | n <4}且L2 = {a ^ n b ^ n | n <10 ^ 10 ^ 10},常规语言? - Are L1 = {a^n b^n | n < 4 } and L2 = {a^n b^n | n < 10^10^10 }, regular languages? 是n log n = O(n)且是n log n = Omega(n) - Is n log n = O(n) and is n log n = Omega(n) pda 接受语言 L={a^nb^m | n <m}< div><div id="text_translate"><p> 我知道如何解决 m&lt;n,但我很难理解 m&gt;n 的逻辑。</p><p> 在 m&lt;n 中,我们将所有 a 压入堆栈,当我们得到 b 时,我们弹出一个 a,当输入以包含 mn a 的堆栈结束时,机器应该进入最终的 state</p><p> 我该怎么办 m&gt;n.... </p></div></m}<> - pda to accept the language L={a^n b^m | n<m} 计算倒数:n **(-1)或(1 / n)? - Calculating Reciprocals: n**(-1) or (1/n)? 无上下文语法的算法 - Algorithm for a Context Free Grammar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM