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

Top Down Parsing Questions and Answers

21.

Consider the following conditions for a grammar to be LL(1).
1. No two alternatives of a nonterminal have overlapping FIRST sets.
2. If an alternative derives epsilon, the others avoid FOLLOW of that nonterminal.
3. The grammar contains no productions with more than two symbols.

Answer: A

Correct answer: 1 and 2 only

Statements 1 and 2 are precisely the LL(1) conditions: the alternatives must be distinguishable on one token of lookahead, and where one derives epsilon the others must avoid whatever may follow the nonterminal. Statement 3 confuses this with a normal form - the length of a right side has nothing to do with whether the grammar is LL(1).

Please log in or register to report this question.

Answer: B

Left recursion, common prefixes and ambiguity each create a table conflict. Right recursion is perfectly acceptable and is in fact what left recursion elimination produces. Bottom up parsers by contrast prefer left recursion for exactly the opposite reason.

Please log in or register to report this question.

23.

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.

27.

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.

28.

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.

29.

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.

Loading…

Other Subjects

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