Which of the following is true about regular expressions?
a) Regular expressions define a sequence of tokens
b) Regular expressions can only match numeric values
c) Regular expressions are used to describe patterns in strings
d) Regular expressions are used for syntax analysisAnswer: c) Regular expressions are used to describe patterns in strings
What is the purpose of a finite automaton in the context of lexical analysis?
a) To execute the program
b) To determine the meaning of a program
c) To recognize patterns specified by regular expressions
d) To parse the syntactic structure of the codeAnswer: c) To recognize patterns specified by regular expressions
Which of the following symbols is used in regular expressions to represent “zero or more occurrences” of the preceding element?
a) +
b) *
c) ?
d) .Answer: b) *
What is the primary difference between a deterministic finite automaton (DFA) and a non-deterministic finite automaton (NFA)?
a) DFA can be used for syntax analysis, while NFA cannot
b) DFA has one possible transition for each symbol in the alphabet, while NFA can have multiple transitions for the same symbol
c) NFA is faster than DFA
d) DFA can accept more strings than NFAAnswer: b) DFA has one possible transition for each symbol in the alphabet, while NFA can have multiple transitions for the same symbol
Which of the following is a valid regular expression to match a string that starts with “a” and ends with “b”?
a) a*b
b) a.b
c) ^a.b$
d) a.bAnswer: c) ^a.*b$
In a regular expression, what does the symbol “+” represent?
a) One or more occurrences of the preceding element
b) Zero or more occurrences of the preceding element
c) A character set
d) Any single characterAnswer: a) One or more occurrences of the preceding element
Which of the following statements is true about the relation between regular expressions and finite automata?
a) Every regular expression can be converted into a finite automaton
b) Every finite automaton can be converted into a regular expression
c) Regular expressions and finite automata are mutually exclusive concepts
d) Both a and bAnswer: d) Both a and b
Which of the following is NOT a valid regular expression?
a) (ab|cd)
b) [a-zA-Z0-9]
c) (a|b|c)
d) [0-9]*[a-z]+Answer: d) [0-9]*[a-z]+
What is the main advantage of using a deterministic finite automaton (DFA) over a non-deterministic finite automaton (NFA)?
a) DFA has more states than an NFA
b) DFA is more difficult to implement
c) DFA always requires fewer computational resources
d) DFA is guaranteed to run in linear timeAnswer: d) DFA is guaranteed to run in linear time
Which of the following best describes a regular language in terms of finite automata?
a) A language that can be recognized by a finite automaton
b) A language that requires a pushdown automaton for recognition
c) A language that requires a Turing machine for recognition
d) A language that has no finite representationAnswer: a) A language that can be recognized by a finite automaton