0

The problem is to provide context free grammar where L={w∈{a,b}∗∣the number of a's in w is one bigger than the number of b's}.My solution is

S -> LaL
L -> aLb|abL|bLa|Lab|Lba|baL|_

Can anyone tell why my solution doesn't work for this language?

Blake
  • 7,367
  • 19
  • 54
  • 80
  • 1
    How do you know it doesn't work? – O. R. Mapper Apr 06 '15 at 14:58
  • there is a check system saying my solution doesn't describe the language. for example my solution doesn't produce the string aabaabbbbbababaabaabbababbaabaa that belongs to the language. – Blake Apr 06 '15 at 16:30
  • Well, *can* you show a way to create that word with your grammar? If not, isn't it evident why your grammar doesn't fit? I'm unclear about what the answer to your question could look like (or what you're trying to find out), could you clarify? – O. R. Mapper Apr 06 '15 at 18:08
  • The answer should describe all the strings that belongs to L={w∈{a,b}∗∣the number of a's in w is one bigger than the number of b's}. is it clearer to you no? – Blake Apr 06 '15 at 18:16
  • 1
    @blake: That sounds like you are asking for the answer to your homework, rather than an explanation of why your solution is incorrect. – rici Apr 06 '15 at 18:39
  • it is incorrect due to that it doesn't produce this string "aabaabbbbbababaabaabbababbaabaa" – Blake Apr 06 '15 at 18:48

1 Answers1

0

Try this.. There might be a better/easier answer but this passes the test of the verifier.

S -> A
A -> BaAbB | BAabB | BabAB | BbaAB | BbAaB | a
B -> bBa | aBb | _ 
M-k
  • 11
  • 1