Compilers Questions and Answers – LR Parser – 1

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “LR Parser – 1”.

1. Which of these is also known as look-head LR parser?
a) SLR
b) LR
c) LLR
d) None of the mentioned
View Answer

Answer: c
Explanation: LLR is the look ahead parser.

2. What is the similarity between LR, LALR and SLR?
a) Use same algorithm, but different parsing table
b) Same parsing table, but different algorithm
c) Their Parsing tables and algorithm are similar but uses top down approach
d) Both Parsing tables and algorithm are different
View Answer

Answer: a
Explanation: The common grounds of these 3 parser is the algorithm but parsing table is different.

3. An LR-parser can detect a syntactic error as soon as __________
a) The parsing starts
b) It is possible to do so a left-to-right scan of the input
c) It is possible to do so a right-to-left scan of the input
d) Parsing ends
View Answer

Answer: b
Explanation: Error is found when it the input string is scanned.
advertisement
advertisement

4. Which of these is true about LR parsing?
a) Is most general non-backtracking shift-reduce parsing
b) It is still efficient
c) Is most general non-backtracking shift-reduce parsing & It is still efficient
d) None of the mentioned
View Answer

Answer: c
Explanation: LR parsers are a type of bottom-up parsers that efficiently handle deterministic context-free languages in guaranteed linear time.

5. Which of the following is incorrect for the actions of A LR-Parser I) shift s ii) reduce A->ß iii) Accept iv) reject?
a) Only I)
b) I) and ii)
c) I), ii) and iii)
d) I), ii) , iii) and iv)
View Answer

Answer: c
Explanation: Only reject out of the following is a correct LR parser action.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. If a state does not know whether it will make a shift operation or reduction for a terminal is called _________
a) Shift/reduce conflict
b) Reduce /shift conflict
c) Shift conflict
d) Reduce conflict
View Answer

Answer: a
Explanation: As the name suggests that the conflict is between shift and reduce hence it is called shift reduce conflict.

7. When there is a reduce/reduce conflict?
a) If a state does not know whether it will make a shift operation using the production rule i or j for a terminal
b) If a state does not know whether it will make a shift or reduction operation using the production rule i or j for a terminal
c) If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal
d) None of the mentioned
View Answer

Answer: c
Explanation: It occurs when If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal.
advertisement

8. When ß (in the LR(1) item A -> ß.a,a) is not empty, the look-head _________
a) Will be affecting
b) Does not have any affect
c) Shift will take place
d) Reduction will take place
View Answer

Answer: b
Explanation: There is no terminal before the non terminal beta.

9. When ß is empty (A -> ß.,a), the reduction by A-> a is done by _________
a) If next symbol is a terminal
b) Only If the next input symbol is a
c) Only If the next input symbol is A
d) Only if the next input symbol is a
View Answer

Answer: d
Explanation: The next token is considered in this case it’s a.
advertisement

10. The construction of the canonical collection of the sets of LR (1) items are similar to the construction of the canonical collection of the sets of LR (0) items. Which is an exception?
a) Closure and goto operations work a little bit different
b) Closure and goto operations work similarly
c) Closure and additive operations work a little bit different
d) Closure and associatively operations work a little bit different
View Answer

Answer: a
Explanation: Closure and goto do work differently in case of LR (0) and LR (1).

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.