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

Top Down Parsing Questions and Answers

11.

Arrange the steps of building a predictive parsing table in the order performed.
1. compute FIRST and FOLLOW for every nonterminal
2. remove left recursion from the grammar
3. fill each table cell from the FIRST and FOLLOW sets
4. left factor the remaining common prefixes

Answer: C

Correct answer: 2 - 4 - 1 - 3

The transformations must come before the analysis, since they change the grammar the sets are computed from. Left recursion is removed first, then common prefixes are factored out, then FIRST and FOLLOW are computed on the resulting grammar, and only then can the table be filled from those sets.

Please log in or register to report this question.

Answer: D

The marker records that the symbol may vanish entirely, which is what forces the parser to look at FOLLOW instead. Whether epsilon propagates through a whole right side depends on every symbol in it being able to vanish, and tracking that is the part most often got wrong when the sets are computed by hand.

Please log in or register to report this question.

Answer: A

Whatever can follow the left side can equally follow the last symbol of any of its right sides, so the whole set is copied across. The same rule applies to a symbol whose successors can all derive the empty string, which is where the computation most often goes astray when it is worked through by hand.

Please log in or register to report this question.

Answer: B

Correct answer: the start symbol of the grammar

The end of input marker can follow the start symbol and nothing else at the outermost level, so it is placed in FOLLOW of the start symbol and propagates from there to whatever can appear at the end of a sentence. It is not added to every nonterminal, though many will acquire it through propagation.

Please log in or register to report this question.

15.

Given productions S goes to aAb and A goes to c or epsilon, FOLLOW(A) is

Answer: C

A appears in the right side aAb followed immediately by the terminal b, so FIRST of what follows A is simply b. Nothing else can follow A anywhere in this grammar. Small grammars like this one are worth working through by hand until the rule is automatic.

Please log in or register to report this question.

16.

Given productions S goes to AB, A goes to a or epsilon and B goes to b, FIRST(S) is

Answer: D

S begins with A, which contributes a. Because A can also derive epsilon, FIRST of B contributes b as well. Epsilon is not included since S itself cannot derive the empty string. Tracking when epsilon propagates is the part most often got wrong by hand.

Please log in or register to report this question.

17.

A grammar has 5 nonterminals and 7 terminals. Including the end of input marker, how many cells does the LL(1) parsing table contain?

Answer: A

Correct answer: 40

The rows are the nonterminals and the columns the terminals together with the end of input marker: \[ 5 \times (7 + 1) = 40. \] Forgetting the marker gives 35, which is the trap here - the column for the end of input is what allows the parser to accept, and to reduce by an epsilon production at the end of the input.

Please log in or register to report this question.

Answer: B

Correct answer: whichever rule fits when A heads the stack and a is in hand

The cell holds the production to apply when the nonterminal A is on top of the stack and the lookahead is the terminal a. An empty cell means no production applies and the parser reports an error. A cell with two entries means the grammar is not LL(1).

Please log in or register to report this question.

Answer: C

The two clauses cover the ordinary case and the epsilon case. Applying them to every production of every nonterminal fills the whole table mechanically. No judgement is involved, which is why the construction can be automated entirely.

Please log in or register to report this question.

Answer: D

A conflict means one token of lookahead is not enough to decide. The grammar may still be fixable by factoring or by removing left recursion, or it may need more lookahead. The generator reports the offending cell, which usually identifies the cause.

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