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

Syntax Analysis and Parsing Questions and Answers

Answer: C

Correct answer: performing syntax directed translation during the parse

Building no tree and calling the semantic actions as each production is recognised is exactly syntax directed translation, and it is what a one-pass compiler does. It is available to both top-down and bottom-up parsers, and it detects syntax errors as readily as any other - what it gives up is the ability to make a second pass over the structure.

Please log in or register to report this question.

Answer: D

Optimisation and analysis often need several traversals in different orders. An explicit tree makes those possible, at the cost of the memory to hold it. Optimising compilers therefore build a tree while simple translators often do not.

Please log in or register to report this question.

73.

State whether the following is true or false.
A parser can detect that a variable has been used before its declaration.

Answer: A

Correct answer: False

Use before declaration depends on what has appeared elsewhere in the program, which no context free grammar can express - the grammar constrains the shape of the token stream, not the relationship between distant parts of it. The check belongs to semantic analysis and is made against the symbol table.

Please log in or register to report this question.

Answer: B

Epsilon productions let a construct be optional. They complicate parsing, since the parser must consult FOLLOW to decide when to apply them rather than looking only at FIRST. Removing them is possible but usually multiplies the number of productions.

Please log in or register to report this question.

Answer: C

Standard constructions eliminate epsilon productions, usually at the cost of many more productions. The empty string itself must be handled separately if the language contains it. The construction is theoretical groundwork rather than a step compilers perform.

Please log in or register to report this question.

Answer: D

The restricted shape is what makes the CYK parsing algorithm work. It is a theoretical convenience rather than something compiler writers impose on real language grammars. Converting a real grammar to this form would obscure it beyond recognition.

Please log in or register to report this question.

Answer: A

The cubic bound covers every context free grammar, including ambiguous ones. Compilers use linear methods instead by restricting the grammars they accept. A cubic algorithm on a large source file would make compilation unacceptably slow.

Please log in or register to report this question.

Answer: B

Linear time matters when compiling large programs. The price is that the grammar must fall in a restricted class, which language designers accommodate deliberately. Language syntax is shaped in part by what parsers can handle efficiently.

Please log in or register to report this question.

Answer: C

GLR forks the parse at a conflict and discards branches that fail. It handles ambiguous grammars at the cost of losing the linear time guarantee. Natural language processing uses the method far more often than compilers do.

Please log in or register to report this question.

Answer: D

Correct answer: composing small parsing functions using higher order operators

A parser combinator is a function that consumes input and returns a result, and larger parsers are built by combining smaller ones with operators for sequence, choice and repetition. The grammar is thereby expressed directly in the host language, with no separate specification file and no generation step.

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