Unit 1: Introduction to Compilers & Lexical Analysis
1. What is the primary function of a compiler?
a) To execute a program
b) To translate a program from source code to object code
c) To edit a program
d) To debug a program
2. Which phase of compilation involves breaking the source code into tokens?
a) Syntax analysis
b) Semantic analysis
c) Lexical analysis
d) Code generation
3. What is the purpose of a lexical analyzer?
a) To parse the syntax of the program
b) To generate intermediate code
c) To identify tokens in the source code
d) To optimize the generated code
4. What is a token in compiler design?
a) A keyword
b) A symbol
c) A sequence of characters with a specific meaning
d) A statement
5. Which of the following is an example of a finite automata?
a) Pushdown automata
b) Turing machine
c) Deterministic finite automata (DFA)
, d) Context-free grammar
6. What is the purpose of regular expressions in compiler design?
a) To define the syntax of a language
b) To specify the semantics of a language
c) To describe patterns in strings
d) To generate code
7. Which phase of compilation involves reporting errors?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) All of the above
8. What is the input to a compiler?
a) Object code
b) Source code
c) Intermediate code
d) Executable code
9. What is the output of a compiler?
a) Source code
b) Object code
c) Intermediate code
d) Executable code
10. Which of the following is a type of compiler?
a) Interpreter
b) Assembler
1. What is the primary function of a compiler?
a) To execute a program
b) To translate a program from source code to object code
c) To edit a program
d) To debug a program
2. Which phase of compilation involves breaking the source code into tokens?
a) Syntax analysis
b) Semantic analysis
c) Lexical analysis
d) Code generation
3. What is the purpose of a lexical analyzer?
a) To parse the syntax of the program
b) To generate intermediate code
c) To identify tokens in the source code
d) To optimize the generated code
4. What is a token in compiler design?
a) A keyword
b) A symbol
c) A sequence of characters with a specific meaning
d) A statement
5. Which of the following is an example of a finite automata?
a) Pushdown automata
b) Turing machine
c) Deterministic finite automata (DFA)
, d) Context-free grammar
6. What is the purpose of regular expressions in compiler design?
a) To define the syntax of a language
b) To specify the semantics of a language
c) To describe patterns in strings
d) To generate code
7. Which phase of compilation involves reporting errors?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) All of the above
8. What is the input to a compiler?
a) Object code
b) Source code
c) Intermediate code
d) Executable code
9. What is the output of a compiler?
a) Source code
b) Object code
c) Intermediate code
d) Executable code
10. Which of the following is a type of compiler?
a) Interpreter
b) Assembler