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

Syntax Analysis and Parsing Questions and Answers

Answer: A

Correct answer: resolve conflicts without rewriting the grammar into levels

Declaring the precedence and associativity of the operators lets the generator settle shift-reduce conflicts in a short ambiguous expression grammar, instead of the grammar being expanded into one nonterminal per precedence level. The result is a smaller grammar, a smaller table and a specification that reads more directly.

Please log in or register to report this question.

Answer: B

Correct answer: a smaller parse table than the equivalent unambiguous grammar

The unambiguous grammar needs a nonterminal for each precedence level and a chain of single-symbol productions linking them, and every one of those levels adds states to the table. The ambiguous grammar has one nonterminal for expressions and lets the declarations resolve the conflicts, so the table is smaller and the parse does less work.

Please log in or register to report this question.

Answer: C

Synchronising tokens are typically statement terminators or closing brackets. The parser pops stack symbols until a state accepting the found token is reached, then continues. The method never loops and is simple to implement, which is why it is ubiquitous.

Please log in or register to report this question.

Answer: D

By writing a production for an anticipated error the author can attach a tailored message. The construct is recognised and reported, but no code is generated for the faulty program. Anticipating the most common mistakes pays for itself in support time.

Please log in or register to report this question.

Answer: A

Position and expectation are what a programmer needs. Dumping internal state helps nobody outside the compiler team, and confident rewriting suggestions are often wrong. The best messages name the construct in the terms the programmer used.

Please log in or register to report this question.

Answer: B

Once the parser is out of step, subsequent messages are usually spurious. Resynchronising at a statement boundary before resuming keeps later reports meaningful. A compiler that floods the screen after one typing slip is worse than useless.

Please log in or register to report this question.

67.

A parse tree with n leaves for a grammar in which every production has exactly two symbols on the right has

Answer: C

Each internal node combines two subtrees into one, reducing the count by one. Starting from n leaves and ending at a single root therefore requires exactly n minus 1 combinations. The same identity underlies the node count of any full binary tree.

Please log in or register to report this question.

68.

A grammar in which every production has two symbols on the right side derives a sentence of 8 tokens. How many reduction steps does a bottom-up parse perform?

Answer: D

Correct answer: 7

Each reduction combines two symbols into one, so it reduces the count on the stack by one. Starting from 8 tokens and finishing with the single start symbol requires \[ 8 - 1 = 7 \] reductions. Equivalently, a binary tree with 8 leaves has 7 internal nodes, and each internal node is one reduction.

Please log in or register to report this question.

Answer: A

The abstract tree keeps operators and operands and discards syntactic scaffolding. Semantic analysis and code generation both become simpler on the smaller structure. The parse tree is often never materialised at all, only the abstract one.

Please log in or register to report this question.

Answer: B

Correct answer: semantic rules computing attribute values for the symbols

A syntax directed definition pairs each production with rules that compute attributes of the symbols in it - a type, a value, an address, a piece of generated code. The parse then carries the semantic work along with it, which is how meaning is attached to structure without a separate traversal.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Syntax Analysis and Parsing Questions and Answers || Syntax Analysis and Parsing MCQ Questions and Answers || Syntax Analysis and Parsing GK Questions and Answers || Syntax Analysis and Parsing GK MCQ Questions || Syntax Analysis and Parsing Multiple Choice Questions and Answers || Syntax Analysis and Parsing GK || GK on Syntax Analysis and Parsing || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design