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

let \({{\bf{G}}_{\bf{1}}}\) and \({{\bf{G}}_{\bf{2}}}\) be context-free grammars, generating the language\({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\) and \({\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\), respectively. Show that there is a context-free grammar generating each of these sets.

a) \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{UL}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\)

b) \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\)

c) \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\)

Short Answer

Expert verified

a) Add S and productions \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}\) and \({\bf{S}} \to {{\bf{S}}_{\bf{2}}}\).

b) Add S and production \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{{\bf{S}}_{\bf{2}}}\).

c) Add S and production S → λ and \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{\bf{S}}\).

Step by step solution

01

Types of Phrase-Structure Grammars Phrase-structure grammars.

(l)A type- 0 grammar has no restrictions on its production.

(II) A type-1 grammar can have productions of the form \({{\bf{W}}_{\bf{1}}} \to {{\bf{W}}_{\bf{2}}}\), where \({{\bf{W}}_{\bf{1}}} \to {\bf{lAr}}\). and \({{\bf{W}}_{\bf{2}}} \to {\bf{lWr}}\), where A is a non-terminal, I and r, are zero or more terminal or non-terminals and W is a non-empty string of terminal or non-terminals. It can also have the production Sàλ. as long as S does not appear on the right-hand side of any other production.

(III)A type- 2 grammar can have the productions only of the form \({{\bf{W}}_{\bf{1}}} \to {{\bf{W}}_{\bf{2}}}\), where \({{\bf{W}}_{\bf{1}}}\) is a single non-terminal.

(IV) A type- 3 grammar can have the productions only of the form \({{\bf{W}}_{\bf{1}}} \to {{\bf{W}}_{\bf{2}}}\) with \({{\bf{W}}_{\bf{1}}}{\bf{ = A}}\) and either \({{\bf{W}}_{\bf{2}}}{\bf{ = aB}}\) or \({{\bf{W}}_{\bf{2}}}{\bf{ = a}}\) where A and B are non-terminals and a is a terminal or with \({{\bf{W}}_{\bf{1}}}{\bf{ = S}}\) and \({{\bf{W}}_{\bf{2}}}{\bf{ = \lambda }}\).

Type 2 grammars are called context-free grammars because a nonterminal symbol that is the left side of a production can be replaced in a string whenever it occurs, no matter what else is in the string.

02

Firstly, it shall show that there is a context-free grammar generating \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{UL}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) sets

(a)

Take two non-terminal symbols \({{\bf{G}}_{\bf{1}}}\) and \({{\bf{G}}_{\bf{2}}}\) which are of context free grammars.

Here, the start symbols are \({{\bf{S}}_{\bf{1}}}\) and \({{\bf{S}}_{\bf{2}}}\).

Let ‘S’ be the non-terminal symbol.

Let \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\) and \({\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) be language generators for \({{\bf{G}}_{\bf{1}}}\) and \({{\bf{G}}_{\bf{2}}}\) respectively.

The language generated by the union contains all the strings generated by both the languages \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\) and \({\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\).

Here, apply the production rules to \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}\) and \({\bf{S}} \to {{\bf{S}}_{\bf{2}}}\).

So, the productions rules for \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}\) and \({\bf{S}} \to {{\bf{S}}_{\bf{2}}}\) are of type 2.

Thus, the language \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{UL}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) is a context free language.

Therefore, the string\({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{UL}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\)is a context-free grammar.

03

Now, we shall show that there is a context-free grammar generating \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) sets.

(b)

The language generated by the product contains the strings generated by both the languages \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right),\,{\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) and more strings.

Here, applies the production rule to \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{{\bf{S}}_{\bf{2}}}\).

So, the productions rule for \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{{\bf{S}}_{\bf{2}}}\) is of type 2. Thus, the language \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\) is a context free language.

In the above rule, the left side of production is replaced by the string, \({{\bf{S}}_{\bf{1}}}{{\bf{S}}_{\bf{2}}}\).

So, this production comes under type 2 grammars.

04

Now, we shall show that there is a context-free grammar generating \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\) sets.

(c)

The language \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\) contains all the strings of the language \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\). The language \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\) contains the strings, which are repetitions of the strings generated by the language \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\).

First, add a non-terminal string S to the set of all non-terminal strings.

So, the grammar contains the production rule of \({{\bf{G}}_{\bf{1}}}\) and along with it, it also contains S \(\to\) λ and \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{\bf{S}}\).

Apply the production rule to \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{\bf{S}}\). A string of concatenation is formed. To obtained string apply the production rule Sàλ to get the string generated by the language \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\). The language generated by \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\) is obtained by applying the production rules \({\bf{S}} \to {{\bf{S}}_{\bf{1}}}{\bf{S}}\) to \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\).

So, this production comes under type 2 grammar.

Therefore, the language\({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\)is a context free language.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

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

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

Suppose that S, I and O are finite sets such that \(\left| S \right| = n, \left| I \right| = k\), and \(\left| O \right| = m\).

\(a)\)How many different finite-state machines (Mealy machines) \(M = \left( {S,I,O,f,g,{s_0}} \right)\) can be constructed, where the starting state \({s_0}\) can be arbitrarily chosen?

\({\bf{b)}}\)How many different Moore machines \(M = \left( {S,I,O,f,g,{s_0}} \right)\) can be constructed, where the starting state \({s_0}\) can be arbitrarily chosen?

Describe how productions for a grammar in extended Backus–Naur form can be translated into a set of productions for the grammar in Backus–Naur form.

This is the Backus–Naur form that describes the syntax of expressions in postfix (or reverse Polish) notation.

\(\begin{array}{c}\left\langle {{\bf{expression}}} \right\rangle {\bf{ :: = }}\left\langle {{\bf{term}}} \right\rangle {\bf{|}}\left\langle {{\bf{term}}} \right\rangle \left\langle {{\bf{term}}} \right\rangle \left\langle {{\bf{addOperator}}} \right\rangle \\{\bf{ }}\left\langle {{\bf{addOperator}}} \right\rangle {\bf{:: = + | - }}\\\left\langle {{\bf{term}}} \right\rangle {\bf{:: = }}\left\langle {{\bf{factor}}} \right\rangle {\bf{|}}\left\langle {{\bf{factor}}} \right\rangle \left\langle {{\bf{factor}}} \right\rangle \left\langle {{\bf{mulOperator}}} \right\rangle {\bf{ }}\\\left\langle {{\bf{mulOperator}}} \right\rangle {\bf{:: = *|/}}\\\left\langle {{\bf{factor}}} \right\rangle {\bf{:: = }}\left\langle {{\bf{identifier}}} \right\rangle {\bf{|}}\left\langle {{\bf{expression }}} \right\rangle \\\left\langle {{\bf{identifier}}} \right\rangle {\bf{:: = a }}\left| {{\bf{ b }}} \right|...{\bf{| z}}\end{array}\)

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

In Exercises 16–22 find the language recognized by the given deterministic finite-state automaton

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

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