Parser MCQ Quiz - Objective Question with Answer for Parser - Download Free PDF
Last updated on Jul 16, 2025
Latest Parser MCQ Objective Questions
Parser Question 1:
Which of the following is the most powerful parser ?
Answer (Detailed Solution Below)
Parser Question 1 Detailed Solution
The correct answer is Canonical LR
Key Points
- SLR Parser: ✅ Simple LR (SLR) parser is the simplest type of LR parser and works with a smaller set of items. It is less powerful as it cannot handle all grammars that are LR(1).
- LALR Parser: ✅ Look-Ahead LR (LALR) parser is more powerful than SLR and is widely used in practice due to its efficiency. However, it is still less powerful than Canonical LR.
- Canonical LR Parser: ✅ The Canonical LR parser is the most powerful among LR parsers. It uses the full set of LR(1) items and can handle a larger class of grammars compared to SLR and LALR.
- Operator Precedence: ❌ Operator precedence parsers are specialized parsers for handling operator grammars. They are not as general or powerful as LR parsers.
Additional Information
- SLR: Uses fewer states and is less computationally expensive but cannot handle all LR(1) grammars.
- LALR: Combines states with similar look-ahead sets to reduce the number of states, making it more space-efficient.
- Canonical LR: Uses the full LR(1) item set, making it the most powerful but computationally expensive due to the larger number of states.
Hence, the correct answer is: option 3) Canonical LR
Parser Question 2:
Shift reduce parsers are
Answer (Detailed Solution Below)
Parser Question 2 Detailed Solution
The correct answer is Bottom up parser
Key Points
- Shift-Reduce Parser: ✅ A shift-reduce parser is a type of Bottom-Up Parser, which attempts to construct the parse tree for an input string by starting from the leaves (tokens) and working up to the root (start symbol).
- Top-Down Parsers: ❌ These parsers start from the root and attempt to derive the input string by expanding non-terminals. Examples include recursive descent parsers and LL parsers, which are not applicable here.
- May be top-down or bottom-up: ❌ A parser cannot be both top-down and bottom-up simultaneously. The shift-reduce parser specifically belongs to the bottom-up category.
- None of the above: ❌ This option is incorrect as shift-reduce parsers clearly belong to the bottom-up parsing family.
Additional Information
- Shift Operation: During the shift operation, the parser shifts the next input symbol onto the stack.
- Reduce Operation: During the reduce operation, the parser replaces a sequence of stack symbols (matching the right-hand side of a production rule) with the corresponding non-terminal on the left-hand side.
- LR Parsers: Many shift-reduce parsers are implemented as LR parsers (e.g., SLR, LALR, and CLR), which are powerful and handle a wide variety of grammars.
Hence, the correct answer is: option 2) Bottom up parser
Parser Question 3:
Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.
Answer (Detailed Solution Below)
Parser Question 3 Detailed Solution
The correct answer is Leftmost derivation
Concept:
A top down parser starts with the start symbol and generate the output. It tries to parse a string using the left most derivation. It can be stated as parsing starts from start symbol.
Explanation:
Top down parser is of two types: one with back tracking and another is without back-tracking. Parser without back- tracking is known as predictive parser.
Parser Question 4:
The Bottom-up parsing method is also called
Answer (Detailed Solution Below)
Parser Question 4 Detailed Solution
The correct answer is Shift reduce parsing.
Key Points
- Bottom-up parsing is a method of parsing in which the parse tree is constructed from the leaves (input symbols) to the root (start symbol).
- Shift reduce parsing is a type of bottom-up parsing. It uses a stack to hold grammar symbols and an input buffer to hold the string to be parsed.
- The parser shifts input symbols onto the stack and reduces the stack contents to grammar rules.
Additional Information
- Predictive parsing (Option 1) is a type of top-down parsing that uses a lookahead to predict which production to use. It is not a bottom-up method.
- Recursive descent parsing (Option 3) is another form of top-down parsing where each non-terminal in the grammar has a corresponding procedure in the parser. It is also not a bottom-up method.
Parser Question 5:
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon-production and unit-production (i.e., of type A→
Answer (Detailed Solution Below)
Parser Question 5 Detailed Solution
The correct answer is n - 1
Explanation:
Grammar with no epsilon- and unit-production
S → PQ
P → pp
Q → qq
Derive String: ppqq
S → PQ
S → ppQ
S → pppqq
String length = 4
Production needed = 4 – 1 = 3.
Top Parser MCQ Objective Questions
Match the following:
(P) |
Lexical analysis |
(i) |
Leftmost derivation |
(Q) |
Top down parsing |
(ii) |
Type checking |
(R) |
Semantic analysis |
(iii) |
Regular expressions |
(S) |
Runtime environments |
(iv) |
Activation records |
Answer (Detailed Solution Below)
Parser Question 6 Detailed Solution
Download Solution PDFLexical analysis: Lexical analysis is the first phase of a compiler. It takes the modified source code from language pre-processors that are written in the form of sentences. Lexical analyser breaks these syntaxes into a series of tokens. Lexical analysis uses regular expression to recognize identifiers.
Top down parsing: Top down parsing technique parses the input by starts constructing a parse tree from the root node moving down to the leaf nodes. Top down parser uses the left most derivation to generate the string.
Semantic analysis: Semantic analysis is the task of ensuring that declarations and statements of a program are semantically correct. For this, it uses type casting.
Run time environments: Run time environment is a state of the target machine, which may include software libraries, environment variables etc. to provide services to the processes running in the system. Activation records of a function are loaded into stack at runtime.Which one of the following kinds of derivation is used by LR parsers?
Answer (Detailed Solution Below)
Parser Question 7 Detailed Solution
Download Solution PDF
Parser |
Derivation |
LR parsers or Bottom-up Parsers |
Rightmost reverse Derivation |
LL parsers or Top-down Parsers |
Leftmost Derivation |
Which of the following statements about parser is/are CORRECT?
I. Canonical LR is more powerful than SLR.
II. SLR is more powerful than LALR.
III. SLR is more powerful than Canonical LR.Answer (Detailed Solution Below)
Parser Question 8 Detailed Solution
Download Solution PDFConcept: LR parsers in terms of their power:
CLR > LALR > SLR > LR (0)
Explanation:
I. Canonical LR is more powerful than SLR. TRUE
II. SLR is more powerful than LALR. FALSE
III. SLR is more powerful than Canonical LR. FALSE
Consider the following grammar
S → m | mn | mno
Choose correct statement from the following:
Answer (Detailed Solution Below)
Parser Question 9 Detailed Solution
Download Solution PDFConcept:
In LL(K) grammar, first L means scanning input from left to right and second L stands for left most derivation where k means k symbols are used at each step.
If first(production 1) ꓵ first(production 2) = empty, then it is LL(1). , it must be true for any two prductions.
For LL(2) we will check intersection of second(production) means second element of that production. Moving forward one step with symbol in bracket.
Explanation:
Given grammar:
S → m | mn | mno
Case 1: For LL(1)
First(m) ꓵ first (mn) = m (which is not empty).
So, grammar is not LL(1).
Case 2: For LL(2)
Second (mn) ꓵ second(mno) = n (which is not empty)
So, grammar is not LL(2).
Case 3: For LL(3)
Third(mn) ꓵ third (mno) = empty
So, grammar is LL(3).
Consider the following parse tree for the expression a # b $ c $ d # e # f, involving two binary operators $ and #.
Which one of the following is correct for the given parse tree?
Answer (Detailed Solution Below)
Parser Question 10 Detailed Solution
Download Solution PDFHighest Precedence Operator is at the lowest level in the expression tree so that it is evaluated first.
For unambiguous grammar, we can get precedence and associativity directly from production or expression tree.
Left Associativity => Left Linear Grammar or in expression, tree it should expand on left child for the same operator and vice versa.
Here at the lowest level, we have $ so it has the highest precedence.
# is right associative and $ is left associative.
Which one of the following statements is TRUE?
Answer (Detailed Solution Below)
Parser Question 11 Detailed Solution
Download Solution PDFThe correct answer is option 4.
Concept:
Option 1: The LALR(1) parser for a grammar G cannot have a reduce-reduce conflict if the LR(1) parser for G does not have a reduce-reduce conflict.
False, If there is no S-R conflict in LR(1) state, it will never be reflected in the LALR(1) state obtained by combining LR(1) states; but, this merging method may create R-R conflict, and the Grammar will not be LALR (1).
Option 2: Symbol table is accessed only during the lexical analysis phase
False, The information in the symbol table is provided during the lexical and syntax analysis phases, but it is needed in subsequent stages of the compiler (semantic analysis, intermediate code generation, code optimization, and code generation).
Option 3:Data flow analysis is necessary for run-time memory management.
False, Data flow analysis is used in control flow graphs for code optimization. It is the analysis of data flow in a control flow graph, that is, the analysis that determines information about data definition and usage in a program. Optimization can be achieved with the use of this analysis.
Option 4: LR(1) parsing is sufficient for deterministic context-free languages
True, LR(k) grammars (also known as deterministic context-free grammars) allow parsing (string recognition) with deterministic pushdown automata (PDA), they can only define deterministic context-free languages.
Hence the correct answer is LR(1) parsing is sufficient for deterministic context-free languages.
Consider the following statements.
S1 : Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2 : For any context-free grammar, there is a parser that takes at most O(n3) time to parse a string of length n.
Which one of the following option is correct?
Answer (Detailed Solution Below)
Parser Question 12 Detailed Solution
Download Solution PDFAnswer: Option 1
Explanation:
Statement 1:Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
As you can see in the diagram Not all Unambiguous grammars are SLR(1) but All SLR(1) grammars are Unambiguous.
This Statement is True.
Statement 2:For any context-free grammar, there is a parser that takes at most O(n3) time to parse a string of length n.
This Statement is also True. There exists a standard algorithm for general Context-free grammars known as the CYK algorithm whose time complexity is O(n3).
Note:
- LR parsers have linear time(O(n)) complexity.
A bottom-up parser generates :
Answer (Detailed Solution Below)
Parser Question 13 Detailed Solution
Download Solution PDF
Parser |
Derivation |
LR parsers or Bottom-up Parsers |
Rightmost reverse Derivation |
LL parsers or Top-down Parsers |
Leftmost Derivation |
Consider the augmented grammar given below:
S' → S
S → < L > | id
L → L, S | S
Let, I0 = CLOSURE ({[S' → •S]}). The number of items in the set GOTO (I0, <) is: ______Answer (Detailed Solution Below) 5
Parser Question 14 Detailed Solution
Download Solution PDFGOTO (I0, <)
S → < .L >
L → .L,S
L → .S
S → .< L >
L → .id
∴ number of items in the set GOTO (I0, <) is 5A top-down parser generates
Answer (Detailed Solution Below)
Parser Question 15 Detailed Solution
Download Solution PDF- A top-down parsing technique parses the input by starts constructing a parse tree from the root node moving down to the leaf nodes.
- A top-down parser uses the leftmost derivation to generate the string.
Therefore, option 3 is correct
Parser |
Derivation |
LR parsers or Bottom-up Parsers |
Rightmost reverse Derivation |
LL parsers or Top-down Parsers |
Leftmost Derivation |