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

Syntax Analysis and Parsing Questions and Answers

51.

State whether the following is true or false.
Every property a programming language requires can be checked by its context free grammar.

Answer: C

Correct answer: False

A context free grammar can describe the shape of a program but not conditions that depend on what has been declared elsewhere: that a variable is declared before use, that the types of an assignment agree, that a function is called with the right number of arguments. All of these are checked by semantic analysis, using the symbol table.

Please log in or register to report this question.

Answer: D

The grammar can describe an argument list of any length but cannot tie its length to a declaration elsewhere. Semantic analysis consults the symbol table to make the comparison. The same applies to argument types, which the grammar likewise cannot constrain.

Please log in or register to report this question.

Answer: A

Adding S prime going to S means the parser accepts by reducing that one production. Without it, acceptance would be harder to detect unambiguously. The augmentation costs one extra state and removes an awkward special case.

Please log in or register to report this question.

Answer: B

The dot separates what the parser has already seen from what it still expects. Sets of such items become the states of the automaton that drives the parse. Constructing those sets is the mechanical heart of every LR table generator.

Please log in or register to report this question.

Answer: C

If the parser expects a nonterminal, it may be about to begin any of that nonterminal's productions. Closure records all those possibilities in the same state. Without closure the automaton would have no way to begin a nested construct.

Please log in or register to report this question.

Answer: D

LALR merges canonical LR states sharing a core, which cuts the table greatly. The merge can introduce reduce-reduce conflicts, though never shift-reduce ones. That guarantee is what makes LALR a safe default for a parser generator.

Please log in or register to report this question.

57.

Consider the following statements about LALR parsing.
1. It has the same number of states as the SLR parser.
2. Merging states can introduce reduce-reduce conflicts.
3. It can introduce shift-reduce conflicts not present in canonical LR.

Answer: A

LALR has the SLR state count with better lookaheads. Merging may create a reduce-reduce conflict but provably never a shift-reduce one, so the third statement is false. That asymmetry is a standard result quoted in every treatment of the method.

Please log in or register to report this question.

58.

Arrange these parser classes in order of increasing grammar coverage.
1. LALR(1)
2. LL(1)
3. canonical LR(1)
4. SLR(1)

Answer: B

Each class handles every grammar the previous one does and more. The practical sweet spot is LALR(1), which covers nearly every language grammar at a table size close to SLR. Moving up the scale costs table space and gains coverage that is rarely needed.

Please log in or register to report this question.

Answer: C

Both tools produce LALR(1) parsers by default. The choice reflects the balance between grammar coverage and table size that suits nearly all programming language grammars. Canonical LR tables would be several times larger for very little extra coverage.

Please log in or register to report this question.

Answer: D

Preferring the shift resolves the dangling else the way languages specify. The generator still reports the conflict so the author can check the default is what was intended. Silently accepting the default without reading the report is a common mistake.

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