•
•
•
•
•
For the string given below,
the number of tokens (excluding ) that will be produced by the lexical analyzer is __________. (answer in integer)
13
Step-by-Step Solution
Key idea: Apply the maximal munch rule (longest match) to tokenize the input string based on the given regular expressions.
Step 1: The input string is separated by whitespace. We process each space-separated chunk.
Step 2: x1 starts with a letter and is followed by a digit. Matches id. (1 token)
Step 3: 23mm starts with digits. The longest match for number is 23. The remaining mm matches id. (2 tokens)
Step 4: 78 matches number. (1 token)
Step 5: y matches id. (1 token)
Step 6: 7z starts with a digit. 7 matches number. z matches id. (2 tokens)
Step 7: zz5 starts with a letter, followed by letters/digits. Matches id. (1 token)
Step 8: 14A starts with digits. 14 matches number. A matches id. (2 tokens)
Step 9: 8H starts with a digit. 8 matches number. H matches id. (2 tokens)
Step 10: AaYcD starts with a letter, followed by letters. Matches id. (1 token)
Step 11: Sum the tokens: 1 + 2 + 1 + 1 + 2 + 1 + 2 + 2 + 1 = 13.
Answer: 13