Machine-translated by Google. Questions are authored in English.
Top

Top Down Parsing Questions and Answers

Answer: A

Pushing the marker first and the start symbol above it lets the parser recognise successful completion when the marker surfaces at the same moment the input is exhausted. Using an explicit marker removes the need for a special case in the driver loop.

Please log in or register to report this question.

22.

Arrange the actions of a table driven predictive parser when a nonterminal is on top of the stack.
1. pop the nonterminal from the stack
2. read the current lookahead token
3. push the right side of the chosen production in reverse
4. consult the table cell for that nonterminal and token

Answer: B

Correct answer: 2 - 4 - 1 - 3

The lookahead is read first because the table cannot be consulted without it. The cell for the nonterminal and that token gives the production, the nonterminal is popped, and the right side is pushed in reverse so that its leftmost symbol ends up on top - which is what makes the parser expand leftmost.

Please log in or register to report this question.

Answer: C

A stack yields symbols in the reverse of the order they were pushed. Pushing the right side backwards therefore presents its symbols left to right, matching the input order. Getting the direction wrong is a classic bug when the driver is written by hand.

Please log in or register to report this question.

Answer: D

Matching consumes one input token and one stack symbol. A mismatch is a syntax error, and the recovery routine decides whether to skip input or to pop the stack symbol. Choosing well between those two options is what makes recovery feel intelligent.

Please log in or register to report this question.

Answer: A

Both conditions must hold together. Reaching the marker with input remaining, or exhausting the input with symbols still on the stack, are both errors rather than acceptance. Checking both conditions costs nothing and catches a whole class of mistakes.

Please log in or register to report this question.

Answer: B

Correct answer: popping the nonterminal and pushing nothing at all

An epsilon production derives the empty string, so applying it removes the nonterminal from the stack and contributes nothing in its place. No input is consumed, and there is no epsilon symbol to push - epsilon is the absence of symbols rather than a symbol of its own.

Please log in or register to report this question.

27.

Assertion (A): FOLLOW sets are needed to build a predictive parsing table even though FIRST sets alone identify the productions.
Reason (R): A production deriving epsilon matches no input, so the decision must rest on what may come after the nonterminal.

Answer: C

Correct answer: Both A and R are true, and R is the correct explanation of A

Both are true and the reason gives the mechanism. A production deriving epsilon has an empty FIRST set, so nothing in the input can indicate that it is the right choice. The parser must instead ask whether the lookahead is something that could legitimately follow the nonterminal, and FOLLOW is exactly that set.

Please log in or register to report this question.

Answer: D

Correct answer: the procedure for the nonterminal calls itself before consuming input

A production such as \( E \rightarrow E + T \) makes the procedure for E call itself as its first action, with the input position unchanged. The recursion therefore never terminates and the stack overflows. Removing the left recursion by rewriting it as right recursion is the standard preparation.

Please log in or register to report this question.

Answer: A

Without the epsilon alternative the new nonterminal could never be discharged and the repetition would be obliged to continue for ever. The epsilon alternative is precisely what converts unbounded left recursion into a loop that the parser can leave, and it is also why FOLLOW must be consulted when the table is filled

Please log in or register to report this question.

Answer: B

The standard algorithm orders the nonterminals and substitutes earlier ones into later ones, exposing the recursion as immediate. Only then is the usual transformation applied. The algorithm terminates because each substitution reduces the remaining cycles.

Please log in or register to report this question.

Loading…
Tags: Top Down Parsing Questions and Answers || Top Down Parsing MCQ Questions and Answers || Top Down Parsing GK Questions and Answers || Top Down Parsing GK MCQ Questions || Top Down Parsing Multiple Choice Questions and Answers || Top Down Parsing GK || GK on Top Down Parsing || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design