Americas
Europe
Q25E
Expert-verifieduse top-down parsing to determine whether each of the following strings belongs to the language generated by the grammar in Example 12.
\(\begin{array}{*{20}{l}}{{\bf{a) baba}}}\\{{\bf{b) abab}}}\\{{\bf{c) cbaba}}}\\{{\bf{d) bbbcba}}}\end{array}\)
(a) Yes, \(baba\) belong to the language generated by G.
(b) No, \(abab\) does not belong to the language generated by G.
(c) Yes, \(cbaba\) belong to the language generated by G.
(d) No, \(bbbcba\) does not belong to the language generated by G.
To find out rather a word belongs to the language made by a phrase structure grammar, the way to approach the problem is to start with S, the beginning symbol and anything empty to decide the required word using a series of productions is called top-down parsing.
The language made by the grammar \(G{\bf{ }} = {\bf{ }}\left( {V,{\bf{ }}T,{\bf{ }}S,{\bf{ }}P} \right)\), where \(V{\bf{ }} = {\bf{ }}\left\{ {a,{\bf{ }}b,{\bf{ }}c,{\bf{ }}A,{\bf{ }}B,{\bf{ }}C,{\bf{ }}S} \right\}\), \(T{\bf{ }} = {\bf{ }}\left\{ {a,{\bf{ }}b,{\bf{ }}c} \right\}\), S is the symbol of beginning, and the productions are
\(\begin{array}{c}S \to AB{\bf{ }}\\A \to {\bf{ }}Ca{\bf{ }}\\B \to {\bf{ }}Ba{\bf{ }}\\B \to {\bf{ }}Cb{\bf{ }}\\B \to {\bf{ }}b{\bf{ }}\\C \to {\bf{ }}cb{\bf{ }}\\C \to {\bf{ }}b.\end{array}\)
(a)
Using the given information and let’s starting the symbol ‘S’;
\(\begin{array}{c}S \to AB{\bf{ }}\\ \to {\bf{ }}CaB{\bf{ }}\\ \to {\bf{ }}baB{\bf{ }}\\ \to {\bf{ }}baBa{\bf{ }}\\ \to {\bf{ }}baba{\bf{ }}\end{array}\)
Hence, ‘\({\bf{baba}}\)’ belong to the language generated by G.
(b)
Since \(S \to AB,{\bf{ }}A \to {\bf{ }}Ca,{\bf{ }}C \to {\bf{ }}cb,{\bf{ }}C \to {\bf{ }}b\) are the only options, any sentence starts with either c or b.
Hence ‘\({\bf{abab}}\)’ does not belong to the language generated by G.
(c)
Using the given information and let’s start the symbol ‘S’;
\(\begin{array}{c}S \to AB{\bf{ }}\\ \to {\bf{ }}caB{\bf{ }}\\ \to {\bf{ }}cbaB{\bf{ }}\\ \to {\bf{ }}cbaBa{\bf{ }}\\ \to {\bf{ }}cbaba{\bf{ }}\end{array}\)
Hence, ‘\({\bf{cbaba}}\)’ belong to the language generated by G.
(d)
Since \(S \to AB,{\bf{ }}A \to {\bf{ }}Ca,{\bf{ }}C \to {\bf{ }}cb,{\bf{ }}C \to {\bf{ }}b.\)are the only options, any sentence starts with either cba or ba.
Hence ‘\({\bf{bbbcba}}\)’ does not belong to the language generated by G.
94% of StudySmarter users get better grades.
Sign up for free