NPTEL Compiler Design Week 5 Assignment Answers 2024

Join Our WhatsApp Group Join Now
Join Us On Telegram Join Now

NPTEL Compiler Design Week 5 Assignment Answers 2024

1. In a predictive parsing table if any cell has multiple entries, the grammar is:

(A) Ambiguous
(B) Erroneous
(C) Both ambiguous and erroneous
(D) None of the other options

Answer :- For Answer Click Here 

2. Consider the following grammar G:
S → iEtS | iEtSeS | a
E → b
After some transformation X, the grammar G becomes G’ as given below:
S → iEtSS’ | a
S’ → eS | ε
E → b
What is transformation X?

(A) Elimination of left recursion
(B) Left factoring
(C) Elimination of immediate left recursion
(D) None of the above

Answer :-  For Answer Click Here 

3. In the name “LR Parser”, the ‘R’ stands for:

(A) Constructing a Rightmost Derivation
(B) Constructing a Rightmost Derivation in Reverse
(C) Constructing a Recursive Parser
(D) None of the other options

Answer :-  For Answer Click Here 

4. Assuming that lower-case characters are terminals and upper-case ones are non-terminals in a grammar, which rule prevents the grammar from being an operator grammar?

(A) S → aA
(B) S → AB
(C) S → AbB
(D) All of the other options

Answer :- 

5. Which of the following cannot be performed by a parser?

(A) Detection of misspelling a keyword
(B) Detection of unbalanced parentheses in an arithmetic expression
(C) Detection of variable re-declaration
(D) All of the above

Answer :- 

6. In operator precedence parsing, the shift and reduce operations are done based on the priority between:

(A) The symbols referred by stack[top] and stack[top-1]
(B) The symbol referred by stack[top] and the current input symbol
(C) The current input symbol and the immediately next input symbol
(D) None of the above options

Answer :-  For Answer Click Here 

7. Consider the following grammar:
S → aABb
A → c | ε
B → d | ε
The LL(1) parsing table P is constructed for the above grammar. The production B → ε will be contained in which cell/cells of the table?

(A) P[B][d] and P[B][b] both
(B) P[B][a] only
(C) P[B][d] only
(D) P[B][b] only

Answer :- 

8. Consider the following grammar:
S → aABb
A → c | ε
B → d | ε
The LL(1) parsing table P is constructed for the above grammar. The production A → ε will be contained in which cell/cells of the table?

(A) P[A][d] and P[A][b] both
(B) P[A][d] only
(C) P[A][b] only
(D) P[A][c] only

Answer :- 

9. Consider the following grammar G:
S → ( L ) | a
L → L , S | S
How many “Reduce” to be applied to parse the string ( a , ( a , a ) ) using the production rules of the grammar G?

(A) 15
(B) 12
(C) 9
(D) 5

Answer :- 

10. You are to write an unambiguous grammar to generate the set of all strings over the alphabet {0, 1, +, -}. Here, ‘+’ and ‘-’ are binary infix operators. An incomplete grammar is given below for the same.
S → P | S – P
P → D
D → 0 | 1
Which production given below is most appropriate to complete the grammar written above.

(A) P → S
(B) P → P + D
(C) S → P + D
(D) None of the above options

Answer :-  For Answer Click Here