Write a BNF specification where each string in the language starts with x’s followed by y’s followed by z’s, with the following constraint: number of occurrences of y is greater than the number of occurrences of x and z (|y| > |x|+|z|).
Asked
Active
Viewed 306 times
-2
-
Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then check the [help/on-topic] to see what questions you can ask. Please see: [How do I ask and answer homework questions?](https://meta.stackoverflow.com/q/334822) – Progman Feb 12 '21 at 19:36
-
You might want to delete this question and ask it on https://cs.stackexchange.com/ instead, but check the help pages there first. – Progman Feb 12 '21 at 19:48
-
Start by trying the language where `|y|=|x|+|z|`. Then think about what needs to change to get more `y`s. – rici Feb 12 '21 at 21:15
1 Answers
-1
I figured it out eventually. BNF specification :
<S"> --> <A'> <C'>
<A'> --> x<A'>yy | xyy
<C'> --> yy<C'>z | yyz

Daniel James
- 3
- 3
-
You can't build some valid strings with that specification like `y` or `xyyyz`. – Progman Feb 12 '21 at 21:31