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 Backus–Naur form to describe the syntax of expressions in infix notation, where the set of operators and identifiers is the same as in the BNF for postfix expressions given in the preamble to Exercise 39, but parentheses must surround expressions being used as factors.

Short Answer

Expert verified

The Backus-Naur form for postfix expressions:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {expression} \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 :: = + | - \\\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 {expression} \right\rangle }\\{\,\,\,\,\,\,\,\,\,\left\langle {identifier} \right\rangle :: = a|b|c|...|z}\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

About Backus-Nour form

The Backus-Naur form is a notation for specifying a type 2 grammar.

Productions in a type 2 grammar have a single non-terminal symbol on the left.

Rather of listing all the productions separately, we can merge all those with the same non terminal symbol on the left-hand side into one statement instead of using the symbolàin a production,

The symbol:: =

All non-terminal symbols are enclosed in brackets (>), and all productions' right-hand sides are listed in the same statement, separated by bars.

02

Step 2: Let’s use Backus–Naur form to describe the syntax of expressions in infix notation.

The syntax of expressions in infixed notation of the Backus-Naur form with the same set of operators and identifiers as in the Backus-Naur form for postfix expressions can be given as:

\(\begin{array}{*{20}{l}}\begin{array}{c}\left\langle {expression} \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 :: = + | - \\\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 {expression} \right\rangle }\\{\,\,\,\,\,\,\,\,\,\left\langle {identifier} \right\rangle :: = a|b|c|...|z}\end{array}\)

The difference between the syntax of expressions in postfix and infix is that the operators are inserted between their operands and not behind them as in postfix.

Also, the parentheses are required in expressions used as factors.

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

Question:Let G = (V, T, S, P) be the phrase-structure grammar with V = {0, 1, A, B, S}, T = {0, 1}, and set of productions P consisting of S → 0A, S → 1A, A → 0B, B → 1A, B → 1.

a) Show that 10101 belongs to the language generated by G.

b) Show that 10110 does not belong to the language generated by G.

c) What is the language generated by G?

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

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

Let \({\bf{G = }}\left( {{\bf{V, T, S, P}}} \right)\) be the context-free grammar with \({\bf{V = }}\left\{ {\left( {\bf{,}} \right){\bf{S,A,B}}} \right\}{\bf{, T = }}\left\{ {\left( {\bf{,}} \right)} \right\}\) starting symbol \({\bf{S}}\), and productions \({\bf{S}} \to {\bf{A,A}} \to {\bf{AB,A}} \to {\bf{B,B}} \to {\bf{A,}}\)and \({\bf{B}} \to {\bf{(),S}} \to {\bf{\lambda }}\)

Construct the derivation trees of these strings.

\({\bf{a)}}\)\({\bf{(())}}\)

\({\bf{b)}}\)\({\bf{()(())}}\)

\({\bf{c)}}\)\({\bf{((()()))}}\)

Construct phrase-structure grammars to generate each of these sets.

a) \(\left\{ {\left. {{{\bf{0}}^{\bf{n}}}} \right|{\bf{n}} \ge {\bf{0}}} \right\}\)

b) \(\left\{ {\left. {{{\bf{1}}^{\bf{n}}}{\bf{0}}} \right|{\bf{n}} \ge {\bf{0}}} \right\}\)

c) \(\left\{ {\left. {{{\left( {{\bf{000}}} \right)}^{\bf{n}}}} \right|{\bf{n}} \ge {\bf{0}}} \right\}\)

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