[英]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:这个集合可以通过重复以下规则来生成:
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.