- What is the main function of the lexical analyzer?
a) Check the syntax of the program
b) Convert high-level code into machine code
c) Break the input source code into tokens
d) Optimize the codeAnswer: c) Break the input source code into tokens
- Which of the following represents a sequence of characters that matches a specific pattern?
a) Token
b) Lexeme
c) Grammar
d) SyntaxAnswer: b) Lexeme
- Which of the following is true about tokens?
a) Tokens are the smallest units of code with a defined meaning.
b) Tokens are keywords only.
c) Tokens are instructions that the computer executes.
d) Tokens are only used in the code generation phase.Answer: a) Tokens are the smallest units of code with a defined meaning.
- Which of the following tools is commonly used for lexical analysis?
a) YACC
b) Lex
c) GCC
d) BisonAnswer: b) Lex
- Which of the following is NOT typically a part of the lexical analysis phase?
a) Identifying keywords
b) Assigning memory addresses to variables
c) Identifying identifiers and operators
d) Converting the input into tokensAnswer: b) Assigning memory addresses to variables
- What is the role of regular expressions in lexical analysis?
a) They define the syntax of the programming language
b) They specify the patterns to identify tokens
c) They convert source code into machine code
d) They are used for semantic checkingAnswer: b) They specify the patterns to identify tokens
- What type of automaton is commonly used to perform lexical analysis?
a) Pushdown Automata
b) Finite Automata
c) Turing Machine
d) Linear Bounded AutomataAnswer: b) Finite Automata
- Which of the following is a common output of lexical analysis?
a) An Abstract Syntax Tree
b) A list of tokens
c) Optimized machine code
d) A syntax treeAnswer: b) A list of tokens
- Which of the following is a characteristic of a lexical error?
a) It occurs during the syntax analysis phase.
b) It occurs when a token is identified but not found in the lexicon.
c) It refers to incorrect grammar in the source code.
d) It occurs during code generation.Answer: b) It occurs when a token is identified but not found in the lexicon.
- What is the purpose of finite automata in lexical analysis?
a) To define the syntax of the language
b) To check the validity of the program’s semantic rules
c) To match strings of characters with regular expressions and identify tokens
d) To generate intermediate code from source codeAnswer: c) To match strings of characters with regular expressions and identify tokens