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

a) Explain what the productions are in a grammar if the Backus–Naur form for productions is as follows:

\(\begin{array}{*{20}{l}}{{\bf{ < expression > :: = }}\left( {{\bf{ < expression > }}} \right){\bf{ }}\left| {{\bf{ < expression > + < expression > }}} \right|}\\\begin{array}{c}{\bf{\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;}}\,\,\,\,{\bf{ < expression > * < expression > |}}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,{\bf{ < variable > }}\end{array}\\{\,\,\,\,\,\,\,\,\,{\bf{ < variable > :: = xly}}}\end{array}\)

b) Find a derivation tree for \(\left( {{\bf{x*y}}} \right){\bf{ + x}}\) in this grammar.

Short Answer

Expert verified

(a) The productions of the grammar in the usual form are as follows:

expression \(\to\) (expression),

expression \(\to\) expression + expression,

expression \(\to\) expression * expression,

expression \(\to\) variable,

variable \(\to\) x

variable \(\to\) y

(b) The derivation tree for \(\left( {{\bf{x*y}}} \right){\bf{ + x}}\) is the following:

Step by step solution

01

About Backus-Nour form.

A type-2 grammar is designated by the notation known as Backus-Naur form.

The left side of a type 2 grammar's production is one non-terminal symbol.

It can merge all of the productions into a single statement using the same left non-terminal symbolàrather than listing each one separately in production,

It use the symbol:: =

It encloses all non-terminal symbols in brackets <>, and it list all right-hand sides of productions in the same statement, separating them by bars.

02

The Backus-Naur form of production of grammar is as follow:

\(\begin{array}{*{20}{l}}{{\bf{ < expression > :: = }}\left( {{\bf{ < expression > }}} \right){\bf{ }}\left| {{\bf{ < expression > + < expression > }}} \right|}\\\begin{array}{c}{\bf{\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;}}\,\,\,\,{\bf{ < expression > * < expression > |}}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,{\bf{ < variable > }}\end{array}\\{\,\,\,\,\,\,\,\,\,{\bf{ < variable > :: = xly}}}\end{array}\)

The productions of the grammar in the usual form are as follows:

expression \(\to\) (expression),

expression \(\to\) expression + expression,

expression \(\to\) expression * expression,

expression \(\to\) variable,

variable \(\to\) x

variable \(\to\) y

Hence, the above production is The Backus-Naur of a grammar.

03

Let’s find a derivation tree for \(\left( {{\bf{x*y}}} \right){\bf{ +  x}}\) in this grammar.

\(\begin{array}{*{20}{l}}\begin{array}{c}{\bf{expression}} \to {\bf{expression + expression}}\\ \to \left( {{\bf{expression}}} \right){\bf{ + expression}}\end{array}\\{ \to \left( {{\bf{expression*expression}}} \right){\bf{ + expression}}}\\{ \to \left( {{\bf{expression*expression}}} \right){\bf{ + variable}}}\\{ \to \left( {{\bf{expression*variable}}} \right){\bf{ + variable}}}\\{ \to \left( {{\bf{variable*variable}}} \right){\bf{ + variable}}}\\{ \to \left( {{\bf{variable*variable}}} \right){\bf{ + x}}}\\{ \to \left( {{\bf{variable*y}}} \right){\bf{ + x}}}\\{ \to \left( {{\bf{x* y}}} \right){\bf{ + x}}}\end{array}\)

Let’s construct a derivation tree for \(\left( {{\bf{x*y}}} \right){\bf{ + x}}\).

Hence, the above derivation tree for\(\left( {{\bf{x*y}}} \right){\bf{ + x}}\).

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

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{*}}}\)

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

a){0}* b){0} {0}* c){1} {0}*

d){01}* e){0}*{1}* f){1} {0,1}*

Suppose that A is a subset of\({{\bf{V}}^{\bf{*}}}\)where V is an alphabet.Prove or disprove each of these statements.

\(\begin{array}{l}{\bf{a)}}\,\,{\bf{A}} \subseteq {{\bf{A}}^{\bf{2}}}\\{\bf{b)}}\,\,{\bf{if}}\,{\bf{A = }}{{\bf{A}}^{\bf{2}}}{\bf{,then}}\,{\bf{\lambda }} \in {\bf{A}}\\{\bf{c)}}\,\,{\bf{A\{ \lambda \} = A}}\\{\bf{d)}}\,\,{{\bf{(}}{{\bf{A}}^{\bf{*}}}{\bf{)}}^{\bf{*}}}{\bf{ = }}{{\bf{A}}^{\bf{*}}}\\{\bf{e)}}\,\,{{\bf{A}}^{\bf{*}}}{\bf{A = }}{{\bf{A}}^{\bf{*}}}\\{\bf{f)}}\,\,\left| {{{\bf{A}}^{\bf{n}}}} \right|{\bf{ = }}{\left| {\bf{A}} \right|^{\bf{n}}}\end{array}\)

Let G be the grammar with V = {a, b, c, S}; T = {a, b, c}; starting symbol S; and productions \({\bf{S }} \to {\bf{ abS, S }} \to {\bf{ bcS, S }} \to {\bf{ bbS, S }} \to {\bf{ a, and S }} \to {\bf{ cb}}{\bf{.}}\)Construct derivation trees for

\(\begin{array}{*{20}{l}}{{\bf{a) bcbba}}{\bf{.}}}\\{{\bf{b) bbbcbba}}{\bf{.}}}\\{{\bf{c) bcabbbbbcb}}{\bf{.}}}\end{array}\)

Show that if A is a set of strings, then\({\bf{A}}\emptyset {\bf{ = }}\emptyset {\bf{A = }}\emptyset \).

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