views:

88

answers:

1

I have this language:

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

What's the proper grammar for this?

+3  A: 
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

fschmitt
You got me, embarrassing really ;) Your solution is not entirely correct, though. You don't accept `bb`. You could make `aaC` to `bbC`.
lasseespeholt
Nice catch, thanks. Fixed.
fschmitt
You catched the 10 seconds where I mistyped...
fschmitt
Thank you for your instant answer
Hamid.P