I want to design a context free grammar for the following language:
L = { w e {(, )}* | w is balanced}
I proposed the following grammar:
S -> (S)S | E
Whereas the proposed solution in the lecture is:
S -> (S) | SS | E
I am not able to figure out, what could be the problem with my solution. I ran both the grammar for various cases such as:
(()()), ()()(), and (())()
and both the CFG accepts these strings.
Can someone please help, what are the cases that my CFG would not cover. Or are they both equivalent. Or the number of transitions required to reach the final state are different.
Both grammars generate the same language, so neither is incorrect.
I prefer yours because it is unambiguous, but that wasn't part of the requirements. Many people seem to find the other answer easier to understand, but that wasn't part off the requirements either, and it is a highly subjective criterion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With