Compilers Questions and Answers – Recovery from Syntactic Phase Errors – 2


This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Recovery from Syntactic Phase Errors –

1. Find the TRUE statement?
I. There exist parsing algorithms for some programming languages which has O (3) complexities
II. A programming language which allows recursion can be implemented with static storage allocation.
III.No L-attributed definition can be evaluated in The framework of bottom-up parsing.
IV. Code improving transformations can be performed at both intermediate code level and source Language.
a) I and II
b) I and IV
c) III and IV
d) I III and IV
View Answer

Answer: b
Explanation: In recursion, space used but recursive call can’t be calculated by the compiler.


2. Which of the following describes a handle (as applicable to LR-parsing) appropriately?
a) Position where next reduce or shift operation will occur
b) The next step has use of Non-terminal for reduction
c) Used for reduction in a coming-up step along with a position in the sentential form where the next shift or reduce operation will occur
d) Used in the next step for reduction along with a position in the sentential form where the right hand side of the production may be found
View Answer

Answer: d
Explanation: The next step in LR parsing shall have Reduction.

3. Which one of the following is a top-down parser?
a) Recursive descent parser
b) Operator precedence parser
c) An LR(k) parser
d) An LALR(k) parser
View Answer

Answer: a
Explanation: Recursive Descent also known as top down parsing also known to be LL(1).

4.Consider the following two statements:
P: Every regular grammar is LL(1)
Q:Regular is 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
View Answer

Answer: c
Explanation: Ambiguity can be seen in regular grammar
S → aA/a
A → aA/ε
In above grammar, string ‘a’ has two leftmost
S → aA
S → a
S->a (using A->ε).

5. Consider the grammar defined by the following production rules

 S --> T * P 
    T --> U | T * U
    P --> Q + P | Q
    Q --> Id
    U --> Id

Which one of the following is TRUE?
a) + is left associative, while ∗ is right associative
b) + is right associative, while ∗ is left associative
c) Both + and ∗ are right associative
d) Both + and ∗ are left associative
View Answer

Answer: b
Explanation: It is associative we can see and tell.Second productions latter part shows left recursion and is left associative.

6. The grammar A → AA | (A) | e is not suitable for predictive-parsing because the grammar is
a) Ambiguous
b) Left recursive
c) Right recursive
d) An operator grammar
View Answer

Answer: b
A ::= A a
| b is the left recursive language.

7. Consider the grammar
E → E + n | E × n | n
For a sentence n + n × n, the handles in the right-sentential form of the reduction are
a) n, E + n and E + n × n
b) n, E + n and E + n × n
c) n, n + n and n + n × n
d) n, E + n and E × n
View Answer

Answer: d
Explanation: E → E + n {Applying E → E + n }
→ E + E * n {Applying E → E * n }
→ E + n * n {Applying E → n }
→ n + n * n {Applying E → n }.

8. Which grammar rules violate the requirements of an operator grammar ?
1.P → Q R
2.P → Q s R
3.P → ε
4.P → Q t R r
a) 1 only
b) 1 and 3 only
c) 2 and 3 only
d) 3 and 4 only
View Answer

Answer: b
Explanation: Top down parsing: We begin with the start symbol and compare the right side of the different productions against the first piece of input to see which of the productions should be used.

9. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a) Removing left Recursive alone
b) Factoring the grammar alone
c) Along with removing left recursion we also perform the factoring of the grammar
d) None of the mentioned
View Answer

Answer: d
Explanation: Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar.

10. In a bottom-up evaluation of a syntax directed definition its inherited attributes can do which of the following?
a) Always evaluated
b) Can be evaluated if the definition is L attributed
c) Can be evaluated if the definition has synthesized attributes
d) Never be evaluated
View Answer

Answer: b
Explanation: A Syntax Directed Definition (SDD) is called S Attributed if it has only synthesized attributes. Also the-Attributed Definitions contain both synthesized and inherited attributes but do not need to build a dependency graph to evaluate them.

Sanfoundry Global Education & Learning Series – Compilers.
To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn