NPTEL Compiler Design Assignment Answers

1. Choose correct option.

(A) Left-to-right scanning and constructing a Rightmost Derivation in Reverse
(B) Left-to-right scanning and constructing a Rightmost Derivation
(C) Left to right reduction
(D) None of the other options

Answer :- a

2. SLR parser is LR(k) parser with k equals to:

(A) 1
(B) 2
(C) 3
(D) None of the other options

Answer :- d

3. In SLR parsing for the grammar
S’ → S
S → aSbS
S → bSaS | ε
In state 0, for inputs ‘a’ and ‘b’

(A) Both ‘a’ and ‘b’ will have shift-reduce conflict
(B) Only ‘a’ will have shift-reduce conflict
(C) Only ‘b’ will have shift-reduce conflict
(D) Neither of the other options

Answer :- a

4. Consider the grammar given below:
E → E + T
E → T
T → T * F
T → F
F → (E)
F → id
Let, I0 = CLOSURE([E’ → .E]). How many items are there in the set GOTO( I0 , ( )?

(A) 4
(B) 5
(C) 6
(D) 7

Answer :- d

5. Consider the following grammar:
S → L = R
S → R
L → * R
L → id
R → L
Consider the set of LR(0) items and let I2 is as given below:
S → L .=R
R → L.
The entry in ACTION[2, =] is:

(A) Shift to some state
(B) Reduce using some production
(C) A shift-reduce conflict
(D) None of the above

Answer :- c

6. In LR(1) parsing, we reduce by A → α only on those input symbols a for which [A → α., a] is an LR(1) item in the state on top of the stack. The set of such a’s will always be:

(A) Equal to the set FOLLOW(A)
(B) A subset of FOLLOW(A)
(C) A proper subset of FOLLOW(A)
(D) None of the above

Answer :- b

7. Consider the following grammar G:
S → A | B
A →a | c
B → b | c

Here, S, A and B are non-terminals and a, b, and c are terminals. Consider the two statements given below:
S1: Unambiguous LL(1) parser can be constructed to parse all strings in L(G)
S2: Conflict-free LR(1) parser exists to parse all strings in L(G) Which one of the following is true?

(A) S1
(B) S2
(C) Both S1 and S2
(D) Neither S1 nor S2

Answer :- d

8. Consider the following two statements:
P: Every regular grammar is LL(1)
Q: Every regular set has a LR(1) grammar
Which of the following is TRUE?

(A) Both P and Q are true
(B) P is true and Q is false
(C) P is false and Q is true
(D) Both P and Q are false

Answer :- c

9. Which one from the following is false?

(A) LALR parser is Bottom-up parser
(B) A parsing algorithm which performs a left to right scanning and a right most deviation in reverse is RL(1)
(C) LR parser is Bottom-up parser
(D) In LL(1), the 1 indicates that there is a one-symbol look-ahead.

Answer :- b

10. Which of the following statements is false?

(A) An ambiguous grammar may have LL(1) parser without multiple definitions
(B) An LL(1) parser is a top-down parser
(C) LALR is more powerful than SLR
(D) An ambiguous grammar can never be LR(k) for any k

Answer :- a

11. In a syntax directed translation scheme, the actions are written corresponding to the:

(A) Variables of the grammar
(B) Terminals of the grammar
(C) Production rules of the grammar
(D) None of the other options

Answer :- c

12. Consider a grammar E → E + n | E * n | n. For the sentence n + n * n, the handles in the right-sentential form during reductions are:

(A) n, n + n * n, n + n * n
(B) n, E + n * n, E + n
(C) n, E + n, E * n
(D) None of the other options

Answer :- c

13. Consider the grammar given below:
E → E + T | E – T | T
T → 0|1|2|…|9
Now, Consider the following syntax directed translation scheme:
E → E1 + T {E.val = E1.val || T.val || ‘+’}
E → E1 – T {E.val = E1.val || T.val || ‘-’}
E → T {E.val = T.val}
T → 0|1|2|…|9 {T.val = number}
Here, the symbol ‘||’ denotes concatenation of strings.
Attribute values of E and T hold the strings corresponding to the:

(A) Postfix expression
(B) Infix expression
(C) Prefix expression
(D) Neither of the other options

Answer :- a

14. Consider the syntax directed translation scheme given below (here, x, y and z are terminals):

S → AC {print “#”}
S → xB {print “###”}
A → Sy {print “##”}
B → z {print “#”}
C → S {print “#”}
How many ‘#’ will be printed for the input “xzyxz”?

(A) 6
(B) 8
(C) 10
(D) 12

Answer :- d

15. Synthesized attributes (an attribute of the non-terminal on the left-hand side of a production) represent information that can take value only from its:

(A) Children nodes
(B) Sibling nodes
(C) Parent node
(D) None of the above

Answer :- a

16. The output of the YACC software tool is:

(A) A semantic analyzer
(B) A parser
(C) A machine code representation of the source code
(D) None of the above

Answer :- b

17. Which of the following is TRUE for shift-reduce parsers?

(A) Scans and parses the input in one forward pass over the text
(B) A shift operation advances in the input stream
(C) To avoid guessing, the shift-reduce parser often looks ahead
(D) All of the above statements

Answer :- d

18. Consider the following grammar:

S → a E c
S → a F d
S → b F c
S → b E d
E → e
F → e
Which of the following statements is TRUE?

(A) The grammar can be parsed by both LR(1) and LALR(1) parsers
(B) The grammar can be parsed neither by LR(1) parser nor by LALR(1) parser
(C) The grammar can be parsed by LR(1) parser but not by LALR(1) parser
(D) None of the above

Answer :- c

19. Consider the following syntax directed translation scheme with non-terminals {S, A} and terminals {a,b}.

S→aA {print ‘1’}
A→a {print ‘2’}
S→Sb {print ‘3’}
Using the above scheme, the output printed by a bottom-up parser for the input “aab” is:

(A) 123
(B) 231
(C) 213
(D) 312

Answer :- c

20. Which of the following statements is TRUE?

(A) The LALR(1) parser is more powerful than the LR(1) parser
(B) The LALR(1) parser is less powerful than the LR(1) parser
(C) LALR(1) parser has same power as of the LR(1) parser
(D) None of the above

Answer :- b

21. Which of the following is/are TRUE about type checking?

(A) Type checking is one of the most important semantic aspects of compilation
(B) It checks types of objects and report a type-error in case of a violation
(C) Incorrect types may be corrected in this phase of compilation
(D) All of the above are true

Answer :- d

22. Consider the following two statements and choose the correct option.

S1: Static type checking done at compile time.
S2: Dynamic type checking is Performed during program execution.
(A) Only S1 is TRUE
(B) Only S2 is TRUE
(C) Both S1 and S2 are TRUE
(D) None of S1 and S2 are TRUE

Answer :- c

23. Which of the following tasks should be performed in semantic analysis?

(A) Scope resolution
(B) Type checking
(C) Array-bound checking
(D) All of the above

Answer :- d

24. Which of the following statements is TRUE about Attribute Grammar?

(A) Attribute grammar is a special form of context-free grammar
(B) Each attribute has well-defined domain of values
(C) The right part of the definition contains the semantic rules
(D) All of the above

Answer :- d

25. When can semantic errors be detected?

(A) During run-time
(B) During compilation time
(C) Both (A) and (B)
(D) None of the above

Answer :- c

26. Which of the following provides semantics to the context-free grammar?

(A) Attribute grammar
(B) Derivation tree
(C) Production rules of the grammar
(D) None of the above

Answer :- a

27. In a syntax-directed translation which attributes get values from their child nodes?

(A) Synthesized attributes
(B) Inherited attributes
(C) S-attributed SDT
(D) L-attributed SDT

Answer :- a

28. Which form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings?

(A) T-attributed SDT
(B) A-attributed SDT
(C) S-attributed SDT
(D) L-attributed SDT

Answer :- d

29. Let the syntax-directed translation (SDT) be defined as given below: S → AB {A.val = B.val} The SDT is:

(A) S-attributed
(B) L-attributed
(C) Both S-attributed and L-attributed
(D) Neither S-attributed nor L-attributed

Answer :- d

30. Consider the following SDT and choose the correct option:

S → A + B {S.val = A.val + B.val}
A → n {A.val = n.val}
B → n { B.val = n.val}
(A) The SDT is L-attributed only
(B) The SDT is S-attributed only
(C) The SDT is both L-attributed and S-attributed
(D) None of the other options

Answer :- c

31. What is the use of a symbol table in compiler design?

(A) Finding name’s scope
(B) Type checking
(C) Keeping all of the names of all entities in one place
(D) All of the above mentioned

Answer :- d

32. In self-organizing list based symbol table, position of a symbol is dictated by

(A) Recency of reference
(B) Alphabetical order
(C) Size of the symbol
(D) None of the given options

Answer :- a

33. In the worst case, lookup time for a tree-based symbol table is

(A) O(log n)
(B) O(n)
(C) O(n log n)
(D) None of the other options

Answer :- b

34. Which of the following is NOT likely to be kept in a symbol table?

(A) Name
(B) Location
(C) Scope
(D) None of the other options

Answer :- d

35. Which of the following has the maximum impact on reducing overall symbol table access time?

(A) Quick insert
(B) Quick delete
(C) Quick lookup
(D) None of the other options

Answer :- c

36. What is the average time complexity of lookup in a symbol table which is organized as a balanced search tree of order k?

(A) O(logk n )
(B) O(nk)
(C) O(n + k)
(D) None of the other options

Answer :- a

37. Consider the following code segment:

a = b + c;
e = a + 1;
d = b + c;
f = d + 1;
g = e + f;
If this code segment is represented as a directed acyclic graph (DAG), minimum possible number of nodes in the DAG will be:

(A) 4
(B) 5
(C) 6
(D) 7

Answer :- c

38. Consider the following expression:

((a+a)+(a+a))+((a+a)+(a+a))
The expression is represented as a directed acyclic graph (DAG) with minimum possible number of nodes. How many internal nodes will be there in the DAG?

(A) 2
(B) 3
(C) 4
(D) 5

Answer :- b

39. A typical activation record does not contain:

(A) Parameters passed to the procedure
(B) Bookkeeping information, including return values
(C) Space for compiler generated local variables to hold sub-expression values
(D) None of the other options

Answer :- d

40. If one symbol table per scope is considered then which of the following is NOT true?

(A) It is best suited for single-pass compiler
(B) It is best suited for multi-pass compiler
(C) Search may be expensive if variable is defined much above in the hierarchy
(D) None of the options is true

Answer :- b

Leave a Comment