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

Bottom Up Parsing Questions and Answers

Answer: C

Correct answer: state and terminal symbol

The action table answers “in this state, with this lookahead, what should I do”, so it is indexed by state and terminal, and its entries are shift, reduce, accept or error. The goto table is the one indexed by state and nonterminal, and it is consulted only after a reduction.

Please log in or register to report this question.

Answer: D

Shifting uses the action table, which already names the state to push. Only a reduction leaves the parser holding a nonterminal with no state attached, and the goto table exists precisely to supply it from the state exposed beneath the popped symbols.

Please log in or register to report this question.

33.

Arrange the steps an LR parser performs when it decides to reduce by A goes to alpha.
1. consult the goto table for that state and A
2. pop as many stack entries as there are symbols in alpha
3. push A together with the state that goto returned
4. read the state now exposed on top of the stack

Answer: A

Popping removes the right side, the exposed state identifies the context, goto supplies the successor, and pushing completes the reduction. The input pointer does not move at all. Several reductions may therefore occur before the next token is examined.

Please log in or register to report this question.

Answer: B

Correct answer: does not move, since no token is consumed by a reduction

A reduction rearranges what is already on the stack and consumes nothing from the input. Only a shift advances the pointer. This is why a parser may perform several reductions in succession on the same lookahead, and why the lookahead is examined repeatedly without being consumed.

Please log in or register to report this question.

35.

An LR parser reduces by a production whose right side has 4 symbols. How many entries does it pop from the stack?

Answer: C

One stack entry is popped per symbol of the right side, so four are removed. The state beneath them is then exposed and used to index the goto table for the left side nonterminal. Popping the wrong number of entries is a classic bug in a hand written driver.

Please log in or register to report this question.

36.

A grammar has 30 states, 15 terminals including the end marker and 8 nonterminals. How many cells do the action and goto tables have together?

Answer: D

The action table has 30 times 15 which is 450 cells and the goto table 30 times 8 which is 240, giving 690 in all. Most cells are error entries, which is why compression pays. A table this size is entirely ordinary for a real language grammar.

Please log in or register to report this question.

Answer: A

Correct answer: the lookahead cannot legally follow the current viable prefix

An empty entry means there is no continuation: nothing in the grammar allows this token after what has been read so far. This is the viable prefix property, and it is valuable because it means the parser detects the error at the earliest point at which the input has become impossible.

Please log in or register to report this question.

38.

Assertion (A): An LR parser detects a syntax error as soon as it is possible to do so.
Reason (R): It reports an error the moment the input can no longer extend a viable prefix of some right sentential form.

Answer: B

Both are true and the reason gives the mechanism, and this is called the viable prefix property. No incorrect symbol is ever shifted, so the reported position is as close to the actual mistake as any parser can manage.

Please log in or register to report this question.

Answer: C

The parser scans down the stack for a state that can accept a major construct such as a statement, discards input until a token in that nonterminal's FOLLOW set appears, and resumes. Choosing statement as the recovery nonterminal is the usual practice.

Please log in or register to report this question.

Answer: D

Correct answer: attach a specific diagnostic to an anticipated mistake

An error production admits a construct the language does not contain, so that the parser recognises the mistake rather than merely failing, and its action can report a message written for that case. It does not correct the program, and the parser will not proceed to generate code for the faulty construct.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Bottom Up Parsing Questions and Answers || Bottom Up Parsing MCQ Questions and Answers || Bottom Up Parsing GK Questions and Answers || Bottom Up Parsing GK MCQ Questions || Bottom Up Parsing Multiple Choice Questions and Answers || Bottom Up Parsing GK || GK on Bottom Up Parsing || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design