Question

I have this language:

{an bm | m+n is an even number}

What's the proper grammar for this?

Was it helpful?

Solution

S -> aaS | aB | bbC | ε
B -> bbB | b
C -> bbC | ε

you see, it is a regular language. 'S' stands for "we have constructed an even number of a's and more a's may follow, 'B' stands for "we have constructed an uneven number of a's and now an uneven number of b's follows. 'C' stands for "we have constructed an even number of a's and now an even number of b's follows.

ε stands for "", the empty string

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top