Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

use bottom-up parsing to determine whether the strings in Exercise 25 belong to the language generated by the grammar in Example 12.

Short Answer

Expert verified

(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.

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Definition of Bottom-up parsing

Bottom-up parsing uses production steps starting from the given string to derive S. If S is not obtained, then the string cannot be generated by the grammar.

02

Writing the language generated by the grammar from Example 12 and the strings from Exercise 25.

The language produced 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 sign 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}\)

The strings from exercise 25.

\(\begin{array}{*{20}{l}}{a){\bf{ }}baba}\\{b){\bf{ }}abab}\\{c){\bf{ }}cbaba}\\{d){\bf{ }}bbbcba}\end{array}\)

03

Using Bottom-up parsing to determine ‘\({\bf{baba}}\)’ string belong to the language generated by G.

(a)

The string is \(baba\),

Use the production C \(\to\) b, so baba \(\to\) Caba.

Then use the production A \(\to\) Ca, so that Caba \(\to\) Aba.

Using the production B \(\to\) b gives Aba \(\to\) ABa.

Then use the production B \(\to\) Ba, so that ABa \(\to\) AB.

Finally, using A \(\to\) AB shows that the complete derivation for \(baba\) is

\(\begin{array}{c}S \to AB{\bf{ }}\\ \to {\bf{ }}ABa{\bf{ }}\\ \to {\bf{ }}Aba{\bf{ }}\\ \to {\bf{ }}Cabb{\bf{ }}\\ \to {\bf{ }}baba{\bf{ }}\end{array}\)

Thus, ‘baba’ belongs to the language generated by the grammar.

04

Using Bottom-up parsing to determine ‘\({\bf{abab}}\)’ string belong to the language generated by G.

(b)

The string is ‘\(abab\)’.

From the production steps, observe that a is on the right side, this implies that a string cannot start with a.

Thus, the string does not belong to the language generated by the grammar.

05

Using Bottom-up parsing to determine ‘\({\bf{cbaba}}\)’ string belongs to the language generated by G.

(c)

The string is ‘\(cbaba\)’.

Use the production C \(\to\) cb, so cbaba \(\to\) Caba.

Then use the production A \(\to\) Ca, so that Caba \(\to\) Aba.

Using the production B \(\to\) b gives Aba \(\to\) ABa.

Then use the production B \(\to\) Ba, so that ABa \(\to\) AB.

Finally, using S \(\to\) AB shows that the complete derivation for ‘baba’ is

\(\begin{array}{c}S \to AB{\bf{ }}\\ \to {\bf{ }}ABa{\bf{ }}\\ \to {\bf{ }}Aba{\bf{ }}\\ \to {\bf{ }}Caba{\bf{ }}\\ \to {\bf{ }}cbaba{\bf{ }}\end{array}\)

Hence, ‘cbaba’ belongs to the language generated by the grammar.

06

Using Bottom-up parsing to determine ‘\({\bf{bbbcba}}\)’ string belong to the language generated by G.

(d)

The string is ‘\(bbbcba\)’.

Now Use the production C \(\to\) cb, so bbbcba \(\to\) bbbCa

Then use the production A \(\to\) Ca, so that bbbCa \(\to\) bbbA.

From the production steps, observe that none of the steps has a right side starting with A, this implies that a string cannot end with A.

Thus, the string does not belong to the language generated by the grammar.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Give production rules in extended Backus–Naur form that generate a sandwich if a sandwich consists of a lower slice of bread; mustard or mayonnaise; optional lettuce; an optional slice of tomato; one or more slices of either turkey, chicken, or roast beef (in any combination); optionally some number of slices of cheese; and a top slice of bread.

Let V be an alphabet, and let A and B be subsets of \({\bf{V*}}\) with A⊆B. Show that \({\bf{A*}}\)⊆B*.

Determine whether each of these strings is recognized by the deterministic finite-state automaton in Figure 1.

a)010b) 1101 c) 1111110d) 010101010

a) Construct a phrase-structure grammar that generates all signed decimal numbers, consisting of a sign, either + or −; a nonnegative integer; and a decimal fraction that is either the empty string or a decimal point followed by a positive integer, where initial zeros in an integer are allowed.

b) Give the Backus–Naur form of this grammar.

c) Construct a derivation tree for −31.4 in this grammar.

Find a phrase-structure grammar for each of these languages.

a) the set of all bit strings containing an even number of 0s and no 1s

b) the set of all bit strings made up of a 1 followed by an odd number of 0s

c) the set of all bit strings containing an even number of 0s and an even number of 1s

d) the set of all strings containing 10 or more 0s and no 1s

e) the set of all strings containing more 0s than 1s

f) the set of all strings containing an equal number of 0s and 1s

g) the set of all strings containing an unequal number of 0s and 1s

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free