-1

I need help creating a Context Free Grammar which starts and ends with 00.

The language to be used will be {0,1}

Tayyab Shabab
  • 259
  • 1
  • 6
  • 16

1 Answers1

2
S -> AA | AAA | AABAA
A -> 0
B -> eps | 0B | 1B
sve
  • 4,336
  • 1
  • 19
  • 30
  • lnwvr, Thankyou for this fast reply. It looks like a professional grammar. However I have also tried something like A → 00A00 | AA | 0 | 1 . Is it also correct? – Tayyab Shabab Oct 26 '13 at 18:47
  • 3
    @TayyabShabab If you consider `A` to be your starting state then no because A would generate `0` and `1` which neither of them satisfies the condition. I would suggest you to look once again at the definition of context-free grammar and to try to construct some simple grammar in order to get the feeling how the things should be. – sve Oct 26 '13 at 18:53
  • Thanks for your guidance. Now I have started to get some concept about it. Sorry for annoyance but I would like you to please check this one. S -> 00A00, A -> AA | 0 | 1 – Tayyab Shabab Oct 26 '13 at 19:00
  • 2
    @TayyabShabab This would work only if you had the rules `S -> 00`, `S -> 000`, `S -> 0000` too (notice that `S` does not generate the word `0000` otherwise). Other than this everything's fine. You can also check it by yourself by answering those two question: 1. Can every word which begins and ends with `00` be generated from this grammar? 2. Does every word generated by the grammar begin and end with `00`? If the answer to both of these questions is positive then you've found your grammar. – sve Oct 26 '13 at 19:05