Parsing · Compiler Design
58 questions · asked in 25 of 27 years (2000–2026)
MCQ 46 · MSQ 5 · NAT 71-mark 39 · 2-mark 19
2000Questions per year2026
Questions 21–25 of 58
Among simple LR (SLR) , canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful , in that order?
Answer: (C)
SLR builds its table from LR(0) items and uses FOLLOW sets. This makes it the easiest method to implement. Canonical LR(1) has the largest number of states. It accepts the biggest class of grammars, so it is the most powerful. LALR is in the middle of the two.
Answer: SLR, canonical LR
Answer: SLR, canonical LR
Consider the following grammar
S F|H
F p|c
H d|c
where S,F, and H are non-terminal symbols, p,d, and c are terminal symbols. Which of the following statement(s) is/are correct?
S1. LL(1) can parse all strings that are generated using grammar G
S2. LR(1) can parse all strings that are generated using grammar G
S F|H
F p|c
H d|c
where S,F, and H are non-terminal symbols, p,d, and c are terminal symbols. Which of the following statement(s) is/are correct?
S1. LL(1) can parse all strings that are generated using grammar G
S2. LR(1) can parse all strings that are generated using grammar G
Answer: (D)
The string "c" can be derived in two ways: and . This means the grammar is ambiguous.
An ambiguous grammar can never be LL(1) or LR(1).
Answer: Neither S1 nor S2
An ambiguous grammar can never be LL(1) or LR(1).
Answer: Neither S1 nor S2
A canonical set of items is given below
S
QR.
On input symbol the set has
S
QR.
On input symbol the set has
Answer: (D)
Look at the item S L. R. It can shift only on the symbol "". So there is no shift on "". The set has only one complete item, Q R., so two reductions are not possible. There is no conflict on "".
Answer: neither a shift-reduce nor a reduce-reduce conflict
Answer: neither a shift-reduce nor a reduce-reduce conflict
Consider the grammar defined by the following production rules, with two operators * and +
S T *P
T U| T*U
P Q +P |Q
Q Id
U Id
Which one of the following is TRUE?
S T *P
T U| T*U
P Q +P |Q
Q Id
U Id
Which one of the following is TRUE?
Answer: (B)
Look at each operator in turn:
- The rule recurses on the left side, so is left associative.
- The rule recurses on the right side, so is right associative.
Answer: (B)
- The rule recurses on the left side, so is left associative.
- The rule recurses on the right side, so is right associative.
Answer: (B)
Consider the following two sets of LR(1) items of an LR(1) grammar.
Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
1. Cannot be merged since look aheads are different.
2. Can be merged but will result in S-R conflict.
3. Can be merged but will result in R-R conflict.
4. Cannot be merged since goto on c will lead to two different sets.
Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
1. Cannot be merged since look aheads are different.
2. Can be merged but will result in S-R conflict.
3. Can be merged but will result in R-R conflict.
4. Cannot be merged since goto on c will lead to two different sets.
Answer: (D)
The two sets have the same core. The items are the same and only the lookaheads differ, so LALR can merge them. The merged set has no reduce items. It only has shifts on c and d, so it gives no S-R conflict and no R-R conflict. GOTO on c from both sets leads to sets that are also merged.
So all four statements are false.
Answer: 1, 2, 3 and 4
So all four statements are false.
Answer: 1, 2, 3 and 4
Keep practising