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

For each of these strings, determine whether it is generated by the grammar for infix expressions from Exercise 40. If it is, find the steps used to generate the string.

\(\begin{array}{*{20}{l}}{{\bf{a) x + y + z}}}\\{{\bf{b) a/b + c/d}}}\\{{\bf{c) m*}}\left( {{\bf{n + p}}} \right)}\\{{\bf{d) + m - n + p - q}}}\\{{\bf{e) }}\left( {{\bf{m + n}}} \right){\bf{*}}\left( {{\bf{p - q}}} \right)}\end{array}\)

Short Answer

Expert verified

a) Not generated

b) The grammar for expressions in infixed notation is reproduced below:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \end{array}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {identifier} \right\rangle }\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > a/b + c/d}\end{array}\)

c) The given string can be derived as:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {\exp ression} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\end{array}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > m*\left( {n + p} \right)}\end{array}\)

d) Not generated

e) The string can be derived as given below:

\(\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {\exp ression} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {\exp ression} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {m + n} \right)*\left( {p - q} \right)\end{array}\)

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 infit notation

Represent complicated expressions, e.g: compound propositions, set combinations and arithmetic expressions using ordered rooted trees.

Consider how an arithmetic phrase with the operators + (addition), - (subtraction), + (multiplication), / (division), and is represented (exponentiation).

02

Step 2: Create the steps used to generate the string.

The following is a reproduction of the syntax for infix notation expressions:

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

03

Create the steps to generate the string \({\bf{x  +   y  +  z}}\).

(a)

The given string \(x + {\rm{ }}y + {\rm{ }}z\), cannot be derived as it not possible to have more than one \( + \) in strings generated by the grammar.

As a can be an or an, if the string converted to \(x + {\rm{ }}\left( {y + {\rm{ }}z} \right)\)it can be produced by the grammar.

Therefore, the given expression is not obtained.

04

Step 4:Create the steps to generate the string \(\frac{{\bf{a}}}{{\bf{b}}}{\bf{  +   }}\frac{{\bf{c}}}{{\bf{d}}}\).

(b)

The given string can be derived as:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \end{array}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {identifier} \right\rangle }\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \frac{a}{b} + \frac{c}{d}}\end{array}\)

To generate the string first it take the expression, and then it could be expanded using the rule;

\(\left\langle {\exp ression} \right\rangle :: = \left\langle {term} \right\rangle |\left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle \)

Then using the rule,

\(\left\langle {term} \right\rangle :: = \left\langle {factor} \right\rangle |\left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \)it is expanded again.

Now rule.

\(\left\langle {factor} \right\rangle :: = \left\langle {identifier} \right\rangle |\left\langle {\exp ression} \right\rangle \)is applied to generate next line.

Hence, the given expression is obtained.

05

Create the steps to generate the string \({\bf{m*}}\left( {{\bf{n  +  p}}} \right)\).

(c)

The given string can be derived as:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {\exp ression} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\end{array}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {identifier} \right\rangle \left\langle {mulOperator} \right\rangle \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)}\\{\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > m*\left( {n + p} \right)}\end{array}\)

So, this is the required expression.

06

Step 6:Create the steps to generate the string \({\bf{ +  m   -  n  +   p  -  q}}\).

(d)

This is not generated as there cannot be more than a single \( + \) or a \( - \) in the grammar (more details are given in the solution for part (a)).

Thus, the given expression is not obtained.

07

Create the steps to generate the string \(\left( {{\bf{m  +  n}}} \right){\bf{*}}\left( {{\bf{p  -  q}}} \right)\).

(e)

The string can be derived as given below:

\(\begin{array}{c}\left\langle {\exp ression} \right\rangle \mathop = \limits^* > \left\langle {term} \right\rangle {\bf{ }}\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {factor} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {factor} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left\langle {\exp ression} \right\rangle \left\langle {mulOperator} \right\rangle \left\langle {\exp ression} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {term} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {term} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \left( {\left\langle {factor} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {factor} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)\left\langle {mulOperator} \right\rangle \left( {\left\langle {identifier} \right\rangle \left\langle {addOperator} \right\rangle \left\langle {identifier} \right\rangle } \right)\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\mathop = \limits^* > \left( {m + n} \right)*\left( {p - q} \right)\end{array}\)

Accordingly, this is the required expression.

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 Backusโ€“Naur form that generate all identifiers in the C programming language. In โ€˜Cโ€™ an identifier starts with a letter or an underscore (_) that is followed by one or more lowercase letters, uppercase letters, underscores, and digits.

Several extensions to Backusโ€“Naur form are commonly used to define phrase-structure grammars. In one such extension, a question mark (?) indicates that the symbol, or group of symbols inside parentheses, to its left can appear zero or once (that is, it is optional), an asterisk (*) indicates that the symbol to its left can appear zero or more times, and a plus (+) indicates that the symbol to its left can appear one or more times. These extensions are part of extended Backusโ€“Naur form (EBNF), and the symbols?, *, and + are called metacharacters. In EBNF the brackets used to denote nonterminal are usually not shown.

In Exercises 16โ€“22 find the language recognized by the given deterministic finite-state automaton

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

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?

Let V be an alphabet, and let A and B be subsets of \({\bf{V*}}\) Show that \({\bf{|AB}}\left| {{\rm{ }} \le {\rm{ }}} \right|{\bf{A||B|}}\).

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