- What is a compiler?
a) A hardware device
b) A software program
c) A peripheral device
d) A storage device
Answer: b) A software program
Explanation: A compiler is a software program that translates source code written in a high-level programming language into machine code that can be understood and executed by a computer. - Which of the following is a major data structure used in compilers?
a) Arrays
b) Stacks
c) Trees
d) Linked lists
Answer: c) Trees
Explanation: Trees, particularly Abstract Syntax Trees (ASTs), are commonly used in compilers for representing the structure of source code. - How many types of compilers are there based on the translation process?
a) One
b) Two
c) Three
d) Four
Answer: b) Two
Explanation: Compilers can be classified into two types based on the translation process: Single-pass compilers and Multi-pass compilers. - Which part of the compiler translates high-level code into intermediate code?
a) Front-end
b) Back-end
c) Middle-end
d) Preprocessor
Answer: a) Front-end
Explanation: The front-end of the compiler translates high-level source code into an intermediate representation or code. - Which part of the compiler generates machine code from the intermediate code?
a) Front-end
b) Back-end
c) Middle-end
d) Postprocessor
Answer: b) Back-end
Explanation: The back-end of the compiler generates machine code from the intermediate representation produced by the front-end. - Which model of compilation involves two phases: analysis and synthesis?
a) Single-pass model
b) Multi-pass model
c) Analysis-synthesis model
d) Interpretation model
Answer: c) Analysis-synthesis model
Explanation: The analysis-synthesis model involves two main phases: analysis, where the source code is analyzed, and synthesis, where the target code is generated. - Which phase of the compiler checks the syntax of the source code?
a) Lexical analysis
b) Semantic analysis
c) Syntax analysis
d) Code generation
Answer: c) Syntax analysis
Explanation: Syntax analysis, also known as parsing, checks the syntax of the source code to ensure it follows the rules of the programming language’s grammar. - What is the purpose of lexical analysis in a compiler?
a) Checking syntax errors
b) Generating machine code
c) Tokenizing the source code
d) Optimizing code
Answer: c) Tokenizing the source code
Explanation: Lexical analysis breaks the source code into tokens such as keywords, identifiers, operators, etc., which are the basic building blocks of the language. - Which phase of lexical analysis involves grouping characters into tokens?
a) Input buffering
b) Token specification
c) Token recognition
d) Token generation
Answer: c) Token recognition
Explanation: Token recognition involves identifying and grouping characters into tokens based on predefined patterns. - Which tool is used for generating lexical analyzers automatically?
a) Yacc
b) Bison
c) Flex
d) ANTLR
Answer: c) Flex
Explanation: Flex is a tool for generating lexical analyzers automatically based on regular expressions specified by the user. - What does LEX stand for?
a) Lexical Extraction
b) Lexical Extension
c) Lexical Analyzer Generator
d) Lexical Expression
Answer: c) Lexical Analyzer Generator
Explanation: LEX is a lexical analyzer generator that produces lexical analyzers based on user-specified regular expressions. - Which phase of the compiler handles input buffering?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
Answer: a) Lexical analysis
Explanation: Input buffering involves reading characters from the source file and buffering them for processing by the lexical analyzer. - Which data structure is commonly used for implementing symbol tables in compilers?
a) Arrays
b) Linked lists
c) Hash tables
d) Trees
Answer: c) Hash tables
Explanation: Hash tables are commonly used for implementing symbol tables due to their efficiency in searching, insertion, and deletion operations. - Which phase of the compiler checks the meaning of the source code?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
Answer: c) Semantic analysis
Explanation: Semantic analysis checks the meaning of the source code, ensuring that it adheres to the language’s semantic rules. - Which phase of the compiler translates intermediate code into machine code?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
Answer: d) Code generation
Explanation: Code generation translates the intermediate representation produced by earlier phases into machine code for execution by the target machine. - Which part of the compiler optimizes the generated code for efficiency?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code optimization
Answer: d) Code optimization
Explanation: Code optimization improves the efficiency of the generated code by applying various transformations to reduce execution time or memory usage. - Which phase of the compiler resolves references to variables and functions?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
Answer: c) Semantic analysis
Explanation: Semantic analysis resolves references to variables and functions by checking their declarations and ensuring their correct usage. - Which part of the compiler translates source code into an intermediate representation?
a) Front-end
b) Back-end
c) Middle-end
d) Preprocessor
Answer: a) Front-end
Explanation: The front-end of the compiler translates source code into an intermediate representation, which is then processed by the back-end. - Which phase of the compiler removes unnecessary code and reduces code size?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code optimization
Answer: d) Code optimization
Explanation: Code optimization removes unnecessary code and reduces code size to improve performance and reduce memory usage. - Which part of the compiler performs error checking and reporting?
a) Front-end
b) Back-end
c) Middle-end
d) Preprocessor
Answer: a) Front-end
Explanation: The front-end of the compiler performs error checking and reporting to identify syntax and semantic errors in the source code.
EasyExamNotes.com
Introduction to compiling & Lexical Analysis MCQs
Source: https://easyexamnotes.com/introduction-to-compiling-lexical-analysis-mcqs/
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion