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

Phases of a Compiler Questions and Answers

11.

State whether the following is true or false.
A missing semicolon is normally detected by the lexical analyser.

Answer: C

Correct answer: False

The lexical analyser recognises tokens individually and has no view of how they should be arranged. A semicolon is simply a token that is absent; the scanner has nothing to compare its absence against.

The parser detects it, when the token stream fails to match any grammar production at the point where a statement should have ended. The distinction is the general one: lexical analysis catches malformed tokens, syntax analysis catches malformed sequences of well-formed tokens.

Please log in or register to report this question.

Answer: D

Correct answer: the lexical analyser

A string literal is a single token, and the scanner is the phase that assembles it from characters. Reaching the end of the line or the file with the closing quote still missing means the token cannot be completed, which the scanner discovers immediately.

The parser never sees a token at all in this case, so it cannot be the reporter. The contrast with the missing semicolon is instructive: one is a malformed token, the other a malformed sequence of good tokens.

Please log in or register to report this question.

13.

Match each error with the phase that detects it.
List I
A. an illegal character in the source
B. an unbalanced parenthesis
C. adding an integer to a function name
D. a call to an undefined external routine
List II
1. semantic analysis
2. lexical analysis
3. linking
4. syntax analysis

Answer: A

Correct answer: A-2, B-4, C-1, D-3

Each error surfaces at the level where the property it violates is checked. An illegal character cannot form any token, so lexical analysis catches it.

An unbalanced parenthesis is a well-formed sequence of tokens that fits no production, so syntax analysis catches it. Adding an integer to a function name is grammatically legal but meaningless, so semantic analysis catches it. An undefined external routine is unresolvable only when all modules are present, so the linker catches it - character, form, meaning, then program-wide resolution.

Please log in or register to report this question.

Answer: B

Every phase reads or writes the symbol table. The scanner enters identifiers, the analyser records types and scopes, and the code generator consults it for storage allocation, so it spans the whole compiler rather than belonging to one phase.

Please log in or register to report this question.

15.

Consider the following statements about the symbol table.
1. It is created and used by several phases rather than by one.
2. It records attributes such as type, scope and storage location.
3. It is discarded as soon as syntax analysis is complete.

Answer: C

Correct answer: 1 and 2 only

The first two are correct. The symbol table is created during lexical and syntax analysis and consulted by every later phase, and it records type, scope, storage location and other attributes.

The third is false and would break the compiler. Semantic analysis needs the types, the intermediate code generator needs storage information, and the code generator needs offsets - all held there. The table is one of the few structures that persists across the whole compilation.

Please log in or register to report this question.

Answer: D

Errors arise in every phase, so the handler is drawn spanning all of them in the classical diagram. Each phase reports what it finds and, where possible, recovers so that compilation can continue and further errors be reported.

Please log in or register to report this question.

Answer: A

Recovery lets one compilation report many errors. The compiler does not repair the program and does not emit code for an erroneous source; it simply continues checking so the programmer sees more than one fault per run.

Please log in or register to report this question.

Answer: B

An explicit intermediate representation lets one front end serve several target machines and one back end serve several source languages. It is also a convenient level at which to perform machine independent optimisation.

Please log in or register to report this question.

Answer: C

A typical instruction has the form x = y op z, naming a result and two operands. The restriction to at most three addresses per instruction keeps the representation simple and close to what most machines can execute directly.

Please log in or register to report this question.

Answer: D

Machine independent optimisation is placed after intermediate code generation and before code generation precisely so that it can improve the program without knowing anything about the target instruction set or register file.

Please log in or register to report this question.

Loading…
Tags: Phases of a Compiler Questions and Answers || Phases of a Compiler MCQ Questions and Answers || Phases of a Compiler GK Questions and Answers || Phases of a Compiler GK MCQ Questions || Phases of a Compiler Multiple Choice Questions and Answers || Phases of a Compiler GK || GK on Phases of a Compiler || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design