Compiler Design - MCQs and One-Word Questions
Multiple-Choice Questions (MCQs)
1. A compiler translates:
a) High-level language to Machine language
b) Machine language to High-level language
c) High-level language to Assembly language
d) Assembly language to High-level language
Answer: a) High-level language to Machine language
2. The first phase of a compiler is:
a) Syntax Analysis
b) Lexical Analysis
c) Semantic Analysis
d) Code Generation
Answer: b) Lexical Analysis
3. Syntax analysis is also called:
a) Scanning
b) Parsing
c) Compiling
d) Translating
Answer: b) Parsing
4. Which phase ensures operations are applied to compatible types?
a) Lexical Analysis
b) Syntax Analysis
c) Semantic Analysis
d) Code Optimization
Answer: c) Semantic Analysis
5. Which type of grammar is used by a parser?
a) Regular Grammar
b) Context-Free Grammar
c) Context-Sensitive Grammar
d) Unrestricted Grammar
Answer: b) Context-Free Grammar
6. What is the output of the lexical analysis phase?
a) Intermediate Code
b) Token Stream
c) Machine Code
d) Abstract Syntax Tree
Answer: b) Token Stream
7. Which parser does not require backtracking?
a) LL(1)
b) Recursive Descent
c) Operator Precedence
d) Shift-Reduce
Answer: a) LL(1)
8. The purpose of register allocation is:
a) Assign variables to memory locations
b) Assign values to registers
c) Optimize code execution
d) Allocate stack memory
Answer: b) Assign values to registers
9. The grammar used for syntax analysis is:
a) Regular Grammar
b) Context-Free Grammar
c) Context-Sensitive Grammar
d) Unrestricted Grammar
Answer: b) Context-Free Grammar
10. The output of code generation is:
a) Machine Code
b) Parse Tree
c) Abstract Syntax Tree
d) Token Stream
Answer: a) Machine Code
One-Word Questions
11. Which phase generates tokens?
Answer: Lexical Analysis
12. Which phase builds the parse tree?
Answer: Syntax Analysis
13. Which type of parsing method is most powerful?
Answer: LR Parsing
14. What is the smallest unit of meaning in a program?
Answer: Token
15. Which phase removes redundant instructions?
Answer: Code Optimization
16. Which phase assigns registers for variables?
Answer: Code Generation
17. What is the starting symbol in a context-free grammar?
Answer: Non-terminal
18. Which phase translates IR to machine code?
Answer: Code Generation
19. Which table stores variable names and their attributes?
Answer: Symbol Table
20. What does an assembler do?
Answer: Converts Assembly Code to Machine Code