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

Short Answer

Expert verified

a) A phrase-structure grammar that generates all signed.

\(\begin{array}{c}V = \left\{ {0,1,...,9, + , - ,...,sign,{\bf{ }}{\mathop{\rm int}} eger,{\bf{ }}positive{\bf{ }}{\mathop{\rm int}} eger,digit{\bf{ }},{\bf{ }}nonzero{\bf{ }}digit,{\bf{ }}S} \right\}\\T = \left\{ { + , - ,...,0,1,...,9} \right\}\\S{\bf{ }} = {\bf{ }}{\rm{starting symbol or production symbol}}{\bf{ }}\\S \to {\rm{sign integer}},{\bf{ }}\\{\rm{Sign}}{\bf{ }} \to + ,{\bf{ }}{\rm{sign}}{\bf{ }} \to - \\{\rm{integer}} \to {\bf{ }}{\rm{digit, integer}}{\bf{ }} \to {\bf{ }}{\rm{integer digit}}{\bf{ }}\\{\rm{digit}}{\bf{ }} \to i,i = {\bf{ }}0,1,2,\;...,9{\bf{ }}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{integer non zero digit}}{\bf{ }}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{non zero digit integer}}{\bf{ }}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{integer non zero digit integer}}{\bf{ }}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{non zero digit}}\\{\rm{non zero digit}}{\bf{ }}i,i{\bf{ }} = {\bf{ }}1,2,...,9\end{array}\)

b) The Backus–Naur form of the grammar G.

\(\begin{array}{c} < S > :: = < sign > < {\rm{integer}} > | < {\rm{sign}} > < {\rm{integer}} > < {\rm{positive integer}} > {\bf{ }}\\ < {\rm{sign}}{\bf{ }} > :: = + | - \\ < {\rm{integer}} > :: = < {\rm{digit}} > | < {\rm{integer}} > < {\rm{digit}} > {\bf{ }}\\ < {\rm{digit}} > :: = 0|1|2|3|4|5|6|7|8|9{\bf{ }}\\ < {\rm{positive integer}} > :: = < {\rm{integer}} > < {\rm{non zero digit}} > |\\ < {\rm{nonzero}}\,{\rm{digit}} > < {\rm{integer}} > |\\ < {\rm{integer}} > < {\rm{nonzero digit}} > < {\rm{integer}} > |\\ < {\rm{nonzero digit}} > {\bf{ }}\\ < nonzerodigit > :: = 0|1|2|3|4|5|6|7|8|9{\rm{ }}\end{array}\)

c) The derivation tree for -31.4.

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 production is one non-terminal symbol.

I 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,

Use the symbol:: =

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

02

Let’s construct a phrase-structure grammar:

(a)The phrase structure grammar, \(G{\bf{ }} = {\bf{ }}\left( {V,{\bf{ }}T,{\bf{ }}S,{\bf{ }}P} \right)\), generates all signed decimal numbers, consisting of a sign, either + or -, a non-negative integer, and a decimal fraction, which is either the empty string or a decimal point followed by a positive integer, where the initial zeros in an integer are allowed, with initial zeros in the following format:

\(\begin{array}{c}V = \left\{ {0,1,...,9, + , - ,...,{\rm{sign, integer, positive integer,digit , nonzero digit}},{\bf{ }}S{\bf{ }}} \right\}\\T = \left\{ { + , - ,...,0,1,...,9} \right\}\\S{\bf{ }} = {\bf{ }}{\rm{starting symbol or production symbol}}{\bf{ }}\\S \to {\rm{sign integer}},\\{\rm{Sign}}{\bf{ }} \to + ,{\bf{ }}{\rm{sign}}{\bf{ }} \to - \\{\rm{integer}} \to {\bf{ }}{\rm{digit, integer}}{\bf{ }} \to {\bf{ }}{\rm{integer digit}}\\{\rm{digit}}{\bf{ }} \to i,i = {\bf{ }}0,1,2,\;...,9{\bf{ }}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{integer non zero digit}}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{non zero digit integer}}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{integer non zero digit integer}}\\{\rm{positive integer}}{\bf{ }} \to {\bf{ }}{\rm{non zero digit}}\\{\rm{non zero digit}}{\bf{ }}i,i{\bf{ }} = {\bf{ }}1,2,...,9\end{array}\)

Hence, A phrase-structure grammar that generates all signed.

03

Backus-Naur form of productions of the above grammar.

(b)Now, the Backus–Naur form of the grammar G is

\(\begin{array}{c} < S > :: = < {\rm{sign}} > < {\rm{integer}} > | < {\rm{sign}} > < {\rm{integer}} > < {\rm{positive integer}} > {\bf{ }}\\ < {\rm{sign}}{\bf{ }} > :: = + | - \\ < {\rm{integer}} > :: = < {\rm{digit}} > | < {\rm{integer}} > < {\rm{digit}} > {\bf{ }}\\ < {\rm{digit}} > :: = 0|1|2|3|4|5|6|7|8|9{\bf{ }}\\ < {\rm{positive integer}} > :: = < {\rm{integer}} > < {\rm{non zero digit}} > |{\bf{ }}\\ < {\rm{nonzero}}\,\,{\rm{digit}} > < {\rm{integer}} > |{\bf{ }}\\ < {\rm{integer}} > < {\rm{nonzero digit}} > < {\rm{integer}} > |{\bf{ }}\\ < {\rm{nonzero digit}} > {\bf{ }}\\ < {\rm{nonzero digit}} > :: = 0|1|2|3|4|5|6|7|8|9{\rm{ }}\end{array}\)

Hence, the Backus–Naur form of the grammar G.

04

Let’s construct a derivation tree for -31.4 in the above grammar

(c)

Hence, the above derivation tree for -31.4.

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

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?

Let V = {S, A, B, a, b} and T = {a, b}. Find the language generated by the grammar (V, T, S, P) when theset P of productions consists of

\(\begin{array}{*{20}{l}}{{\bf{a) S }} \to {\bf{ AB, A }} \to {\bf{ ab, B }} \to {\bf{ bb}}{\bf{.}}}\\{{\bf{b) S }} \to {\bf{ AB, S }} \to {\bf{ aA, A }} \to {\bf{ a, B }} \to {\bf{ ba}}{\bf{.}}}\\{{\bf{c) S }} \to {\bf{ AB, S }} \to {\bf{ AA, A }} \to {\bf{ aB, A }} \to {\bf{ ab, B }} \to {\bf{ b}}{\bf{.}}}\\{{\bf{d) S }} \to {\bf{ AA, S }} \to {\bf{ B, A }} \to {\bf{ aaA, A }} \to {\bf{ aa, B }} \to {\bf{ bB, B }} \to {\bf{ b}}{\bf{.}}}\\{{\bf{e) S }} \to {\bf{ AB, A }} \to {\bf{ aAb, B }} \to {\bf{ bBa, A }} \to {\bf{ \lambda , B }} \to {\bf{ \lambda }}{\bf{.}}}\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}\)

A context-free grammar is ambiguous if there is a word in \({\bf{L(G)}}\) with two derivations that produce different derivation trees, considered as ordered, rooted trees.

Show that the grammar \({\bf{G = }}\left( {{\bf{V, T, S, P}}} \right)\) with \({\bf{V = }}\left\{ {{\bf{0, S}}} \right\}{\bf{,T = }}\left\{ {\bf{0}} \right\}\), starting state \({\bf{S}}\), and productions \({\bf{S}} \to {\bf{0S,S}} \to {\bf{S0}}\), and \({\bf{S}} \to 0\) is ambiguous by constructing two different derivation trees for \({{\bf{0}}^{\bf{3}}}\).

Show that a set is generated by a regular grammar if and only if it is a regular set.

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