Tokens, Patterns, and Lexemes MCQs December 19, 2025December 13, 2024 by u930973931_answers 10 min Score: 0 Attempted: 0/10 Subscribe 1. What is a token in the context of lexical analysis? (A) A sequence of instructions (B) A sequence of characters that represents a meaningful element of the source code (C) A basic unit of syntax (D) A pattern used to recognize keywords 2. Which of the following is an example of a token? (A) Both (A) and (B) (B) x = 10 (C) 10 + 20 (D) “int” 3. What is the relationship between tokens, patterns, and lexemes? (A) A lexeme is the category, a pattern is the instance, and a token is the definition (B) A lexeme is the definition, a pattern is the category, and a token is the instance (C) A pattern is the definition, a lexeme is the instance, and a token is the category (D) A token defines patterns and lexemes 4. Which of the following is a lexeme for the token “integer”? (A) number (B) float (C) integer (D) int 5. What is a pattern in lexical analysis? (A) A sequence of characters used to identify lexemes (B) A specific representation of a token in the source code (C) A rule for matching regular expressions (D) A sequence of instructions 6. What is a lexeme in the context of programming language syntax? (A) The syntax of a language (B) A valid regular expression (C) A sequence of characters that matches a pattern (D) The structure of a token 7. In lexical analysis, how are tokens typically represented? (A) As numbers (B) As a data structure containing information like type and value (C) As characters only (D) As keywords 8. Which of the following is NOT a valid example of a token? (A) identifier (B) keyword (C) expression (D) operator 9. What does the lexical analyzer do with patterns during the analysis process? (A) Matches the patterns to the lexemes in the source code (B) Converts the patterns into machine code (C) Passes patterns to the semantic analyzer (D) Removes patterns from the source code 10. What type of regular expression would be used to identify a lexeme for an integer? (A) [a-zA-Z]+ (B) \d+ (C) [\w]+ (D) [0-9]+