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

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

Short Answer

Expert verified

a) The phase structure grammar is \({\bf{S}} \to {\bf{00A and A}} \to {\bf{00A, A}} \to {\bf{\lambda }}\)

b) The phase structure grammar is\({\bf{S}} \to {\bf{10A and A}} \to {\bf{00A and A}} \to {\bf{\lambda }}\).

c) The phase structure grammar is:

\({\bf{S}} \to {\bf{AB and A}} \to {\bf{00A, A}} \to {\bf{\lambda , B}} \to {\bf{11B and B}} \to {\bf{\lambda }}\).

d) The phase structure grammar is\({\bf{S}} \to {\bf{0000000000A, A}} \to {\bf{0A, A}} \to {\bf{\lambda }}\).

e) The phase structure grammar is:

\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

f) The phase structure grammar is:

\({\bf{S}} \to {\bf{S1A, S}} \to {\bf{A1A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

g) The phase structure grammar is:

\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, S}} \to {\bf{S1A, S}} \to {\bf{A1A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

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 the language generated by the grammar.

Let \({\bf{G = }}\left( {{\bf{V, T, S, P}}} \right)\) be a phrase-structure grammar. The language generated by G (or the language of G), denoted by L(G), and is the set of all strings of terminals that are derivable from the starting state S.

02

Now, we shall find a phrase-structure grammar for part (a) languages.

We can start with\({\bf{S}} \to {\bf{00A}}\)and\({\bf{A}} \to {\bf{00A, A}} \to {\bf{\lambda }}\).

So, the string starts with an even number of 0's and it will consist of only even numbers of 0's by the rule \({\bf{A}} \to {\bf{00A}}\) and no 1's.

Hence, the phrase structure grammar for the language is\({\bf{S}} \to {\bf{00A}}\) and\({\bf{A}} \to {\bf{00A, A}} \to {\bf{\lambda }}\).

03

Now, we shall find a phrase-structure grammar for part (b) languages.

We can start with\({\bf{S}} \to {\bf{10A}}\)and \({\bf{A}} \to {\bf{00A}}\)and\({\bf{A}} \to {\bf{\lambda }}\).

So, the production starts with a \({\bf{1(S}} \to {\bf{10 A)}}\) and continues with the odd number of 0s as the rule \({\bf{A}} \to {\bf{004a}}\) adds two Os to the end of the string 10.

Hence, the phrase structure grammar for the language is\({\bf{S}} \to {\bf{10A}}\)and\({\bf{A}} \to {\bf{00A}}\)and\({\bf{A}} \to {\bf{\lambda }}\).

04

Now, we shall find a phrase-structure grammar for part (c) languages.

We can start with\({\bf{S}} \to {\bf{AB}}\)and \({\bf{A}} \to {\bf{00A, A}} \to {\bf{\lambda , B}} \to {\bf{11B}}\)and\({\bf{B}} \to {\bf{\lambda }}\).

So, the string starts with even numbers of 0's and 1’s and it will consist of only even numbers of 0's and 1's.

Hence, the phrase structure grammar for the language is\({\bf{S}} \to {\bf{AB}}\)and\({\bf{A}} \to {\bf{00A, A}} \to {\bf{\lambda , B}} \to {\bf{11B}}\)and\({\bf{B}} \to {\bf{\lambda }}\).

05

Now, we shall find a phrase-structure grammar for part (d) languages.

We can start with\({\bf{S}} \to {\bf{0000000000A, A}} \to {\bf{0A, A}} \to {\bf{\lambda }}\).

So, the string starts with ten 0s and can stop by the rule \({\bf{A}} \to {\bf{\lambda }}\) or continue to add a 0 at a time by rule\({\bf{A}} \to {\bf{0A}}\).

Hence, the phrase structure grammar for the language is:

\({\bf{S}} \to {\bf{0000000000A, A}} \to {\bf{0A, A}} \to {\bf{\lambda }}\).

06

Now, we shall find a phrase-structure grammar for part (e) languages.

We can start with\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

The productions for A will create strings that have an equal number of 0s and 1s.

The start symbol S will generate strings of the form A0A, A0A0A, ..., (A0) nA, that 0s in between strings that contain an equal number of 0s and 1s.

Thus, these strings have more 0s than 1s.

Hence, the phrase structure grammar for the language is:

\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{l}}\).

07

Now, we shall find a phrase-structure grammar for part (f) languages.

In part (e) we created a grammar for strings that have more Os than 1s.

The grammar was\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

If we replace the 0s with 1s in the productions for S, in the grammar listed above, then it will generate strings that have more is than 0s.

The grammar will become\({\bf{S}} \to {\bf{S1A, S}} \to {\bf{A1A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

08

Now, we shall find a phrase-structure grammar for part (g) languages.

There are two cases possible, which are there are more 1s than 0s or there are more 0s than 1s.

In part (e) we created a grammar for strings that have more 0s than 1s.

The grammar was\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

In part (f) we created a grammar for strings that have more is than Os. The grammar was\({\bf{S}} \to {\bf{S1A, S}} \to {\bf{A1A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

Merging these two grammars will give us the required grammar for strings in which the number of 1s is not equal to the number of 0s.

The grammar is given below:

\({\bf{S}} \to {\bf{S0A, S}} \to {\bf{A0A, S}} \to {\bf{S1A, S}} \to {\bf{A1A, A}} \to {\bf{1A0A, A}} \to {\bf{0A1A, A}} \to {\bf{\lambda }}\).

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

a) Construct a phrase-structure grammar for the set of all fractions of the form a/b, where a is a signed integer in decimal notation and b is a positive integer.

b) What is the Backus–Naur form for this grammar?

c) Construct a derivation tree for +311/17 in this grammar.

Find a phrase-structure grammar for each of these languages.

a) the set consisting of the bit strings 0, 1, and 11

b) the set of bit strings containing only 1s

c) the set of bit strings that start with 0 and end with 1

d) the set of bit strings that consist of a 0 followed by an even number of 1s.

Construct a deterministic finite-state automaton that recognizes the set of all bit strings beginning with 01.

Let V = {S, A, B, a, b} and T = {a, b}. Determine whether G = (V, T, S, P) is a type 0 grammar but not a type 1 grammar, a type 1 grammar but not a type 2 grammar, or a type 2 grammar but not a type 3 grammar if P, the set of productions, is

\(\begin{array}{*{20}{l}}{{\bf{a) S }} \to {\bf{ aAB, A }} \to {\bf{ Bb, B }} \to {\bf{ \lambda }}{\bf{.}}}\\{{\bf{b) S }} \to {\bf{ aA, A }} \to {\bf{ a, A }} \to {\bf{ b}}{\bf{.}}}\\{{\bf{c) S }} \to {\bf{ABa, AB }} \to {\bf{ a}}{\bf{.}}}\\{{\bf{d) S }} \to {\bf{ ABA, A }} \to {\bf{ aB, B }} \to {\bf{ ab}}{\bf{.}}}\\{{\bf{e) S }} \to {\bf{ bA, A }} \to {\bf{ B, B }} \to {\bf{ a}}{\bf{.}}}\\{{\bf{f ) S }} \to {\bf{ aA, aA }} \to {\bf{ B, B }} \to {\bf{ aA, A }} \to {\bf{ b}}{\bf{.}}}\\{{\bf{g) S }} \to {\bf{ bA, A }} \to {\bf{ b, S }} \to {\bf{ \lambda }}{\bf{.}}}\\{{\bf{h) S }} \to {\bf{ AB, B }} \to {\bf{ aAb, aAb }} \to {\bf{ b}}{\bf{.}}}\\{{\bf{i) S }} \to {\bf{ aA, A }} \to {\bf{ bB, B }} \to {\bf{ b, B }} \to {\bf{ \lambda }}{\bf{.}}}\\{{\bf{j) S }} \to {\bf{ A, A }} \to {\bf{ B, B }} \to {\bf{ \lambda }}{\bf{.}}}\end{array}\)

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.

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