One thing that I am very clear is that there is no hard and fast algorithm to create CFG. The only wat to practice only. But how do I deal with new questions in exam? Are there types of problems that I need to know in order to be able to solve different types of problems? Can you guide me a bit about this issue?
-
$\begingroup$ What is CFG? That is new to me. $\endgroup$– BuffyNov 11, 2021 at 10:59
-
1$\begingroup$ @Buffy CFG - Context Free Grammar. $\endgroup$– Guy CoderNov 11, 2021 at 13:09
-
$\begingroup$ @GuyCoder Hmmm. It shouldn't have flown by me, I guess. $\endgroup$– BuffyNov 11, 2021 at 13:20
-
2$\begingroup$ @GuyCoder, actually, I taught language principles and compilers for about 20 years. Getting old. Not Dead Yet. $\endgroup$– BuffyNov 11, 2021 at 14:26
-
2$\begingroup$ I'm not sure why this is being close-voted, I think it's an excellent question, with important bearing for educators. There are some standard formations that will get you pretty far, and teachers would certainly benefit from thinking through them. I've thought through them for PDAs, and I provide those to my students for practice, but I don't have them specifically in CFG form. $\endgroup$– Ben I. ♦Nov 11, 2021 at 16:02
1 Answer
Here is one useful strategy. The union of context-free languages is context-free. If you can think of your target language as the union of simpler pieces, and you can think of a grammar for each piece (with start symbol $A_1$, $A_2$, etc.) then you can join all the grammars together with a production like $S \to A_1 \mid A_2 \mid \cdots$.