I'm trying to make a CFG for the language:
I did this:
S -> a S b b
S -> epsilon
It fulfills the requirement, but is it correct?
What if I wanted abbb
? n
is 1, therefore 2n
is 2 and 4n
is 4, m
is 3, so 2n <= m < 4n
. If you mean "does it create all the words in the language" as "is it correct", then no, it does not. Also, you are creating epsilon
(zero a
and zero b
), but it's not correct that 2*0 <= 0 < 4*0
because zero is not less than zero (second part of the comparison).
Your grammar is creating only words where there is twice more b
than a
. However, the language contains also other words - you need to have between 2 times more b
(including) and less than 4 times more b
than a
. Eg for n = 2
your m
can be 4, 5, 6 or 7.
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.