简体   繁体   中英

What is the language described by this CFG?

What is the language described by this 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 . Also, we can get any number of S in our intermediate forms using just S -> SS . Therefore, this is the regular language (ab + aabb)+ .

Proof is by induction on the string length n.

Base case: the shortest strings ab and aabb are in the language (ab + aabb)+ and are generated by the grammar as shown above.

Induction hypothesis: the language generated by the grammar matches the language (ab + aabb)+ for all strings up to length k .

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 .

  1. We know the language and the grammar match for strings of length 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. 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. 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.

  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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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