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 6–10 of 58
Which of the following is/are Bottom-Up Parser(s)?
One or more options are correct.
Answer: (A), (D)
A bottom-up parser starts at the leaves and builds the parse tree up to the root. It does this by using reductions. Shift-reduce parsers, the operator precedence parser and the LR family (LR(0), SLR, LALR, CLR) are of this type.
The predictive parser and the LL(1) parser are top-down parsers.
Answer: Shift-reduce Parser, LR Parser
The predictive parser and the LL(1) parser are top-down parsers.
Answer: Shift-reduce Parser, LR Parser
Consider the following grammar , with as the start symbol. The grammar has three incomplete productions denoted by (1), (2), and (3).
The set of terminals is . The FIRST and FOLLOW sets of the different non-terminals are as follows.
Which one of the following options CORRECTLY fills in the incomplete productions?
The set of terminals is . The FIRST and FOLLOW sets of the different non-terminals are as follows.
Which one of the following options CORRECTLY fills in the incomplete productions?
Answer: (A)
Fill each blank so that the given FIRST and FOLLOW sets come out right.
(1) , but gives only . So (1) must give and . gives because can be empty. gives only .
(2) and , give only , so (2) is . would put in .
(3) and is already there, so (3) starts with . Try .
Check FOLLOW with , , , :
- : is followed by in , and it is last in (adds nothing new). So .
- : in , is followed by , so . Since can be empty, also . From , , and from , . So .
- is the start symbol, so .
- Putting these together, , as given.
With instead, nothing would put after , so would be missing from .
Answer: (A)
(1) , but gives only . So (1) must give and . gives because can be empty. gives only .
(2) and , give only , so (2) is . would put in .
(3) and is already there, so (3) starts with . Try .
Check FOLLOW with , , , :
- : is followed by in , and it is last in (adds nothing new). So .
- : in , is followed by , so . Since can be empty, also . From , , and from , . So .
- is the start symbol, so .
- Putting these together, , as given.
With instead, nothing would put after , so would be missing from .
Answer: (A)
Which one of the following statements is TRUE?
Answer: (D)
Let us check each statement one by one:
- LALR(1) joins LR(1) states that have the same core. This joining can bring in a new reduce-reduce conflict so the statement is FALSE.
- The symbol table is used in almost all phases, such as semantic analysis, code generation, so the statement is FALSE.
- Data flow analysis is used for code optimization. It is not used for run-time memory management so the statement is FALSE.
- Each deterministic CFL has an LR(1) grammar. So LR(1) parsing is enough for DCFLs so the statement is TRUE.
Answer: LR(1) parsing is sufficient for deterministic context-free languages
- LALR(1) joins LR(1) states that have the same core. This joining can bring in a new reduce-reduce conflict so the statement is FALSE.
- The symbol table is used in almost all phases, such as semantic analysis, code generation, so the statement is FALSE.
- Data flow analysis is used for code optimization. It is not used for run-time memory management so the statement is FALSE.
- Each deterministic CFL has an LR(1) grammar. So LR(1) parsing is enough for DCFLs so the statement is TRUE.
Answer: LR(1) parsing is sufficient for deterministic context-free languages
Consider the augmented grammar with as the set of terminals.
If is the set of two items , then contains exactly ______ items.
If is the set of two items , then contains exactly ______ items.
Answer: 5
Closure of adds no items (the dot is before + or at the end, never before a non-terminal).
goto on +: . Closure (dot before R, then P):
1.
2.
3.
4.
5.
Answer: 5
goto on +: . Closure (dot before R, then P):
1.
2.
3.
4.
5.
Answer: 5
Consider the following grammar along with translation rules.
Here and are operators and is a token that represents an integer and represents the corresponding integer value. The set of non-terminals is and a subscripted non-terminal indicates an instance of the non-terminal.
Using this translation scheme, the computed value of for root of the parse tree for the expression is
Here and are operators and is a token that represents an integer and represents the corresponding integer value. The set of non-terminals is and a subscripted non-terminal indicates an instance of the non-terminal.
Using this translation scheme, the computed value of for root of the parse tree for the expression is
Answer: 80
Look at the grammar. The operator # (multiply) comes at the S level, so it has lower precedence. The operator % (divide) comes at the T level, so it binds tighter. Both rules are left recursive, so both operators are left associative.
Evaluate the expression:
Answer: 80
Evaluate the expression:
Answer: 80
Keep practising