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

Give production rule in Backus-Naur form for an identifier if it can consist of

a. One or more lower case letters.

b. At least three but no more than six lowercase letter

c. One to six uppercase or lowercase letters beginning with an uppercase letter.

d. A lowercase letter, followed by a digit or an underscore, followed by three or four alphanumeric characters (lower or uppercase letters and digits.)

Short Answer

Expert verified

a) \(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {identifier} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\left\langle {letter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\end{array}\)

b) \(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle |\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\left\langle {letter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\end{array}\)

c) \(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {ucletter} \right\rangle |\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\left\langle {letter} \right\rangle :: = = \left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \\\left\langle {lcletter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\\\left\langle {ucletter} \right\rangle :: = = A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,W|X|Y|Z\end{array}\)

d) \(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {lcletter} \right\rangle \left\langle {digitorus} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle |\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {lcletter} \right\rangle \left\langle {digitorus} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\left\langle {alphanumeric} \right\rangle \\\left\langle {digitorus} \right\rangle :: = = \left\langle {digit} \right\rangle |\_\\\left\langle {alphanumeric} \right\rangle :: = = \left\langle {digit} \right\rangle |\left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \\\left\langle {digit} \right\rangle :: = = 0|1|2|3|4|5|6|7|8|9\\\left\langle {lcletter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\\\left\langle {ucletter} \right\rangle :: = = A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,W|X|Y|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

Backus-Naur form

Many programming languages, including Java, define their grammatical rules using the Backus-Naur form. A type 2 grammar has a single nonterminal symbol on the left side of each production. it can group all the productions that share the same nonterminal symbol on the left side into a single statement rather than listing each one separately.

02

Giving Production rule in Backus-Naur form for an identifier if it can consist of one or more lower case letters.

(a) The identifier must consist of at least one letter, therefore it can either be a single letter or an identifier that is followed by a single letter.

Now, the lowercase letters are

\(a,\,b,\,c,\,d,\,e,\,f,\,g,\,h,\,i,\,j,\,k,\,l,\,m,\,n,\,o,\,p,\,q,\,r,\,s,\,t,\,u,\,v,\,w,\,x,\,y,\,z\).

Now, \(|\) will be used to represent “or”.

Now, the Backus-Nour form is given by,

\(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {identifier} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\left\langle {letter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\end{array}\)

03

Giving Production rule in Backus-Naur form for an identifier if it can consist of at least three but no more than six lowercase letters

(b) It is given that it can consists of at least three but no more than six lowercase letters.

So, the identifier can only contain three, four, five or six lowercase letters.

Now, the lowercase letters are

\(a,\,b,\,c,\,d,\,e,\,f,\,g,\,h,\,i,\,j,\,k,\,l,\,m,\,n,\,o,\,p,\,q,\,r,\,s,\,t,\,u,\,v,\,w,\,x,\,y,\,z\).

Now, \(|\) will be used to represent “or”.

Now, the Backus-Nour form is given by,

\(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle |\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \left\langle {letter} \right\rangle \\\left\langle {letter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\end{array}\)

04

Giving Production rule in Backus-Naur form for an identifier if it can consist of one to six uppercase or lowercase letters beginning with an uppercase letter.

(c) It is given that it can consists of one to six uppercase or lowercase letters beginning with an uppercase letter.

So, the identifier can only contain one, two, three, four, five or six letters.

The first letter has to be uppercase, while other letter can be lowercase or uppercase letter.

Now, the lowercase letters are

\(a,\,b,\,c,\,d,\,e,\,f,\,g,\,h,\,i,\,j,\,k,\,l,\,m,\,n,\,o,\,p,\,q,\,r,\,s,\,t,\,u,\,v,\,w,\,x,\,y,\,z\).

The uppercase letters are

\(A,\,B,\,C,\,D,\,E,\,F,\,G,\,H,\,I\,,J,\,K,\,L,\,M,\,N,\,O,\,P,\,Q,\,R,\,S,\,T,\,U,\,V,\,W,\,X,\,Y,\,Z\)

Now, \(|\) will be used to represent “or”. \(\left\langle {ucletter} \right\rangle \) will be used to represent Uppercase letter. \(\left\langle {lcletter} \right\rangle \) will be used to represent Uppercase letter.

Now, the Backus-Nour form is given by,

\(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {ucletter} \right\rangle |\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {ucletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \left\langle {lcletter} \right\rangle \\\left\langle {letter} \right\rangle :: = = \left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \\\left\langle {lcletter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\\\left\langle {ucletter} \right\rangle :: = = A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,W|X|Y|Z\end{array}\)

05

Giving Production rule in Backus-Naur form for an identifier if it can consist of a lowercase letter, followed by a digit or an underscore, followed by three or four alphanumeric characters (lower or uppercase letters and digits.)

(d) It is given that it can consists of a lowercase letter, followed by a digit or an underscore, followed by three or four alphanumeric characters.

The identifier contains a lowercase letter, then a digitorus, then three or four alphanumeric characters.

A digitorus is a digit or underscore _.

A digit, lowercase letter, or capital letter are examples of alphanumeric characters.

Now, the lowercase letters are

\(a,\,b,\,c,\,d,\,e,\,f,\,g,\,h,\,i,\,j,\,k,\,l,\,m,\,n,\,o,\,p,\,q,\,r,\,s,\,t,\,u,\,v,\,w,\,x,\,y,\,z\).

The digits are \(0,\,1,\,2,\,3,\,4,\,5,\,6,\,7,\,8,\,9\).

The uppercase letters are

\(A,\,B,\,C,\,D,\,E,\,F,\,G,\,H,\,I\,,J,\,K,\,L,\,M,\,N,\,O,\,P,\,Q,\,R,\,S,\,T,\,U,\,V,\,W,\,X,\,Y,\,Z\).

Now, \(|\) will be used to represent “or”. \(\left\langle {ucletter} \right\rangle \) will be used to represent Uppercase letter. \(\left\langle {lcletter} \right\rangle \) will be used to represent Uppercase letter.

Now, the Backus-Nour form is given by,

\(\begin{array}{l}\left\langle {identifier} \right\rangle :: = = \left\langle {lcletter} \right\rangle \left\langle {digitorus} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle |\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,|\left\langle {lcletter} \right\rangle \left\langle {digitorus} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \left\langle {alphanumeric} \right\rangle \\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\left\langle {alphanumeric} \right\rangle \\\left\langle {digitorus} \right\rangle :: = = \left\langle {digit} \right\rangle |\_\\\left\langle {alphanumeric} \right\rangle :: = = \left\langle {digit} \right\rangle |\left\langle {lcletter} \right\rangle |\left\langle {ucletter} \right\rangle \\\left\langle {digit} \right\rangle :: = = 0|1|2|3|4|5|6|7|8|9\\\left\langle {lcletter} \right\rangle :: = = a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\\\left\langle {ucletter} \right\rangle :: = = A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|\\\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,W|X|Y|Z\end{array}\)

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

Determine whether the string 11101 is in each of these sets.

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

c){11} {0}*{01 d){11}*{01}*

e){111}*{0}*{1} f){11,0} {00,101}

Construct a finite-state machine that delays an input string by two bits, giving 00 as the first two bits of output.

construct a derivation tree for −109 using the grammar given in Example 15.

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}*

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

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