Consider the language consisting of strings that have n copi

Consider the language consisting of strings that have n copies of the letter a followed by the same number of copies of the letter b where n > 0. For example, the strings ab, aaabbb, and aaaabbbb are in the language but a, abb, ba and aabbb are not. Give a BNF grammar for the language.

Solution

BNF grammer for the language consisting of strings that have n copies of the letter a followed by the same number of copies of the letter b, where n > 0.

<S> -> a <S> b | ab

This will accept strings like: ab, aaabbb, aaaabbbb

but not like: a, abb, ba, aabbb

 Consider the language consisting of strings that have n copies of the letter a followed by the same number of copies of the letter b where n > 0. For exampl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site