This is for a practice exam question, so please explain answers and also give tips for thinking about similar problems. So I have the question:
Create a context free grammar for a language that accepts strings on the alphabet {a,b} where the number of a's are divisible by 3 or the length of x is divisible by 3, or both....where x = input string.
I'm struggling a lot with how I'm supposed to begin the problem.
I understand that a grammar for accepting strings from alphabet {a,b} that's divisible by 3 might look like:
0 -> a1 | b1
1 -> a2 | b2
2 -> a | b | a0 | b0
Below is where I'm at so far, trying to keep track of both the total length of x and the amount of a's in x, for any combo of a's and b's:
0 -> a1 | b1
1 -> a2 | b3
2 -> a | a0 | b1
3 -> a | b | a2 | b4
4 -> a1 | b5
5 -> b | b1 | a2
The above is obviously wrong but I need some help. So example strings that should pass:
ababab
abaa
abbabb