0% found this document useful (0 votes)
84 views

Compiler Design - Practice Set 1

A compiler is a system program that converts instructions in a high-level language into machine-readable object code. The stages of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. A symbol table, created and maintained by the compiler, keeps track of all variable names and scopes to enable type checking and scope resolution during compilation. Compilers can detect syntax errors but not logical errors in a program.

Uploaded by

Max
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Compiler Design - Practice Set 1

A compiler is a system program that converts instructions in a high-level language into machine-readable object code. The stages of a compiler include lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. A symbol table, created and maintained by the compiler, keeps track of all variable names and scopes to enable type checking and scope resolution during compilation. Compilers can detect syntax errors but not logical errors in a program.

Uploaded by

Max
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Compiler Design

1. What is a compiler?
a) system program that converts instructions to machine language
b) system program that converts machine language to high-level language
c) system program that writes instructions to perform
d) None of the mentioned
Answer: a
Explanation: A compiler is a system program that converts instructions in form of code to machine
understandable language.

2. Which of the following is a stage of compiler design?


a) Semantic analysis
b) Intermediate code generator
c) Code generator
d) All of the mentioned
Answer: d
Explanation: The phases of a compiler are:
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Intermediate code generator
5. Code optimizer
6. Code generator

3. What is the use of a symbol table in compiler design?


a) Finding name’s scope
b) Type checking
c) Keeping all of the names of all entities in one place
d) All of the mentioned
Answer: d
Explanation: Both the analysis and synthesis components of a compiler use the symbol table.
i) To keep all of the names of all entities in one place in a systematic format.
ii) To determine whether or not a variable has been declared.
iii) Type checking is implemented by ensuring that assignments and expressions in source code are
semantically accurate.
iv) To figure out what a name’s scope is (scope resolution).

4. Which of the following error can a compiler check?


a) Syntax Error
b) Logical Error
c) Both Logical and Syntax Error
d) Compiler cannot check errors
Answer: a
Explanation: Logic flaws can never be checked by a compiler.

5. A programmer, writes a program to multiply two numbers instead of dividing them by mistake, how
can this error be detected?
a) Compiler or interpreter
b) Compiler only
c) Interpreter only
d) None of the mentioned
Answer: d
Explanation: This is a logical error that can’t be detected by any compiler or interpreter.
advertisement

6. Who is responsible for the creation of the symbol table?


a) Assembler
b) Compiler
c) Interpreter
d) All of the mentioned
Answer: b
Explanation: The compiler generates a symbol table, which contains a list of lexemes or tokens.

7. Which of the following is known as a compiler for a high-level language that runs on one machine and
produces code for a different machine?
a) Cross compiler
b) Multipass compiler
c) Optimizing compiler
d) One pass compiler
Answer: a
Explanation: So done by the definition.

8. Which of the following is a system program that integrates a program’s individually compiled modules
into a form that can be executed?
a) Interpreter
b) Assembler
c) Compiler
d) Linking Loader
Answer: d
Explanation: A loader that combines the functionality of a relocation loader with the ability to combine a
number of independently compiled program segments.

9. Which of the following is a definition of compiler?


a) Acceptance of a program written in a high-level language and produces an object program
b) Program is put into memory and executes it
c) Translation of assembly language into machine language
d) None of the mentioned
Answer: a
Explanation: A compiler is a software (or combination of programs) that converts source code written in
one programming language (the source language) into code written in another programming language
(the target language) (the target language, often having a binary form known as object code).

10. Which of the following phase of the compiler is Syntax Analysis?


a) Second
b) Third
c) First
d) All of the mentioned
Answer: a
Explanation: It is the Second Phase of the Compiler after Lexical Analyzer. It is also called Hierarchical
Analysis or Parsing.

You might also like