Here is the language and I want to create a context-free grammar for it:
b(bc+a)*a(a+b)*c*
Here is my answer but I don't know if it's right or not:
S → bAaB
A → bcA | aA | epsilon
B → cB | aB | epsilon
Here is the language and I want to create a context-free grammar for it:
b(bc+a)*a(a+b)*c*
Here is my answer but I don't know if it's right or not:
S → bAaB
A → bcA | aA | epsilon
B → cB | aB | epsilon
Copyright © 2021 Jogjafile Inc.
See the grammar below. It might be possible to simplify it a bit, but it should do the trick.
The
Arule allows onebfollowed by any number (but at least one)cfollowed by a singlea. And this can occur any number of times (also zero)The
Brule allows any number (but at least one) ofafollowed by a singleb. Again the whole expression can occur any number of times.The
Crule allows any number ofc. This is used for thec*at the end of the word but also for thec+in the first part (ie it's used in ruleA)The
Drule allows any number ofa. It's just a helper in ruleBto accept thea+in the second part of the word.