250+ TOP MCQs on LR Parser and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “LR Parser”.

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

Answer: c
Clarification: 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

Answer: a
Clarification: 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

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

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

Answer: c
Clarification: 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)

Answer: c
Clarification: Only reject out of the following is a correct LR parser action.

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

Answer: a
Clarification: 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

Answer: c
Clarification: 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.

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

Answer: b
Clarification: 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

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *