简体   繁体   English

这个CFG描述的语言是什么?

[英]What is the language described by this CFG?

What is the language described by this CFG?这个CFG描述的语言是什么?

在此处输入图片说明

We can write out some of the shortest strings in the language to get a feel a for it:我们可以写出一些语言中最短的字符串来感受一下:

S -> aTb -> ab
S -> aTb -> aabb
S -> SS -> … -> abab
S -> SS -> … -> abaabb
S -> SS -> … -> aabbab

We note that the only strings generated by the grammar take every instance of S to either ab or aabb .我们注意到,语法生成的唯一字符串将S每个实例都转换为abaabb Also, we can get any number of S in our intermediate forms using just S -> SS .此外,我们可以仅使用S -> SS以中间形式获得任意数量的S Therefore, this is the regular language (ab + aabb)+ .因此,这是常规语言(ab + aabb)+

Proof is by induction on the string length n.证明是通过对字符串长度 n 进行归纳。

Base case: the shortest strings ab and aabb are in the language (ab + aabb)+ and are generated by the grammar as shown above.基本情况:最短的字符串 ab 和 aabb 在语言(ab + aabb)+ ,并由如上所示的语法生成。

Induction hypothesis: the language generated by the grammar matches the language (ab + aabb)+ for all strings up to length k .归纳假设:语法生成的语言与长度为k所有字符串的语言(ab + aabb)+相匹配。

Induction step: we must show that strings generated by the grammar of the next highest length are in the language, and strings in the language of the next highest length are generated by the grammar.归纳步骤:我们必须证明由次高长度的语法生成的字符串在该语言中,而次高长度的语言中的字符串由该语法生成​​。 Note: the grammar can only generate even-length strings, and the language (ab + aabb)+ only contains even-length strings, so really the next highest step is the smallest even number greater than k .注意:语法只能生成偶数字符串,而语言(ab + aabb)+只包含偶数字符串,所以真正的下一个最高步骤是大于k的最小偶数。

  1. We know the language and the grammar match for strings of length k .我们知道长度为k字符串的语言和语法匹配。 Let X be the set of all strings in the language of length k, and Y be the set of all strings in the language of length k - 2. Then, the grammar generates a set of strings X' by modifying the derivations of strings in X to use production S -> SS one extra time and then choosing S -> aTb -> ab for that instance of S just introduced.设 X 为长度为 k 的语言的所有字符串的集合,Y 为长度为 k - 2 的语言的所有字符串的集合。 然后,语法通过修改中的字符串的派生生成一组字符串 X' X 使用生产S -> SS一次额外的时间,然后为刚刚引入的S实例选择S -> aTb -> ab The grammar also generates a set of strings Y' by modifying the derivations of strings in Y to use production S -> SS one extra time and then choosing S -> aTb -> aabb for that instance of S just introduced.该语法还通过修改 Y 中字符串的派生来生成一组字符串 Y' 以使用产生式S -> SS一次额外的时间,然后为刚刚引入的S实例选择S -> aTb -> aabb These same strings match the regular expression since strings in X and Y matched, and X' and Y' are just those strings with ab or aabb added, which the Kleene star allows.这些相同的字符串匹配正则表达式,因为 X 和 Y 中的字符串匹配,而 X' 和 Y' 只是添加了 ab 或 aabb 的那些字符串,这是 Kleene 星允许的。

  2. Similarly, strings of length k and k-2 that match the regular expression can have either ab or aabb added to the end (thanks to the Kleene star) to get all matched strings of length k+2.类似地,匹配正则表达式的长度为 k 和 k-2 的字符串可以在末尾添加 ab 或 aabb(感谢 Kleene 星)以获得所有匹配的长度为 k+2 的字符串。 But these must also be generated by the grammar since the prefixes were generated by the grammar and we have productions (outlined above) that allow us to introduce an extra ab or aabb to our derived strings.但是这些也必须由语法生成,因为前缀是由语法生成的,我们有生产(上面概述)允许我们向我们的派生字符串引入额外的 ab 或 aabb。

In words, the language is the set of all strings which are concatenations of any number of instances of the strings ab and aabb, in any order.换句话说,语言是所有字符串的集合,这些字符串是以任意顺序连接任意数量的字符串 ab 和 aabb 的实例。

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

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